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

Unified Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 1840113005: Move viewport actions into an ApplyScroll callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/dom/Element.cpp
diff --git a/third_party/WebKit/Source/core/dom/Element.cpp b/third_party/WebKit/Source/core/dom/Element.cpp
index 1d8eb540620047648bc6945377e95e2489f05c72..3ba518509f2afed260d84a8f22c51f11923ccf44 100644
--- a/third_party/WebKit/Source/core/dom/Element.cpp
+++ b/third_party/WebKit/Source/core/dom/Element.cpp
@@ -147,7 +147,6 @@ namespace {
// FrameHosts when elements are moved around.
ScrollCustomizationCallbacks& scrollCustomizationCallbacks()
{
- ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
DEFINE_STATIC_LOCAL(ScrollCustomizationCallbacks, scrollCustomizationCallbacks, (new ScrollCustomizationCallbacks));
return scrollCustomizationCallbacks;
}
@@ -504,9 +503,18 @@ void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback, String na
scrollCustomizationCallbacks().setApplyScroll(this, scrollStateCallback);
}
+void Element::removeApplyScroll()
+{
+ scrollCustomizationCallbacks().removeApplyScroll(this);
+}
+
+ScrollStateCallback* Element::getApplyScroll()
+{
+ return scrollCustomizationCallbacks().getApplyScroll(this);
+}
+
void Element::nativeDistributeScroll(ScrollState& scrollState)
{
- ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
if (scrollState.fullyConsumed())
return;
@@ -548,44 +556,44 @@ void Element::callDistributeScroll(ScrollState& scrollState)
void Element::nativeApplyScroll(ScrollState& scrollState)
{
ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
+
+ // All elements in the scroll chain should be boxes.
+ ASSERT(!layoutObject() || layoutObject()->isBox());
+
if (scrollState.fullyConsumed())
return;
- const double deltaX = scrollState.deltaX();
- const double deltaY = scrollState.deltaY();
- bool scrolled = false;
+ FloatSize delta(scrollState.deltaX(), scrollState.deltaY());
+
+ if (delta.isZero())
+ return;
// TODO(esprehn): This should use updateLayoutIgnorePendingStylesheetsForNode.
- if (deltaY || deltaX)
- document().updateLayoutIgnorePendingStylesheets();
-
- // Handle the scrollingElement separately, as it scrolls the viewport.
- if (this == document().scrollingElement()) {
- FloatSize delta(deltaX, deltaY);
- if (document().frame()->applyScrollDelta(ScrollByPrecisePixel, delta, scrollState.isBeginning()).didScroll()) {
- scrolled = true;
- scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.deltaY());
- }
- } else {
- if (!layoutObject())
- return;
- LayoutBoxItem curBox = LayoutBoxItem(toLayoutBox(layoutObject())).enclosingBox();
- // FIXME: Native scrollers should only consume the scroll they
- // apply. See crbug.com/457765.
- if (deltaX && curBox.scroll(ScrollByPrecisePixel, FloatSize(deltaX, 0)).didScrollX) {
- scrollState.consumeDeltaNative(scrollState.deltaX(), 0);
- scrolled = true;
- }
+ document().updateLayoutIgnorePendingStylesheets();
- if (deltaY && curBox.scroll(ScrollByPrecisePixel, FloatSize(0, deltaY)).didScrollY) {
- scrollState.consumeDeltaNative(0, scrollState.deltaY());
- scrolled = true;
- }
- }
+ LayoutBox* boxToScroll = nullptr;
+
+ // Handle the scrollingElement separately, as it should scroll the viewport.
+ if (this == document().scrollingElement())
+ boxToScroll = document().layoutView();
+ else if (layoutObject())
+ boxToScroll = toLayoutBox(layoutObject());
+
+ if (!boxToScroll)
+ return;
+
+ ScrollResult result =
+ LayoutBoxItem(boxToScroll).enclosingBox().scroll(
+ ScrollByPrecisePixel,
+ delta);
- if (!scrolled)
+ if (!result.didScroll())
return;
+ // FIXME: Native scrollers should only consume the scroll they
+ // apply. See crbug.com/457765.
+ scrollState.consumeDeltaNative(delta.width(), delta.height());
+
// We need to setCurrentNativeScrollingElement in both the
// distributeScroll and applyScroll default implementations so
// that if JS overrides one of these methods, but not the

Powered by Google App Engine
This is Rietveld 408576698