From: <mgu...@us...> - 2013-01-21 09:49:26
|
Revision: 8013 http://sourceforge.net/p/htmlunit/code/8013 Author: mguillem Date: 2013-01-21 09:49:21 +0000 (Mon, 21 Jan 2013) Log Message: ----------- JavaScript: - SVGAngle and SVGMatrix: basic support - SVGSVGElement: property style and basic support for methods createSVGMatrix and getScreenCTM. - HTMLDocument.createElementNS can create SVG elements. . Window.getComputedStyle works with SVG elements Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMImplementation.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMImplementationTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGAngle.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGMatrix.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgAngleTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgMatrixTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/changes/changes.xml 2013-01-21 09:49:21 UTC (rev 8013) @@ -8,7 +8,17 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="add" dev="mguillem"> + JavaScript: added basic support for SVGAngle and SVGMatrix. + </action> <action type="fix" dev="mguillem"> + JavaScript: HTMLDocument.createElementNS can create SVG elements. + </action> + <action type="add" dev="mguillem"> + JavaScript: add support for SVGSVGElement's style property and basic support + for methods createSVGMatrix and getScreenCTM. + </action> + <action type="fix" dev="mguillem"> JavaScript: add support for CanvasRenderingContext2D.quadraticCurveTo (FF). </action> <action type="fix" dev="mguillem" issue="1443"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -195,6 +195,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLWBRElement; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGAElement; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGAltGlyphElement; +import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGAngle; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGAnimateElement; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGAnimateMotionElement; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGAnimateTransformElement; @@ -236,6 +237,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGLinearGradientElement; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGMarkerElement; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGMaskElement; +import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGMatrix; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGMetadataElement; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGMpathElement; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGPathElement; @@ -313,7 +315,8 @@ MutationEvent.class, NamedNodeMap.class, Namespace.class, NamespaceCollection.class, Navigator.class, Node.class, NodeFilter.class, NodeList.class, OfflineResourceList.class, Plugin.class, PluginArray.class, Popup.class, Position.class, ProcessingInstruction.class, - Range.class, RowContainer.class, SVGAElement.class, SVGAltGlyphElement.class, SVGAnimateElement.class, + Range.class, RowContainer.class, + SVGAElement.class, SVGAltGlyphElement.class, SVGAngle.class, SVGAnimateElement.class, SVGAnimateMotionElement.class, SVGAnimateTransformElement.class, SVGCircleElement.class, SVGClipPathElement.class, SVGDefsElement.class, SVGDescElement.class, SVGElement.class, SVGEllipseElement.class, SVGFEBlendElement.class, SVGFEColorMatrixElement.class, @@ -325,7 +328,7 @@ SVGFEPointLightElement.class, SVGFESpecularLightingElement.class, SVGFESpotLightElement.class, SVGFETileElement.class, SVGFETurbulenceElement.class, SVGFilterElement.class, SVGForeignObjectElement.class, SVGGElement.class, SVGImageElement.class, SVGLineElement.class, SVGLinearGradientElement.class, - SVGMarkerElement.class, SVGMaskElement.class, SVGMetadataElement.class, SVGMpathElement.class, + SVGMarkerElement.class, SVGMaskElement.class, SVGMatrix.class, SVGMetadataElement.class, SVGMpathElement.class, SVGPathElement.class, SVGPatternElement.class, SVGPolygonElement.class, SVGPolylineElement.class, SVGRadialGradientElement.class, SVGRectElement.class, SVGSVGElement.class, SVGScriptElement.class, SVGSetElement.class, SVGStopElement.class, SVGStyleElement.class, SVGSwitchElement.class, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -468,7 +468,8 @@ // simple hack, no need to implement the XUL objects (at least in a first time) element = new HtmlDivision(namespaceURI, qualifiedName, getPage(), null); } - else if (HTMLParser.XHTML_NAMESPACE.equals(namespaceURI)) { + else if (HTMLParser.XHTML_NAMESPACE.equals(namespaceURI) + || HTMLParser.SVG_NAMESPACE.equals(namespaceURI)) { element = getPage().createElementNS(namespaceURI, qualifiedName); } else { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -37,6 +37,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; +import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration; import com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration; import com.gargoylesoftware.htmlunit.javascript.host.dom.DOMTokenList; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection; @@ -55,7 +56,15 @@ private NamedNodeMap attributes_; private Map<String, HTMLCollection> elementsByTagName_; // for performance and for equality (==) + private CSSStyleDeclaration style_; + @Override + public void setDomNode(final DomNode domNode) { + super.setDomNode(domNode); + + style_ = new CSSStyleDeclaration(this); + } + /** * Applies the specified XPath expression to this node's context and returns the generated list of matching nodes. * @param expression a string specifying an XPath expression @@ -508,4 +517,31 @@ public void removeAttributeNS(final String namespaceURI, final String localName) { getDomNodeOrDie().removeAttributeNS(namespaceURI, localName); } + + /** + * Returns the style object for this element. + * @return the style object for this element + */ + @JsxGetter + public CSSStyleDeclaration getStyle() { + return style_; + } + + /** + * Returns the runtime style object for this element. + * @return the runtime style object for this element + */ + @JsxGetter(@WebBrowser(IE)) + public CSSStyleDeclaration getRuntimeStyle() { + return style_; + } + + /** + * Returns the current (calculated) style object for this element. + * @return the current (calculated) style object for this element + */ + @JsxGetter(@WebBrowser(IE)) + public ComputedCSSStyleDeclaration getCurrentStyle() { + return getWindow().getComputedStyle(this, null); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -1576,7 +1576,7 @@ * @return the computed style */ @JsxFunction(@WebBrowser(FF)) - public ComputedCSSStyleDeclaration getComputedStyle(final HTMLElement element, final String pseudo) { + public ComputedCSSStyleDeclaration getComputedStyle(final Element element, final String pseudo) { ComputedCSSStyleDeclaration style; synchronized (computedStyles_) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -470,8 +470,8 @@ * Returns the element to which this style belongs. * @return the element to which this style belongs */ - protected HTMLElement getElement() { - return (HTMLElement) jsElement_; + protected Element getElement() { + return jsElement_; } /** @@ -5981,11 +5981,11 @@ * @return the integer number of pixels corresponding to the specified length CSS attribute value * @see #pixelValue(String) */ - protected static int pixelValue(final HTMLElement element, final CssValue value) { + protected static int pixelValue(final Element element, final CssValue value) { final String s = value.get(element); if (s.endsWith("%") || (s.isEmpty() && element instanceof HTMLHtmlElement)) { final int i = NumberUtils.toInt(TO_INT_PATTERN.matcher(s).replaceAll("$1"), 100); - final HTMLElement parent = (HTMLElement) element.getParentElement(); + final Element parent = (Element) element.getParentElement(); final int absoluteValue = (parent == null) ? value.getWindowDefaultValue() : pixelValue(parent, value); return (int) ((i / 100D) * absoluteValue); } @@ -6067,7 +6067,7 @@ * @param element the element for which the CSS attribute value is to be retrieved * @return the CSS attribute value for the specified element */ - public final String get(final HTMLElement element) { + public final String get(final Element element) { final ComputedCSSStyleDeclaration style = element.getCurrentStyle(); final String value = get(style); return value; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -175,7 +175,7 @@ protected String getStyleAttribute(final String name, final Map<String, StyleElement> styleMap) { String s = super.getStyleAttribute(name, null); if (s.isEmpty() && isInheritable(name)) { - final HTMLElement parent = (HTMLElement) getElement().getParentElement(); + final Element parent = getElement().getParentElement(); if (parent != null) { s = getWindow().getComputedStyle(parent, null).getStyleAttribute(name, null); } @@ -2193,7 +2193,7 @@ * @return the specified length CSS attribute value as a pixel length value * @see #pixelString(String) */ - protected String pixelString(final HTMLElement element, final CssValue value) { + protected String pixelString(final Element element, final CssValue value) { final String s = value.get(element); if (getBrowserVersion().hasFeature(JS_LENGTH_WITHOUT_PX)) { return s; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMImplementation.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMImplementation.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMImplementation.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -67,6 +67,10 @@ && ("1.0".equals(version) || "1.1".equals(version))) { return true; } + else if ("http://www.w3.org/TR/SVG11/feature#Shape".equals(feature) + && ("1.0".equals(version) || "1.1".equals(version))) { + return true; + } //TODO: other features. } return false; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -177,7 +177,6 @@ private int scrollLeft_; private int scrollTop_; private String uniqueID_; - private CSSStyleDeclaration style_; static { COLORS_MAP_IE.put("AliceBlue", "#F0F8FF"); @@ -388,8 +387,6 @@ public void setDomNode(final DomNode domNode) { super.setDomNode(domNode); - style_ = new CSSStyleDeclaration(this); - /** * Convert JavaScript snippets defined in the attribute map to executable event handlers. * Should be called only on construction. @@ -2497,15 +2494,6 @@ } /** - * Returns the current (calculated) style object for this element. - * @return the current (calculated) style object for this element - */ - @JsxGetter(@WebBrowser(IE)) - public ComputedCSSStyleDeclaration getCurrentStyle() { - return getWindow().getComputedStyle(this, null); - } - - /** * Returns this element's <tt>offsetLeft</tt>, which is the calculated left position of this * element relative to the <tt>offsetParent</tt>. * @@ -2767,24 +2755,6 @@ } /** - * Returns the style object for this element. - * @return the style object for this element - */ - @JsxGetter - public CSSStyleDeclaration getStyle() { - return style_; - } - - /** - * Returns the runtime style object for this element. - * @return the runtime style object for this element - */ - @JsxGetter(@WebBrowser(IE)) - public CSSStyleDeclaration getRuntimeStyle() { - return style_; - } - - /** * Gets the token list of class attribute. * @return the token list of class attribute */ Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGAngle.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGAngle.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGAngle.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host.svg; + +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; + +import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; + +/** + * A JavaScript object for SVGAngle. + * + * @version $Revision: 7931 $ + * @author Marc Guillemot + */ +@JsxClass(browsers = { @WebBrowser(value = IE, minVersion = 9), @WebBrowser(FF), @WebBrowser(CHROME) }) +public class SVGAngle extends SimpleScriptable { + + /** Invalid unit type. */ + @JsxConstant + public static final short SVG_ANGLETYPE_UNKNOWN = 0; + + /** Unspecified unit type. */ + @JsxConstant + public static final short SVG_ANGLETYPE_UNSPECIFIED = 1; + + /** Degree unit type. */ + @JsxConstant + public static final short SVG_ANGLETYPE_DEG = 2; + + /** Radian unit type. */ + @JsxConstant + public static final short SVG_ANGLETYPE_RAD = 3; + + /** Grad unit type. */ + @JsxConstant + public static final short SVG_ANGLETYPE_GRAD = 4; + + /** + * Creates an instance. JavaScript objects must have a default constructor. + */ + public SVGAngle() { + } +} Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGMatrix.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGMatrix.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGMatrix.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.javascript.host.svg; + +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; + +import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; +import com.gargoylesoftware.htmlunit.javascript.host.Window; + +/** + * A JavaScript object for SVGMatrix. + * @see <a href="https://developer.mozilla.org/en-US/docs/DOM/SVGMatrix">MDN doc</a> + * @version $Revision: 7931 $ + * @author Marc Guillemot + */ +@JsxClass(browsers = { @WebBrowser(value = IE, minVersion = 9), @WebBrowser(FF), @WebBrowser(CHROME) }) +public class SVGMatrix extends SimpleScriptable { + private double fieldA_ = 1; + private double fieldB_ = 0; + private double fieldC_ = 0; + private double fieldD_ = 1; + private double fieldE_ = 0; + private double fieldF_ = 0; + + /** + * Creates an instance. JavaScript objects must have a default constructor. + */ + public SVGMatrix() { + } + + /** + * Instantiates and configure scope and prototype. + * @param scope the parent scope + */ + public SVGMatrix(final Window scope) { + setParentScope(scope); + setPrototype(getPrototype(getClass())); + } + + /** + * Gets the <code>a</code> entry of the matrix. + * @return the field + **/ + @JsxGetter + public double getA() { + return fieldA_; + } + + /** + * Gets the <code>b</code> entry of the matrix. + * @return the field + **/ + @JsxGetter + public double getB() { + return fieldB_; + } + + /** + * Gets the <code>c</code> entry of the matrix. + * @return the field + **/ + @JsxGetter + public double getC() { + return fieldC_; + } + + /** + * Gets the <code>d</code> entry of the matrix. + * @return the field + **/ + @JsxGetter + public double getD() { + return fieldD_; + } + + /** + * Gets the <code>e</code> entry of the matrix. + * @return the field + **/ + @JsxGetter + public double getE() { + return fieldE_; + } + + /** + * Gets the <code>f</code> entry of the matrix. + * @return the field + **/ + @JsxGetter + public double getF() { + return fieldF_; + } + + /** + * Sets the <code>a</code> entry of the matrix. + * @param newValue the new value for the field + **/ + @JsxSetter + public void setA(final double newValue) { + fieldA_ = newValue; + } + + /** + * Sets the <code>b</code> entry of the matrix. + * @param newValue the new value for the field + **/ + @JsxSetter + public void setB(final double newValue) { + fieldB_ = newValue; + } + + /** + * Sets the <code>c</code> entry of the matrix. + * @param newValue the new value for the field + **/ + @JsxSetter + public void setC(final double newValue) { + fieldC_ = newValue; + } + + /** + * Sets the <code>d</code> entry of the matrix. + * @param newValue the new value for the field + **/ + @JsxSetter + public void setD(final double newValue) { + fieldD_ = newValue; + } + + /** + * Sets the <code>e</code> entry of the matrix. + * @param newValue the new value for the field + **/ + @JsxSetter + public void setE(final double newValue) { + fieldE_ = newValue; + } + + /** + * Sets the <code>f</code> entry of the matrix. + * @param newValue the new value for the field + **/ + @JsxSetter + public void setF(final double newValue) { + fieldF_ = newValue; + } + + /** + * Transforms the matrix. + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix flipX() { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Transforms the matrix. + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix flipY() { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Transforms the matrix. + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix inverse() { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Transforms the matrix. + * @param by the matrix to multiply by + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix multiply(final SVGMatrix by) { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Rotates the matrix. + * @param angle the rotation angle + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix rotate(final double angle) { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Transforms the matrix. + * @param x the x-coordinate of the vector + * @param y the y-coordinate of the vector + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix rotateFromVector(final double x, final double y) { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Transforms the matrix. + * @param factor the scale factor + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix scale(final double factor) { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Transforms the matrix. + * @param factorX the factor for the x-axis + * @param factorY the factor for the y-axis + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix scaleNonUniform(final double factorX, final double factorY) { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Transforms the matrix. + * @param angle the skew angle + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix skewX(final double angle) { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Transforms the matrix. + * @param angle the skew angle + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix skewY(final double angle) { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } + + /** + * Translates the matrix. + * @param x the distance along the x-axis + * @param y the distance along the y-axis + * @return the resulting matrix + */ + @JsxFunction + public SVGMatrix translate(final double x, final double y) { + return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + } +} Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -19,6 +19,7 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; import com.gargoylesoftware.htmlunit.svg.SvgSvg; @@ -36,5 +37,24 @@ * Creates an instance. JavaScript objects must have a default constructor. */ public SVGSVGElement() { + // nothing } + + /** + * Creates a new {@link SVGMatrix}. + * @return the new matrix + */ + @JsxFunction + public SVGMatrix createSVGMatrix() { + return new SVGMatrix(getWindow()); + } + + /** + * Creates a new {@link SVGMatrix}. + * @return the new matrix + */ + @JsxFunction + public SVGMatrix getScreenCTM() { + return new SVGMatrix(getWindow()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -1008,4 +1008,25 @@ loadPageWithAlerts2(html); } + + /** + * JS code was throwing an exception as of 2.12-SNAPSHOT from 21.01.2013 due to the incorrect signature + * of getComputedStyle. + * @throws Exception if the test fails + */ + @Test + @Alerts(FF = "rgb(0, 0, 0)", IE = "exception") + public void getComputedStyle_svg() throws Exception { + final String html = "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'></svg>\n" + + "<script>\n" + + " var e = document.getElementById('myId');\n" + + " try {\n" + + " alert(window.getComputedStyle(e, null).color);\n" + + " } catch(e) { alert('exception') }\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMImplementationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMImplementationTest.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMImplementationTest.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -100,6 +100,20 @@ hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "['1.0', '1.1', '1.2']"); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "http://www.w3.org/TR/SVG11/feature#Shape 1.0: true", + "http://www.w3.org/TR/SVG11/feature#Shape 1.1: true", + "http://www.w3.org/TR/SVG11/feature#Shape 1.2: false" }, + IE = { "http://www.w3.org/TR/SVG11/feature#Shape 1.0: false", + "http://www.w3.org/TR/SVG11/feature#Shape 1.1: false", + "http://www.w3.org/TR/SVG11/feature#Shape 1.2: false" }) + public void hasFeature_SVG_Shape() throws Exception { + hasFeature("http://www.w3.org/TR/SVG11/feature#Shape", "['1.0', '1.1', '1.2']"); + } + private void hasFeature(final String feature, final String versions) throws Exception { final String html = "<html><head>\n" + "<script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -282,6 +282,23 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = "[object SVGSVGElement]", IE = "exception") + public void createDocumentNS_svg() throws Exception { + final String html = "<html><body>\n" + + "<script>\n" + + "try {\n" + + " var elt = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n" + + " alert(elt);\n" + + "} catch (e) { alert('exception'); }\n" + + "</script></body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = "exception", FF = "Hello", FF10 = "exception") public void createDocumentNS_xul() throws Exception { final String html = "<html><body>\n" Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgAngleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgAngleTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgAngleTest.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.svg; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link SvgAngle}. + * + * @version $Revision: 7931 $ + * @author Marc Guillemot + */ +@RunWith(BrowserRunner.class) +public class SvgAngleTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "[object SVGAngle]", "0", "1", "2", "3", "4" }, IE = "undefined") + public void simpleScriptable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(window.SVGAngle);\n" + + " if (window.SVGAngle) {\n" + + " alert(SVGAngle.SVG_ANGLETYPE_UNKNOWN);\n" + + " alert(SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);\n" + + " alert(SVGAngle.SVG_ANGLETYPE_DEG);\n" + + " alert(SVGAngle.SVG_ANGLETYPE_RAD);\n" + + " alert(SVGAngle.SVG_ANGLETYPE_GRAD);\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgMatrixTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgMatrixTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgMatrixTest.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.svg; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link com.gargoylesoftware.htmlunit.javascript.host.svg.SVGMatrix}. + * + * @version $Revision: 7931 $ + * @author Marc Guillemot + */ +@RunWith(BrowserRunner.class) +public class SvgMatrixTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object SVGMatrix]", IE = "undefined") + public void simpleScriptable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + "<script>\n" + + " alert(window.SVGMatrix);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "1, 0, 0, 1, 0, 0", "2, 3, 4, 5, 6, 7" }, IE = "exception") + public void fields() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + "function alertFields(m) {\n" + + " var fields = ['a', 'b', 'c', 'd', 'e', 'f'];\n" + + " for (var i=0; i<fields.length; ++i) {\n" + + " fields[i] = m[fields[i]];\n" + + " }\n" + + " alert(fields.join(', '));\n" + + "}\n" + + "var svg = document.getElementById('myId');\n" + + "try {\n" + + " var m = svg.createSVGMatrix();\n" + + " alertFields(m);\n" + + " m.a = 2;\n" + + " m.b = 3;\n" + + " m.c = 4;\n" + + " m.d = 5;\n" + + " m.e = 6;\n" + + " m.f = 7;\n" + + " alertFields(m);\n" + + "} catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "function", "function", "function", "function", "function", "function", "function", "function", + "function", "function", "function" }, IE = "exception") + public void methods() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " var svg = document.getElementById('myId');\n" + + "try {\n" + + " var m = svg.createSVGMatrix();\n" + + " alert(typeof m.flipX);\n" + + " alert(typeof m.flipY);\n" + + " alert(typeof m.inverse);\n" + + " alert(typeof m.multiply);\n" + + " alert(typeof m.rotate);\n" + + " alert(typeof m.rotateFromVector);\n" + + " alert(typeof m.scale);\n" + + " alert(typeof m.scaleNonUniform);\n" + + " alert(typeof m.skewX);\n" + + " alert(typeof m.skewY);\n" + + " alert(typeof m.translate);\n" + + "} catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java 2013-01-21 09:07:00 UTC (rev 8012) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java 2013-01-21 09:49:21 UTC (rev 8013) @@ -64,4 +64,63 @@ } } } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("false") + public void style() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " alert(document.getElementById('myId').style == undefined);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "function", "function" }, IE = { "undefined", "undefined" }) + public void functions() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " var svg = document.getElementById('myId');\n" + + " alert(typeof svg.getScreenCTM);\n" + + " alert(typeof svg.createSVGMatrix);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object SVGMatrix]", IE = "exception") + public void getScreenCTM() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " var svg = document.getElementById('myId');\n" + + " try {\n" + + " alert(svg.getScreenCTM());\n" + + " } catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |