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

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

Issue 2961613002: Slightly refactor StickyPositionScrollingConstraints API and add documentation (Closed)
Patch Set: More documentation, split out ancestor offset calculation Created 3 years, 5 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 namespace blink { 47 namespace blink {
48 48
49 namespace { 49 namespace {
50 inline bool IsOutOfFlowPositionedWithImplicitHeight( 50 inline bool IsOutOfFlowPositionedWithImplicitHeight(
51 const LayoutBoxModelObject* child) { 51 const LayoutBoxModelObject* child) {
52 return child->IsOutOfFlowPositioned() && 52 return child->IsOutOfFlowPositioned() &&
53 !child->Style()->LogicalTop().IsAuto() && 53 !child->Style()->LogicalTop().IsAuto() &&
54 !child->Style()->LogicalBottom().IsAuto(); 54 !child->Style()->LogicalBottom().IsAuto();
55 } 55 }
56 56
57 StickyPositionScrollingConstraints* StickyConstraintsForLayoutObject(
58 const LayoutBoxModelObject* obj,
59 const PaintLayer* ancestor_overflow_layer) {
60 if (!obj)
61 return nullptr;
62
63 PaintLayerScrollableArea* scrollable_area =
64 ancestor_overflow_layer->GetScrollableArea();
65 auto it = scrollable_area->GetStickyConstraintsMap().find(obj->Layer());
66 if (it == scrollable_area->GetStickyConstraintsMap().end())
67 return nullptr;
68
69 return &it->value;
70 }
71
72 // Inclusive of |from|, exclusive of |to|. 57 // Inclusive of |from|, exclusive of |to|.
73 LayoutBoxModelObject* FindFirstStickyBetween(LayoutObject* from, 58 PaintLayer* FindFirstStickyBetween(LayoutObject* from, LayoutObject* to) {
74 LayoutObject* to) {
75 LayoutObject* maybe_sticky_ancestor = from; 59 LayoutObject* maybe_sticky_ancestor = from;
76 while (maybe_sticky_ancestor && maybe_sticky_ancestor != to) { 60 while (maybe_sticky_ancestor && maybe_sticky_ancestor != to) {
77 if (maybe_sticky_ancestor->Style()->HasStickyConstrainedPosition()) { 61 if (maybe_sticky_ancestor->Style()->HasStickyConstrainedPosition()) {
78 return ToLayoutBoxModelObject(maybe_sticky_ancestor); 62 return ToLayoutBoxModelObject(maybe_sticky_ancestor)->Layer();
79 } 63 }
80 64
81 maybe_sticky_ancestor = 65 maybe_sticky_ancestor =
82 maybe_sticky_ancestor->IsLayoutInline() 66 maybe_sticky_ancestor->IsLayoutInline()
83 ? maybe_sticky_ancestor->Container() 67 ? maybe_sticky_ancestor->Container()
84 : ToLayoutBox(maybe_sticky_ancestor)->LocationContainer(); 68 : ToLayoutBox(maybe_sticky_ancestor)->LocationContainer();
85 } 69 }
86 return nullptr; 70 return nullptr;
87 } 71 }
88 } // namespace 72 } // namespace
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 FloatRect(scroll_container_relative_padding_box_rect.Location() + 975 FloatRect(scroll_container_relative_padding_box_rect.Location() +
992 ToFloatSize(sticky_location), 976 ToFloatSize(sticky_location),
993 flipped_sticky_box_rect.Size())); 977 flipped_sticky_box_rect.Size()));
994 978
995 // To correctly compute the offsets, the constraints need to know about any 979 // To correctly compute the offsets, the constraints need to know about any
996 // nested position:sticky elements between themselves and their 980 // nested position:sticky elements between themselves and their
997 // containingBlock, and between the containingBlock and their scrollAncestor. 981 // containingBlock, and between the containingBlock and their scrollAncestor.
998 // 982 //
999 // The respective search ranges are [container, containingBlock) and 983 // The respective search ranges are [container, containingBlock) and
1000 // [containingBlock, scrollAncestor). 984 // [containingBlock, scrollAncestor).
1001 constraints.SetNearestStickyBoxShiftingStickyBox( 985 constraints.SetNearestStickyLayerShiftingStickyBox(
1002 FindFirstStickyBetween(location_container, containing_block)); 986 FindFirstStickyBetween(location_container, containing_block));
1003 // We cannot use |scrollAncestor| here as it disregards the root 987 // We cannot use |scrollAncestor| here as it disregards the root
1004 // ancestorOverflowLayer(), which we should include. 988 // ancestorOverflowLayer(), which we should include.
1005 constraints.SetNearestStickyBoxShiftingContainingBlock(FindFirstStickyBetween( 989 constraints.SetNearestStickyLayerShiftingContainingBlock(
1006 containing_block, &Layer()->AncestorOverflowLayer()->GetLayoutObject())); 990 FindFirstStickyBetween(
991 containing_block,
992 &Layer()->AncestorOverflowLayer()->GetLayoutObject()));
1007 993
1008 // We skip the right or top sticky offset if there is not enough space to 994 // We skip the right or top sticky offset if there is not enough space to
1009 // honor both the left/right or top/bottom offsets. 995 // honor both the left/right or top/bottom offsets.
1010 LayoutUnit horizontal_offsets = 996 LayoutUnit horizontal_offsets =
1011 MinimumValueForLength(Style()->Right(), 997 MinimumValueForLength(Style()->Right(),
1012 LayoutUnit(constraining_size.Width())) + 998 LayoutUnit(constraining_size.Width())) +
1013 MinimumValueForLength(Style()->Left(), 999 MinimumValueForLength(Style()->Left(),
1014 LayoutUnit(constraining_size.Width())); 1000 LayoutUnit(constraining_size.Width()));
1015 bool skip_right = false; 1001 bool skip_right = false;
1016 bool skip_left = false; 1002 bool skip_left = false;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 return constraining_rect; 1083 return constraining_rect;
1098 } 1084 }
1099 1085
1100 LayoutSize LayoutBoxModelObject::StickyPositionOffset() const { 1086 LayoutSize LayoutBoxModelObject::StickyPositionOffset() const {
1101 const PaintLayer* ancestor_overflow_layer = Layer()->AncestorOverflowLayer(); 1087 const PaintLayer* ancestor_overflow_layer = Layer()->AncestorOverflowLayer();
1102 // TODO: Force compositing input update if we ask for offset before 1088 // TODO: Force compositing input update if we ask for offset before
1103 // compositing inputs have been computed? 1089 // compositing inputs have been computed?
1104 if (!ancestor_overflow_layer) 1090 if (!ancestor_overflow_layer)
1105 return LayoutSize(); 1091 return LayoutSize();
1106 1092
1107 StickyPositionScrollingConstraints* constraints = 1093 StickyConstraintsMap& constraints_map =
1108 StickyConstraintsForLayoutObject(this, ancestor_overflow_layer); 1094 ancestor_overflow_layer->GetScrollableArea()->GetStickyConstraintsMap();
1109 if (!constraints) 1095 auto it = constraints_map.find(Layer());
1096 if (it == constraints_map.end())
1110 return LayoutSize(); 1097 return LayoutSize();
1111 1098 StickyPositionScrollingConstraints* constraints = &it->value;
smcgruer 2017/06/26 19:18:56 Refactoring this code made me realize how dangerou
flackr 2017/06/29 15:24:10 I think it's okay to modify the value being pointe
1112 StickyPositionScrollingConstraints* shifting_sticky_box_constraints =
1113 StickyConstraintsForLayoutObject(
1114 constraints->NearestStickyBoxShiftingStickyBox(),
1115 ancestor_overflow_layer);
1116
1117 StickyPositionScrollingConstraints* shifting_containing_block_constraints =
1118 StickyConstraintsForLayoutObject(
1119 constraints->NearestStickyBoxShiftingContainingBlock(),
1120 ancestor_overflow_layer);
1121 1099
1122 // The sticky offset is physical, so we can just return the delta computed in 1100 // The sticky offset is physical, so we can just return the delta computed in
1123 // absolute coords (though it may be wrong with transforms). 1101 // absolute coords (though it may be wrong with transforms).
1124 FloatRect constraining_rect = ComputeStickyConstrainingRect(); 1102 FloatRect constraining_rect = ComputeStickyConstrainingRect();
1125 return LayoutSize(constraints->ComputeStickyOffset( 1103 return LayoutSize(
1126 constraining_rect, shifting_sticky_box_constraints, 1104 constraints->ComputeStickyOffset(constraining_rect, constraints_map));
1127 shifting_containing_block_constraints));
1128 } 1105 }
1129 1106
1130 LayoutPoint LayoutBoxModelObject::AdjustedPositionRelativeTo( 1107 LayoutPoint LayoutBoxModelObject::AdjustedPositionRelativeTo(
1131 const LayoutPoint& start_point, 1108 const LayoutPoint& start_point,
1132 const Element* offset_parent) const { 1109 const Element* offset_parent) const {
1133 // If the element is the HTML body element or doesn't have a parent 1110 // If the element is the HTML body element or doesn't have a parent
1134 // return 0 and stop this algorithm. 1111 // return 0 and stop this algorithm.
1135 if (IsBody() || !Parent()) 1112 if (IsBody() || !Parent())
1136 return LayoutPoint(); 1113 return LayoutPoint();
1137 1114
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 if (root_element_style->HasBackground()) 1466 if (root_element_style->HasBackground())
1490 return false; 1467 return false;
1491 1468
1492 if (GetNode() != GetDocument().FirstBodyElement()) 1469 if (GetNode() != GetDocument().FirstBodyElement())
1493 return false; 1470 return false;
1494 1471
1495 return true; 1472 return true;
1496 } 1473 }
1497 1474
1498 } // namespace blink 1475 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698