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