From: <rb...@us...> - 2013-04-17 17:38:38
|
Revision: 8227 http://sourceforge.net/p/htmlunit/code/8227 Author: rbri Date: 2013-04-17 17:38:32 +0000 (Wed, 17 Apr 2013) Log Message: ----------- minor code optimization Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.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-04-15 17:49:15 UTC (rev 8226) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-04-17 17:38:32 UTC (rev 8227) @@ -1357,33 +1357,37 @@ * @return the computed top (Y coordinate), relative to the node's parent's top edge */ public int getTop(final boolean includeMargin, final boolean includeBorder, final boolean includePadding) { - int top; + int top = 0; if (null == top_) { final String p = getPositionWithInheritance(); - final String t = getTopWithInheritance(); - final String b = getBottomWithInheritance(); + if ("absolute".equals(p)) { + final String t = getTopWithInheritance(); - if ("absolute".equals(p) && !"auto".equals(t)) { - // No need to calculate displacement caused by sibling nodes. - top = pixelValue(t); - } - else if ("absolute".equals(p) && !"auto".equals(b)) { - // Estimate the vertical displacement caused by *all* siblings. - // This is very rough, and doesn't even take position or display types into account. - // It also doesn't take into account the fact that the parent's height may be hardcoded in CSS. - top = 0; - DomNode child = getElement().getDomNodeOrDie().getParentNode().getFirstChild(); - while (child != null) { - if (child instanceof HtmlElement && child.mayBeDisplayed()) { - top += 20; + if (!"auto".equals(t)) { + // No need to calculate displacement caused by sibling nodes. + top = pixelValue(t); + } + else { + final String b = getBottomWithInheritance(); + + if (!"auto".equals(b)) { + // Estimate the vertical displacement caused by *all* siblings. + // This is very rough, and doesn't even take position or display types into account. + // It also doesn't take into account the fact that the parent's height may be hardcoded in CSS. + top = 0; + DomNode child = getElement().getDomNodeOrDie().getParentNode().getFirstChild(); + while (child != null) { + if (child instanceof HtmlElement && child.mayBeDisplayed()) { + top += 20; + } + child = child.getNextSibling(); + } + top -= pixelValue(b); } - child = child.getNextSibling(); } - top -= pixelValue(b); } else { // Calculate the vertical displacement caused by *previous* siblings. - top = 0; DomNode prev = getElement().getDomNodeOrDie().getPreviousSibling(); while (prev != null && !(prev instanceof HtmlElement)) { prev = prev.getPreviousSibling(); @@ -1395,6 +1399,7 @@ } // If the position is relative, we also need to add the specified "top" displacement. if ("relative".equals(p)) { + final String t = getTopWithInheritance(); top += pixelValue(t); } } |