Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 ScrollAnchor_h | 5 #ifndef ScrollAnchor_h |
| 6 #define ScrollAnchor_h | 6 #define ScrollAnchor_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "platform/geometry/LayoutPoint.h" | 9 #include "platform/geometry/LayoutPoint.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 // The scroller that is scrolled to componsate for layout movements. Note | 26 // The scroller that is scrolled to componsate for layout movements. Note |
| 27 // that the scroller can only be initialized once. | 27 // that the scroller can only be initialized once. |
| 28 void setScroller(ScrollableArea*); | 28 void setScroller(ScrollableArea*); |
| 29 | 29 |
| 30 // Returns true if the underlying scroller is set. | 30 // Returns true if the underlying scroller is set. |
| 31 bool hasScroller() const { return m_scroller; } | 31 bool hasScroller() const { return m_scroller; } |
| 32 | 32 |
| 33 // The LayoutObject we are currently anchored to. Lazily computed during | 33 // The LayoutObject we are currently anchored to. Lazily computed during |
| 34 // save() and cached until the next call to clear(). | 34 // save() and cached until the next call to clear(). |
| 35 LayoutObject* anchorObject() const { return m_current.m_anchorObject; } | 35 LayoutObject* anchorObject() const { return m_anchorObject; } |
| 36 | 36 |
| 37 // Indicates that the next save() should compute a new anchor. (In certain | 37 // Indicates that the next save() should compute a new anchor. (In certain |
| 38 // cases the previous anchor will be reused; see comments in restore.) | 38 // cases the previous anchor will be reused; see comments in restore.) |
| 39 void clear(); | 39 void clear(); |
| 40 | 40 |
| 41 // Records the anchor's location in relation to the scroller. Should be | 41 // Records the anchor's location in relation to the scroller. Should be |
| 42 // called when the scroller is about to be laid out. | 42 // called when the scroller is about to be laid out. |
| 43 void save(); | 43 void save(); |
| 44 | 44 |
| 45 // Scrolls to compensate for any change in the anchor's relative location | 45 // Scrolls to compensate for any change in the anchor's relative location |
| 46 // since the most recent call to save(). Should be called immediately after | 46 // since the most recent call to save(). Should be called immediately after |
| 47 // the scroller has been laid out. | 47 // the scroller has been laid out. |
| 48 void restore(); | 48 void restore(); |
| 49 | 49 |
| 50 enum class Corner { | 50 enum class Corner { |
| 51 TopLeft = 0, | 51 TopLeft = 0, |
| 52 TopRight, | 52 TopRight, |
| 53 }; | 53 }; |
| 54 // Which corner of the anchor object we are currently anchored to. | 54 // Which corner of the anchor object we are currently anchored to. |
| 55 // Only meaningful if anchorObject() is non-null. | 55 // Only meaningful if anchorObject() is non-null. |
| 56 Corner corner() const { return m_current.m_corner; } | 56 Corner corner() const { return m_corner; } |
| 57 | 57 |
| 58 // Checks if we hold any references to the specified object. | 58 // Checks if we hold any references to the specified object. |
| 59 bool refersTo(const LayoutObject*) const; | 59 bool refersTo(const LayoutObject*) const; |
| 60 | 60 |
| 61 // Notifies us that an object will be removed from the layout tree. | 61 // Notifies us that an object will be removed from the layout tree. |
| 62 void notifyRemoved(LayoutObject*); | 62 void notifyRemoved(LayoutObject*); |
| 63 | 63 |
| 64 DEFINE_INLINE_TRACE() { visitor->trace(m_scroller); } | 64 DEFINE_INLINE_TRACE() { visitor->trace(m_scroller); } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 void findAnchor(); | 67 void findAnchor(); |
| 68 bool computeScrollAnchorDisablingStyleChanged(); | |
| 68 | 69 |
| 69 enum WalkStatus { | 70 enum WalkStatus { |
| 70 Skip = 0, | 71 Skip = 0, |
| 71 Constrain, | 72 Constrain, |
| 72 Continue, | 73 Continue, |
| 73 Return | 74 Return |
| 74 }; | 75 }; |
| 75 struct ExamineResult { | 76 struct ExamineResult { |
| 76 ExamineResult(WalkStatus s) | 77 ExamineResult(WalkStatus s) |
| 77 : status(s) | 78 : status(s) |
| 78 , viable(false) | 79 , viable(false) |
| 79 , corner(Corner::TopLeft) {} | 80 , corner(Corner::TopLeft) {} |
| 80 | 81 |
| 81 ExamineResult(WalkStatus s, Corner c) | 82 ExamineResult(WalkStatus s, Corner c) |
| 82 : status(s) | 83 : status(s) |
| 83 , viable(true) | 84 , viable(true) |
| 84 , corner(c) {} | 85 , corner(c) {} |
| 85 | 86 |
| 86 WalkStatus status; | 87 WalkStatus status; |
| 87 bool viable; | 88 bool viable; |
| 88 Corner corner; | 89 Corner corner; |
| 89 }; | 90 }; |
| 90 ExamineResult examine(const LayoutObject*) const; | 91 ExamineResult examine(const LayoutObject*) const; |
| 91 | 92 |
| 92 struct AnchorPoint { | 93 IntSize computeAdjustment() const; |
| 93 AnchorPoint() | |
| 94 : m_anchorObject(nullptr) | |
| 95 , m_corner(Corner::TopLeft) {} | |
| 96 | |
| 97 AnchorPoint(LayoutObject* anchorObject, Corner corner) | |
| 98 : m_anchorObject(anchorObject) | |
| 99 , m_corner(corner) {} | |
| 100 | |
| 101 explicit operator bool() const { return m_anchorObject; } | |
| 102 | |
| 103 void clear(); | |
| 104 | |
| 105 // The LayoutObject we should anchor to. | |
| 106 LayoutObject* m_anchorObject; | |
| 107 | |
| 108 // Which corner of m_anchorObject's bounding box to anchor to. | |
| 109 Corner m_corner; | |
| 110 | |
| 111 // Location of m_layoutObject relative to scroller at time of save(). | |
| 112 LayoutPoint m_savedRelativeOffset; | |
| 113 }; | |
| 114 IntSize computeAdjustment(const AnchorPoint&) const; | |
| 115 void adjust(IntSize); | |
| 116 | 94 |
| 117 // The scroller that owns and is adjusted by this ScrollAnchor. | 95 // The scroller that owns and is adjusted by this ScrollAnchor. |
| 118 Member<ScrollableArea> m_scroller; | 96 Member<ScrollableArea> m_scroller; |
| 119 | 97 |
| 120 // The current anchor point. Lazily computed. | 98 // The LayoutObject we should anchor to. |
| 121 AnchorPoint m_current; | 99 LayoutObject* m_anchorObject; |
| 122 | 100 |
| 123 // The anchor point that was used for the most recent non-zero adjustment. | 101 // Which corner of m_anchorObject's bounding box to anchor to. |
| 124 AnchorPoint m_lastAdjusted; | 102 Corner m_corner; |
| 125 | 103 |
| 126 // The size of the most recent non-zero adjustment. | 104 // Location of m_layoutObject relative to scroller at time of save(). |
| 127 IntSize m_lastAdjustment; | 105 LayoutPoint m_savedRelativeOffset; |
| 128 | 106 |
| 129 // True iff the last adjustment was the exact opposite of the one before it. | 107 // Whether the anchor node or an ancestor (up to and including the scroller) |
| 130 // A bounce suggests a circular interaction with a scroll event handler. | 108 // has had a scroll-anchor-disabling style changed since the last layout. |
|
ojan
2016/08/18 18:39:48
Nit: Might want to add a bit more to this so peopl
skobes
2016/08/18 21:43:42
Done.
| |
| 131 bool m_hasBounced; | 109 // This field is recomputed in save() and used to suppress the adjustment. |
| 132 | 110 // See http://bit.ly/sanaclap for more info. |
| 133 // Number of adjustments made since the last clear(). | 111 bool m_scrollAnchorDisablingStyleChanged; |
| 134 int m_adjustmentCount; | |
| 135 }; | 112 }; |
| 136 | 113 |
| 137 } // namespace blink | 114 } // namespace blink |
| 138 | 115 |
| 139 #endif // ScrollAnchor_h | 116 #endif // ScrollAnchor_h |
| OLD | NEW |