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

Unified Diff: third_party/WebKit/Source/core/page/scrolling/OverscrollController.cpp

Issue 1915783002: Move overscroll logic out of EventHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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/page/scrolling/OverscrollController.cpp
diff --git a/third_party/WebKit/Source/core/page/scrolling/OverscrollController.cpp b/third_party/WebKit/Source/core/page/scrolling/OverscrollController.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..81e0723c16e1593e76913d7c8d9347fd8e0413dd
--- /dev/null
+++ b/third_party/WebKit/Source/core/page/scrolling/OverscrollController.cpp
@@ -0,0 +1,85 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/page/scrolling/OverscrollController.h"
+
+#include "core/frame/VisualViewport.h"
+#include "core/page/ChromeClient.h"
+#include "platform/geometry/FloatPoint.h"
+#include "platform/geometry/FloatSize.h"
+#include "platform/scroll/ScrollTypes.h"
+
+namespace blink {
+
+namespace {
+
+// Report Overscroll if OverscrollDelta is greater than minimumOverscrollDelta
+// to maintain consistency as done in the compositor.
+const float minimumOverscrollDelta = 0.1;
+
+void adjustOverscroll(FloatSize* unusedDelta)
+{
+ DCHECK(unusedDelta);
+ if (std::abs(unusedDelta->width()) < minimumOverscrollDelta)
+ unusedDelta->setWidth(0);
+ if (std::abs(unusedDelta->height()) < minimumOverscrollDelta)
+ unusedDelta->setHeight(0);
+}
+
+} // namespace
+
+OverscrollController::OverscrollController(
+ const VisualViewport& visualViewport, ChromeClient& chromeClient)
+ : m_visualViewport(&visualViewport)
+ , m_chromeClient(&chromeClient)
+{
+}
+
+DEFINE_TRACE(OverscrollController)
+{
+ visitor->trace(m_visualViewport);
+ visitor->trace(m_chromeClient);
+}
+
+void OverscrollController::resetAccumulated(
+ bool resetX, bool resetY)
+{
+ if (resetX)
+ m_accumulatedRootOverscroll.setWidth(0);
+ if (resetY)
+ m_accumulatedRootOverscroll.setHeight(0);
+}
+
+void OverscrollController::handleOverscroll(
+ const ScrollResult& scrollResult,
+ const FloatPoint& positionInRootFrame,
+ const FloatSize& velocityInRootFrame)
+{
+ DCHECK(m_visualViewport);
+ DCHECK(m_chromeClient);
+
+ FloatSize unusedDelta(
+ scrollResult.unusedScrollDeltaX,
+ scrollResult.unusedScrollDeltaY);
+ adjustOverscroll(&unusedDelta);
+
+ FloatSize deltaInViewport = unusedDelta.scaledBy(m_visualViewport->scale());
+ FloatSize velocityInViewport =
+ velocityInRootFrame.scaledBy(m_visualViewport->scale());
+ FloatPoint positionInViewport =
+ m_visualViewport->rootFrameToViewport(positionInRootFrame);
+
+ resetAccumulated(scrollResult.didScrollX, scrollResult.didScrollY);
+
+ if (deltaInViewport != FloatSize()) {
+ m_accumulatedRootOverscroll += deltaInViewport;
+ m_chromeClient->didOverscroll(
+ deltaInViewport,
+ m_accumulatedRootOverscroll,
+ positionInViewport,
+ velocityInViewport);
+ }
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698