OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "cc/input/top_controls_manager.h" | 5 #include "cc/input/top_controls_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 TopControlsManager::~TopControlsManager() { | 55 TopControlsManager::~TopControlsManager() { |
56 } | 56 } |
57 | 57 |
58 void TopControlsManager::EnableHidingTopControls(bool enable) { | 58 void TopControlsManager::EnableHidingTopControls(bool enable) { |
59 enable_hiding_ = enable; | 59 enable_hiding_ = enable; |
60 | 60 |
61 if (!enable) { | 61 if (!enable) { |
62 ResetAnimations(); | 62 ResetAnimations(); |
63 if (controls_top_offset_ != 0) { | 63 SetupAnimation(SHOWING_CONTROLS); |
64 SetupAnimation(SHOWING_CONTROLS); | |
65 client_->setNeedsRedraw(); | |
66 } | |
67 } | 64 } |
68 } | 65 } |
69 | 66 |
| 67 void TopControlsManager::ShowTopControls(bool show) { |
| 68 if (show) { |
| 69 SetupAnimation(SHOWING_CONTROLS); |
| 70 } else { |
| 71 DCHECK(enable_hiding_); |
| 72 SetupAnimation(HIDING_CONTROLS); |
| 73 } |
| 74 } |
| 75 |
70 void TopControlsManager::ScrollBegin() { | 76 void TopControlsManager::ScrollBegin() { |
71 ResetAnimations(); | 77 ResetAnimations(); |
72 current_scroll_delta_ = 0.f; | 78 current_scroll_delta_ = 0.f; |
73 controls_scroll_begin_offset_ = controls_top_offset_; | 79 controls_scroll_begin_offset_ = controls_top_offset_; |
74 } | 80 } |
75 | 81 |
76 gfx::Vector2dF TopControlsManager::ScrollBy( | 82 gfx::Vector2dF TopControlsManager::ScrollBy( |
77 const gfx::Vector2dF pending_delta) { | 83 const gfx::Vector2dF pending_delta) { |
78 if (!enable_hiding_ && pending_delta.y() > 0) | 84 if (!enable_hiding_ && pending_delta.y() > 0) |
79 return pending_delta; | 85 return pending_delta; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 136 } |
131 | 137 |
132 void TopControlsManager::ResetAnimations() { | 138 void TopControlsManager::ResetAnimations() { |
133 if (top_controls_animation_) | 139 if (top_controls_animation_) |
134 top_controls_animation_.reset(); | 140 top_controls_animation_.reset(); |
135 | 141 |
136 animation_direction_ = NO_ANIMATION; | 142 animation_direction_ = NO_ANIMATION; |
137 } | 143 } |
138 | 144 |
139 void TopControlsManager::SetupAnimation(AnimationDirection direction) { | 145 void TopControlsManager::SetupAnimation(AnimationDirection direction) { |
| 146 DCHECK(direction != NO_ANIMATION); |
| 147 |
| 148 if (direction == SHOWING_CONTROLS && controls_top_offset_ == 0) |
| 149 return; |
| 150 |
| 151 if (direction == HIDING_CONTROLS && |
| 152 controls_top_offset_ == -top_controls_height_) |
| 153 return; |
| 154 |
| 155 if (top_controls_animation_ && animation_direction_ == direction) |
| 156 return; |
| 157 |
140 top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); | 158 top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); |
141 double start_time = | 159 double start_time = |
142 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); | 160 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); |
143 top_controls_animation_->AddKeyframe( | 161 top_controls_animation_->AddKeyframe( |
144 FloatKeyframe::Create(start_time, controls_top_offset_, | 162 FloatKeyframe::Create(start_time, controls_top_offset_, |
145 scoped_ptr<TimingFunction>())); | 163 scoped_ptr<TimingFunction>())); |
146 float max_ending_offset = | 164 float max_ending_offset = |
147 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; | 165 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; |
148 top_controls_animation_->AddKeyframe( | 166 top_controls_animation_->AddKeyframe( |
149 FloatKeyframe::Create(start_time + kShowHideMaxDurationMs, | 167 FloatKeyframe::Create(start_time + kShowHideMaxDurationMs, |
150 controls_top_offset_ + max_ending_offset, | 168 controls_top_offset_ + max_ending_offset, |
151 EaseTimingFunction::Create())); | 169 EaseTimingFunction::Create())); |
152 animation_direction_ = direction; | 170 animation_direction_ = direction; |
| 171 client_->setNeedsRedraw(); |
153 } | 172 } |
154 | 173 |
155 void TopControlsManager::StartAnimationIfNecessary() { | 174 void TopControlsManager::StartAnimationIfNecessary() { |
156 if (controls_top_offset_ != 0 | 175 if (controls_top_offset_ != 0 |
157 && controls_top_offset_ != -top_controls_height_) { | 176 && controls_top_offset_ != -top_controls_height_) { |
158 AnimationDirection show_controls = NO_ANIMATION; | 177 AnimationDirection show_controls = NO_ANIMATION; |
159 | 178 |
160 if (controls_top_offset_ >= -top_controls_show_height_) { | 179 if (controls_top_offset_ >= -top_controls_show_height_) { |
161 // If we're showing so much that the hide threshold won't trigger, show. | 180 // If we're showing so much that the hide threshold won't trigger, show. |
162 show_controls = SHOWING_CONTROLS; | 181 show_controls = SHOWING_CONTROLS; |
163 } else if (controls_top_offset_ <= -top_controls_hide_height_) { | 182 } else if (controls_top_offset_ <= -top_controls_hide_height_) { |
164 // If we're showing so little that the show threshold won't trigger, hide. | 183 // If we're showing so little that the show threshold won't trigger, hide. |
165 show_controls = HIDING_CONTROLS; | 184 show_controls = HIDING_CONTROLS; |
166 } else { | 185 } else { |
167 // If we could be either showing or hiding, we determine which one to | 186 // If we could be either showing or hiding, we determine which one to |
168 // do based on whether or not the total scroll delta was moving up or | 187 // do based on whether or not the total scroll delta was moving up or |
169 // down. | 188 // down. |
170 show_controls = current_scroll_delta_ <= 0.f ? | 189 show_controls = current_scroll_delta_ <= 0.f ? |
171 SHOWING_CONTROLS : HIDING_CONTROLS; | 190 SHOWING_CONTROLS : HIDING_CONTROLS; |
172 } | 191 } |
173 | 192 |
174 if (show_controls != NO_ANIMATION && | 193 if (show_controls != NO_ANIMATION) |
175 (!top_controls_animation_ || animation_direction_ != show_controls)) { | |
176 SetupAnimation(show_controls); | 194 SetupAnimation(show_controls); |
177 client_->setNeedsRedraw(); | |
178 } | |
179 } | 195 } |
180 } | 196 } |
181 | 197 |
182 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { | 198 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { |
183 if (!top_controls_animation_) | 199 if (!top_controls_animation_) |
184 return true; | 200 return true; |
185 | 201 |
186 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); | 202 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); |
187 float new_offset = top_controls_animation_->GetValue(time_ms); | 203 float new_offset = top_controls_animation_->GetValue(time_ms); |
188 | 204 |
189 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || | 205 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || |
190 (animation_direction_ == HIDING_CONTROLS | 206 (animation_direction_ == HIDING_CONTROLS |
191 && new_offset <= -top_controls_height_)) { | 207 && new_offset <= -top_controls_height_)) { |
192 return true; | 208 return true; |
193 } | 209 } |
194 return false; | 210 return false; |
195 } | 211 } |
196 | 212 |
197 } // namespace cc | 213 } // namespace cc |
OLD | NEW |