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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/overscroll/ui_input_handler.cc
diff --git a/ui/compositor/overscroll/ui_input_handler.cc b/ui/compositor/overscroll/ui_input_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2a3e2856b73bf6e160b7c52b47596511e8d1a297
--- /dev/null
+++ b/ui/compositor/overscroll/ui_input_handler.cc
@@ -0,0 +1,137 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/compositor/overscroll/ui_input_handler.h"
+
+#include "base/logging.h"
+#include "ui/events/event.h"
+
+namespace ui {
+
+namespace {
+
+// Populate fields general to all event phases. Beginning/end isn't read by the
+// InputHandler, but it will get upset if deltas are put on those updates.
+cc::ScrollState CreateScrollState(const ScrollEvent& scroll,
+ bool begin,
+ bool end) {
+ cc::ScrollStateData scroll_state_data;
+ scroll_state_data.position_x = scroll.x();
+ scroll_state_data.position_y = scroll.y();
+ if (!begin && !end) {
+ scroll_state_data.delta_x = -scroll.x_offset_ordinal();
+ scroll_state_data.delta_y = -scroll.y_offset_ordinal();
+ }
+ scroll_state_data.is_in_inertial_phase =
+ (scroll.momentum_phase() & EM_PHASE_INERTIAL_UPDATE) != 0;
+ scroll_state_data.is_beginning = begin;
+ scroll_state_data.is_ending = end;
+ return cc::ScrollState(scroll_state_data);
+}
+
+} // namespace
+
+UIInputHandler::UIInputHandler(
+ const base::WeakPtr<cc::InputHandler>& input_handler)
+ : input_handler_(input_handler.get()) {
+ input_handler_->BindToClient(this);
+}
+
+UIInputHandler::~UIInputHandler() {
+ DCHECK(!input_handler_);
+}
+
+void UIInputHandler::WillShutdown() {
+ input_handler_ = NULL;
+}
+
+void UIInputHandler::Animate(base::TimeTicks time) {
+ scroll_elasticity_controller_.Animate(time);
+}
+
+void UIInputHandler::MainThreadHasStoppedFlinging() {}
+
+void UIInputHandler::ReconcileElasticOverscrollAndRootScroll() {
+ scroll_elasticity_controller_.ReconcileStretchAndScroll();
+}
+
+void UIInputHandler::UpdateRootLayerStateForSynchronousInputHandler(
+ const gfx::ScrollOffset& total_scroll_offset,
+ const gfx::ScrollOffset& max_scroll_offset,
+ const gfx::SizeF& scrollable_size,
+ float page_scale_factor,
+ float min_page_scale_factor,
+ float max_page_scale_factor) {}
+
+void UIInputHandler::HandleScrollBegin(const ScrollEvent& scroll) {
+ // Not handled: Cancelling a any fling or elasticity animation,
+ // ScrollUnits::Page, viewport targeting, smooth-scrolling animations. These
+ // aren't currently needed for UI scrolling on Mac.
+
+ cc::ScrollState scroll_state = CreateScrollState(scroll, true, false);
+ // Communicate a "resume" to the input handler by calling ScrollBegin with
+ // ScrollStateData::is_beginning set to false.
+ if ((scroll.momentum_phase() &
+ (EM_PHASE_INERTIAL_UPDATE | EM_PHASE_MAY_BEGIN)) ==
+ EM_PHASE_INERTIAL_UPDATE)
+ scroll_state.set_is_beginning(false);
+
+ cc::InputHandler::ScrollStatus scroll_status =
+ input_handler_->ScrollBegin(&scroll_state, cc::InputHandler::WHEEL);
+
+ switch (scroll_status.thread) {
+ case cc::InputHandler::SCROLL_ON_MAIN_THREAD:
+ // Main thread means "not here", but this should only happen if the
+ // scroll status has already entered this mode, or the scrolling layer has
+ // set main_thread_scrolling_reasons to something. Neither of which should
+ // occur for UI scrolling.
+ NOTREACHED();
+ return;
+ case cc::InputHandler::SCROLL_UNKNOWN:
+ return; // Unknown usually means a failed hit test. Did not handle.
+ case cc::InputHandler::SCROLL_IGNORED:
+ return; // Something hit, but it wasn't scrollable. Ignored.
+ case cc::InputHandler::SCROLL_ON_IMPL_THREAD:
+ break;
+ }
+
+ // The event may be the start of a momentum portion of touchpad event stream.
+ // The input handler needs to resume scrolling, but elasticity doesn't change.
+ if ((scroll.momentum_phase() & EM_PHASE_MAY_BEGIN) == 0)
+ return;
+
+ // Lock scrolling to the thing that was hit.
+ scroll_elasticity_controller_.SetActiveHelper(
+ input_handler_->ScrollElasticityHelperForScrollingLayer());
+
+ // The elasticity controller doesn't reset when observing event streams that
+ // can't result in momentum, but that's handled above by EM_PHASE_MAY_BEGIN.
+ // So |leave_momentum| is just the inverse of |enter_momentum|.
+ bool has_momentum = scroll_state.is_in_inertial_phase();
+ scroll_elasticity_controller_.ObserveRealScrollBegin(has_momentum,
+ !has_momentum);
+}
+
+void UIInputHandler::HandleScrollUpdate(const ScrollEvent& scroll) {
+ // Not handled: Early-exit if nothing was hit earlier, animation management,
+ // pinning a fling curve to an overscroll direction, did_overscroll_root.
+ cc::ScrollState scroll_state = CreateScrollState(scroll, false, false);
+ gfx::Point scroll_point(scroll_state.position_x(), scroll_state.position_y());
+ cc::InputHandlerScrollResult scroll_result =
+ input_handler_->ScrollBy(&scroll_state);
+
+ gfx::Vector2dF event_delta(scroll_state.delta_x(), scroll_state.delta_y());
+ scroll_elasticity_controller_.ObserveScrollUpdate(
+ event_delta, scroll_result.unused_scroll_delta, scroll.time_stamp(),
+ scroll_state.is_in_inertial_phase());
+}
+
+void UIInputHandler::HandleScrollEnd(const ScrollEvent& scroll) {
+ // Not handled: Smooth scrolling / animations (i.e. ignore event).
+ cc::ScrollState scroll_state = CreateScrollState(scroll, false, true);
+ input_handler_->ScrollEnd(&scroll_state);
+ scroll_elasticity_controller_.ObserveRealScrollEnd(scroll.time_stamp());
+}
+
+} // namespace ui
« 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