| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/compositor/overscroll/ui_input_handler.h" | 5 #include "ui/compositor/overscroll/ui_input_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "cc/trees/layer_tree_impl.h" | 8 #include "cc/trees/layer_tree_impl.h" |
| 9 #include "cc/trees/scroll_node.h" | 9 #include "cc/trees/scroll_node.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 UIInputHandler::~UIInputHandler() { | 41 UIInputHandler::~UIInputHandler() { |
| 42 DCHECK(!input_handler_); | 42 DCHECK(!input_handler_); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void UIInputHandler::WillShutdown() { | 45 void UIInputHandler::WillShutdown() { |
| 46 input_handler_ = nullptr; | 46 input_handler_ = nullptr; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void UIInputHandler::Animate(base::TimeTicks time) {} | 49 void UIInputHandler::Animate(base::TimeTicks time) { |
| 50 scroll_elasticity_controller_.Animate(time); |
| 51 } |
| 50 | 52 |
| 51 void UIInputHandler::MainThreadHasStoppedFlinging() {} | 53 void UIInputHandler::MainThreadHasStoppedFlinging() {} |
| 52 | 54 |
| 53 void UIInputHandler::ReconcileElasticOverscrollAndRootScroll() {} | 55 void UIInputHandler::ReconcileElasticOverscrollAndRootScroll() { |
| 56 scroll_elasticity_controller_.ReconcileStretchAndScroll(); |
| 57 } |
| 54 | 58 |
| 55 void UIInputHandler::UpdateRootLayerStateForSynchronousInputHandler( | 59 void UIInputHandler::UpdateRootLayerStateForSynchronousInputHandler( |
| 56 const gfx::ScrollOffset& total_scroll_offset, | 60 const gfx::ScrollOffset& total_scroll_offset, |
| 57 const gfx::ScrollOffset& max_scroll_offset, | 61 const gfx::ScrollOffset& max_scroll_offset, |
| 58 const gfx::SizeF& scrollable_size, | 62 const gfx::SizeF& scrollable_size, |
| 59 float page_scale_factor, | 63 float page_scale_factor, |
| 60 float min_page_scale_factor, | 64 float min_page_scale_factor, |
| 61 float max_page_scale_factor) {} | 65 float max_page_scale_factor) {} |
| 62 | 66 |
| 63 void UIInputHandler::HandleScrollUpdate(const ScrollEvent& scroll, | 67 void UIInputHandler::HandleScrollUpdate(const ScrollEvent& scroll, |
| 64 cc::ElementId element) { | 68 cc::ElementId element) { |
| 65 cc::ScrollState scroll_state = CreateScrollState(scroll, false); | 69 cc::ScrollState scroll_state = CreateScrollState(scroll, false); |
| 66 scroll_state.data()->set_current_native_scrolling_element(element); | 70 scroll_state.data()->set_current_native_scrolling_element(element); |
| 67 input_handler_->ScrollBy(&scroll_state); | 71 cc::InputHandlerScrollResult result = input_handler_->ScrollBy(&scroll_state); |
| 72 |
| 73 base::WeakPtr<cc::ScrollElasticityHelper> overscroll_helper = |
| 74 input_handler_->ScrollElasticityHelperForScrollingLayer(); |
| 75 if (!overscroll_helper) |
| 76 return; // E.g., the scrolling layer doesn't support overscroll. |
| 77 |
| 78 scroll_elasticity_controller_.SetActiveHelper(overscroll_helper); |
| 79 |
| 80 gfx::Vector2dF event_delta(scroll_state.delta_x(), scroll_state.delta_y()); |
| 81 bool begin = scroll.momentum_phase() == EventMomentumPhase::MAY_BEGIN; |
| 82 bool momentum_begin = event_delta.IsZero() && |
| 83 scroll.momentum_phase() == EventMomentumPhase::INERTIAL_UPDATE; |
| 84 |
| 85 scroll_elasticity_controller_.ObserveRealScrollBegin(momentum_begin, begin); |
| 86 scroll_elasticity_controller_.ObserveScrollUpdate( |
| 87 event_delta, result.unused_scroll_delta, scroll.time_stamp(), |
| 88 scroll_state.is_in_inertial_phase()); |
| 68 } | 89 } |
| 69 | 90 |
| 70 void UIInputHandler::HandleScrollEnd(const ScrollEvent& scroll) { | 91 void UIInputHandler::HandleScrollEnd(const ScrollEvent& scroll) { |
| 71 cc::ScrollState scroll_state = CreateScrollState(scroll, true); | 92 cc::ScrollState scroll_state = CreateScrollState(scroll, true); |
| 72 input_handler_->ScrollEnd(&scroll_state); | 93 input_handler_->ScrollEnd(&scroll_state); |
| 94 scroll_elasticity_controller_.ObserveRealScrollEnd(scroll.time_stamp()); |
| 73 } | 95 } |
| 74 | 96 |
| 75 } // namespace ui | 97 } // namespace ui |
| OLD | NEW |