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