Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef StickyPositionScrollingConstraints_h | 5 #ifndef StickyPositionScrollingConstraints_h |
| 6 #define StickyPositionScrollingConstraints_h | 6 #define StickyPositionScrollingConstraints_h |
| 7 | 7 |
| 8 #include "platform/geometry/FloatRect.h" | 8 #include "platform/geometry/FloatRect.h" |
| 9 #include "platform/geometry/FloatSize.h" | |
| 9 | 10 |
| 10 namespace blink { | 11 namespace blink { |
| 11 | 12 |
| 13 class LayoutBoxModelObject; | |
| 14 | |
| 12 class StickyPositionScrollingConstraints final { | 15 class StickyPositionScrollingConstraints final { |
| 13 public: | 16 public: |
| 14 enum AnchorEdgeFlags { | 17 enum AnchorEdgeFlags { |
| 15 AnchorEdgeLeft = 1 << 0, | 18 AnchorEdgeLeft = 1 << 0, |
| 16 AnchorEdgeRight = 1 << 1, | 19 AnchorEdgeRight = 1 << 1, |
| 17 AnchorEdgeTop = 1 << 2, | 20 AnchorEdgeTop = 1 << 2, |
| 18 AnchorEdgeBottom = 1 << 3 | 21 AnchorEdgeBottom = 1 << 3 |
| 19 }; | 22 }; |
| 20 typedef unsigned AnchorEdges; | 23 typedef unsigned AnchorEdges; |
| 21 | 24 |
| 22 StickyPositionScrollingConstraints() | 25 StickyPositionScrollingConstraints() |
| 23 : m_anchorEdges(0), | 26 : m_anchorEdges(0), |
| 24 m_leftOffset(0), | 27 m_leftOffset(0), |
| 25 m_rightOffset(0), | 28 m_rightOffset(0), |
| 26 m_topOffset(0), | 29 m_topOffset(0), |
| 27 m_bottomOffset(0) {} | 30 m_bottomOffset(0), |
| 31 m_nearestStickyElementToContainingBlock(nullptr), | |
| 32 m_nearestStickyElementFromContainingBlockToScrollContainer(nullptr) {} | |
| 28 | 33 |
| 29 StickyPositionScrollingConstraints( | 34 StickyPositionScrollingConstraints( |
| 30 const StickyPositionScrollingConstraints& other) | 35 const StickyPositionScrollingConstraints& other) |
| 31 : m_anchorEdges(other.m_anchorEdges), | 36 : m_anchorEdges(other.m_anchorEdges), |
| 32 m_leftOffset(other.m_leftOffset), | 37 m_leftOffset(other.m_leftOffset), |
| 33 m_rightOffset(other.m_rightOffset), | 38 m_rightOffset(other.m_rightOffset), |
| 34 m_topOffset(other.m_topOffset), | 39 m_topOffset(other.m_topOffset), |
| 35 m_bottomOffset(other.m_bottomOffset), | 40 m_bottomOffset(other.m_bottomOffset), |
| 36 m_scrollContainerRelativeContainingBlockRect( | 41 m_scrollContainerRelativeContainingBlockRect( |
| 37 other.m_scrollContainerRelativeContainingBlockRect), | 42 other.m_scrollContainerRelativeContainingBlockRect), |
| 38 m_scrollContainerRelativeStickyBoxRect( | 43 m_scrollContainerRelativeStickyBoxRect( |
| 39 other.m_scrollContainerRelativeStickyBoxRect) {} | 44 other.m_scrollContainerRelativeStickyBoxRect), |
| 45 m_nearestStickyElementToContainingBlock( | |
| 46 other.m_nearestStickyElementToContainingBlock), | |
| 47 m_nearestStickyElementFromContainingBlockToScrollContainer( | |
| 48 other.m_nearestStickyElementFromContainingBlockToScrollContainer), | |
| 49 m_accumulatedStickyOffsetToContainingBlock( | |
| 50 other.m_accumulatedStickyOffsetToContainingBlock), | |
| 51 m_accumulatedStickyOffsetFromContainingBlockToScrollContainer( | |
| 52 other | |
| 53 .m_accumulatedStickyOffsetFromContainingBlockToScrollContainer) { | |
| 54 } | |
| 40 | 55 |
| 41 FloatSize computeStickyOffset(const FloatRect& viewportRect) const; | 56 FloatSize computeStickyOffset(const FloatRect& viewportRect, |
| 57 const FloatSize& accumulatedToCB, | |
| 58 const FloatSize& accumulatedToVP); | |
| 59 | |
| 60 bool hasAncestorStickyElement() { | |
| 61 return m_nearestStickyElementToContainingBlock || | |
| 62 m_nearestStickyElementFromContainingBlockToScrollContainer; | |
| 63 } | |
| 42 | 64 |
| 43 AnchorEdges anchorEdges() const { return m_anchorEdges; } | 65 AnchorEdges anchorEdges() const { return m_anchorEdges; } |
| 44 bool hasAnchorEdge(AnchorEdgeFlags flag) const { | 66 bool hasAnchorEdge(AnchorEdgeFlags flag) const { |
| 45 return m_anchorEdges & flag; | 67 return m_anchorEdges & flag; |
| 46 } | 68 } |
| 47 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } | 69 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } |
| 48 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } | 70 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } |
| 49 | 71 |
| 50 float leftOffset() const { return m_leftOffset; } | 72 float leftOffset() const { return m_leftOffset; } |
| 51 float rightOffset() const { return m_rightOffset; } | 73 float rightOffset() const { return m_rightOffset; } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 64 return m_scrollContainerRelativeContainingBlockRect; | 86 return m_scrollContainerRelativeContainingBlockRect; |
| 65 } | 87 } |
| 66 | 88 |
| 67 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) { | 89 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) { |
| 68 m_scrollContainerRelativeStickyBoxRect = rect; | 90 m_scrollContainerRelativeStickyBoxRect = rect; |
| 69 } | 91 } |
| 70 const FloatRect& scrollContainerRelativeStickyBoxRect() const { | 92 const FloatRect& scrollContainerRelativeStickyBoxRect() const { |
| 71 return m_scrollContainerRelativeStickyBoxRect; | 93 return m_scrollContainerRelativeStickyBoxRect; |
| 72 } | 94 } |
| 73 | 95 |
| 96 void setNearestStickyElementToContainingBlock(LayoutBoxModelObject* layer) { | |
| 97 m_nearestStickyElementToContainingBlock = layer; | |
| 98 } | |
| 99 const LayoutBoxModelObject* nearestStickyElementToContainingBlock() { | |
| 100 return m_nearestStickyElementToContainingBlock; | |
| 101 } | |
| 102 | |
| 103 void setNearestStickyElementFromContainingBlockToScrollContainer( | |
| 104 LayoutBoxModelObject* layer) { | |
| 105 m_nearestStickyElementFromContainingBlockToScrollContainer = layer; | |
| 106 } | |
| 107 const LayoutBoxModelObject* | |
| 108 nearestStickyElementFromContainingBlockToScrollContainer() { | |
| 109 return m_nearestStickyElementFromContainingBlockToScrollContainer; | |
| 110 } | |
| 111 | |
| 112 const FloatSize& getAccumulatedStickyOffsetToContainingBlock() { | |
| 113 return m_accumulatedStickyOffsetToContainingBlock; | |
| 114 } | |
| 115 const FloatSize& | |
| 116 getAccumulatedStickyOffsetFromContainingBlockToScrollContainer() { | |
| 117 return m_accumulatedStickyOffsetFromContainingBlockToScrollContainer; | |
| 118 } | |
| 119 | |
| 74 bool operator==(const StickyPositionScrollingConstraints& other) const { | 120 bool operator==(const StickyPositionScrollingConstraints& other) const { |
| 75 return m_leftOffset == other.m_leftOffset && | 121 return m_leftOffset == other.m_leftOffset && |
| 76 m_rightOffset == other.m_rightOffset && | 122 m_rightOffset == other.m_rightOffset && |
| 77 m_topOffset == other.m_topOffset && | 123 m_topOffset == other.m_topOffset && |
| 78 m_bottomOffset == other.m_bottomOffset && | 124 m_bottomOffset == other.m_bottomOffset && |
| 79 m_scrollContainerRelativeContainingBlockRect == | 125 m_scrollContainerRelativeContainingBlockRect == |
| 80 other.m_scrollContainerRelativeContainingBlockRect && | 126 other.m_scrollContainerRelativeContainingBlockRect && |
| 81 m_scrollContainerRelativeStickyBoxRect == | 127 m_scrollContainerRelativeStickyBoxRect == |
| 82 other.m_scrollContainerRelativeStickyBoxRect; | 128 other.m_scrollContainerRelativeStickyBoxRect && |
| 129 m_nearestStickyElementToContainingBlock == | |
| 130 other.m_nearestStickyElementToContainingBlock && | |
| 131 m_nearestStickyElementFromContainingBlockToScrollContainer == | |
| 132 other | |
| 133 .m_nearestStickyElementFromContainingBlockToScrollContainer & & | |
| 134 m_accumulatedStickyOffsetToContainingBlock == | |
| 135 other.m_accumulatedStickyOffsetToContainingBlock && | |
| 136 m_accumulatedStickyOffsetFromContainingBlockToScrollContainer == | |
| 137 other | |
| 138 .m_accumulatedStickyOffsetFromContainingBlockToScrollContaine r; | |
| 83 } | 139 } |
| 84 | 140 |
| 85 bool operator!=(const StickyPositionScrollingConstraints& other) const { | 141 bool operator!=(const StickyPositionScrollingConstraints& other) const { |
| 86 return !(*this == other); | 142 return !(*this == other); |
| 87 } | 143 } |
| 88 | 144 |
| 89 private: | 145 private: |
| 90 AnchorEdges m_anchorEdges; | 146 AnchorEdges m_anchorEdges; |
| 91 float m_leftOffset; | 147 float m_leftOffset; |
| 92 float m_rightOffset; | 148 float m_rightOffset; |
| 93 float m_topOffset; | 149 float m_topOffset; |
| 94 float m_bottomOffset; | 150 float m_bottomOffset; |
| 95 FloatRect m_scrollContainerRelativeContainingBlockRect; | 151 FloatRect m_scrollContainerRelativeContainingBlockRect; |
| 96 FloatRect m_scrollContainerRelativeStickyBoxRect; | 152 FloatRect m_scrollContainerRelativeStickyBoxRect; |
| 153 | |
| 154 // In order to properly compute the stickyOffset, we need to know if we have | |
| 155 // any sticky ancestors both between ourselves and our containingBlock and | |
| 156 // between our containingBlock and the viewport. | |
| 157 // | |
| 158 // Any such ancestors are computed at layout time, and then the accumulated | |
| 159 // offset from them is recomputed after each scroll update. | |
| 160 LayoutBoxModelObject* m_nearestStickyElementToContainingBlock; | |
| 161 LayoutBoxModelObject* | |
| 162 m_nearestStickyElementFromContainingBlockToScrollContainer; | |
|
flackr
2017/01/20 02:42:44
Maybe m_nearestStickyElementShifting(ContainingBlo
smcgruer
2017/01/24 15:45:22
Done.
| |
| 163 | |
| 164 // For performance, we cache our accumulated sticky offset for descendant | |
| 165 // sticky elements to use. Because we can either be the "to containing block" | |
|
flackr
2017/01/20 02:42:44
nit: explain that we offset the constraint rects o
smcgruer
2017/01/24 15:45:22
Done.
| |
| 166 // or the "to scroll container" ancestor for a given sticky element, we need | |
| 167 // to accumulate both. | |
| 168 // | |
| 169 // NOTE(smcgruer): The case where we can be both a "to containing block" | |
| 170 // and a "to scroll container" ancestor for different sticky descendants is | |
| 171 // quite complex. See the NAME_ME test in LayoutBoxModelObjectTest.cpp. | |
| 172 FloatSize m_accumulatedStickyOffsetToContainingBlock; | |
| 173 FloatSize m_accumulatedStickyOffsetFromContainingBlockToScrollContainer; | |
|
flackr
2017/01/20 02:42:44
How about m_totalStickyBoxStickyOffset and m_total
smcgruer
2017/01/24 15:45:22
Done.
| |
| 97 }; | 174 }; |
| 98 | 175 |
| 99 } // namespace blink | 176 } // namespace blink |
| 100 | 177 |
| 101 #endif // StickyPositionScrollingConstraints_h | 178 #endif // StickyPositionScrollingConstraints_h |
| OLD | NEW |