Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / input / scroll_state.h
blob2cd437d0ea706413947f39c9569ee6aa23c22618
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.
5 #ifndef CC_INPUT_SCROLL_STATE_H_
6 #define CC_INPUT_SCROLL_STATE_H_
8 #include <list>
10 #include "cc/base/cc_export.h"
12 namespace cc {
14 class LayerImpl;
16 // ScrollState is based on the proposal for scroll customization in blink, found
17 // here: https://goo.gl/1ipTpP.
18 class CC_EXPORT ScrollState {
19 public:
20 ScrollState(double delta_x,
21 double delta_y,
22 int start_position_x,
23 int start_position_y,
24 bool should_propagate,
25 bool delta_consumed_for_scroll_sequence,
26 bool is_direct_manipulation);
27 ~ScrollState();
29 // Reduce deltas by x, y.
30 void ConsumeDelta(double x, double y);
31 // Pops the first layer off of |scroll_chain_| and calls
32 // |DistributeScroll| on it.
33 void DistributeToScrollChainDescendant();
34 // Positive when scrolling left.
35 double delta_x() const { return delta_x_; }
36 // Positive when scrolling up.
37 double delta_y() const { return delta_y_; }
38 // The location the scroll started at. For touch, the starting
39 // position of the finger. For mouse, the location of the cursor.
40 int start_position_x() const { return start_position_x_; }
41 int start_position_y() const { return start_position_y_; }
43 // True if this scroll is allowed to bubble upwards.
44 bool should_propagate() const { return should_propagate_; }
45 // True if the user interacts directly with the screen, e.g., via touch.
46 bool is_direct_manipulation() const { return is_direct_manipulation_; }
48 void set_scroll_chain(const std::list<LayerImpl*>& scroll_chain) {
49 scroll_chain_ = scroll_chain;
52 void set_current_native_scrolling_layer(LayerImpl* layer) {
53 current_native_scrolling_layer_ = layer;
56 LayerImpl* current_native_scrolling_layer() const {
57 return current_native_scrolling_layer_;
60 bool delta_consumed_for_scroll_sequence() const {
61 return delta_consumed_for_scroll_sequence_;
64 bool FullyConsumed() const { return !delta_x_ && !delta_y_; }
66 void set_caused_scroll(bool x, bool y) {
67 caused_scroll_x_ |= x;
68 caused_scroll_y_ |= y;
71 bool caused_scroll_x() const { return caused_scroll_x_; }
72 bool caused_scroll_y() const { return caused_scroll_y_; }
74 private:
75 ScrollState();
76 double delta_x_;
77 double delta_y_;
78 double start_position_x_;
79 double start_position_y_;
81 bool should_propagate_;
83 // The last layer to respond to a scroll, or null if none exists.
84 LayerImpl* current_native_scrolling_layer_;
85 // Whether the scroll sequence has had any delta consumed, in the
86 // current frame, or any child frames.
87 bool delta_consumed_for_scroll_sequence_;
88 // True if the user interacts directly with the display, e.g., via
89 // touch.
90 bool is_direct_manipulation_;
91 // TODO(tdresser): ScrollState shouldn't need to keep track of whether or not
92 // this ScrollState object has caused a scroll. Ideally, any native scroller
93 // consuming delta has caused a scroll. Currently, there are some cases where
94 // we consume delta without scrolling, such as in
95 // |Viewport::AdjustOverscroll|. Once these cases are fixed, we should get rid
96 // of |caused_scroll_*_|. See crbug.com/510045 for details.
97 bool caused_scroll_x_;
98 bool caused_scroll_y_;
100 // TODO(tdresser): Change LayerImpl* to an abstract scrollable type. See
101 // crbug.com/476553 for detail on the effort to unify impl and main thread
102 // scrolling, which will require an abstract scrollable type.
103 std::list<LayerImpl*> scroll_chain_;
106 } // namespace cc
108 #endif // CC_INPUT_SCROLL_STATE_H_