From: <asa...@us...> - 2014-01-18 08:24:53
|
Revision: 8976 http://sourceforge.net/p/htmlunit/code/8976 Author: asashour Date: 2014-01-18 08:24:49 +0000 (Sat, 18 Jan 2014) Log Message: ----------- JavaScript: ClientRect: add 'width' and 'height' properties. Issue 1570 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRect.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-01-15 11:16:47 UTC (rev 8975) +++ trunk/htmlunit/src/changes/changes.xml 2014-01-18 08:24:49 UTC (rev 8976) @@ -8,6 +8,9 @@ <body> <release version="2.14" date="???" description="FF24, Bugfixes, initial work on IE11"> + <action type="add" dev="asashour" issue="1570"> + JavaScript: ClientRect: add 'width' and 'height' properties. + </action> <action type="fix" dev="asashour" issue="1569"> CSSStyleDeclaration: fix serialization of StyleElement. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRect.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRect.java 2014-01-15 11:16:47 UTC (rev 8975) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRect.java 2014-01-18 08:24:49 UTC (rev 8976) @@ -14,10 +14,14 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; + import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; /** * Specifies a rectangle that contains a line of text in either an element or a TextRange object. @@ -127,4 +131,22 @@ public int getTop() { return top_; } + + /** + * Returns the "width" property. + * @return the "width" property + */ + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF) }) + public int getWidth() { + return getRight() - getLeft(); + } + + /** + * Returns the "height" property. + * @return the "height" property + */ + @JsxGetter({ @WebBrowser(CHROME), @WebBrowser(FF) }) + public int getHeight() { + return getBottom() - getTop(); + } } 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 2014-01-15 11:16:47 UTC (rev 8975) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2014-01-18 08:24:49 UTC (rev 8976) @@ -2752,7 +2752,7 @@ top += 2; } - final ClientRect textRectangle = new ClientRect(0, left, 0, top); + final ClientRect textRectangle = new ClientRect(top + getOffsetHeight(), left, left + getOffsetWidth(), top); textRectangle.setParentScope(getWindow()); textRectangle.setPrototype(getPrototype(textRectangle.getClass())); return textRectangle; Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectTest.java 2014-01-18 08:24:49 UTC (rev 8976) @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2014 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; + +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; + +/** + * Tests for {@link ClientRect}. + * + * @version $Revision$ + * @author Ahmed Ashour + */ +@RunWith(BrowserRunner.class) +public class ClientRectTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "100", "400", "100", "450", "50", "0" }, + IE8 = { "102", "402", "102", "452", "undefined", "undefined" }) + public void width() throws Exception { + final String html = "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " try {\n" + + " var d1 = document.getElementById('div1');\n" + + " var pos = d1.getBoundingClientRect();\n" + + " alert(pos.top);\n" + + " alert(pos.left);\n" + + " alert(pos.bottom);\n" + + " alert(pos.right);\n" + + " alert(pos.width);\n" + + " alert(pos.height);\n" + + " } catch (e) { alert('exception');}\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "<div id='outer' style='position: absolute; left: 400px; top: 100px; width: 50px; height: 80px;'>" + + "<div id='div1'></div></div>" + + "</body></html>"; + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectTest.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |