Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Unified Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: Use ancestorOverflowLayer instead of stickyAncestor + test fixing Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
index 486a11a43eb50a95648e8c40706d57d7d6d7f796..07f642ccfc50dddbcbd5b733ddc097a85bdf6db2 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
@@ -873,6 +873,41 @@ void LayoutBoxModelObject::updateStickyPositionConstraints() const {
toFloatSize(stickyLocation),
flippedStickyBoxRect.size()));
+ // To correctly compute the offsets, the constraints need to know about any
+ // nested position:sticky between themselves and their containingBlock, and
+ // between the containingBlock and their scrollAncestor.
+ //
+ // The respective search ranges are [parent(), containingBlock) and
+ // [containingBlock, scrollAncestor).
+
+ // TODO(smcgruer): Fold these into the walks to find the containingBlock and
+ // scrollAncestor.
+
+ LayoutObject* maybeStickyAncestor = parent();
+ while (maybeStickyAncestor && maybeStickyAncestor != containingBlock) {
+ if (maybeStickyAncestor->isStickyPositioned()) {
+ constraints.setNearestStickyElementShiftingStickyBox(
+ toLayoutBoxModelObject(maybeStickyAncestor));
+ break;
+ }
+ maybeStickyAncestor = maybeStickyAncestor->parent();
+ }
+
+ // NOTE(smcgruer): We cannot use |scrollAncestor| here as it disregards the
+ // root ancestorOverflowLayer(), which we should include for the purposes of
+ // finding the nearest sticky element that shifts the containing block rect.
+ LayoutObject* ancestorOverflowLayer =
+ layer()->ancestorOverflowLayer()->layoutObject();
+ maybeStickyAncestor = containingBlock;
+ while (maybeStickyAncestor && maybeStickyAncestor != ancestorOverflowLayer) {
+ if (maybeStickyAncestor->isStickyPositioned()) {
+ constraints.setNearestStickyElementShiftingContainingBlock(
+ toLayoutBoxModelObject(maybeStickyAncestor));
+ break;
+ }
+ maybeStickyAncestor = maybeStickyAncestor->parent();
flackr 2017/01/24 20:28:48 Technically we should be following the locationCon
smcgruer 2017/01/28 00:55:31 Done.
+ }
+
// We skip the right or top sticky offset if there is not enough space to
// honor both the left/right or top/bottom offsets.
LayoutUnit horizontalOffsets =
@@ -970,15 +1005,39 @@ LayoutSize LayoutBoxModelObject::stickyPositionOffset() const {
PaintLayerScrollableArea* scrollableArea =
ancestorOverflowLayer->getScrollableArea();
+ auto it = scrollableArea->stickyConstraintsMap().find(layer());
+
// The sticky offset is physical, so we can just return the delta computed in
// absolute coords (though it may be wrong with transforms).
// TODO: Force compositing input update if we ask for offset with stale
// compositing inputs.
- if (!scrollableArea->stickyConstraintsMap().contains(layer()))
+ if (it == scrollableArea->stickyConstraintsMap().end())
return LayoutSize();
+
+ StickyPositionScrollingConstraints& constraints = it->value;
+
+ FloatSize ancestorStickyBoxOffset;
+ FloatSize ancestorContainingBlockOffset;
+
+ const LayoutBoxModelObject* toContainingBlock =
+ constraints.nearestStickyElementShiftingStickyBox();
+ if (toContainingBlock) {
+ ancestorStickyBoxOffset = scrollableArea->stickyConstraintsMap()
+ .get(toContainingBlock->layer())
+ .getTotalStickyBoxStickyOffset();
+ }
+
+ const LayoutBoxModelObject* toViewport =
+ constraints.nearestStickyElementShiftingContainingBlock();
+ if (toViewport) {
+ ancestorContainingBlockOffset = scrollableArea->stickyConstraintsMap()
+ .get(toViewport->layer())
+ .getTotalContainingBlockStickyOffset();
+ }
+
return LayoutSize(
- scrollableArea->stickyConstraintsMap().get(layer()).computeStickyOffset(
- constrainingRect));
+ constraints.computeStickyOffset(constrainingRect, ancestorStickyBoxOffset,
+ ancestorContainingBlockOffset));
}
LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeTo(
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.cpp ('k') | third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698