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

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: Make m_visualViewport a WeakMember 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 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 }
43
44 void OverscrollController::resetAccumulated(
45 bool resetX, bool resetY)
46 {
47 if (resetX)
48 m_accumulatedRootOverscroll.setWidth(0);
49 if (resetY)
50 m_accumulatedRootOverscroll.setHeight(0);
51 }
52
53 void OverscrollController::handleOverscroll(
54 const ScrollResult& scrollResult,
55 const FloatPoint& positionInRootFrame,
56 const FloatSize& velocityInRootFrame)
57 {
58 DCHECK(m_visualViewport);
59
60 FloatSize unusedDelta(
61 scrollResult.unusedScrollDeltaX,
62 scrollResult.unusedScrollDeltaY);
63 adjustOverscroll(&unusedDelta);
64
65 FloatSize deltaInViewport = unusedDelta.scaledBy(m_visualViewport->scale());
66 FloatSize velocityInViewport =
67 velocityInRootFrame.scaledBy(m_visualViewport->scale());
68 FloatPoint positionInViewport =
69 m_visualViewport->rootFrameToViewport(positionInRootFrame);
70
71 resetAccumulated(scrollResult.didScrollX, scrollResult.didScrollY);
72
73 if (deltaInViewport != FloatSize()) {
74 m_accumulatedRootOverscroll += deltaInViewport;
75 m_chromeClient.didOverscroll(
76 deltaInViewport,
77 m_accumulatedRootOverscroll,
78 positionInViewport,
79 velocityInViewport);
80 }
81 }
82
83 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698