| 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_nearestStickyElementFromContainingBlockToViewport(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_nearestStickyElementFromContainingBlockToViewport( |
| 48 other.m_nearestStickyElementFromContainingBlockToViewport), |
| 49 m_cachedAccumulatedStickyOffset(other.m_cachedAccumulatedStickyOffset) { |
| 50 } |
| 40 | 51 |
| 41 FloatSize computeStickyOffset(const FloatRect& viewportRect) const; | 52 FloatSize computeStickyOffset(const FloatRect& viewportRect, |
| 53 const FloatSize& accumulatedToCB, |
| 54 const FloatSize& accumulatedToVP); |
| 55 |
| 56 bool hasAncestorStickyElement() { |
| 57 return m_nearestStickyElementToContainingBlock || |
| 58 m_nearestStickyElementFromContainingBlockToViewport; |
| 59 } |
| 42 | 60 |
| 43 AnchorEdges anchorEdges() const { return m_anchorEdges; } | 61 AnchorEdges anchorEdges() const { return m_anchorEdges; } |
| 44 bool hasAnchorEdge(AnchorEdgeFlags flag) const { | 62 bool hasAnchorEdge(AnchorEdgeFlags flag) const { |
| 45 return m_anchorEdges & flag; | 63 return m_anchorEdges & flag; |
| 46 } | 64 } |
| 47 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } | 65 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } |
| 48 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } | 66 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } |
| 49 | 67 |
| 50 float leftOffset() const { return m_leftOffset; } | 68 float leftOffset() const { return m_leftOffset; } |
| 51 float rightOffset() const { return m_rightOffset; } | 69 float rightOffset() const { return m_rightOffset; } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 return m_scrollContainerRelativeContainingBlockRect; | 82 return m_scrollContainerRelativeContainingBlockRect; |
| 65 } | 83 } |
| 66 | 84 |
| 67 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) { | 85 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) { |
| 68 m_scrollContainerRelativeStickyBoxRect = rect; | 86 m_scrollContainerRelativeStickyBoxRect = rect; |
| 69 } | 87 } |
| 70 const FloatRect& scrollContainerRelativeStickyBoxRect() const { | 88 const FloatRect& scrollContainerRelativeStickyBoxRect() const { |
| 71 return m_scrollContainerRelativeStickyBoxRect; | 89 return m_scrollContainerRelativeStickyBoxRect; |
| 72 } | 90 } |
| 73 | 91 |
| 92 void setNearestStickyElementToContainingBlock(LayoutBoxModelObject* layer) { |
| 93 m_nearestStickyElementToContainingBlock = layer; |
| 94 } |
| 95 const LayoutBoxModelObject* nearestStickyElementToContainingBlock() { |
| 96 return m_nearestStickyElementToContainingBlock; |
| 97 } |
| 98 |
| 99 void setNearestStickyElementFromContainingBlockToViewport( |
| 100 LayoutBoxModelObject* layer) { |
| 101 m_nearestStickyElementFromContainingBlockToViewport = layer; |
| 102 } |
| 103 const LayoutBoxModelObject* |
| 104 nearestStickyElementFromContainingBlockToViewport() { |
| 105 return m_nearestStickyElementFromContainingBlockToViewport; |
| 106 } |
| 107 |
| 108 const FloatSize& getCachedAccumulatedStickyOffset() { |
| 109 return m_cachedAccumulatedStickyOffset; |
| 110 } |
| 111 |
| 74 bool operator==(const StickyPositionScrollingConstraints& other) const { | 112 bool operator==(const StickyPositionScrollingConstraints& other) const { |
| 75 return m_leftOffset == other.m_leftOffset && | 113 return m_leftOffset == other.m_leftOffset && |
| 76 m_rightOffset == other.m_rightOffset && | 114 m_rightOffset == other.m_rightOffset && |
| 77 m_topOffset == other.m_topOffset && | 115 m_topOffset == other.m_topOffset && |
| 78 m_bottomOffset == other.m_bottomOffset && | 116 m_bottomOffset == other.m_bottomOffset && |
| 79 m_scrollContainerRelativeContainingBlockRect == | 117 m_scrollContainerRelativeContainingBlockRect == |
| 80 other.m_scrollContainerRelativeContainingBlockRect && | 118 other.m_scrollContainerRelativeContainingBlockRect && |
| 81 m_scrollContainerRelativeStickyBoxRect == | 119 m_scrollContainerRelativeStickyBoxRect == |
| 82 other.m_scrollContainerRelativeStickyBoxRect; | 120 other.m_scrollContainerRelativeStickyBoxRect && |
| 121 m_nearestStickyElementToContainingBlock == |
| 122 other.m_nearestStickyElementToContainingBlock && |
| 123 m_nearestStickyElementFromContainingBlockToViewport == |
| 124 other.m_nearestStickyElementFromContainingBlockToViewport && |
| 125 m_cachedAccumulatedStickyOffset == |
| 126 other.m_cachedAccumulatedStickyOffset; |
| 83 } | 127 } |
| 84 | 128 |
| 85 bool operator!=(const StickyPositionScrollingConstraints& other) const { | 129 bool operator!=(const StickyPositionScrollingConstraints& other) const { |
| 86 return !(*this == other); | 130 return !(*this == other); |
| 87 } | 131 } |
| 88 | 132 |
| 89 private: | 133 private: |
| 90 AnchorEdges m_anchorEdges; | 134 AnchorEdges m_anchorEdges; |
| 91 float m_leftOffset; | 135 float m_leftOffset; |
| 92 float m_rightOffset; | 136 float m_rightOffset; |
| 93 float m_topOffset; | 137 float m_topOffset; |
| 94 float m_bottomOffset; | 138 float m_bottomOffset; |
| 95 FloatRect m_scrollContainerRelativeContainingBlockRect; | 139 FloatRect m_scrollContainerRelativeContainingBlockRect; |
| 96 FloatRect m_scrollContainerRelativeStickyBoxRect; | 140 FloatRect m_scrollContainerRelativeStickyBoxRect; |
| 141 |
| 142 // In order to properly compute the stickyOffset, we need to know if we have |
| 143 // any sticky ancestors both between ourselves and our containingBlock and |
| 144 // between our containingBlock and the viewport. |
| 145 // |
| 146 // Any such ancestors are computed at layout time, and then the accumulated |
| 147 // offset from them is recomputed after each scroll update. |
| 148 LayoutBoxModelObject* m_nearestStickyElementToContainingBlock; |
| 149 LayoutBoxModelObject* m_nearestStickyElementFromContainingBlockToViewport; |
| 150 |
| 151 FloatSize m_cachedAccumulatedStickyOffset; |
| 97 }; | 152 }; |
| 98 | 153 |
| 99 } // namespace blink | 154 } // namespace blink |
| 100 | 155 |
| 101 #endif // StickyPositionScrollingConstraints_h | 156 #endif // StickyPositionScrollingConstraints_h |
| OLD | NEW |