Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: cc/input/top_controls_manager.cc

Issue 961023002: (Reland) Always create top controls manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed calculate_top_controls_position flag from Android flags Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/input/top_controls_manager.h ('k') | cc/input/top_controls_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "cc/animation/keyframed_animation_curve.h" 10 #include "cc/animation/keyframed_animation_curve.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return client_->CurrentTopControlsShownRatio(); 62 return client_->CurrentTopControlsShownRatio();
63 } 63 }
64 64
65 float TopControlsManager::TopControlsHeight() const { 65 float TopControlsManager::TopControlsHeight() const {
66 return client_->TopControlsHeight(); 66 return client_->TopControlsHeight();
67 } 67 }
68 68
69 void TopControlsManager::UpdateTopControlsState(TopControlsState constraints, 69 void TopControlsManager::UpdateTopControlsState(TopControlsState constraints,
70 TopControlsState current, 70 TopControlsState current,
71 bool animate) { 71 bool animate) {
72 if (!TopControlsEnabled())
aelias_OOO_until_Jul13 2015/03/04 20:05:53 This one shouldn't be suppressed by height. We sh
bokan 2015/03/04 21:48:30 Done.
73 return;
74
72 DCHECK(!(constraints == SHOWN && current == HIDDEN)); 75 DCHECK(!(constraints == SHOWN && current == HIDDEN));
73 DCHECK(!(constraints == HIDDEN && current == SHOWN)); 76 DCHECK(!(constraints == HIDDEN && current == SHOWN));
74 77
75 permitted_state_ = constraints; 78 permitted_state_ = constraints;
76 79
77 // Don't do anything if it doesn't matter which state the controls are in. 80 // Don't do anything if it doesn't matter which state the controls are in.
78 if (constraints == BOTH && current == BOTH) 81 if (constraints == BOTH && current == BOTH)
79 return; 82 return;
80 83
81 // Don't do anything if there is no change in offset. 84 // Don't do anything if there is no change in offset.
82 float final_shown_ratio = 1.f; 85 float final_shown_ratio = 1.f;
83 if (constraints == HIDDEN || current == HIDDEN) 86 if (constraints == HIDDEN || current == HIDDEN)
84 final_shown_ratio = 0.f; 87 final_shown_ratio = 0.f;
85 if (final_shown_ratio == TopControlsShownRatio()) 88 if (final_shown_ratio == TopControlsShownRatio())
86 return; 89 return;
87 90
88 if (animate) { 91 if (animate) {
89 SetupAnimation(final_shown_ratio ? SHOWING_CONTROLS : HIDING_CONTROLS); 92 SetupAnimation(final_shown_ratio ? SHOWING_CONTROLS : HIDING_CONTROLS);
90 } else { 93 } else {
91 ResetAnimations(); 94 ResetAnimations();
92 client_->SetCurrentTopControlsShownRatio(final_shown_ratio); 95 client_->SetCurrentTopControlsShownRatio(final_shown_ratio);
93 } 96 }
94 } 97 }
95 98
96 void TopControlsManager::ScrollBegin() { 99 void TopControlsManager::ScrollBegin() {
100 if (!TopControlsEnabled())
aelias_OOO_until_Jul13 2015/03/04 20:05:53 I think we should remove all of the extra early-re
bokan 2015/03/04 21:48:30 Done.
101 return;
102
97 DCHECK(!pinch_gesture_active_); 103 DCHECK(!pinch_gesture_active_);
98 ResetAnimations(); 104 ResetAnimations();
99 ResetBaseline(); 105 ResetBaseline();
100 } 106 }
101 107
102 gfx::Vector2dF TopControlsManager::ScrollBy( 108 gfx::Vector2dF TopControlsManager::ScrollBy(
103 const gfx::Vector2dF& pending_delta) { 109 const gfx::Vector2dF& pending_delta) {
110 if (!TopControlsEnabled())
111 return pending_delta;
112
104 if (pinch_gesture_active_) 113 if (pinch_gesture_active_)
105 return pending_delta; 114 return pending_delta;
106 115
107 if (permitted_state_ == SHOWN && pending_delta.y() > 0) 116 if (permitted_state_ == SHOWN && pending_delta.y() > 0)
108 return pending_delta; 117 return pending_delta;
109 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0) 118 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0)
110 return pending_delta; 119 return pending_delta;
111 120
112 accumulated_scroll_delta_ += pending_delta.y(); 121 accumulated_scroll_delta_ += pending_delta.y();
113 122
114 float old_offset = ContentTopOffset(); 123 float old_offset = ContentTopOffset();
115 client_->SetCurrentTopControlsShownRatio( 124 client_->SetCurrentTopControlsShownRatio(
aelias_OOO_until_Jul13 2015/03/04 20:05:53 For similar reasons of preserving state in case he
bokan 2015/03/04 21:48:30 I agree in other cases, but I think preserving sta
116 (baseline_content_offset_ - accumulated_scroll_delta_) / 125 (baseline_content_offset_ - accumulated_scroll_delta_) /
117 TopControlsHeight()); 126 TopControlsHeight());
118 127
119 // If the controls are fully visible, treat the current position as the 128 // If the controls are fully visible, treat the current position as the
120 // new baseline even if the gesture didn't end. 129 // new baseline even if the gesture didn't end.
121 if (TopControlsShownRatio() == 1.f) 130 if (TopControlsShownRatio() == 1.f)
122 ResetBaseline(); 131 ResetBaseline();
123 132
124 ResetAnimations(); 133 ResetAnimations();
125 134
126 gfx::Vector2dF applied_delta(0.f, old_offset - ContentTopOffset()); 135 gfx::Vector2dF applied_delta(0.f, old_offset - ContentTopOffset());
127 return pending_delta - applied_delta; 136 return pending_delta - applied_delta;
128 } 137 }
129 138
130 void TopControlsManager::ScrollEnd() { 139 void TopControlsManager::ScrollEnd() {
140 if (!TopControlsEnabled())
141 return;
142
131 DCHECK(!pinch_gesture_active_); 143 DCHECK(!pinch_gesture_active_);
132 StartAnimationIfNecessary(); 144 StartAnimationIfNecessary();
133 } 145 }
134 146
135 void TopControlsManager::PinchBegin() { 147 void TopControlsManager::PinchBegin() {
148 if (!TopControlsEnabled())
149 return;
150
136 DCHECK(!pinch_gesture_active_); 151 DCHECK(!pinch_gesture_active_);
137 pinch_gesture_active_ = true; 152 pinch_gesture_active_ = true;
138 StartAnimationIfNecessary(); 153 StartAnimationIfNecessary();
139 } 154 }
140 155
141 void TopControlsManager::PinchEnd() { 156 void TopControlsManager::PinchEnd() {
157 if (!TopControlsEnabled())
158 return;
159
142 DCHECK(pinch_gesture_active_); 160 DCHECK(pinch_gesture_active_);
143 // Pinch{Begin,End} will always occur within the scope of Scroll{Begin,End}, 161 // Pinch{Begin,End} will always occur within the scope of Scroll{Begin,End},
144 // so return to a state expected by the remaining scroll sequence. 162 // so return to a state expected by the remaining scroll sequence.
145 pinch_gesture_active_ = false; 163 pinch_gesture_active_ = false;
146 ScrollBegin(); 164 ScrollBegin();
147 } 165 }
148 166
149 void TopControlsManager::MainThreadHasStoppedFlinging() { 167 void TopControlsManager::MainThreadHasStoppedFlinging() {
168 if (!TopControlsEnabled())
169 return;
170
150 StartAnimationIfNecessary(); 171 StartAnimationIfNecessary();
151 } 172 }
152 173
153 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) { 174 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) {
175 DCHECK(TopControlsEnabled());
aelias_OOO_until_Jul13 2015/03/04 20:05:53 I'd suggest removing this DCHECK. If you're worri
bokan 2015/03/04 21:48:30 Done.
176
154 if (!top_controls_animation_ || !client_->HaveRootScrollLayer()) 177 if (!top_controls_animation_ || !client_->HaveRootScrollLayer())
155 return gfx::Vector2dF(); 178 return gfx::Vector2dF();
156 179
157 base::TimeDelta time = monotonic_time - base::TimeTicks(); 180 base::TimeDelta time = monotonic_time - base::TimeTicks();
158 181
159 float old_offset = ContentTopOffset(); 182 float old_offset = ContentTopOffset();
160 client_->SetCurrentTopControlsShownRatio( 183 client_->SetCurrentTopControlsShownRatio(
161 top_controls_animation_->GetValue(time)); 184 top_controls_animation_->GetValue(time));
162 185
163 if (IsAnimationCompleteAtTime(monotonic_time)) 186 if (IsAnimationCompleteAtTime(monotonic_time))
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return true; 247 return true;
225 } 248 }
226 return false; 249 return false;
227 } 250 }
228 251
229 void TopControlsManager::ResetBaseline() { 252 void TopControlsManager::ResetBaseline() {
230 accumulated_scroll_delta_ = 0.f; 253 accumulated_scroll_delta_ = 0.f;
231 baseline_content_offset_ = ContentTopOffset(); 254 baseline_content_offset_ = ContentTopOffset();
232 } 255 }
233 256
257 bool TopControlsManager::TopControlsEnabled() {
aelias_OOO_until_Jul13 2015/03/04 20:05:53 I don't think we should have a method called this,
bokan 2015/03/04 21:48:30 Done.
258 return TopControlsHeight();
259 }
260
234 } // namespace cc 261 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/top_controls_manager.h ('k') | cc/input/top_controls_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698