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/geometry/size.h"
13 #include "ui/gfx/geometry/vector2d_f.h"
21 class KeyframedFloatAnimationCurve
;
23 class TopControlsManagerClient
;
25 // Manages the position of the top controls.
26 class CC_EXPORT TopControlsManager
27 : public base::SupportsWeakPtr
<TopControlsManager
> {
29 enum AnimationDirection
{
35 static scoped_ptr
<TopControlsManager
> Create(
36 TopControlsManagerClient
* client
,
37 float top_controls_show_threshold
,
38 float top_controls_hide_threshold
);
39 virtual ~TopControlsManager();
41 float ControlsTopOffset();
42 float ContentTopOffset();
44 KeyframedFloatAnimationCurve
* animation() {
45 return top_controls_animation_
.get();
47 AnimationDirection
animation_direction() { return animation_direction_
; }
49 void UpdateTopControlsState(TopControlsState constraints
,
50 TopControlsState current
,
54 gfx::Vector2dF
ScrollBy(const gfx::Vector2dF
& pending_delta
);
57 // The caller should ensure that |Pinch{Begin,End}| are called within
58 // the scope of |Scroll{Begin,End}|.
62 gfx::Vector2dF
Animate(base::TimeTicks monotonic_time
);
63 void SetControlsTopOffset(float offset
);
64 void SetTopControlsHeight(float top_controls_height
);
65 float top_controls_height() { return top_controls_height_
; }
68 TopControlsManager(TopControlsManagerClient
* client
,
69 float top_controls_show_threshold
,
70 float top_controls_hide_threshold
);
73 void ResetAnimations();
74 void SetupAnimation(AnimationDirection direction
);
75 void StartAnimationIfNecessary();
76 bool IsAnimationCompleteAtTime(base::TimeTicks time
);
78 TopControlsManagerClient
* client_
; // The client manages the lifecycle of
81 scoped_ptr
<KeyframedFloatAnimationCurve
> top_controls_animation_
;
82 AnimationDirection animation_direction_
;
83 TopControlsState permitted_state_
;
84 float top_controls_height_
;
86 float current_scroll_delta_
;
87 float controls_scroll_begin_offset_
;
89 // The percent height of the visible top control such that it must be shown
90 // when the user stops the scroll.
91 float top_controls_show_threshold_
;
93 // The percent height of the visible top control such that it must be hidden
94 // when the user stops the scroll.
95 float top_controls_hide_threshold_
;
97 bool pinch_gesture_active_
;
99 DISALLOW_COPY_AND_ASSIGN(TopControlsManager
);
104 #endif // CC_INPUT_TOP_CONTROLS_MANAGER_H_