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

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

Issue 1680613002: Adding momentum/overscroll to views:: ScrollViews Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Tableview layout. aaaand I think we are done Created 4 years, 4 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 "ui/events/event.h"
9
10 namespace ui {
11
12 namespace {
13
14 // Populate fields general to all event phases. Beginning/end isn't read by the
15 // InputHandler, but it will get upset if deltas are put on those updates.
16 cc::ScrollState CreateScrollState(const ScrollEvent& scroll,
17 bool begin,
18 bool end) {
19 cc::ScrollStateData scroll_state_data;
20 scroll_state_data.position_x = scroll.x();
21 scroll_state_data.position_y = scroll.y();
22 if (!begin && !end) {
23 scroll_state_data.delta_x = -scroll.x_offset_ordinal();
24 scroll_state_data.delta_y = -scroll.y_offset_ordinal();
25 }
26 scroll_state_data.is_in_inertial_phase =
27 (scroll.momentum_phase() & EM_PHASE_INERTIAL_UPDATE) != 0;
28 scroll_state_data.is_beginning = begin;
29 scroll_state_data.is_ending = end;
30 return cc::ScrollState(scroll_state_data);
31 }
32
33 } // namespace
34
35 UIInputHandler::UIInputHandler(
36 const base::WeakPtr<cc::InputHandler>& input_handler)
37 : input_handler_(input_handler.get()) {
38 input_handler_->BindToClient(this);
39 }
40
41 UIInputHandler::~UIInputHandler() {
42 DCHECK(!input_handler_);
43 }
44
45 void UIInputHandler::WillShutdown() {
46 input_handler_ = NULL;
47 }
48
49 void UIInputHandler::Animate(base::TimeTicks time) {
50 scroll_elasticity_controller_.Animate(time);
51 }
52
53 void UIInputHandler::MainThreadHasStoppedFlinging() {}
54
55 void UIInputHandler::ReconcileElasticOverscrollAndRootScroll() {
56 scroll_elasticity_controller_.ReconcileStretchAndScroll();
57 }
58
59 void UIInputHandler::UpdateRootLayerStateForSynchronousInputHandler(
60 const gfx::ScrollOffset& total_scroll_offset,
61 const gfx::ScrollOffset& max_scroll_offset,
62 const gfx::SizeF& scrollable_size,
63 float page_scale_factor,
64 float min_page_scale_factor,
65 float max_page_scale_factor) {}
66
67 void UIInputHandler::HandleScrollBegin(const ScrollEvent& scroll) {
68 // Not handled: Cancelling a any fling or elasticity animation,
69 // ScrollUnits::Page, viewport targeting, smooth-scrolling animations. These
70 // aren't currently needed for UI scrolling on Mac.
71
72 cc::ScrollState scroll_state = CreateScrollState(scroll, true, false);
73 // Communicate a "resume" to the input handler by calling ScrollBegin with
74 // ScrollStateData::is_beginning set to false.
75 if ((scroll.momentum_phase() &
76 (EM_PHASE_INERTIAL_UPDATE | EM_PHASE_MAY_BEGIN)) ==
77 EM_PHASE_INERTIAL_UPDATE)
78 scroll_state.set_is_beginning(false);
79
80 cc::InputHandler::ScrollStatus scroll_status =
81 input_handler_->ScrollBegin(&scroll_state, cc::InputHandler::WHEEL);
82
83 switch (scroll_status.thread) {
84 case cc::InputHandler::SCROLL_ON_MAIN_THREAD:
85 // Main thread means "not here", but this should only happen if the
86 // scroll status has already entered this mode, or the scrolling layer has
87 // set main_thread_scrolling_reasons to something. Neither of which should
88 // occur for UI scrolling.
89 NOTREACHED();
90 return;
91 case cc::InputHandler::SCROLL_UNKNOWN:
92 return; // Unknown usually means a failed hit test. Did not handle.
93 case cc::InputHandler::SCROLL_IGNORED:
94 return; // Something hit, but it wasn't scrollable. Ignored.
95 case cc::InputHandler::SCROLL_ON_IMPL_THREAD:
96 break;
97 }
98
99 // The event may be the start of a momentum portion of touchpad event stream.
100 // The input handler needs to resume scrolling, but elasticity doesn't change.
101 if ((scroll.momentum_phase() & EM_PHASE_MAY_BEGIN) == 0)
102 return;
103
104 // Lock scrolling to the thing that was hit.
105 scroll_elasticity_controller_.SetActiveHelper(
106 input_handler_->ScrollElasticityHelperForScrollingLayer());
107
108 // The elasticity controller doesn't reset when observing event streams that
109 // can't result in momentum, but that's handled above by EM_PHASE_MAY_BEGIN.
110 // So |leave_momentum| is just the inverse of |enter_momentum|.
111 bool has_momentum = scroll_state.is_in_inertial_phase();
112 scroll_elasticity_controller_.ObserveRealScrollBegin(has_momentum,
113 !has_momentum);
114 }
115
116 void UIInputHandler::HandleScrollUpdate(const ScrollEvent& scroll) {
117 // Not handled: Early-exit if nothing was hit earlier, animation management,
118 // pinning a fling curve to an overscroll direction, did_overscroll_root.
119 cc::ScrollState scroll_state = CreateScrollState(scroll, false, false);
120 gfx::Point scroll_point(scroll_state.position_x(), scroll_state.position_y());
121 cc::InputHandlerScrollResult scroll_result =
122 input_handler_->ScrollBy(&scroll_state);
123
124 gfx::Vector2dF event_delta(scroll_state.delta_x(), scroll_state.delta_y());
125 scroll_elasticity_controller_.ObserveScrollUpdate(
126 event_delta, scroll_result.unused_scroll_delta, scroll.time_stamp(),
127 scroll_state.is_in_inertial_phase());
128 }
129
130 void UIInputHandler::HandleScrollEnd(const ScrollEvent& scroll) {
131 // Not handled: Smooth scrolling / animations (i.e. ignore event).
132 cc::ScrollState scroll_state = CreateScrollState(scroll, false, true);
133 input_handler_->ScrollEnd(&scroll_state);
134 scroll_elasticity_controller_.ObserveRealScrollEnd(scroll.time_stamp());
135 }
136
137 } // 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