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

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

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: First attempt at compositing side, does NOT work properly yet 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 3c99a4f3c5eb3da5913a534299fbc9bd5576aa89..df453d9f9c8a8a97fea696210c1bd755fb18783e 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
@@ -46,6 +46,32 @@
namespace blink {
+namespace {
+inline bool isOutOfFlowPositionedWithImplicitHeight(
+ const LayoutBoxModelObject* child) {
+ return child->isOutOfFlowPositioned() &&
+ !child->style()->logicalTop().isAuto() &&
+ !child->style()->logicalBottom().isAuto();
+}
+
+StickyPositionScrollingConstraints* stickyConstraintsForLayoutObject(
+ const LayoutBoxModelObject* o) {
+ if (!o || !o->layer() || !o->layer()->ancestorOverflowLayer())
flackr 2017/02/02 18:18:11 Are all of these checks necessary? If we have a st
smcgruer 2017/02/02 20:21:27 I can switch them to DCHECKS, if that makes more s
flackr 2017/02/02 23:31:15 No need to DCHECK if it will crash on failure tryi
smcgruer 2017/02/07 19:05:26 Did some digging. ancestorOverflowLayer() can be n
+ return nullptr;
+
+ PaintLayerScrollableArea* scrollableArea =
+ o->layer()->ancestorOverflowLayer()->getScrollableArea();
+ if (!scrollableArea)
flackr 2017/02/02 18:18:11 scrollableArea should never be null afaik.
smcgruer 2017/02/02 20:21:27 Replaced with DCHECK then.
smcgruer 2017/02/07 19:05:26 Per advice above, removed since it'll just crash a
+ return nullptr;
+
+ auto it = scrollableArea->stickyConstraintsMap().find(o->layer());
+ if (it == scrollableArea->stickyConstraintsMap().end())
+ return nullptr;
+
+ return &it->value;
+}
+} // namespace
+
class FloatStateForStyleChange {
public:
static void setWasFloating(LayoutBoxModelObject* boxModelObject,
@@ -648,13 +674,6 @@ void LayoutBoxModelObject::updateFromStyle() {
setHorizontalWritingMode(styleToUse.isHorizontalWritingMode());
}
-static inline bool isOutOfFlowPositionedWithImplicitHeight(
- const LayoutBoxModelObject* child) {
- return child->isOutOfFlowPositioned() &&
- !child->style()->logicalTop().isAuto() &&
- !child->style()->logicalBottom().isAuto();
-}
-
LayoutBlock* LayoutBoxModelObject::containingBlockForAutoHeightDetection(
Length logicalHeight) const {
// For percentage heights: The percentage is calculated with respect to the
@@ -787,7 +806,7 @@ void LayoutBoxModelObject::updateStickyPositionConstraints() const {
while (containingBlock->isAnonymous()) {
containingBlock = containingBlock->containingBlock();
}
- MapCoordinatesFlags flags = 0;
+ MapCoordinatesFlags flags = IgnoreStickyOffset;
skippedContainersOffset =
toFloatSize(locationContainer
->localToAncestorQuadWithoutTransforms(
@@ -885,6 +904,46 @@ 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 [container, containingBlock) and
+ // [containingBlock, scrollAncestor).
+
+ // TODO(smcgruer): Fold these into the walks to find the containingBlock and
+ // scrollAncestor.
+ LayoutObject* maybeStickyAncestor = locationContainer;
+ while (maybeStickyAncestor && maybeStickyAncestor != containingBlock) {
+ if (maybeStickyAncestor->isStickyPositioned()) {
+ constraints.setNearestStickyElementShiftingStickyBox(
+ toLayoutBoxModelObject(maybeStickyAncestor));
+ break;
+ }
+ maybeStickyAncestor =
+ maybeStickyAncestor->isLayoutInline()
+ ? maybeStickyAncestor->containingBlock()
+ : toLayoutBox(maybeStickyAncestor)->locationContainer();
+ }
+
+ // 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->isLayoutInline()
+ ? maybeStickyAncestor->containingBlock()
+ : toLayoutBox(maybeStickyAncestor)->locationContainer();
+ }
+
// 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 =
@@ -973,24 +1032,24 @@ FloatRect LayoutBoxModelObject::computeStickyConstrainingRect() const {
}
LayoutSize LayoutBoxModelObject::stickyPositionOffset() const {
- const PaintLayer* ancestorOverflowLayer = layer()->ancestorOverflowLayer();
- // TODO: Force compositing input update if we ask for offset before
- // compositing inputs have been computed?
- if (!ancestorOverflowLayer)
+ StickyPositionScrollingConstraints* constraints =
+ stickyConstraintsForLayoutObject(this);
+ if (!constraints)
return LayoutSize();
- FloatRect constrainingRect = computeStickyConstrainingRect();
- PaintLayerScrollableArea* scrollableArea =
- ancestorOverflowLayer->getScrollableArea();
+
+ StickyPositionScrollingConstraints* toContainingBlockConstraints =
+ stickyConstraintsForLayoutObject(
+ constraints->nearestStickyElementShiftingStickyBox());
+
+ StickyPositionScrollingConstraints* toViewportConstraints =
+ stickyConstraintsForLayoutObject(
+ constraints->nearestStickyElementShiftingContainingBlock());
// 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()))
- return LayoutSize();
- return LayoutSize(
- scrollableArea->stickyConstraintsMap().get(layer()).computeStickyOffset(
- constrainingRect));
+ FloatRect constrainingRect = computeStickyConstrainingRect();
+ return LayoutSize(constraints->computeStickyOffset(
+ constrainingRect, toContainingBlockConstraints, toViewportConstraints));
}
LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeTo(

Powered by Google App Engine
This is Rietveld 408576698