Index: third_party/WebKit/Source/core/layout/LayoutObject.cpp |
diff --git a/third_party/WebKit/Source/core/layout/LayoutObject.cpp b/third_party/WebKit/Source/core/layout/LayoutObject.cpp |
index 24b588d3a47c96c288e5b9f7a8f81d02cc95732f..c4d016e971f6d03fcc8891218ff39fa1b12e6d2a 100644 |
--- a/third_party/WebKit/Source/core/layout/LayoutObject.cpp |
+++ b/third_party/WebKit/Source/core/layout/LayoutObject.cpp |
@@ -3179,12 +3179,12 @@ void LayoutObject::imageChanged(ImageResource* image, const IntRect* rect) |
imageChanged(static_cast<WrappedImagePtr>(image), rect); |
} |
-Element* LayoutObject::offsetParent() const |
+Element* LayoutObject::offsetParent(const Element* unclosedBase) const |
{ |
if (isDocumentElement() || isBody()) |
return nullptr; |
- if (isOutOfFlowPositioned() && style()->position() == FixedPosition) |
+ if (isFixedPositioned()) |
return nullptr; |
float effectiveZoom = style()->effectiveZoom(); |
@@ -3197,6 +3197,16 @@ Element* LayoutObject::offsetParent() const |
if (!node) |
continue; |
+ // TODO(kochi): If |unclosedBase| or |node| is nested deep in shadow roots, this loop may |
+ // get expensive, as isUnclosedNodeOf() can take up to O(N+M) time (N and M are depths). |
+ if (unclosedBase && (!node->isUnclosedNodeOf(*unclosedBase) || (node->isInShadowTree() && node->containingShadowRoot()->type() == ShadowRootType::UserAgent))) { |
+ // If 'position: fixed' node is found while traversing up, terminate the loop and |
+ // return null. |
+ if (ancestor->isFixedPositioned()) |
+ return nullptr; |
+ continue; |
+ } |
+ |
if (ancestor->isPositioned()) |
break; |