Chromium Code Reviews| 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 06b747857bf5c636f032f9636b2e59c468b49fec..c19c9e44fb1ad291cdbe3d463f93625435effb5a 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp |
| @@ -178,6 +178,21 @@ void LayoutBoxModelObject::styleWillChange(StyleDifference diff, const ComputedS |
| LayoutObject::styleWillChange(diff, newStyle); |
| } |
| +static inline LayoutBox* findScrollAncestor(const Node* startNode) |
| +{ |
| + ASSERT(startNode->layoutObject()); |
| + LayoutBox* curBox = startNode->layoutObject()->containingBlock(); |
| + |
| + // Scrolling propagates along the containing block chain. |
| + while (curBox && !curBox->isLayoutView()) { |
| + if (curBox->hasOverflowClip()) |
| + return curBox; |
| + curBox = curBox->containingBlock(); |
| + } |
| + |
| + return nullptr; |
| +} |
| + |
| void LayoutBoxModelObject::styleDidChange(StyleDifference diff, const ComputedStyle* oldStyle) |
| { |
| bool hadTransform = hasTransformRelatedProperty(); |
| @@ -268,8 +283,17 @@ void LayoutBoxModelObject::styleDidChange(StyleDifference diff, const ComputedSt |
| } |
| if (FrameView *frameView = view()->frameView()) { |
| - bool newStyleIsViewportConstained = style()->hasViewportConstrainedPosition(); |
| - bool oldStyleIsViewportConstrained = oldStyle && oldStyle->hasViewportConstrainedPosition(); |
| + bool newStyleIsViewportConstained = style()->position() == FixedPosition; |
| + bool oldStyleIsViewportConstrained = oldStyle && oldStyle->position() == FixedPosition; |
| + |
| + // Sticky positioned elements are only viewport constrained if they have no ancestor scroller. |
| + if (style()->position() == StickyPosition || (oldStyle && oldStyle->position() == StickyPosition)) { |
| + if (!findScrollAncestor(node())) { |
| + newStyleIsViewportConstained |= style()->position() == StickyPosition; |
| + oldStyleIsViewportConstrained |= oldStyle && oldStyle->position() == StickyPosition; |
| + } |
| + } |
| + |
| if (newStyleIsViewportConstained != oldStyleIsViewportConstrained) { |
| if (newStyleIsViewportConstained && layer()) |
| frameView->addViewportConstrainedObject(this); |
| @@ -608,6 +632,118 @@ LayoutSize LayoutBoxModelObject::relativePositionOffset() const |
| return offset; |
| } |
| +void LayoutBoxModelObject::computeStickyPositionConstraints(StickyPositionViewportConstraints& constraints, const LayoutRect& constrainingRect) const |
|
chrishtr
2015/12/09 00:37:38
I have a bunch of questions about this method. The
flackr
2015/12/10 23:43:15
Acknowledged.
|
| +{ |
| + LayoutBlock* containingBlock = this->containingBlock(); |
| + |
| + LayoutRect containerContentRect = containingBlock->contentBoxRect(); |
| + LayoutUnit maxWidth = containingBlock->availableLogicalWidth(); |
| + |
| + // Sticky positioned element ignore any override logical width on the containing block (as they don't call |
| + // containingBlockLogicalWidthForContent). It's unclear whether this is totally fine. |
| + // Compute the container-relative area within which the sticky element is allowed to move. |
| + containerContentRect.contractEdges( |
| + minimumValueForLength(style()->marginTop(), maxWidth), |
| + minimumValueForLength(style()->marginRight(), maxWidth), |
| + minimumValueForLength(style()->marginBottom(), maxWidth), |
| + minimumValueForLength(style()->marginLeft(), maxWidth)); |
| + |
| + // Map to the view to avoid including page scale factor. |
| + constraints.setAbsoluteContainingBlockRect(LayoutRect(containingBlock->localToContainerQuad(FloatRect(containerContentRect), view()).boundingBox())); |
| + |
| + LayoutRect stickyBoxRect = isLayoutInline() |
| + ? LayoutRect(toLayoutInline(this)->linesBoundingBox()) |
| + : toLayoutBox(this)->frameRect(); |
| + LayoutRect flippedStickyBoxRect = stickyBoxRect; |
| + containingBlock->flipForWritingMode(flippedStickyBoxRect); |
| + LayoutPoint stickyLocation = flippedStickyBoxRect.location(); |
| + |
| + // FIXME: sucks to call localToAbsolute again, but we can't just offset from the previously computed rect if there are transforms. |
| + // Map to the view to avoid including page scale factor. |
| + LayoutRect absContainerFrame = LayoutRect(containingBlock->localToContainerQuad(FloatRect(FloatPoint(), FloatSize(containingBlock->size())), view()).boundingBox()); |
| + |
| + if (containingBlock->hasOverflowClip()) { |
| + LayoutSize scrollOffset(containingBlock->layer()->scrollableArea()->adjustedScrollOffset()); |
|
chrishtr
2015/12/09 19:12:21
Is this code useless? Can the containing block be
flackr
2015/12/10 23:43:15
No, the containing block can't be a scroller witho
chrishtr
2015/12/11 02:06:11
Ok please add a comment explaining this then.
flackr
2016/01/19 15:40:48
Done.
|
| + stickyLocation -= scrollOffset; |
| + } |
| + |
| + // We can't call localToAbsolute on |this| because that will recur. FIXME: For now, assume that |this| is not transformed. |
| + constraints.setAbsoluteStickyBoxRect(LayoutRect(LayoutPoint(absContainerFrame.location()) + stickyLocation, flippedStickyBoxRect.size())); |
| + |
| + LayoutUnit horizontalOffsets = minimumValueForLength(style()->right(), constrainingRect.width()) + |
| + minimumValueForLength(style()->left(), constrainingRect.width()); |
| + bool skipRight = false; |
| + bool skipLeft = false; |
| + if (!style()->left().isAuto() && !style()->right().isAuto()) { |
| + if (horizontalOffsets > containerContentRect.width() |
| + || horizontalOffsets + containerContentRect.width() > constrainingRect.width()) { |
| + skipRight = style()->isLeftToRightDirection(); |
| + skipLeft = !skipRight; |
| + } |
| + } |
| + |
| + if (!style()->left().isAuto() && !skipLeft) { |
| + constraints.setLeftOffset(minimumValueForLength(style()->left(), constrainingRect.width())); |
| + constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft); |
| + } |
| + |
| + if (!style()->right().isAuto() && !skipRight) { |
| + constraints.setRightOffset(minimumValueForLength(style()->right(), constrainingRect.width())); |
| + constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeRight); |
| + } |
| + |
| + bool skipBottom = false; |
| + // FIXME(ostap): Exclude top or bottom edge offset depending on the writing mode when related |
| + // sections are fixed in spec: http://lists.w3.org/Archives/Public/www-style/2014May/0286.html |
| + LayoutUnit verticalOffsets = minimumValueForLength(style()->top(), constrainingRect.width()) + |
| + minimumValueForLength(style()->bottom(), constrainingRect.width()); |
| + if (!style()->top().isAuto() && !style()->bottom().isAuto()) { |
| + if (verticalOffsets > containerContentRect.height() |
| + || verticalOffsets + containerContentRect.height() > constrainingRect.height()) { |
| + skipBottom = true; |
| + } |
| + } |
| + |
| + if (!style()->top().isAuto()) { |
| + constraints.setTopOffset(minimumValueForLength(style()->top(), constrainingRect.height())); |
| + constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop); |
| + } |
| + |
| + if (!style()->bottom().isAuto() && !skipBottom) { |
| + constraints.setBottomOffset(minimumValueForLength(style()->bottom(), constrainingRect.height())); |
| + constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeBottom); |
| + } |
| +} |
| + |
| +LayoutRect LayoutBoxModelObject::computeStickyConstrainingRect() const |
| +{ |
| + LayoutRect constrainingRect; |
| + |
| + ASSERT(hasLayer()); |
| + LayoutBox* enclosingClippingBox = findScrollAncestor(node()); |
| + if (enclosingClippingBox) { |
| + LayoutRect clipRect = enclosingClippingBox->overflowClipRect(LayoutPoint()); |
| + clipRect.move(enclosingClippingBox->paddingLeft(), enclosingClippingBox->paddingTop()); |
| + clipRect.contract(LayoutSize(enclosingClippingBox->paddingLeft() + enclosingClippingBox->paddingRight(), |
|
chrishtr
2015/12/09 19:12:21
Why is special code needed to remove padding?
flackr
2015/12/10 23:43:15
The padding is not clipped from an overflow box, s
|
| + enclosingClippingBox->paddingTop() + enclosingClippingBox->paddingBottom())); |
| + constrainingRect = LayoutRect(enclosingClippingBox->localToContainerQuad(FloatRect(clipRect), view()).boundingBox()); |
| + } else { |
| + constrainingRect = LayoutRect(view()->frameView()->visibleContentRect()); |
| + } |
| + |
| + return constrainingRect; |
| +} |
| + |
| +LayoutSize LayoutBoxModelObject::stickyPositionOffset() const |
| +{ |
| + LayoutRect constrainingRect = computeStickyConstrainingRect(); |
| + StickyPositionViewportConstraints constraints; |
| + computeStickyPositionConstraints(constraints, constrainingRect); |
| + |
| + // The sticky offset is physical, so we can just return the delta computed in absolute coords (though it may be wrong with transforms). |
| + return LayoutSize(constraints.computeStickyOffset(constrainingRect)); |
| +} |
| + |
| LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeToOffsetParent(const LayoutPoint& startPoint) const |
| { |
| // If the element is the HTML body element or doesn't have a parent |
| @@ -630,7 +766,7 @@ LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeToOffsetParent(const L |
| referencePoint.move(-toLayoutBox(offsetParent)->borderLeft(), -toLayoutBox(offsetParent)->borderTop()); |
| if (!isOutOfFlowPositioned() || flowThreadContainingBlock()) { |
| if (isInFlowPositioned()) |
| - referencePoint.move(relativePositionOffset()); |
| + referencePoint.move(offsetForInFlowPosition()); |
| LayoutObject* current; |
| for (current = parent(); current != offsetParent && current->parent(); current = current->parent()) { |
| @@ -652,7 +788,13 @@ LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeToOffsetParent(const L |
| LayoutSize LayoutBoxModelObject::offsetForInFlowPosition() const |
| { |
| - return isRelPositioned() ? relativePositionOffset() : LayoutSize(); |
| + if (isRelPositioned()) |
| + return relativePositionOffset(); |
| + |
| + if (isStickyPositioned()) |
| + return stickyPositionOffset(); |
| + |
| + return LayoutSize(); |
| } |
| LayoutUnit LayoutBoxModelObject::offsetLeft() const |
| @@ -975,7 +1117,7 @@ const LayoutObject* LayoutBoxModelObject::pushMappingToContainer(const LayoutBox |
| return nullptr; |
| bool isInline = isLayoutInline(); |
| - bool isFixedPos = !isInline && style()->position() == FixedPosition; |
| + bool isFixedPosition = !isInline && style()->position() == FixedPosition; |
| bool hasTransform = !isInline && hasLayer() && layer()->transform(); |
| LayoutSize adjustmentForSkippedAncestor; |
| @@ -987,16 +1129,19 @@ const LayoutObject* LayoutBoxModelObject::pushMappingToContainer(const LayoutBox |
| bool offsetDependsOnPoint = false; |
| LayoutSize containerOffset = offsetFromContainer(container, LayoutPoint(), &offsetDependsOnPoint); |
| + LayoutSize stickyOffset; |
| + if (style()->position() == StickyPosition) |
| + stickyOffset = offsetForInFlowPosition(); |
| bool preserve3D = container->style()->preserves3D() || style()->preserves3D(); |
| if (shouldUseTransformFromContainer(container)) { |
| TransformationMatrix t; |
| getTransformFromContainer(container, containerOffset, t); |
| t.translateRight(adjustmentForSkippedAncestor.width().toFloat(), adjustmentForSkippedAncestor.height().toFloat()); |
| - geometryMap.push(this, t, preserve3D, offsetDependsOnPoint, isFixedPos, hasTransform); |
| + geometryMap.push(this, t, preserve3D, offsetDependsOnPoint, isFixedPosition, hasTransform, LayoutSize(), stickyOffset); |
| } else { |
| containerOffset += adjustmentForSkippedAncestor; |
| - geometryMap.push(this, containerOffset, preserve3D, offsetDependsOnPoint, isFixedPos, hasTransform); |
| + geometryMap.push(this, containerOffset, preserve3D, offsetDependsOnPoint, isFixedPosition, hasTransform, LayoutSize(), stickyOffset); |
| } |
| return ancestorSkipped ? ancestorToStopAt : container; |