1 // Copyright 2015 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 #ifndef CC_INPUT_SCROLL_STATE_H_ 6 #define CC_INPUT_SCROLL_STATE_H_ 7 8 #include <list> 9 #include <memory> 10 11 #include "cc/cc_export.h" 12 #include "cc/input/scroll_state_data.h" 13 #include "ui/gfx/geometry/point.h" 14 #include "ui/gfx/geometry/vector2d.h" 15 16 namespace cc { 17 18 // ScrollState is based on the proposal for scroll customization in blink, found 19 // here: https://goo.gl/1ipTpP. 20 class CC_EXPORT ScrollState { 21 public: 22 explicit ScrollState(ScrollStateData data); 23 ScrollState(const ScrollState& other); 24 ~ScrollState(); 25 26 // Reduce deltas by x, y. 27 void ConsumeDelta(double x, double y); 28 // Positive when scrolling right. delta_x()29 double delta_x() const { return data_.delta_x; } 30 // Positive when scrolling down. delta_y()31 double delta_y() const { return data_.delta_y; } 32 // Positive when scrolling right. delta_x_hint()33 double delta_x_hint() const { return data_.delta_x_hint; } 34 // Positive when scrolling down. delta_y_hint()35 double delta_y_hint() const { return data_.delta_y_hint; } 36 // The location associated with this scroll update. For touch, this is the 37 // position of the finger. For mouse, the location of the cursor. position_x()38 int position_x() const { return data_.position_x; } position_y()39 int position_y() const { return data_.position_y; } 40 velocity_x()41 double velocity_x() const { return data_.velocity_x; } velocity_y()42 double velocity_y() const { return data_.velocity_y; } 43 is_beginning()44 bool is_beginning() const { return data_.is_beginning; } set_is_beginning(bool is_beginning)45 void set_is_beginning(bool is_beginning) { 46 data_.is_beginning = is_beginning; 47 } is_in_inertial_phase()48 bool is_in_inertial_phase() const { return data_.is_in_inertial_phase; } set_is_in_inertial_phase(bool is_in_inertial_phase)49 void set_is_in_inertial_phase(bool is_in_inertial_phase) { 50 data_.is_in_inertial_phase = is_in_inertial_phase; 51 } is_ending()52 bool is_ending() const { return data_.is_ending; } set_is_ending(bool is_ending)53 void set_is_ending(bool is_ending) { data_.is_ending = is_ending; } 54 55 // True if the user interacts directly with the screen, e.g., via touch. is_direct_manipulation()56 bool is_direct_manipulation() const { return data_.is_direct_manipulation; } set_is_direct_manipulation(bool is_direct_manipulation)57 void set_is_direct_manipulation(bool is_direct_manipulation) { 58 data_.is_direct_manipulation = is_direct_manipulation; 59 } 60 delta_consumed_for_scroll_sequence()61 bool delta_consumed_for_scroll_sequence() const { 62 return data_.delta_consumed_for_scroll_sequence; 63 } set_delta_consumed_for_scroll_sequence(bool delta_consumed)64 void set_delta_consumed_for_scroll_sequence(bool delta_consumed) { 65 data_.delta_consumed_for_scroll_sequence = delta_consumed; 66 } 67 set_caused_scroll(bool x,bool y)68 void set_caused_scroll(bool x, bool y) { 69 data_.caused_scroll_x |= x; 70 data_.caused_scroll_y |= y; 71 } 72 caused_scroll_x()73 bool caused_scroll_x() const { return data_.caused_scroll_x; } caused_scroll_y()74 bool caused_scroll_y() const { return data_.caused_scroll_y; } 75 set_is_scroll_chain_cut(bool cut)76 void set_is_scroll_chain_cut(bool cut) { data_.is_scroll_chain_cut = cut; } 77 is_scroll_chain_cut()78 bool is_scroll_chain_cut() const { return data_.is_scroll_chain_cut; } 79 delta_granularity()80 ui::ScrollGranularity delta_granularity() const { 81 return data_.delta_granularity; 82 } 83 data()84 ScrollStateData* data() { return &data_; } 85 86 private: 87 ScrollStateData data_; 88 }; 89 90 } // namespace cc 91 92 #endif // CC_INPUT_SCROLL_STATE_H_ 93