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 13 matching lines...) Expand all Loading... | |
24 ~ScrollAnchor(); | 24 ~ScrollAnchor(); |
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 // notifyBeforeLayout() and cached until the next call to clear(). |
35 LayoutObject* anchorObject() const { return m_anchorObject; } | 35 LayoutObject* anchorObject() const { return m_anchorObject; } |
36 | 36 |
37 // Indicates that the next save() should compute a new anchor for the | 37 // Indicates that this ScrollAnchor, and all ancestor ScrollAnchors, should |
38 // containing scroller and all ancestor scrollers. | 38 // compute new anchor nodes on their next notifyBeforeLayout(). |
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 notifyBeforeLayout(); |
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 // Should be called at the end of the animation frame. |
47 // the scroller has been laid out. | 47 void adjust(); |
48 void restore(); | |
49 | 48 |
50 enum class Corner { | 49 enum class Corner { |
51 TopLeft = 0, | 50 TopLeft = 0, |
52 TopRight, | 51 TopRight, |
53 }; | 52 }; |
54 // Which corner of the anchor object we are currently anchored to. | 53 // Which corner of the anchor object we are currently anchored to. |
55 // Only meaningful if anchorObject() is non-null. | 54 // Only meaningful if anchorObject() is non-null. |
56 Corner corner() const { return m_corner; } | 55 Corner corner() const { return m_corner; } |
57 | 56 |
58 // Checks if we hold any references to the specified object. | 57 // Checks if we hold any references to the specified object. |
59 bool refersTo(const LayoutObject*) const; | 58 bool refersTo(const LayoutObject*) const; |
60 | 59 |
61 // Notifies us that an object will be removed from the layout tree. | 60 // Notifies us that an object will be removed from the layout tree. |
62 void notifyRemoved(LayoutObject*); | 61 void notifyRemoved(LayoutObject*); |
63 | 62 |
64 DEFINE_INLINE_TRACE() { visitor->trace(m_scroller); } | 63 DEFINE_INLINE_TRACE() { visitor->trace(m_scroller); } |
65 | 64 |
66 private: | 65 private: |
67 // Indicates that the next save() should compute a new anchor for the | 66 // Indicates that this ScrollAnchor should compute a new anchor node on the |
68 // containing scroller. | 67 // next call to notifyBeforeLayout(). |
69 void clearSelf(bool unconditionally = false); | 68 void clearSelf(bool unconditionally = false); |
70 | 69 |
71 void findAnchor(); | 70 void findAnchor(); |
72 bool computeScrollAnchorDisablingStyleChanged(); | 71 bool computeScrollAnchorDisablingStyleChanged(); |
73 | 72 |
74 enum WalkStatus { Skip = 0, Constrain, Continue, Return }; | 73 enum WalkStatus { Skip = 0, Constrain, Continue, Return }; |
75 struct ExamineResult { | 74 struct ExamineResult { |
76 ExamineResult(WalkStatus s) | 75 ExamineResult(WalkStatus s) |
77 : status(s), viable(false), corner(Corner::TopLeft) {} | 76 : status(s), viable(false), corner(Corner::TopLeft) {} |
78 | 77 |
79 ExamineResult(WalkStatus s, Corner c) | 78 ExamineResult(WalkStatus s, Corner c) |
80 : status(s), viable(true), corner(c) {} | 79 : status(s), viable(true), corner(c) {} |
81 | 80 |
82 WalkStatus status; | 81 WalkStatus status; |
83 bool viable; | 82 bool viable; |
84 Corner corner; | 83 Corner corner; |
85 }; | 84 }; |
86 ExamineResult examine(const LayoutObject*) const; | 85 ExamineResult examine(const LayoutObject*) const; |
87 | 86 |
88 IntSize computeAdjustment() const; | 87 IntSize computeAdjustment() const; |
89 | 88 |
90 // The scroller that owns and is adjusted by this ScrollAnchor. | 89 // The scroller to be adjusted by this ScrollAnchor. This is also the scroller |
90 // that owns us, unless it is the RootFrameViewport in which case we are owned | |
91 // by the main frame's FrameView. | |
ymalik
2016/10/13 13:05:40
s/owned by the main frame's FrameView/owned by Roo
bokan
2016/10/13 14:23:57
Right, if we swapped the layout viewport using doc
skobes
2016/10/13 17:21:37
Done.
skobes
2016/10/13 17:21:37
Acknowledged.
| |
91 Member<ScrollableArea> m_scroller; | 92 Member<ScrollableArea> m_scroller; |
92 | 93 |
93 // The LayoutObject we should anchor to. | 94 // The LayoutObject we should anchor to. |
94 LayoutObject* m_anchorObject; | 95 LayoutObject* m_anchorObject; |
95 | 96 |
96 // Which corner of m_anchorObject's bounding box to anchor to. | 97 // Which corner of m_anchorObject's bounding box to anchor to. |
97 Corner m_corner; | 98 Corner m_corner; |
98 | 99 |
99 // Location of m_layoutObject relative to scroller at time of save(). | 100 // Location of m_layoutObject relative to scroller at time of |
101 // notifyBeforeLayout(). | |
100 LayoutPoint m_savedRelativeOffset; | 102 LayoutPoint m_savedRelativeOffset; |
101 | 103 |
102 // We suppress scroll anchoring after a style change on the anchor node or | 104 // We suppress scroll anchoring after a style change on the anchor node or |
103 // one of its ancestors, if that change might have caused the node to move. | 105 // one of its ancestors, if that change might have caused the node to move. |
104 // This bit tracks whether we have had a scroll-anchor-disabling style | 106 // This bit tracks whether we have had a scroll-anchor-disabling style |
105 // change since the last layout. It is recomputed in save(), and used to | 107 // change since the last layout. It is recomputed in notifyBeforeLayout(), |
106 // suppress the adjustment in restore(). More at http://bit.ly/sanaclap. | 108 // and used to suppress adjustment in adjust(). See http://bit.ly/sanaclap. |
107 bool m_scrollAnchorDisablingStyleChanged; | 109 bool m_scrollAnchorDisablingStyleChanged; |
108 | 110 |
109 // True iff save has been called, and restore has not been called since | 111 // True iff an adjustment check has been queued with the FrameView but not yet |
110 // the call to save. In this state, additional calls to save are ignored, | 112 // performed. |
111 // to make things easier for multi-pass layout modes such as flexbox. | 113 bool m_queued; |
112 // TODO(skobes): explore anchoring at frame boundaries instead of layouts, | |
113 // which would allow this field to be removed. | |
114 bool m_saved; | |
115 }; | 114 }; |
116 | 115 |
117 } // namespace blink | 116 } // namespace blink |
118 | 117 |
119 #endif // ScrollAnchor_h | 118 #endif // ScrollAnchor_h |
OLD | NEW |