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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp

Issue 2494933002: Exclude border from overflow scroller in sticky constraints. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2010 Google Inc. All rights reserved. 7 * Copyright (C) 2010 Google Inc. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 containingBlock->isLayoutView() 797 containingBlock->isLayoutView()
798 ? containingBlock->logicalWidth() 798 ? containingBlock->logicalWidth()
799 : containingBlock->containingBlockLogicalWidthForContent(); 799 : containingBlock->containingBlockLogicalWidthForContent();
800 // Sticky positioned element ignore any override logical width on the 800 // Sticky positioned element ignore any override logical width on the
801 // containing block, as they don't call containingBlockLogicalWidthForContent. 801 // containing block, as they don't call containingBlockLogicalWidthForContent.
802 // It's unclear whether this is totally fine. 802 // It's unclear whether this is totally fine.
803 // Compute the container-relative area within which the sticky element is 803 // Compute the container-relative area within which the sticky element is
804 // allowed to move. 804 // allowed to move.
805 LayoutUnit maxWidth = containingBlock->availableLogicalWidth(); 805 LayoutUnit maxWidth = containingBlock->availableLogicalWidth();
806 806
807 // Map the containing block to the scroll ancestor without transforms. 807 // Map the containing block to the inner corner of the scroll ancestor without
808 // transforms.
808 FloatRect scrollContainerRelativePaddingBoxRect( 809 FloatRect scrollContainerRelativePaddingBoxRect(
809 containingBlock->layoutOverflowRect()); 810 containingBlock->layoutOverflowRect());
811 FloatSize scrollContainerBorderOffset;
812 if (scrollAncestor) {
813 scrollContainerBorderOffset =
814 FloatSize(scrollAncestor->borderLeft(), scrollAncestor->borderTop());
815 }
810 if (containingBlock != scrollAncestor) { 816 if (containingBlock != scrollAncestor) {
811 FloatQuad localQuad(FloatRect(containingBlock->paddingBoxRect())); 817 FloatQuad localQuad(FloatRect(containingBlock->paddingBoxRect()));
812 TransformState transformState(TransformState::ApplyTransformDirection, 818 TransformState transformState(TransformState::ApplyTransformDirection,
813 localQuad.boundingBox().center(), localQuad); 819 localQuad.boundingBox().center(), localQuad);
814 containingBlock->mapLocalToAncestor(scrollAncestor, transformState, 820 containingBlock->mapLocalToAncestor(scrollAncestor, transformState,
815 ApplyContainerFlip); 821 ApplyContainerFlip);
816 transformState.flatten(); 822 transformState.flatten();
817 scrollContainerRelativePaddingBoxRect = 823 scrollContainerRelativePaddingBoxRect =
818 transformState.lastPlanarQuad().boundingBox(); 824 transformState.lastPlanarQuad().boundingBox();
819 825
820 // The sticky position constraint rects should be independent of the current 826 // The sticky position constraint rects should be independent of the current
821 // scroll position, so after mapping we add in the scroll position to get 827 // scroll position, so after mapping we add in the scroll position to get
822 // the container's position within the ancestor scroller's unscrolled layout 828 // the container's position within the ancestor scroller's unscrolled layout
823 // overflow. 829 // overflow.
824 ScrollOffset scrollOffset( 830 ScrollOffset scrollOffset(
825 scrollAncestor 831 scrollAncestor
826 ? toFloatSize(scrollAncestor->getScrollableArea()->scrollPosition()) 832 ? toFloatSize(scrollAncestor->getScrollableArea()->scrollPosition())
827 : FloatSize()); 833 : FloatSize());
828 scrollContainerRelativePaddingBoxRect.move(scrollOffset); 834 scrollContainerRelativePaddingBoxRect.move(scrollOffset);
829 } 835 }
836 // Remove top-left border offset from overflow scroller.
837 scrollContainerRelativePaddingBoxRect.move(-scrollContainerBorderOffset);
830 838
831 LayoutRect scrollContainerRelativeContainingBlockRect( 839 LayoutRect scrollContainerRelativeContainingBlockRect(
832 scrollContainerRelativePaddingBoxRect); 840 scrollContainerRelativePaddingBoxRect);
833 // This is removing the padding of the containing block's overflow rect to get 841 // This is removing the padding of the containing block's overflow rect to get
834 // the flow box rectangle and removing the margin of the sticky element to 842 // the flow box rectangle and removing the margin of the sticky element to
835 // ensure that space between the sticky element and its containing flow box. 843 // ensure that space between the sticky element and its containing flow box.
836 // It is an open issue whether the margin should collapse. 844 // It is an open issue whether the margin should collapse.
837 // See https://www.w3.org/TR/css-position-3/#sticky-pos 845 // See https://www.w3.org/TR/css-position-3/#sticky-pos
838 scrollContainerRelativeContainingBlockRect.contractEdges( 846 scrollContainerRelativeContainingBlockRect.contractEdges(
839 minimumValueForLength(containingBlock->style()->paddingTop(), 847 minimumValueForLength(containingBlock->style()->paddingTop(),
(...skipping 15 matching lines...) Expand all
855 FloatRect stickyBoxRect = 863 FloatRect stickyBoxRect =
856 isLayoutInline() ? FloatRect(toLayoutInline(this)->linesBoundingBox()) 864 isLayoutInline() ? FloatRect(toLayoutInline(this)->linesBoundingBox())
857 : FloatRect(toLayoutBox(this)->frameRect()); 865 : FloatRect(toLayoutBox(this)->frameRect());
858 FloatRect flippedStickyBoxRect = stickyBoxRect; 866 FloatRect flippedStickyBoxRect = stickyBoxRect;
859 containingBlock->flipForWritingMode(flippedStickyBoxRect); 867 containingBlock->flipForWritingMode(flippedStickyBoxRect);
860 FloatPoint stickyLocation = 868 FloatPoint stickyLocation =
861 flippedStickyBoxRect.location() + skippedContainersOffset; 869 flippedStickyBoxRect.location() + skippedContainersOffset;
862 870
863 // The scrollContainerRelativePaddingBoxRect's position is the padding box so 871 // The scrollContainerRelativePaddingBoxRect's position is the padding box so
864 // we need to remove the border when finding the position of the sticky box 872 // we need to remove the border when finding the position of the sticky box
865 // within the scroll ancestor if the container is not our scroll ancestor. 873 // within the scroll ancestor if the container is not our scroll ancestor. If
866 if (containingBlock != scrollAncestor) { 874 // the container is our scroll ancestor, we also need to remove the border
867 FloatSize containerBorderOffset(containingBlock->borderLeft(), 875 // box because we want the position from within the scroller border.
868 containingBlock->borderTop()); 876 FloatSize containerBorderOffset(containingBlock->borderLeft(),
869 stickyLocation -= containerBorderOffset; 877 containingBlock->borderTop());
870 } 878 stickyLocation -= containerBorderOffset;
871 constraints.setScrollContainerRelativeStickyBoxRect( 879 constraints.setScrollContainerRelativeStickyBoxRect(
872 FloatRect(scrollContainerRelativePaddingBoxRect.location() + 880 FloatRect(scrollContainerRelativePaddingBoxRect.location() +
873 toFloatSize(stickyLocation), 881 toFloatSize(stickyLocation),
874 flippedStickyBoxRect.size())); 882 flippedStickyBoxRect.size()));
875 883
876 // We skip the right or top sticky offset if there is not enough space to 884 // We skip the right or top sticky offset if there is not enough space to
877 // honor both the left/right or top/bottom offsets. 885 // honor both the left/right or top/bottom offsets.
878 LayoutUnit horizontalOffsets = 886 LayoutUnit horizontalOffsets =
879 minimumValueForLength(style()->right(), 887 minimumValueForLength(style()->right(),
880 LayoutUnit(constrainingSize.width())) + 888 LayoutUnit(constrainingSize.width())) +
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 FloatRect LayoutBoxModelObject::computeStickyConstrainingRect() const { 950 FloatRect LayoutBoxModelObject::computeStickyConstrainingRect() const {
943 if (layer()->ancestorOverflowLayer()->isRootLayer()) 951 if (layer()->ancestorOverflowLayer()->isRootLayer())
944 return view()->frameView()->visibleContentRect(); 952 return view()->frameView()->visibleContentRect();
945 953
946 LayoutBox* enclosingClippingBox = 954 LayoutBox* enclosingClippingBox =
947 toLayoutBox(layer()->ancestorOverflowLayer()->layoutObject()); 955 toLayoutBox(layer()->ancestorOverflowLayer()->layoutObject());
948 FloatRect constrainingRect; 956 FloatRect constrainingRect;
949 constrainingRect = 957 constrainingRect =
950 FloatRect(enclosingClippingBox->overflowClipRect(LayoutPoint(DoublePoint( 958 FloatRect(enclosingClippingBox->overflowClipRect(LayoutPoint(DoublePoint(
951 enclosingClippingBox->getScrollableArea()->scrollPosition())))); 959 enclosingClippingBox->getScrollableArea()->scrollPosition()))));
952 constrainingRect.move(enclosingClippingBox->paddingLeft(), 960 constrainingRect.move(
953 enclosingClippingBox->paddingTop()); 961 -enclosingClippingBox->borderLeft() + enclosingClippingBox->paddingLeft(),
962 -enclosingClippingBox->borderTop() + enclosingClippingBox->paddingTop());
954 constrainingRect.contract( 963 constrainingRect.contract(
955 FloatSize(enclosingClippingBox->paddingLeft() + 964 FloatSize(enclosingClippingBox->paddingLeft() +
956 enclosingClippingBox->paddingRight(), 965 enclosingClippingBox->paddingRight(),
957 enclosingClippingBox->paddingTop() + 966 enclosingClippingBox->paddingTop() +
958 enclosingClippingBox->paddingBottom())); 967 enclosingClippingBox->paddingBottom()));
959 return constrainingRect; 968 return constrainingRect;
960 } 969 }
961 970
962 LayoutSize LayoutBoxModelObject::stickyPositionOffset() const { 971 LayoutSize LayoutBoxModelObject::stickyPositionOffset() const {
963 const PaintLayer* ancestorOverflowLayer = layer()->ancestorOverflowLayer(); 972 const PaintLayer* ancestorOverflowLayer = layer()->ancestorOverflowLayer();
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 if (rootElementStyle->hasBackground()) 1348 if (rootElementStyle->hasBackground())
1340 return false; 1349 return false;
1341 1350
1342 if (node() != document().firstBodyElement()) 1351 if (node() != document().firstBodyElement())
1343 return false; 1352 return false;
1344 1353
1345 return true; 1354 return true;
1346 } 1355 }
1347 1356
1348 } // namespace blink 1357 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698