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

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

Issue 988823003: Use scroll customization primitives for touch scrolling (behind REF). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address rbyers' nit. Created 5 years, 9 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 | « Source/core/dom/Element.h ('k') | Source/core/frame/LocalFrame.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index aebce70c1eea268caebacf66d177720ec94b3cd8..8212305406095a4e98f0d94f33addd1433220b92 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -112,6 +112,7 @@
#include "core/page/Page.h"
#include "core/page/PointerLockController.h"
#include "core/page/SpatialNavigation.h"
+#include "core/page/scrolling/ScrollState.h"
#include "core/paint/DeprecatedPaintLayer.h"
#include "core/svg/SVGDocumentExtensions.h"
#include "core/svg/SVGElement.h"
@@ -481,6 +482,78 @@ void Element::scrollIntoViewIfNeeded(bool centerIfNeeded)
layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
}
+void Element::distributeScroll(ScrollState& scrollState)
+{
+ ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
+ if (scrollState.fullyConsumed())
+ return;
+
+ scrollState.distributeToScrollChainDescendant();
+
+ // If the scroll doesn't propagate, and we're currently scrolling
+ // an element other than this one, prevent the scroll from
+ // propagating to this element.
+ if (!scrollState.shouldPropagate()
+ && scrollState.deltaConsumedForScrollSequence()
+ && scrollState.currentNativeScrollingElement() != this) {
+ return;
+ }
+
+ const double deltaX = scrollState.deltaX();
+ const double deltaY = scrollState.deltaY();
+
+ applyScroll(scrollState);
+
+ if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY())
+ scrollState.setCurrentNativeScrollingElement(this);
+}
+
+void Element::applyScroll(ScrollState& scrollState)
+{
+ ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
+ if (scrollState.fullyConsumed())
+ return;
+
+ const double deltaX = scrollState.deltaX();
+ const double deltaY = scrollState.deltaY();
+ bool scrolled = false;
+
+ // Handle the documentElement separately, as it scrolls the FrameView.
+ if (this == document().documentElement()) {
+ FloatSize delta(deltaX, deltaY);
+ if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning())) {
+ scrolled = true;
+ scrollState.consumeDeltaNative(scrollState.deltaX(), scrollState.deltaY());
+ }
+ } else {
+ if (!layoutObject())
+ return;
+ LayoutBox* curBox = layoutObject()->enclosingBox();
+ // FIXME: Native scrollers should only consume the scroll they
+ // apply. See crbug.com/457765.
+ if (deltaX && curBox->scroll(ScrollLeft, ScrollByPrecisePixel, deltaX)) {
+ scrollState.consumeDeltaNative(scrollState.deltaX(), 0);
+ scrolled = true;
+ }
+
+ if (deltaY && curBox->scroll(ScrollUp, ScrollByPrecisePixel, deltaY)) {
+ scrollState.consumeDeltaNative(0, scrollState.deltaY());
+ scrolled = true;
+ }
+ }
+
+ if (!scrolled)
+ return;
+
+ // We need to setCurrentNativeScrollingElement in both the
+ // distributeScroll and applyScroll default implementations so
+ // that if JS overrides one of these methods, but not the
+ // other, this bookkeeping remains accurate.
+ scrollState.setCurrentNativeScrollingElement(this);
+ if (scrollState.fromUserInput())
+ document().frame()->view()->setWasScrolledByUser(true);
+};
+
static float localZoomForRenderer(LayoutObject& renderer)
{
// FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/frame/LocalFrame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698