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

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: Rebase over my own changes 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | third_party/WebKit/Source/core/frame/LocalFrame.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7c0ce545a2e190f042784245f69865a1003d0b39..90aaf5dad4797d90cee9c4a8a39118c19cae7e69 100644
--- a/third_party/WebKit/Source/core/dom/Element.cpp
+++ b/third_party/WebKit/Source/core/dom/Element.cpp
@@ -149,7 +149,6 @@ namespace {
// FrameHosts when elements are moved around.
ScrollCustomizationCallbacks& scrollCustomizationCallbacks()
{
- DCHECK(RuntimeEnabledFeatures::scrollCustomizationEnabled());
DEFINE_STATIC_LOCAL(ScrollCustomizationCallbacks, scrollCustomizationCallbacks, (new ScrollCustomizationCallbacks));
return scrollCustomizationCallbacks;
}
@@ -506,9 +505,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)
{
- DCHECK(RuntimeEnabledFeatures::scrollCustomizationEnabled());
if (scrollState.fullyConsumed())
return;
@@ -550,44 +558,44 @@ void Element::callDistributeScroll(ScrollState& scrollState)
void Element::nativeApplyScroll(ScrollState& scrollState)
{
DCHECK(RuntimeEnabledFeatures::scrollCustomizationEnabled());
+
+ // All elements in the scroll chain should be boxes.
+ DCHECK(!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
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | third_party/WebKit/Source/core/frame/LocalFrame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698