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

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

Issue 2394053004: Clear scroll anchor on all parent scrollers from ScrollAnchor::clear (Closed)
Patch Set: review comments Created 4 years, 2 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.cpp
diff --git a/third_party/WebKit/Source/core/layout/ScrollAnchor.cpp b/third_party/WebKit/Source/core/layout/ScrollAnchor.cpp
index f5ca659f11a40a29519966a588cf29d4d31d143d..23a3c6f569b6144a84db638f67df2d22671676ac 100644
--- a/third_party/WebKit/Source/core/layout/ScrollAnchor.cpp
+++ b/third_party/WebKit/Source/core/layout/ScrollAnchor.cpp
@@ -9,6 +9,7 @@
#include "core/layout/LayoutBlockFlow.h"
#include "core/layout/api/LayoutBoxItem.h"
#include "core/layout/line/InlineTextBox.h"
+#include "core/paint/PaintLayer.h"
#include "core/paint/PaintLayerScrollableArea.h"
#include "platform/Histogram.h"
@@ -34,7 +35,7 @@ void ScrollAnchor::setScroller(ScrollableArea* scroller) {
DCHECK(scroller->isRootFrameViewport() || scroller->isFrameView() ||
scroller->isPaintLayerScrollableArea());
m_scroller = scroller;
- clear();
+ clearSelf();
}
// TODO(pilgrim): Replace all instances of scrollerLayoutBox with
@@ -222,7 +223,7 @@ void ScrollAnchor::save() {
? scrollOffset.height()
: scrollOffset.width();
if (blockDirectionScrollOffset == 0) {
- clear();
+ clearSelf();
return;
}
@@ -278,7 +279,7 @@ void ScrollAnchor::restore() {
// Note that we only clear if the adjustment would have been non-zero.
// This minimizes redundant calls to findAnchor.
// TODO(skobes): add UMA metric for this.
- clear();
+ clearSelf();
DEFINE_STATIC_LOCAL(EnumerationHistogram, suppressedBySanaclapHistogram,
("Layout.ScrollAnchor.SuppressedBySanaclap", 2));
@@ -298,12 +299,36 @@ void ScrollAnchor::restore() {
UseCounter::ScrollAnchored);
}
-void ScrollAnchor::clear() {
+void ScrollAnchor::clearSelf(bool unconditionally) {
LayoutObject* anchorObject = m_anchorObject;
m_anchorObject = nullptr;
if (anchorObject)
- anchorObject->maybeClearIsScrollAnchorObject();
+ anchorObject->clearIsScrollAnchorObject(unconditionally);
+}
+
+void ScrollAnchor::clear() {
+ LayoutObject* layoutObject =
+ m_anchorObject ? m_anchorObject : scrollerLayoutBox(m_scroller);
+ PaintLayer* layer = nullptr;
+ if (LayoutObject* parent = layoutObject->parent())
+ layer = parent->enclosingLayer();
+
+ // Walk up the layer tree to clear any scroll anchors.
+ while (layer) {
+ if (PaintLayerScrollableArea* scrollableArea = layer->getScrollableArea()) {
+ ScrollAnchor* anchor = scrollableArea->scrollAnchor();
+ DCHECK(anchor);
+ anchor->clearSelf(true);
+ }
+ layer = layer->parent();
+ }
+
+ if (FrameView* view = layoutObject->frameView()) {
+ ScrollAnchor* anchor = view->scrollAnchor();
+ DCHECK(anchor);
+ anchor->clearSelf(true);
+ }
}
bool ScrollAnchor::refersTo(const LayoutObject* layoutObject) const {
@@ -312,7 +337,7 @@ bool ScrollAnchor::refersTo(const LayoutObject* layoutObject) const {
void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) {
if (m_anchorObject == layoutObject)
- clear();
+ clearSelf();
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/layout/ScrollAnchor.h ('k') | third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698