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/top_controls_manager.h" | 5 #include "cc/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 16 matching lines...) Expand all Loading... | |
27 scoped_ptr<TopControlsManager> TopControlsManager::Create( | 27 scoped_ptr<TopControlsManager> TopControlsManager::Create( |
28 TopControlsManagerClient* client, float top_controls_height) { | 28 TopControlsManagerClient* client, float top_controls_height) { |
29 return make_scoped_ptr(new TopControlsManager(client, top_controls_height)); | 29 return make_scoped_ptr(new TopControlsManager(client, top_controls_height)); |
30 } | 30 } |
31 | 31 |
32 TopControlsManager::TopControlsManager(TopControlsManagerClient* client, | 32 TopControlsManager::TopControlsManager(TopControlsManagerClient* client, |
33 float top_controls_height) | 33 float top_controls_height) |
34 : client_(client), | 34 : client_(client), |
35 animation_direction_(NO_ANIMATION), | 35 animation_direction_(NO_ANIMATION), |
36 is_overlay_mode_(false), | 36 is_overlay_mode_(false), |
37 scroll_readjustment_enabled_(false), | |
38 top_controls_height_(top_controls_height), | 37 top_controls_height_(top_controls_height), |
39 controls_top_offset_(0), | 38 controls_top_offset_(0), |
40 content_top_offset_(top_controls_height), | 39 content_top_offset_(top_controls_height), |
41 previous_root_scroll_offset_(0.f) { | 40 in_user_scroll_(false) { |
42 CHECK(client_); | 41 CHECK(client_); |
43 } | 42 } |
44 | 43 |
45 TopControlsManager::~TopControlsManager() { | 44 TopControlsManager::~TopControlsManager() { |
46 } | 45 } |
47 | 46 |
48 void TopControlsManager::UpdateDrawPositions() { | 47 void TopControlsManager::ProgrammaticScroll(gfx::Vector2d targetOffset) { |
49 if (!client_->haveRootScrollLayer()) | 48 if (controls_top_offset_ == -top_controls_height_) |
50 return; | 49 return; |
51 | 50 |
52 // If the scroll position has changed underneath us (i.e. a javascript | 51 // We're in a user scroll. |
53 // scroll), then simulate a scroll that covers the delta. | 52 if (in_user_scroll_) |
54 float scroll_total_y = RootScrollLayerTotalScrollY(); | 53 return; |
55 if (scroll_readjustment_enabled_ | 54 |
56 && scroll_total_y != previous_root_scroll_offset_) { | 55 ScrollBy(gfx::Vector2dF(0, top_controls_height_)); |
Ted C
2013/01/24 22:01:01
hmm...so any javascript scroll will attempt to hid
John Knottenbelt
2013/01/30 16:08:45
We can restrict it here to just 0,0 and 0,1 if we
| |
57 ScrollBy(gfx::Vector2dF(0, scroll_total_y - previous_root_scroll_offset_)); | 56 StartAnimationIfNecessary(); |
Ted C
2013/01/24 22:01:01
The start animation if necessary shouldn't be requ
John Knottenbelt
2013/01/30 16:08:45
Done.
| |
58 StartAnimationIfNecessary(); | |
59 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY(); | |
60 } | |
61 } | 57 } |
62 | 58 |
63 void TopControlsManager::ScrollBegin() { | 59 void TopControlsManager::ScrollBegin() { |
64 ResetAnimations(); | 60 ResetAnimations(); |
65 scroll_readjustment_enabled_ = false; | 61 in_user_scroll_ = true; |
66 } | 62 } |
67 | 63 |
68 gfx::Vector2dF TopControlsManager::ScrollBy( | 64 gfx::Vector2dF TopControlsManager::ScrollBy( |
69 const gfx::Vector2dF pending_delta) { | 65 const gfx::Vector2dF pending_delta) { |
70 ResetAnimations(); | 66 ResetAnimations(); |
71 return ScrollInternal(pending_delta); | 67 return ScrollInternal(pending_delta); |
72 } | 68 } |
73 | 69 |
74 gfx::Vector2dF TopControlsManager::ScrollInternal( | 70 gfx::Vector2dF TopControlsManager::ScrollInternal( |
75 const gfx::Vector2dF pending_delta) { | 71 const gfx::Vector2dF pending_delta) { |
(...skipping 30 matching lines...) Expand all Loading... | |
106 || previous_content_offset != content_top_offset_) { | 102 || previous_content_offset != content_top_offset_) { |
107 client_->setNeedsRedraw(); | 103 client_->setNeedsRedraw(); |
108 client_->setNeedsUpdateDrawProperties(); | 104 client_->setNeedsUpdateDrawProperties(); |
109 } | 105 } |
110 | 106 |
111 return pending_delta - applied_delta; | 107 return pending_delta - applied_delta; |
112 } | 108 } |
113 | 109 |
114 void TopControlsManager::ScrollEnd() { | 110 void TopControlsManager::ScrollEnd() { |
115 StartAnimationIfNecessary(); | 111 StartAnimationIfNecessary(); |
116 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY(); | 112 in_user_scroll_ = false; |
117 scroll_readjustment_enabled_ = true; | |
118 } | 113 } |
119 | 114 |
120 void TopControlsManager::Animate(base::TimeTicks monotonic_time) { | 115 void TopControlsManager::Animate(base::TimeTicks monotonic_time) { |
121 if (!top_controls_animation_ || !client_->haveRootScrollLayer()) | 116 if (!top_controls_animation_ || !client_->haveRootScrollLayer()) |
122 return; | 117 return; |
123 | 118 |
124 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); | 119 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); |
125 float new_offset = top_controls_animation_->getValue(time); | 120 float new_offset = top_controls_animation_->getValue(time); |
126 gfx::Vector2dF scroll_vector(0.f, -(new_offset - controls_top_offset_)); | 121 gfx::Vector2dF scroll_vector(0.f, -(new_offset - controls_top_offset_)); |
127 ScrollInternal(scroll_vector); | 122 ScrollInternal(scroll_vector); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 | 177 |
183 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || | 178 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || |
184 (animation_direction_ == HIDING_CONTROLS | 179 (animation_direction_ == HIDING_CONTROLS |
185 && new_offset <= -top_controls_height_)) { | 180 && new_offset <= -top_controls_height_)) { |
186 return true; | 181 return true; |
187 } | 182 } |
188 return false; | 183 return false; |
189 } | 184 } |
190 | 185 |
191 } // namespace cc | 186 } // namespace cc |
OLD | NEW |