cc: Don't activate rasterize on demand when we have 0 memory.
[chromium-blink-merge.git] / cc / input / top_controls_manager.h
blob1aface88017c0b4556ebf8de7c8050c3530b2fbf
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.
5 #ifndef CC_INPUT_TOP_CONTROLS_MANAGER_H_
6 #define CC_INPUT_TOP_CONTROLS_MANAGER_H_
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/size.h"
13 #include "ui/gfx/vector2d_f.h"
15 namespace base {
16 class TimeTicks;
19 namespace cc {
21 class KeyframedFloatAnimationCurve;
22 class LayerTreeImpl;
23 class TopControlsManagerClient;
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
35 static scoped_ptr<TopControlsManager> Create(
36 TopControlsManagerClient* client,
37 float top_controls_height,
38 float top_controls_show_threshold,
39 float top_controls_hide_threshold);
40 virtual ~TopControlsManager();
42 float controls_height() { return top_controls_height_; }
43 float ControlsTopOffset();
44 float ContentTopOffset();
46 KeyframedFloatAnimationCurve* animation() {
47 return top_controls_animation_.get();
49 AnimationDirection animation_direction() { return animation_direction_; }
51 void UpdateTopControlsState(TopControlsState constraints,
52 TopControlsState current,
53 bool animate);
55 void ScrollBegin();
56 gfx::Vector2dF ScrollBy(const gfx::Vector2dF& pending_delta);
57 void ScrollEnd();
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();
64 gfx::Vector2dF Animate(base::TimeTicks monotonic_time);
65 void SetControlsTopOffset(float offset);
66 float top_controls_height() { return top_controls_height_; }
68 protected:
69 TopControlsManager(TopControlsManagerClient* client,
70 float top_controls_height,
71 float top_controls_show_threshold,
72 float top_controls_hide_threshold);
74 private:
75 void ResetAnimations();
76 void SetupAnimation(AnimationDirection direction);
77 void StartAnimationIfNecessary();
78 bool IsAnimationCompleteAtTime(base::TimeTicks time);
80 TopControlsManagerClient* client_; // The client manages the lifecycle of
81 // this.
83 scoped_ptr<KeyframedFloatAnimationCurve> top_controls_animation_;
84 AnimationDirection animation_direction_;
85 TopControlsState permitted_state_;
86 float top_controls_height_;
88 float current_scroll_delta_;
89 float controls_scroll_begin_offset_;
91 // The height of the visible top control such that it must be shown when
92 // the user stops the scroll.
93 float top_controls_show_height_;
95 // The height of the visible top control such that it must be hidden when
96 // the user stops the scroll.
97 float top_controls_hide_height_;
99 bool pinch_gesture_active_;
101 DISALLOW_COPY_AND_ASSIGN(TopControlsManager);
104 } // namespace cc
106 #endif // CC_INPUT_TOP_CONTROLS_MANAGER_H_