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

Side by Side Diff: third_party/WebKit/Source/core/page/scrolling/ViewportScrollCallback.cpp

Issue 1840113005: Move viewport actions into an ApplyScroll callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disabled track-word-breaking.html on release too and remove position in defaultWheelEventHandler 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 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/ViewportScrollCallback.h"
6
7 #include "core/dom/Document.h"
8 #include "core/frame/FrameHost.h"
9 #include "core/frame/FrameView.h"
10 #include "core/frame/Settings.h"
11 #include "core/frame/TopControls.h"
12 #include "core/frame/VisualViewport.h"
13 #include "core/input/EventHandler.h"
14 #include "core/layout/LayoutView.h"
15 #include "core/page/scrolling/ScrollState.h"
16 #include "platform/geometry/FloatSize.h"
17 #include "platform/scroll/ScrollableArea.h"
18
19 namespace blink {
20
21 ViewportScrollCallback::ViewportScrollCallback(Document& document,
22 FrameHost& frameHost)
23 : m_document(&document)
24 , m_frameHost(&frameHost)
25 {
26 // Only the root document can have a viewport scroll callback for now.
27 ASSERT(!document.ownerElement());
28 }
29
30 ViewportScrollCallback::~ViewportScrollCallback()
31 {
32 }
33
34 DEFINE_TRACE(ViewportScrollCallback)
35 {
36 visitor->trace(m_frameHost);
37 visitor->trace(m_document);
38 ScrollStateCallback::trace(visitor);
39 }
40
41 bool ViewportScrollCallback::shouldScrollTopControls(const FloatSize& delta,
42 ScrollGranularity granularity) const
43 {
44 if (granularity != ScrollByPixel && granularity != ScrollByPrecisePixel)
45 return false;
46
47 ScrollableArea* rootFrameViewport = getRootFrameViewport();
48 if (!rootFrameViewport)
49 return false;
50
51 DoublePoint maxScroll = rootFrameViewport->maximumScrollPositionDouble();
52 DoublePoint scrollPosition = rootFrameViewport->scrollPositionDouble();
53
54 // Always give the delta to the top controls if the scroll is in
55 // the direction to show the top controls. If it's in the
56 // direction to hide the top controls, only give the delta to the
57 // top controls when the frame can scroll.
58 return delta.height() < 0 || scrollPosition.y() < maxScroll.y();
59 }
60
61 void ViewportScrollCallback::handleEvent(ScrollState* state)
62 {
63 TopControls& topControls = m_frameHost->topControls();
64
65 // Scroll top controls.
66 if (state->isBeginning())
67 topControls.scrollBegin();
68
69 FloatSize delta(state->deltaX(), state->deltaY());
70 ScrollGranularity granularity =
71 ScrollGranularity(static_cast<int>(state->deltaGranularity()));
72 FloatSize remainingDelta = delta;
73
74 if (shouldScrollTopControls(delta, granularity))
75 remainingDelta = topControls.scrollBy(delta);
76
77 bool topControlsConsumedScroll = remainingDelta.height() != delta.height();
78
79 // Do the native scroll.
80 ScrollableArea* rootFrameViewport = getRootFrameViewport();
81 if (!rootFrameViewport)
82 return;
83
84 ScrollResult result =
85 rootFrameViewport->userScroll(granularity, remainingDelta);
86
87 // We consider top controls movement to be scrolling.
88 result.didScrollY |= topControlsConsumedScroll;
89
90 // Handle Overscroll.
91 FloatPoint position(state->startPositionX(), state->startPositionY());
92 FloatSize velocity(state->velocityX(), state->velocityY());
93
94 m_document->frame()->eventHandler().handleOverscroll(
95 result, position, velocity);
96
97 // The viewport consumes everything.
98 state->consumeDeltaNative(
99 state->deltaX() - result.unusedScrollDeltaX,
100 state->deltaY() - result.unusedScrollDeltaY);
101 }
102
103 ScrollableArea* ViewportScrollCallback::getRootFrameViewport() const
104 {
105 if (!m_document->layoutView())
106 return nullptr;
107
108 FrameView* frameView = m_document->layoutView()->frameView();
109 if (!frameView)
110 return nullptr;
111
112 ScrollableArea* rootFrameViewport = frameView->getScrollableArea();
113 ASSERT(rootFrameViewport);
114
115 return rootFrameViewport;
116 }
117
118 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698