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

Unified Diff: third_party/WebKit/Source/core/layout/ScrollAnchor.h

Issue 1971423002: Implement bounce suppression in ScrollAnchor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address ymalik review comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ScrollAnchor.h
diff --git a/third_party/WebKit/Source/core/layout/ScrollAnchor.h b/third_party/WebKit/Source/core/layout/ScrollAnchor.h
index 10b8c764ac1fd1a4e77caacc2e3149d1213207f2..0847701788399f3293dd5eeee4c35101e104469f 100644
--- a/third_party/WebKit/Source/core/layout/ScrollAnchor.h
+++ b/third_party/WebKit/Source/core/layout/ScrollAnchor.h
@@ -24,9 +24,10 @@ public:
// The LayoutObject we are currently anchored to. Lazily computed during
// save() and cached until the next call to clear().
- LayoutObject* anchorObject() const { return m_anchorObject; }
+ LayoutObject* anchorObject() const { return m_current.m_anchorObject; }
- // Invalidates the anchor.
+ // Indicates that the next save() should compute a new anchor. (In certain
+ // cases the previous anchor will be reused; see comments in restore.)
void clear();
// Records the anchor's location in relation to the scroller. Should be
@@ -44,7 +45,13 @@ public:
};
// Which corner of the anchor object we are currently anchored to.
// Only meaningful if anchorObject() is non-null.
- Corner corner() const { return m_corner; }
+ Corner corner() const { return m_current.m_corner; }
+
+ // Checks if we hold any references to the specified object.
+ bool refersTo(const LayoutObject*) const;
+
+ // Notifies us that an object will be removed from the layout tree.
+ void notifyRemoved(LayoutObject*);
DEFINE_INLINE_TRACE() { visitor->trace(m_scroller); }
@@ -74,17 +81,46 @@ private:
};
ExamineResult examine(const LayoutObject*) const;
+ struct AnchorPoint {
+ AnchorPoint()
+ : m_anchorObject(nullptr)
+ , m_corner(Corner::TopLeft) {}
+
+ AnchorPoint(LayoutObject* anchorObject, Corner corner)
+ : m_anchorObject(anchorObject)
+ , m_corner(corner) {}
+
+ explicit operator bool() const { return m_anchorObject; }
+
+ void clear();
+
+ // The LayoutObject we should anchor to.
+ LayoutObject* m_anchorObject;
+
+ // Which corner of m_anchorObject's bounding box to anchor to.
+ Corner m_corner;
+
+ // Location of m_layoutObject relative to scroller at time of save().
+ LayoutPoint m_savedRelativeOffset;
+ };
+ IntSize computeAdjustment(const AnchorPoint&) const;
+ void adjust(IntSize);
+
// The scroller that owns and is adjusted by this ScrollAnchor.
Member<ScrollableArea> m_scroller;
- // The LayoutObject we should anchor to. Lazily computed.
- LayoutObject* m_anchorObject;
+ // The current anchor point. Lazily computed.
+ AnchorPoint m_current;
+
+ // The anchor point that was used for the most recent non-zero adjustment.
+ AnchorPoint m_lastAdjusted;
- // Which corner of m_anchorObject's bounding box to anchor to.
- Corner m_corner;
+ // The size of the most recent non-zero adjustment.
+ IntSize m_lastAdjustment;
- // Location of m_layoutObject relative to scroller at time of save().
- LayoutPoint m_savedRelativeOffset;
+ // True iff the last adjustment was the exact opposite of the one before it.
+ // A bounce suggests a circular interaction with a scroll event handler.
+ bool m_hasBounced;
};
} // namespace blink
« 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