@@ -919,7 +919,7 @@ public int getPosX() {
919919 webWindow .getComputedStyle (element .getDomNodeOrDie (), null );
920920 cumulativeOffset += style .getBorderLeftValue ();
921921 }
922- element = element .getOffsetParent ();
922+ element = element .getOffsetParentInternal ( false ). getScriptableObject ();
923923 }
924924 return cumulativeOffset ;
925925 }
@@ -939,23 +939,11 @@ public int getPosY() {
939939 webWindow .getComputedStyle (element .getDomNodeOrDie (), null );
940940 cumulativeOffset += style .getBorderTopValue ();
941941 }
942- element = element .getOffsetParent ();
942+ element = element .getOffsetParentInternal ( false ). getScriptableObject ();
943943 }
944944 return cumulativeOffset ;
945945 }
946946
947- /**
948- * Gets the offset parent or {@code null} if this is not an {@link HTMLElement}.
949- * @return the offset parent or {@code null}
950- */
951- private HTMLElement getOffsetParent () {
952- final Object offsetParent = getOffsetParentInternal (false );
953- if (offsetParent instanceof HTMLElement ) {
954- return (HTMLElement ) offsetParent ;
955- }
956- return null ;
957- }
958-
959947 /**
960948 * Returns this element's {@code offsetTop}, which is the calculated top position of this
961949 * element relative to the {@code offsetParent}.
@@ -985,11 +973,11 @@ public int getOffsetTop() {
985973 return top ;
986974 }
987975
988- final HTMLElement offsetParent = getOffsetParent ( );
976+ final HtmlElement offsetParent = getOffsetParentInternal ( false );
989977
990978 // Add the offset for the ancestor nodes.
991979 DomNode parentNode = htmlElement .getParentNode ();
992- while (parentNode != null && parentNode . getScriptableObject () != offsetParent ) {
980+ while (parentNode != null && parentNode != offsetParent ) {
993981 if (parentNode instanceof HtmlElement ) {
994982 style = webWindow .getComputedStyle ((HtmlElement ) parentNode , null );
995983 top += style .getTop (false , true , true );
@@ -1001,7 +989,7 @@ public int getOffsetTop() {
1001989 style = webWindow .getComputedStyle (htmlElement , null );
1002990 final boolean thisElementHasTopMargin = style .getMarginTopValue () != 0 ;
1003991
1004- style = webWindow .getComputedStyle (offsetParent . getDomNodeOrDie () , null );
992+ style = webWindow .getComputedStyle (offsetParent , null );
1005993 if (!thisElementHasTopMargin ) {
1006994 top += style .getMarginTopValue ();
1007995 }
@@ -1040,10 +1028,10 @@ public int getOffsetLeft() {
10401028 return left ;
10411029 }
10421030
1043- final HTMLElement offsetParent = getOffsetParent ( );
1031+ final HtmlElement offsetParent = getOffsetParentInternal ( false );
10441032
10451033 DomNode parentNode = htmlElement .getParentNode ();
1046- while (parentNode != null && parentNode . getScriptableObject () != offsetParent ) {
1034+ while (parentNode != null && parentNode != offsetParent ) {
10471035 if (parentNode instanceof HtmlElement ) {
10481036 style = webWindow .getComputedStyle ((HtmlElement ) parentNode , null );
10491037 left += style .getLeft (true , true , true );
@@ -1052,7 +1040,7 @@ public int getOffsetLeft() {
10521040 }
10531041
10541042 if (offsetParent != null ) {
1055- style = webWindow .getComputedStyle (offsetParent . getDomNodeOrDie () , null );
1043+ style = webWindow .getComputedStyle (offsetParent , null );
10561044 left += style .getMarginLeftValue ();
10571045 left += style .getPaddingLeftValue ();
10581046 }
@@ -1074,25 +1062,25 @@ public int getOffsetLeft() {
10741062 */
10751063 @ JsxGetter (propertyName = "offsetParent" )
10761064 public HtmlUnitScriptable getOffsetParent_js () {
1077- return getOffsetParentInternal (getBrowserVersion ().hasFeature (JS_OFFSET_PARENT_NULL_IF_FIXED ));
1065+ final boolean feature = getBrowserVersion ().hasFeature (JS_OFFSET_PARENT_NULL_IF_FIXED );
1066+ return getOffsetParentInternal (feature ).getScriptableObject ();
10781067 }
10791068
1080- private HtmlUnitScriptable getOffsetParentInternal (final boolean returnNullIfFixed ) {
1069+ private HtmlElement getOffsetParentInternal (final boolean returnNullIfFixed ) {
10811070 DomNode currentElement = getDomNodeOrDie ();
10821071
10831072 if (currentElement .getParentNode () == null ) {
10841073 return null ;
10851074 }
10861075
1087- final HTMLElement htmlElement = currentElement .getScriptableObject ();
10881076 if (returnNullIfFixed
1089- && FIXED .equals (htmlElement . getStyle ().getStyleAttribute (
1077+ && FIXED .equals (getStyle ().getStyleAttribute (
10901078 StyleAttributes .Definition .POSITION , true ))) {
10911079 return null ;
10921080 }
10931081
1094- final WebWindow webWindow = htmlElement . getWindow ().getWebWindow ();
1095- final ComputedCssStyleDeclaration style = webWindow .getComputedStyle (htmlElement . getDomNodeOrDie () , null );
1082+ final WebWindow webWindow = getWindow ().getWebWindow ();
1083+ final ComputedCssStyleDeclaration style = webWindow .getComputedStyle (( DomElement ) currentElement , null );
10961084 final String position = style .getPositionWithInheritance ();
10971085 final boolean staticPos = "static" .equals (position );
10981086
@@ -1102,16 +1090,16 @@ private HtmlUnitScriptable getOffsetParentInternal(final boolean returnNullIfFix
11021090 if (parentNode instanceof HtmlBody
11031091 || (staticPos && parentNode instanceof HtmlTableDataCell )
11041092 || (staticPos && parentNode instanceof HtmlTable )) {
1105- return parentNode . getScriptableObject () ;
1093+ return ( HtmlElement ) parentNode ;
11061094 }
11071095
1108- if (parentNode != null && parentNode . getScriptableObject () instanceof HTMLElement ) {
1096+ if (parentNode != null && parentNode instanceof HtmlElement ) {
11091097 final HTMLElement parentElement = parentNode .getScriptableObject ();
11101098 final ComputedCssStyleDeclaration parentStyle =
11111099 webWindow .getComputedStyle (parentElement .getDomNodeOrDie (), null );
11121100 final String parentPosition = parentStyle .getPositionWithInheritance ();
11131101 if (!"static" .equals (parentPosition )) {
1114- return parentNode . getScriptableObject () ;
1102+ return ( HtmlElement ) parentNode ;
11151103 }
11161104 }
11171105
0 commit comments