From: <rb...@us...> - 2013-07-05 19:55:51
|
Revision: 8368 http://sourceforge.net/p/htmlunit/code/8368 Author: rbri Date: 2013-07-05 19:55:49 +0000 (Fri, 05 Jul 2013) Log Message: ----------- some more hacking on element visibility Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 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-07-05 18:54:28 UTC (rev 8367) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-07-05 19:55:49 UTC (rev 8368) @@ -45,9 +45,22 @@ import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.html.BaseFrameElement; import com.gargoylesoftware.htmlunit.html.DomNode; +import com.gargoylesoftware.htmlunit.html.HtmlButton; +import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; +import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput; +import com.gargoylesoftware.htmlunit.html.HtmlInlineFrame; +import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; +import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; +import com.gargoylesoftware.htmlunit.html.HtmlResetInput; +import com.gargoylesoftware.htmlunit.html.HtmlSelect; +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlTableRow; +import com.gargoylesoftware.htmlunit.html.HtmlTextArea; +import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.host.Element; import com.gargoylesoftware.htmlunit.javascript.host.Text; @@ -55,8 +68,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLIFrameElement; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTextAreaElement; /** * A JavaScript object for a ComputedCSSStyleDeclaration. @@ -152,7 +163,7 @@ map.put("I", "inline"); map.put("IFRAME", "inline"); map.put("IMG", "inline"); - // map.put("INPUT", "inline-block"); + map.put("INPUT", "inline-block"); map.put("INS", "inline"); map.put("KBD", "inline"); map.put("KEYGEN", "inline"); @@ -183,7 +194,7 @@ map.put("FIGURE", "block"); map.put("FOOTER", "block"); map.put("HEADER", "block"); - // map.put("INPUT", "inline"); + map.put("INPUT", "inline"); map.put("LEGEND", "block"); map.put("METER", "inline-block"); @@ -1161,7 +1172,7 @@ final String cssFloat = getCssFloat(); if ("right".equals(cssFloat) || "left".equals(cssFloat)) { // We're floating; simplistic approximation: text content * pixels per character. - width = getDomNodeOrDie().getTextContent().length() * PIXELS_PER_CHAR; + width = node.getTextContent().length() * PIXELS_PER_CHAR; } else if ("block".equals(display)) { // Block elements take up 100% of the parent's width. @@ -1180,6 +1191,23 @@ } width -= (getBorderHorizontal() + getPaddingHorizontal()); } + else if (node instanceof HtmlSubmitInput || node instanceof HtmlResetInput + || node instanceof HtmlButtonInput || node instanceof HtmlButton) { + final String text = node.asText(); + width = 10 + (text.length() * PIXELS_PER_CHAR); + } + else if (node instanceof HtmlTextInput || node instanceof HtmlPasswordInput) { + width = 50; // wild guess + } + else if (node instanceof HtmlRadioButtonInput || node instanceof HtmlCheckBoxInput) { + width = 20; // wild guess + } + else if (node instanceof HtmlTextInput || node instanceof HtmlPasswordInput) { + width = 50; // wild guess + } + else if (node instanceof HtmlTextArea) { + width = 100; // wild guess + } else { // Inline elements take up however much space is required by their children. width = getContentWidth(); @@ -1310,12 +1338,19 @@ final int defaultHeight; if (getElement().getFirstChild() == null) { - if (getElement() instanceof HTMLIFrameElement) { - defaultHeight = 154; + if (node instanceof HtmlButton + || (node instanceof HtmlInput && !(node instanceof HtmlHiddenInput))) { + defaultHeight = 20; } - else if (getElement() instanceof HTMLTextAreaElement) { + else if (node instanceof HtmlSelect) { + defaultHeight = 20; + } + else if (node instanceof HtmlTextArea) { defaultHeight = 49; } + else if (node instanceof HtmlInlineFrame) { + defaultHeight = 154; + } else { defaultHeight = 0; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-05 18:54:28 UTC (rev 8367) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-07-05 19:55:49 UTC (rev 8368) @@ -535,7 +535,6 @@ "inline", "inline", "inline", "inline" }, IE = { "inline", "inline", "inline", "inline-block", "inline-block", "inline-block", "inline-block", "inline-block", "inline-block", "inline" }) - @NotYetImplemented public void defaultDisplayValues_I() throws Exception { final String html = "<!DOCTYPE HTML>\n<html><body>\n" + " <p id='p'>\n" @@ -902,6 +901,51 @@ } /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "true", "true", "true", "true", "true", "true", "true", "true", + "true", "true", "true", "true", "false", "false", + "true", "true", "true", "true" }) + public void widthAndHeightInputElements() throws Exception { + final String html = "<html>\n" + + "<body>\n" + + " <form id='form'>\n" + + " <input id='submit' type='submit'>\n" + + " <input id='reset' type='reset'>\n" + + " <input id='text' type='text'>\n" + + " <input id='password' type='password'>\n" + + " <input id='checkbox' type='checkbox'>\n" + + " <input id='radio' type='radio'>\n" + + " <input id='hidden' type='hidden'>\n" + + " <button id='button' type='button'></button>\n" + + " <textarea id='myTextarea'></textarea>\n" + + " </form>\n" + + + " <script>\n" + + " function x(id) {\n" + + " var e = document.getElementById(id);\n" + + " alert(e.offsetWidth > 0);\n" + + " alert(e.offsetHeight > 0);\n" + + " }\n" + + " </script>\n" + + + " <script>\n" + + " x('submit');\n" + + " x('reset');\n" + + " x('text');\n" + + " x('password');\n" + + " x('checkbox');\n" + + " x('radio');\n" + + " x('hidden');\n" + + " x('button');\n" + + " x('myTextarea');\n" + + " </script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** * @throws Exception if the test fails */ @Test |