OLD | NEW |
1 // Copyright 2013 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 #ifndef CC_INPUT_TOP_CONTROLS_MANAGER_H_ | 5 #ifndef CC_INPUT_BROWSER_CONTROLS_OFFSET_MANAGER_H_ |
6 #define CC_INPUT_TOP_CONTROLS_MANAGER_H_ | 6 #define CC_INPUT_BROWSER_CONTROLS_OFFSET_MANAGER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "cc/input/top_controls_state.h" | 13 #include "cc/input/browser_controls_state.h" |
14 #include "cc/layers/layer_impl.h" | 14 #include "cc/layers/layer_impl.h" |
15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
16 #include "ui/gfx/geometry/vector2d_f.h" | 16 #include "ui/gfx/geometry/vector2d_f.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 class LayerTreeImpl; | 20 class LayerTreeImpl; |
21 class TopControlsManagerClient; | 21 class BrowserControlsOffsetManagerClient; |
22 | 22 |
23 // Manages the position of the top controls. | 23 // Manages the position of the browser controls. |
24 class CC_EXPORT TopControlsManager | 24 class CC_EXPORT BrowserControlsOffsetManager |
25 : public base::SupportsWeakPtr<TopControlsManager> { | 25 : public base::SupportsWeakPtr<BrowserControlsOffsetManager> { |
26 public: | 26 public: |
27 enum AnimationDirection { | 27 enum AnimationDirection { NO_ANIMATION, SHOWING_CONTROLS, HIDING_CONTROLS }; |
28 NO_ANIMATION, | |
29 SHOWING_CONTROLS, | |
30 HIDING_CONTROLS | |
31 }; | |
32 | 28 |
33 static std::unique_ptr<TopControlsManager> Create( | 29 static std::unique_ptr<BrowserControlsOffsetManager> Create( |
34 TopControlsManagerClient* client, | 30 BrowserControlsOffsetManagerClient* client, |
35 float top_controls_show_threshold, | 31 float controls_show_threshold, |
36 float top_controls_hide_threshold); | 32 float controls_hide_threshold); |
37 virtual ~TopControlsManager(); | 33 virtual ~BrowserControlsOffsetManager(); |
38 | 34 |
39 // The offset from the window top to the top edge of the controls. Runs from 0 | 35 // The offset from the window top to the top edge of the controls. Runs from 0 |
40 // (controls fully shown) to negative values (down is positive). | 36 // (controls fully shown) to negative values (down is positive). |
41 float ControlsTopOffset() const; | 37 float ControlsTopOffset() const; |
42 // The amount of offset of the web content area. Same as the current shown | 38 // The amount of offset of the web content area. Same as the current shown |
43 // height of the top controls. | 39 // height of the browser controls. |
44 float ContentTopOffset() const; | 40 float ContentTopOffset() const; |
45 float TopControlsShownRatio() const; | 41 float TopControlsShownRatio() const; |
46 float TopControlsHeight() const; | 42 float TopControlsHeight() const; |
47 | 43 |
48 // The amount of offset of the web content area, calculating from the bottom. | 44 // The amount of offset of the web content area, calculating from the bottom. |
49 // Same as the current shown height of the bottom controls. | 45 // Same as the current shown height of the bottom controls. |
50 float ContentBottomOffset() const; | 46 float ContentBottomOffset() const; |
51 // Similar to TopControlsHeight(), this method should return a static value. | 47 // Similar to TopControlsHeight(), this method should return a static value. |
52 // The current animated height should be acquired from ContentBottomOffset(). | 48 // The current animated height should be acquired from ContentBottomOffset(). |
53 float BottomControlsHeight() const; | 49 float BottomControlsHeight() const; |
54 float BottomControlsShownRatio() const; | 50 float BottomControlsShownRatio() const; |
55 | 51 |
56 bool has_animation() const { return animation_direction_ != NO_ANIMATION; } | 52 bool has_animation() const { return animation_direction_ != NO_ANIMATION; } |
57 AnimationDirection animation_direction() { return animation_direction_; } | 53 AnimationDirection animation_direction() { return animation_direction_; } |
58 | 54 |
59 void UpdateTopControlsState(TopControlsState constraints, | 55 void UpdateBrowserControlsState(BrowserControlsState constraints, |
60 TopControlsState current, | 56 BrowserControlsState current, |
61 bool animate); | 57 bool animate); |
62 | 58 |
63 void ScrollBegin(); | 59 void ScrollBegin(); |
64 gfx::Vector2dF ScrollBy(const gfx::Vector2dF& pending_delta); | 60 gfx::Vector2dF ScrollBy(const gfx::Vector2dF& pending_delta); |
65 void ScrollEnd(); | 61 void ScrollEnd(); |
66 | 62 |
67 // The caller should ensure that |Pinch{Begin,End}| are called within | 63 // The caller should ensure that |Pinch{Begin,End}| are called within |
68 // the scope of |Scroll{Begin,End}|. | 64 // the scope of |Scroll{Begin,End}|. |
69 void PinchBegin(); | 65 void PinchBegin(); |
70 void PinchEnd(); | 66 void PinchEnd(); |
71 | 67 |
72 void MainThreadHasStoppedFlinging(); | 68 void MainThreadHasStoppedFlinging(); |
73 | 69 |
74 gfx::Vector2dF Animate(base::TimeTicks monotonic_time); | 70 gfx::Vector2dF Animate(base::TimeTicks monotonic_time); |
75 | 71 |
76 protected: | 72 protected: |
77 TopControlsManager(TopControlsManagerClient* client, | 73 BrowserControlsOffsetManager(BrowserControlsOffsetManagerClient* client, |
78 float top_controls_show_threshold, | 74 float controls_show_threshold, |
79 float top_controls_hide_threshold); | 75 float controls_hide_threshold); |
80 | 76 |
81 private: | 77 private: |
82 void ResetAnimations(); | 78 void ResetAnimations(); |
83 void SetupAnimation(AnimationDirection direction); | 79 void SetupAnimation(AnimationDirection direction); |
84 void StartAnimationIfNecessary(); | 80 void StartAnimationIfNecessary(); |
85 bool IsAnimationComplete(float new_ratio); | 81 bool IsAnimationComplete(float new_ratio); |
86 void ResetBaseline(); | 82 void ResetBaseline(); |
| 83 // Offset computation regardless of top or bottom control state. |
| 84 float ContentOffsetInternal() const; |
87 | 85 |
88 TopControlsManagerClient* client_; // The client manages the lifecycle of | 86 // The client manages the lifecycle of this. |
89 // this. | 87 BrowserControlsOffsetManagerClient* client_; |
90 | 88 |
91 base::TimeTicks animation_start_time_; | 89 base::TimeTicks animation_start_time_; |
92 float animation_start_value_; | 90 float animation_start_value_; |
93 base::TimeTicks animation_stop_time_; | 91 base::TimeTicks animation_stop_time_; |
94 float animation_stop_value_; | 92 float animation_stop_value_; |
95 AnimationDirection animation_direction_; | 93 AnimationDirection animation_direction_; |
96 | 94 |
97 TopControlsState permitted_state_; | 95 BrowserControlsState permitted_state_; |
98 | 96 |
99 // Accumulated scroll delta since last baseline reset | 97 // Accumulated scroll delta since last baseline reset |
100 float accumulated_scroll_delta_; | 98 float accumulated_scroll_delta_; |
101 | 99 |
102 // Content offset when last baseline reset occurred | 100 // Content offset when last baseline reset occurred |
103 float baseline_content_offset_; | 101 float baseline_content_offset_; |
104 | 102 |
105 // The percent height of the visible top control such that it must be shown | 103 // The percent height of the visible control such that it must be shown |
106 // when the user stops the scroll. | 104 // when the user stops the scroll. |
107 float top_controls_show_threshold_; | 105 float controls_show_threshold_; |
108 | 106 |
109 // The percent height of the visible top control such that it must be hidden | 107 // The percent height of the visible control such that it must be hidden |
110 // when the user stops the scroll. | 108 // when the user stops the scroll. |
111 float top_controls_hide_threshold_; | 109 float controls_hide_threshold_; |
112 | 110 |
113 bool pinch_gesture_active_; | 111 bool pinch_gesture_active_; |
114 | 112 |
115 DISALLOW_COPY_AND_ASSIGN(TopControlsManager); | 113 DISALLOW_COPY_AND_ASSIGN(BrowserControlsOffsetManager); |
116 }; | 114 }; |
117 | 115 |
118 } // namespace cc | 116 } // namespace cc |
119 | 117 |
120 #endif // CC_INPUT_TOP_CONTROLS_MANAGER_H_ | 118 #endif // CC_INPUT_BROWSER_CONTROLS_OFFSET_MANAGER_H_ |
OLD | NEW |