From: <rb...@us...> - 2018-01-19 07:48:02
|
Revision: 15083 http://sourceforge.net/p/htmlunit/code/15083 Author: rbri Date: 2018-01-19 07:47:59 +0000 (Fri, 19 Jan 2018) Log Message: ----------- Fix the broken initialization of the canvas context that empties the canvas every time canvas.getContext("2d") was called Issue 1674 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCanvasElement.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-01-18 19:56:26 UTC (rev 15082) +++ trunk/htmlunit/src/changes/changes.xml 2018-01-19 07:47:59 UTC (rev 15083) @@ -7,7 +7,10 @@ </properties> <body> - <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented"> + <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators"> + <action type="fix" dev="rbri" issue="1674"> + Fix the broken initialization of the canvas context that empties the canvas every time canvas.getContext("2d") was called. + </action> <action type="add" dev="rbri"> JavaScript: Set and Map constructor now supports user defined iterators also. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCanvasElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCanvasElement.java 2018-01-18 19:56:26 UTC (rev 15082) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCanvasElement.java 2018-01-19 07:47:59 UTC (rev 15083) @@ -40,7 +40,7 @@ @JsxClass(domClass = HtmlCanvas.class) public class HTMLCanvasElement extends HTMLElement { - private Object context_; + private CanvasRenderingContext2D context2d_; /** * Creates an instance. @@ -117,11 +117,13 @@ @JsxFunction public Object getContext(final String contextId) { if ("2d".equals(contextId)) { - final CanvasRenderingContext2D context = new CanvasRenderingContext2D(this); - context.setParentScope(getParentScope()); - context.setPrototype(getPrototype(context.getClass())); - context_ = context; - return context; + if (context2d_ == null) { + final CanvasRenderingContext2D context = new CanvasRenderingContext2D(this); + context.setParentScope(getParentScope()); + context.setPrototype(getPrototype(context.getClass())); + context2d_ = context; + } + return context2d_; } return null; } @@ -134,13 +136,14 @@ */ @JsxFunction public String toDataURL(final Object type) { - if (context_ instanceof CanvasRenderingContext2D) { + if (context2d_ != null) { String typeInUse = type.toString(); if (type == Undefined.instance) { typeInUse = null; } - return ((CanvasRenderingContext2D) context_).toDataURL(typeInUse); + return context2d_.toDataURL(typeInUse); } + if (getBrowserVersion().hasFeature(JS_CANVAS_DATA_URL_IE_PNG)) { return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAACWCAYAAABkW7XSAAAAAXNSR0IArs4c6QAAAARnQU1BAA" + "Cxjwv8YQUAAADGSURBVHhe7cExAQAAAMKg9U9tCF8gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" |