scroll_state.h 3.6 KB

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