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

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

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: 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..f57e76c1574e0dfd078f4889ed45c0a22abe757c 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
@@ -873,6 +873,32 @@ 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 the viewport.
+
+ LayoutObject* maybeStickyAncestor = parent();
+ while (maybeStickyAncestor &&
+ maybeStickyAncestor != containingBlock->parent()) {
flackr 2017/01/18 16:09:47 We should stop before the containing block, the co
smcgruer 2017/01/18 19:10:50 Not sure I follow: no element should have itself a
flackr 2017/01/19 01:44:41 Not true. For the purposes of sticky position, the
smcgruer 2017/01/19 19:28:01 Done.
+ if (maybeStickyAncestor->isStickyPositioned()) {
+ constraints.setNearestStickyElementToContainingBlock(
+ toLayoutBoxModelObject(maybeStickyAncestor));
+ break;
+ }
+ maybeStickyAncestor = maybeStickyAncestor->parent();
+ }
flackr 2017/01/18 14:42:56 We should try combining this with the walk to find
+
+ maybeStickyAncestor = containingBlock->parent();
+ while (maybeStickyAncestor &&
+ maybeStickyAncestor != scrollAncestor->parent()) {
flackr 2017/01/18 14:42:56 I don't think we need to track if the ancestor scr
smcgruer 2017/01/18 19:10:51 Good spot! Fixed and added a test. Also had to wra
+ if (maybeStickyAncestor->isStickyPositioned()) {
+ constraints.setNearestStickyElementFromContainingBlockToViewport(
flackr 2017/01/18 14:42:56 for consistency s/ToViewport/ToScrollContainer (I
smcgruer 2017/01/18 19:10:50 Done.
+ toLayoutBoxModelObject(maybeStickyAncestor));
+ break;
+ }
+ maybeStickyAncestor = maybeStickyAncestor->parent();
+ }
+
// 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 =
@@ -976,9 +1002,35 @@ LayoutSize LayoutBoxModelObject::stickyPositionOffset() const {
// compositing inputs.
if (!scrollableArea->stickyConstraintsMap().contains(layer()))
return LayoutSize();
- return LayoutSize(
- scrollableArea->stickyConstraintsMap().get(layer()).computeStickyOffset(
- constrainingRect));
+
+ auto it = scrollableArea->stickyConstraintsMap().find(layer());
flackr 2017/01/18 14:42:56 Out of curiosity, why not stickyConstraintsMap().g
smcgruer 2017/01/18 19:10:51 As far as I can tell, WTF::HashMap::get() returns
flackr 2017/01/19 01:44:41 Okay no problem.
+ DCHECK(it != scrollableArea->stickyConstraintsMap().end());
+
+ StickyPositionScrollingConstraints& constraints = it->value;
+
+ FloatSize accumulatedOffsetToContainingBlock;
+ FloatSize accumulatedOffsetToViewport;
+
+ const LayoutBoxModelObject* toContainingBlock =
+ constraints.nearestStickyElementToContainingBlock();
+ if (toContainingBlock) {
+ accumulatedOffsetToContainingBlock =
+ scrollableArea->stickyConstraintsMap()
+ .get(toContainingBlock->layer())
+ .getCachedAccumulatedStickyOffset();
+ }
+
+ const LayoutBoxModelObject* toViewport =
+ constraints.nearestStickyElementFromContainingBlockToViewport();
+ if (toViewport) {
+ accumulatedOffsetToViewport = scrollableArea->stickyConstraintsMap()
+ .get(toViewport->layer())
+ .getCachedAccumulatedStickyOffset();
+ }
+
+ return LayoutSize(constraints.computeStickyOffset(
+ constrainingRect, accumulatedOffsetToContainingBlock,
+ accumulatedOffsetToViewport));
}
LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeTo(

Powered by Google App Engine
This is Rietveld 408576698