summaryrefslogtreecommitdiffstats
path: root/cc/input/scroll_state.h
blob: 3e6f92cf972e3b7bdd868d575187ef9464f68231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2015 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.

#ifndef CC_INPUT_SCROLL_STATE_H_
#define CC_INPUT_SCROLL_STATE_H_

#include <list>

#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/input/scroll_state_data.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h"

namespace cc {

class LayerTreeImpl;

// ScrollState is based on the proposal for scroll customization in blink, found
// here: https://goo.gl/1ipTpP.
class CC_EXPORT ScrollState {
 public:
  explicit ScrollState(ScrollStateData data);
  ScrollState(const ScrollState& other);
  ~ScrollState();

  // Reduce deltas by x, y.
  void ConsumeDelta(double x, double y);
  // Pops the first layer off of |scroll_chain_| and calls
  // |DistributeScroll| on it.
  void DistributeToScrollChainDescendant();
  // Positive when scrolling left.
  double delta_x() const { return data_.delta_x; }
  // Positive when scrolling up.
  double delta_y() const { return data_.delta_y; }
  // The location the scroll started at. For touch, the starting
  // position of the finger. For mouse, the location of the cursor.
  int start_position_x() const { return data_.start_position_x; }
  int start_position_y() const { return data_.start_position_y; }

  double velocity_x() const { return data_.velocity_x; }
  double velocity_y() const { return data_.velocity_y; }

  bool is_beginning() const { return data_.is_beginning; }
  void set_is_beginning(bool is_beginning) {
    data_.is_beginning = is_beginning;
  }
  bool is_in_inertial_phase() const { return data_.is_in_inertial_phase; }
  void set_is_in_inertial_phase(bool is_in_inertial_phase) {
    data_.is_in_inertial_phase = is_in_inertial_phase;
  }
  bool is_ending() const { return data_.is_ending; }
  void set_is_ending(bool is_ending) { data_.is_ending = is_ending; }

  // True if this scroll is allowed to bubble upwards.
  bool should_propagate() const { return data_.should_propagate; }
  // True if the user interacts directly with the screen, e.g., via touch.
  bool is_direct_manipulation() const { return data_.is_direct_manipulation; }
  void set_is_direct_manipulation(bool is_direct_manipulation) {
    data_.is_direct_manipulation = is_direct_manipulation;
  }

  void set_scroll_chain_and_layer_tree(
      const std::list<const ScrollNode*>& scroll_chain,
      LayerTreeImpl* layer_tree_impl) {
    layer_tree_impl_ = layer_tree_impl;
    scroll_chain_ = scroll_chain;
  }

  void set_current_native_scrolling_node(ScrollNode* scroll_node) {
    data_.set_current_native_scrolling_node(scroll_node);
  }

  ScrollNode* current_native_scrolling_node() const {
    return data_.current_native_scrolling_node();
  }

  bool delta_consumed_for_scroll_sequence() const {
    return data_.delta_consumed_for_scroll_sequence;
  }
  void set_delta_consumed_for_scroll_sequence(bool delta_consumed) {
    data_.delta_consumed_for_scroll_sequence = delta_consumed;
  }

  bool FullyConsumed() const { return !data_.delta_x && !data_.delta_y; }

  void set_caused_scroll(bool x, bool y) {
    data_.caused_scroll_x |= x;
    data_.caused_scroll_y |= y;
  }

  bool caused_scroll_x() const { return data_.caused_scroll_x; }
  bool caused_scroll_y() const { return data_.caused_scroll_y; }

  LayerTreeImpl* layer_tree_impl() { return layer_tree_impl_; }
  ScrollStateData* data() { return &data_; }

 private:
  ScrollStateData data_;
  LayerTreeImpl* layer_tree_impl_;
  std::list<const ScrollNode*> scroll_chain_;
};

}  // namespace cc

#endif  // CC_INPUT_SCROLL_STATE_H_