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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/page/scrolling/OverscrollController.h"
6
7 #include "core/frame/VisualViewport.h"
8 #include "core/page/ChromeClient.h"
9 #include "platform/geometry/FloatPoint.h"
10 #include "platform/geometry/FloatSize.h"
11 #include "platform/scroll/ScrollTypes.h"
12
13 namespace blink {
14
15 namespace {
16
17 // Report Overscroll if OverscrollDelta is greater than minimumOverscrollDelta
18 // to maintain consistency as done in the compositor.
19 const float minimumOverscrollDelta = 0.1;
20
21 void adjustOverscroll(FloatSize* unusedDelta)
22 {
23 DCHECK(unusedDelta);
24 if (std::abs(unusedDelta->width()) < minimumOverscrollDelta)
25 unusedDelta->setWidth(0);
26 if (std::abs(unusedDelta->height()) < minimumOverscrollDelta)
27 unusedDelta->setHeight(0);
28 }
29
30 } // namespace
31
32 OverscrollController::OverscrollController(
33 const VisualViewport& visualViewport, ChromeClient& chromeClient)
34 : m_visualViewport(&visualViewport)
35 , m_chromeClient(&chromeClient)
36 {
37 }
38
39 DEFINE_TRACE(OverscrollController)
40 {
41 visitor->trace(m_visualViewport);
42 visitor->trace(m_chromeClient);
43 }
44
45 void OverscrollController::resetAccumulated(
46 bool resetX, bool resetY)
47 {
48 if (resetX)
49 m_accumulatedRootOverscroll.setWidth(0);
50 if (resetY)
51 m_accumulatedRootOverscroll.setHeight(0);
52 }
53
54 void OverscrollController::handleOverscroll(
55 const ScrollResult& scrollResult,
56 const FloatPoint& positionInRootFrame,
57 const FloatSize& velocityInRootFrame)
58 {
59 DCHECK(m_visualViewport);
60 DCHECK(m_chromeClient);
61
62 FloatSize unusedDelta(
63 scrollResult.unusedScrollDeltaX,
64 scrollResult.unusedScrollDeltaY);
65 adjustOverscroll(&unusedDelta);
66
67 FloatSize deltaInViewport = unusedDelta.scaledBy(m_visualViewport->scale());
68 FloatSize velocityInViewport =
69 velocityInRootFrame.scaledBy(m_visualViewport->scale());
70 FloatPoint positionInViewport =
71 m_visualViewport->rootFrameToViewport(positionInRootFrame);
72
73 resetAccumulated(scrollResult.didScrollX, scrollResult.didScrollY);
74
75 if (deltaInViewport != FloatSize()) {
76 m_accumulatedRootOverscroll += deltaInViewport;
77 m_chromeClient->didOverscroll(
78 deltaInViewport,
79 m_accumulatedRootOverscroll,
80 positionInViewport,
81 velocityInViewport);
82 }
83 }
84
85 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698