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

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

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: Offset rects correctly and accumulate correctly 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 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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 // the container is our scroll ancestor, we also need to remove the border 866 // the container is our scroll ancestor, we also need to remove the border
867 // box because we want the position from within the scroller border. 867 // box because we want the position from within the scroller border.
868 FloatSize containerBorderOffset(containingBlock->borderLeft(), 868 FloatSize containerBorderOffset(containingBlock->borderLeft(),
869 containingBlock->borderTop()); 869 containingBlock->borderTop());
870 stickyLocation -= containerBorderOffset; 870 stickyLocation -= containerBorderOffset;
871 constraints.setScrollContainerRelativeStickyBoxRect( 871 constraints.setScrollContainerRelativeStickyBoxRect(
872 FloatRect(scrollContainerRelativePaddingBoxRect.location() + 872 FloatRect(scrollContainerRelativePaddingBoxRect.location() +
873 toFloatSize(stickyLocation), 873 toFloatSize(stickyLocation),
874 flippedStickyBoxRect.size())); 874 flippedStickyBoxRect.size()));
875 875
876 // To correctly compute the offsets, the constraints need to know about any
877 // nested position:sticky between themselves and their containingBlock, and
878 // between the containingBlock and their scrollAncestor.
879 //
880 // The respective search ranges are [parent(), containingBlock) and
881 // [containingBlock, scrollAncestor).
882
883 // TODO(smcgruer): Fold these into the walks to find the containingBlock and
884 // scrollAncestor.
885
886 LayoutObject* maybeStickyAncestor = parent();
887 while (maybeStickyAncestor && maybeStickyAncestor != containingBlock) {
888 if (maybeStickyAncestor->isStickyPositioned()) {
889 constraints.setNearestStickyElementToContainingBlock(
890 toLayoutBoxModelObject(maybeStickyAncestor));
891 break;
892 }
893 maybeStickyAncestor = maybeStickyAncestor->parent();
894 }
895
896 if (scrollAncestor) {
flackr 2017/01/20 02:42:44 nullptr scrollAncestor just means the scroll ances
smcgruer 2017/01/20 17:18:14 So I'm clear, we need to do something like: L
flackr 2017/01/23 16:45:42 Yes, that would work, but probably simpler to use
smcgruer 2017/01/24 18:38:25 Done.
897 maybeStickyAncestor = containingBlock;
898 while (maybeStickyAncestor && maybeStickyAncestor != scrollAncestor) {
899 if (maybeStickyAncestor->isStickyPositioned()) {
900 constraints.setNearestStickyElementFromContainingBlockToScrollContainer(
901 toLayoutBoxModelObject(maybeStickyAncestor));
902 break;
903 }
904 maybeStickyAncestor = maybeStickyAncestor->parent();
905 }
906 }
907
876 // We skip the right or top sticky offset if there is not enough space to 908 // 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. 909 // honor both the left/right or top/bottom offsets.
878 LayoutUnit horizontalOffsets = 910 LayoutUnit horizontalOffsets =
879 minimumValueForLength(style()->right(), 911 minimumValueForLength(style()->right(),
880 LayoutUnit(constrainingSize.width())) + 912 LayoutUnit(constrainingSize.width())) +
881 minimumValueForLength(style()->left(), 913 minimumValueForLength(style()->left(),
882 LayoutUnit(constrainingSize.width())); 914 LayoutUnit(constrainingSize.width()));
883 bool skipRight = false; 915 bool skipRight = false;
884 bool skipLeft = false; 916 bool skipLeft = false;
885 if (!style()->left().isAuto() && !style()->right().isAuto()) { 917 if (!style()->left().isAuto() && !style()->right().isAuto()) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 FloatRect constrainingRect = computeStickyConstrainingRect(); 1001 FloatRect constrainingRect = computeStickyConstrainingRect();
970 PaintLayerScrollableArea* scrollableArea = 1002 PaintLayerScrollableArea* scrollableArea =
971 ancestorOverflowLayer->getScrollableArea(); 1003 ancestorOverflowLayer->getScrollableArea();
972 1004
973 // The sticky offset is physical, so we can just return the delta computed in 1005 // The sticky offset is physical, so we can just return the delta computed in
974 // absolute coords (though it may be wrong with transforms). 1006 // absolute coords (though it may be wrong with transforms).
975 // TODO: Force compositing input update if we ask for offset with stale 1007 // TODO: Force compositing input update if we ask for offset with stale
976 // compositing inputs. 1008 // compositing inputs.
977 if (!scrollableArea->stickyConstraintsMap().contains(layer())) 1009 if (!scrollableArea->stickyConstraintsMap().contains(layer()))
978 return LayoutSize(); 1010 return LayoutSize();
979 return LayoutSize( 1011
980 scrollableArea->stickyConstraintsMap().get(layer()).computeStickyOffset( 1012 auto it = scrollableArea->stickyConstraintsMap().find(layer());
981 constrainingRect)); 1013 DCHECK(it != scrollableArea->stickyConstraintsMap().end());
flackr 2017/01/20 02:42:44 Please merge this with the check on 1009 above so
smcgruer 2017/01/24 18:38:25 Done in PS4 (missed this comment.)
1014
1015 StickyPositionScrollingConstraints& constraints = it->value;
1016
1017 FloatSize accumulatedOffsetToContainingBlock;
1018 FloatSize accumulatedOffsetToScrollContainer;
1019
1020 const LayoutBoxModelObject* toContainingBlock =
1021 constraints.nearestStickyElementToContainingBlock();
1022 if (toContainingBlock) {
1023 accumulatedOffsetToContainingBlock =
1024 scrollableArea->stickyConstraintsMap()
1025 .get(toContainingBlock->layer())
1026 .getAccumulatedStickyOffsetToContainingBlock();
1027 }
1028
1029 const LayoutBoxModelObject* toViewport =
1030 constraints.nearestStickyElementFromContainingBlockToScrollContainer();
1031 if (toViewport) {
1032 accumulatedOffsetToScrollContainer =
1033 scrollableArea->stickyConstraintsMap()
1034 .get(toViewport->layer())
1035 .getAccumulatedStickyOffsetFromContainingBlockToScrollContainer();
1036 }
1037
1038 return LayoutSize(constraints.computeStickyOffset(
1039 constrainingRect, accumulatedOffsetToContainingBlock,
1040 accumulatedOffsetToScrollContainer));
982 } 1041 }
983 1042
984 LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeTo( 1043 LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeTo(
985 const LayoutPoint& startPoint, 1044 const LayoutPoint& startPoint,
986 const Element* offsetParent) const { 1045 const Element* offsetParent) const {
987 // If the element is the HTML body element or doesn't have a parent 1046 // If the element is the HTML body element or doesn't have a parent
988 // return 0 and stop this algorithm. 1047 // return 0 and stop this algorithm.
989 if (isBody() || !parent()) 1048 if (isBody() || !parent())
990 return LayoutPoint(); 1049 return LayoutPoint();
991 1050
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 if (rootElementStyle->hasBackground()) 1399 if (rootElementStyle->hasBackground())
1341 return false; 1400 return false;
1342 1401
1343 if (node() != document().firstBodyElement()) 1402 if (node() != document().firstBodyElement())
1344 return false; 1403 return false;
1345 1404
1346 return true; 1405 return true;
1347 } 1406 }
1348 1407
1349 } // namespace blink 1408 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698