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

Side by Side Diff: ui/compositor/overscroll/ui_input_handler.cc

Issue 2189583004: [not for review - epic CL] Adding Elastic+Momentum+Layered scrolling to views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 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 "ui/compositor/overscroll/ui_input_handler.h"
6
7 #include "base/logging.h"
8 #include "cc/trees/layer_tree_impl.h"
9 #include "cc/trees/scroll_node.h"
10 #include "ui/events/event.h"
11
12 namespace ui {
13
14 namespace {
15
16 // Creates a cc::ScrollState from a ui::ScrollEvent, populating fields general
17 // to all event phases. Take care not to put deltas on beginning/end updates,
18 // since InputHandler will DCHECK if they're present.
19 cc::ScrollState CreateScrollState(const ScrollEvent& scroll,
20 bool is_begin,
21 bool is_end) {
22 cc::ScrollStateData scroll_state_data;
23 scroll_state_data.position_x = scroll.x();
24 scroll_state_data.position_y = scroll.y();
25 if (!is_begin && !is_end) {
26 scroll_state_data.delta_x = -scroll.x_offset_ordinal();
27 scroll_state_data.delta_y = -scroll.y_offset_ordinal();
28 }
29 scroll_state_data.is_in_inertial_phase =
30 scroll.momentum_phase() == EventMomentumPhase::INERTIAL_UPDATE;
31 scroll_state_data.is_beginning = is_begin;
32 scroll_state_data.is_ending = is_end;
33 return cc::ScrollState(scroll_state_data);
34 }
35
36 } // namespace
37
38 UIInputHandler::UIInputHandler(
39 const base::WeakPtr<cc::InputHandler>& input_handler)
40 : input_handler_(input_handler.get()) {
41 input_handler_->BindToClient(this);
42 }
43
44 UIInputHandler::~UIInputHandler() {
45 DCHECK(!input_handler_);
46 }
47
48 void UIInputHandler::WillShutdown() {
49 input_handler_ = nullptr;
50 }
51
52 void UIInputHandler::Animate(base::TimeTicks time) {
53 scroll_elasticity_controller_.Animate(time);
54 }
55
56 void UIInputHandler::MainThreadHasStoppedFlinging() {}
57
58 void UIInputHandler::ReconcileElasticOverscrollAndRootScroll() {
59 scroll_elasticity_controller_.ReconcileStretchAndScroll();
60 }
61
62 void UIInputHandler::UpdateRootLayerStateForSynchronousInputHandler(
63 const gfx::ScrollOffset& total_scroll_offset,
64 const gfx::ScrollOffset& max_scroll_offset,
65 const gfx::SizeF& scrollable_size,
66 float page_scale_factor,
67 float min_page_scale_factor,
68 float max_page_scale_factor) {}
69
70 cc::ElementId UIInputHandler::HandleScrollBegin(const ScrollEvent& scroll) {
71 // TODO(tapted): Handle cancelling any fling or elasticity animation,
72 // ScrollUnits::Page, viewport targeting, smooth-scrolling animations. These
73 // are not currently needed for UI scrolling on Mac.
74
75 cc::ScrollState scroll_state = CreateScrollState(scroll, true, false);
76 cc::InputHandler::ScrollStatus scroll_status =
77 input_handler_->ScrollBegin(&scroll_state, cc::InputHandler::WHEEL);
78
79 switch (scroll_status.thread) {
80 case cc::InputHandler::SCROLL_ON_MAIN_THREAD:
81 // Main thread means "not here", but this should only happen if the
82 // scroll status has already entered this mode, or the scrolling layer has
83 // set main_thread_scrolling_reasons to something. Neither of which should
84 // occur for UI scrolling.
85 NOTREACHED();
86 return cc::ElementId();
87 case cc::InputHandler::SCROLL_UNKNOWN:
88 // Unknown usually means a failed hit test. Did not handle.
89 return cc::ElementId();
90 case cc::InputHandler::SCROLL_IGNORED:
91 // Something hit, but it wasn't scrollable. Ignored.
92 return cc::ElementId();
93 case cc::InputHandler::SCROLL_ON_IMPL_THREAD:
94 break;
95 }
96
97 if (!scroll_state.layer_tree_impl()) {
98 LOG(ERROR) << "layer_tree_impl not set - figure out why.";
99 return cc::ElementId();
100 }
101
102 // InputHandler::ScrollBegin() doesn't set the element ID in ScrollState. That
103 // might be nicer than reaching into LayerTreeImpl.
104 cc::LayerImpl* layer =
105 scroll_state.layer_tree_impl()->CurrentlyScrollingLayer();
106 DCHECK(layer);
107
108 // The event may be the start of a momentum portion of touchpad event stream.
109 // The input handler needs to resume scrolling, but elasticity doesn't change.
110 if ((scroll.momentum_phase() == EventMomentumPhase::MAY_BEGIN) == 0)
111 return layer->element_id();
112
113 // Lock scrolling to the thing that was hit.
114 scroll_elasticity_controller_.SetActiveHelper(
115 input_handler_->ScrollElasticityHelperForScrollingLayer());
116
117 // The elasticity controller doesn't reset when observing event streams that
118 // can't result in momentum, but that's handled above by
119 // EventMomentumPhase::MAY_BEGIN. So |leave_momentum| is just the inverse of
120 // |enter_momentum|.
121 bool has_momentum = scroll_state.is_in_inertial_phase();
122 scroll_elasticity_controller_.ObserveRealScrollBegin(has_momentum,
123 !has_momentum);
124 return layer->element_id();
125 }
126
127 void UIInputHandler::HandleScrollUpdate(const ScrollEvent& scroll,
128 cc::ElementId element) {
129 // TODO(tapted): Manage animations, handle pinning a fling curve to an
130 // overscroll direction, handle did_overscroll_root. Most of these don't apply
131 // for Mac events.
132 cc::ScrollState scroll_state = CreateScrollState(scroll, false, false);
133 scroll_state.data()->set_current_native_scrolling_element(element);
134 cc::InputHandlerScrollResult result = input_handler_->ScrollBy(&scroll_state);
135
136 gfx::Vector2dF event_delta(scroll_state.delta_x(), scroll_state.delta_y());
137 scroll_elasticity_controller_.ObserveScrollUpdate(
138 event_delta, result.unused_scroll_delta, scroll.time_stamp(),
139 scroll_state.is_in_inertial_phase());
140 }
141
142 void UIInputHandler::HandleScrollEnd(const ScrollEvent& scroll) {
143 // TODO(tapted): Handle smooth scrolling / animations (i.e. ignore event for
144 // these cases).
145 cc::ScrollState scroll_state = CreateScrollState(scroll, false, true);
146 input_handler_->ScrollEnd(&scroll_state);
147 scroll_elasticity_controller_.ObserveRealScrollEnd(scroll.time_stamp());
148 }
149
150 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/overscroll/ui_input_handler.h ('k') | ui/compositor/overscroll/ui_scroll_input_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698