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

Side by Side Diff: third_party/WebKit/Source/core/layout/ScrollAnchor.h

Issue 2250523003: Implement SANACLAP (http://bit.ly/sanaclap). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improve comment Created 4 years, 4 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 // 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
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 // We suppress scroll anchoring after a style change on the anchor node or
130 // A bounce suggests a circular interaction with a scroll event handler. 108 // one of its ancestors, if that change might have caused the node to move.
131 bool m_hasBounced; 109 // This bit tracks whether we have had a scroll-anchor-disabling style
132 110 // change since the last layout. It is recomputed in save(), and used to
133 // Number of adjustments made since the last clear(). 111 // suppress the adjustment in restore(). More at http://bit.ly/sanaclap.
134 int m_adjustmentCount; 112 bool m_scrollAnchorDisablingStyleChanged;
135 }; 113 };
136 114
137 } // namespace blink 115 } // namespace blink
138 116
139 #endif // ScrollAnchor_h 117 #endif // ScrollAnchor_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutObject.cpp ('k') | third_party/WebKit/Source/core/layout/ScrollAnchor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698