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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 if (visibility_restriction_ != NONE && | 72 if (visibility_restriction_ != NONE && |
73 final_controls_position != controls_top_offset_) { | 73 final_controls_position != controls_top_offset_) { |
74 ResetAnimations(); | 74 ResetAnimations(); |
75 if (animate) { | 75 if (animate) { |
76 SetupAnimation(visibility_restriction_ == ALWAYS_SHOWN ? | 76 SetupAnimation(visibility_restriction_ == ALWAYS_SHOWN ? |
77 SHOWING_CONTROLS : HIDING_CONTROLS); | 77 SHOWING_CONTROLS : HIDING_CONTROLS); |
78 } else { | 78 } else { |
79 controls_top_offset_ = final_controls_position; | 79 controls_top_offset_ = final_controls_position; |
80 } | 80 } |
81 client_->setNeedsRedraw(); | 81 client_->DidChangeTopControlsPosition(); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 void TopControlsManager::ScrollBegin() { | 85 void TopControlsManager::ScrollBegin() { |
86 ResetAnimations(); | 86 ResetAnimations(); |
87 current_scroll_delta_ = 0.f; | 87 current_scroll_delta_ = 0.f; |
88 controls_scroll_begin_offset_ = controls_top_offset_; | 88 controls_scroll_begin_offset_ = controls_top_offset_; |
89 } | 89 } |
90 | 90 |
91 gfx::Vector2dF TopControlsManager::ScrollBy( | 91 gfx::Vector2dF TopControlsManager::ScrollBy( |
(...skipping 27 matching lines...) Expand all Loading... |
119 | 119 |
120 void TopControlsManager::SetControlsTopOffset(float controls_top_offset) { | 120 void TopControlsManager::SetControlsTopOffset(float controls_top_offset) { |
121 controls_top_offset = std::max(controls_top_offset, -top_controls_height_); | 121 controls_top_offset = std::max(controls_top_offset, -top_controls_height_); |
122 controls_top_offset = std::min(controls_top_offset, 0.f); | 122 controls_top_offset = std::min(controls_top_offset, 0.f); |
123 | 123 |
124 if (controls_top_offset_ == controls_top_offset) | 124 if (controls_top_offset_ == controls_top_offset) |
125 return; | 125 return; |
126 | 126 |
127 controls_top_offset_ = controls_top_offset; | 127 controls_top_offset_ = controls_top_offset; |
128 | 128 |
129 client_->setNeedsRedraw(); | 129 client_->DidChangeTopControlsPosition(); |
130 client_->setActiveTreeNeedsUpdateDrawProperties(); | |
131 } | 130 } |
132 | 131 |
133 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) { | 132 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) { |
134 if (!top_controls_animation_ || !client_->haveRootScrollLayer()) | 133 if (!top_controls_animation_ || !client_->HaveRootScrollLayer()) |
135 return gfx::Vector2dF(); | 134 return gfx::Vector2dF(); |
136 | 135 |
137 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); | 136 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); |
138 | 137 |
139 float old_offset = controls_top_offset_; | 138 float old_offset = controls_top_offset_; |
140 SetControlsTopOffset(top_controls_animation_->GetValue(time)); | 139 SetControlsTopOffset(top_controls_animation_->GetValue(time)); |
141 | 140 |
142 if (IsAnimationCompleteAtTime(monotonic_time)) | 141 if (IsAnimationCompleteAtTime(monotonic_time)) |
143 ResetAnimations(); | 142 ResetAnimations(); |
144 | 143 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // If we could be either showing or hiding, we determine which one to | 183 // If we could be either showing or hiding, we determine which one to |
185 // do based on whether or not the total scroll delta was moving up or | 184 // do based on whether or not the total scroll delta was moving up or |
186 // down. | 185 // down. |
187 show_controls = current_scroll_delta_ <= 0.f ? | 186 show_controls = current_scroll_delta_ <= 0.f ? |
188 SHOWING_CONTROLS : HIDING_CONTROLS; | 187 SHOWING_CONTROLS : HIDING_CONTROLS; |
189 } | 188 } |
190 | 189 |
191 if (show_controls != NO_ANIMATION && | 190 if (show_controls != NO_ANIMATION && |
192 (!top_controls_animation_ || animation_direction_ != show_controls)) { | 191 (!top_controls_animation_ || animation_direction_ != show_controls)) { |
193 SetupAnimation(show_controls); | 192 SetupAnimation(show_controls); |
194 client_->setNeedsRedraw(); | 193 client_->DidChangeTopControlsPosition(); |
195 } | 194 } |
196 } | 195 } |
197 } | 196 } |
198 | 197 |
199 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { | 198 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { |
200 if (!top_controls_animation_) | 199 if (!top_controls_animation_) |
201 return true; | 200 return true; |
202 | 201 |
203 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); | 202 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); |
204 float new_offset = top_controls_animation_->GetValue(time_ms); | 203 float new_offset = top_controls_animation_->GetValue(time_ms); |
205 | 204 |
206 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || | 205 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || |
207 (animation_direction_ == HIDING_CONTROLS | 206 (animation_direction_ == HIDING_CONTROLS |
208 && new_offset <= -top_controls_height_)) { | 207 && new_offset <= -top_controls_height_)) { |
209 return true; | 208 return true; |
210 } | 209 } |
211 return false; | 210 return false; |
212 } | 211 } |
213 | 212 |
214 } // namespace cc | 213 } // namespace cc |
OLD | NEW |