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

Side by Side Diff: content/browser/android/edge_effect.cc

Issue 454863003: Revert of [Android] Use UIResource for overscroll glow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 | « content/browser/android/edge_effect.h ('k') | content/browser/android/overscroll_glow.h » ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/browser/android/edge_effect.h" 5 #include "content/browser/android/edge_effect.h"
6 6
7 #include "cc/layers/layer.h" 7 #include "cc/layers/layer.h"
8 #include "cc/layers/ui_resource_layer.h"
9 #include "ui/base/android/system_ui_resource_manager.h"
10 8
11 namespace content { 9 namespace content {
12 10
13 namespace { 11 namespace {
14 12
15 enum State { 13 enum State {
16 STATE_IDLE = 0, 14 STATE_IDLE = 0,
17 STATE_PULL, 15 STATE_PULL,
18 STATE_ABSORB, 16 STATE_ABSORB,
19 STATE_RECEDE, 17 STATE_RECEDE,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return gfx::Size(window_size.width(), height); 111 return gfx::Size(window_size.width(), height);
114 case EdgeEffect::EDGE_LEFT: 112 case EdgeEffect::EDGE_LEFT:
115 case EdgeEffect::EDGE_RIGHT: 113 case EdgeEffect::EDGE_RIGHT:
116 return gfx::Size(window_size.height(), height); 114 return gfx::Size(window_size.height(), height);
117 default: 115 default:
118 NOTREACHED() << "Invalid edge: " << edge; 116 NOTREACHED() << "Invalid edge: " << edge;
119 return gfx::Size(); 117 return gfx::Size();
120 }; 118 };
121 } 119 }
122 120
123 } // namespace 121 void DisableLayer(cc::Layer* layer) {
122 DCHECK(layer);
123 layer->SetIsDrawable(false);
124 layer->SetTransform(gfx::Transform());
125 layer->SetOpacity(1.f);
126 }
124 127
125 class EdgeEffect::EffectLayer { 128 void UpdateLayer(cc::Layer* layer,
126 public: 129 EdgeEffect::Edge edge,
127 EffectLayer(ui::SystemUIResourceManager::ResourceType resource_type, 130 const gfx::SizeF& window_size,
128 ui::SystemUIResourceManager* resource_manager) 131 int offset,
129 : ui_resource_layer_(cc::UIResourceLayer::Create()), 132 int height,
130 resource_type_(resource_type), 133 float opacity) {
131 resource_manager_(resource_manager) {} 134 DCHECK(layer);
135 layer->SetIsDrawable(true);
136 gfx::Size bounds = ComputeBounds(edge, window_size, height);
137 layer->SetTransformOrigin(
138 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0));
139 layer->SetTransform(ComputeTransform(edge, window_size, offset, height));
140 layer->SetBounds(bounds);
141 layer->SetOpacity(Clamp(opacity, 0.f, 1.f));
142 }
132 143
133 ~EffectLayer() { ui_resource_layer_->RemoveFromParent(); } 144 } // namespace
134 145
135 void SetParent(cc::Layer* parent) { 146 EdgeEffect::EdgeEffect(scoped_refptr<cc::Layer> edge,
136 if (ui_resource_layer_->parent() != parent) 147 scoped_refptr<cc::Layer> glow)
137 parent->AddChild(ui_resource_layer_); 148 : edge_(edge)
138 ui_resource_layer_->SetUIResourceId( 149 , glow_(glow)
139 resource_manager_->GetUIResourceId(resource_type_)); 150 , edge_alpha_(0)
140 } 151 , edge_scale_y_(0)
141 152 , glow_alpha_(0)
142 void Disable() { ui_resource_layer_->SetIsDrawable(false); } 153 , glow_scale_y_(0)
143 154 , edge_alpha_start_(0)
144 void Update(EdgeEffect::Edge edge, 155 , edge_alpha_finish_(0)
145 const gfx::SizeF& window_size, 156 , edge_scale_y_start_(0)
146 int offset, 157 , edge_scale_y_finish_(0)
147 int height, 158 , glow_alpha_start_(0)
148 float opacity) { 159 , glow_alpha_finish_(0)
149 ui_resource_layer_->SetUIResourceId( 160 , glow_scale_y_start_(0)
150 resource_manager_->GetUIResourceId(resource_type_)); 161 , glow_scale_y_finish_(0)
151 ui_resource_layer_->SetIsDrawable(true); 162 , state_(STATE_IDLE)
152 gfx::Size bounds = ComputeBounds(edge, window_size, height); 163 , pull_distance_(0) {
153 ui_resource_layer_->SetTransformOrigin( 164 // Prevent the provided layers from drawing until the effect is activated.
154 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); 165 DisableLayer(edge_.get());
155 ui_resource_layer_->SetTransform( 166 DisableLayer(glow_.get());
156 ComputeTransform(edge, window_size, offset, height));
157 ui_resource_layer_->SetBounds(bounds);
158 ui_resource_layer_->SetOpacity(Clamp(opacity, 0.f, 1.f));
159 }
160
161 scoped_refptr<cc::UIResourceLayer> ui_resource_layer_;
162 ui::SystemUIResourceManager::ResourceType resource_type_;
163 ui::SystemUIResourceManager* resource_manager_;
164
165 DISALLOW_COPY_AND_ASSIGN(EffectLayer);
166 };
167
168 EdgeEffect::EdgeEffect(ui::SystemUIResourceManager* resource_manager)
169 : edge_(new EffectLayer(ui::SystemUIResourceManager::OVERSCROLL_EDGE,
170 resource_manager)),
171 glow_(new EffectLayer(ui::SystemUIResourceManager::OVERSCROLL_GLOW,
172 resource_manager)),
173 edge_alpha_(0),
174 edge_scale_y_(0),
175 glow_alpha_(0),
176 glow_scale_y_(0),
177 edge_alpha_start_(0),
178 edge_alpha_finish_(0),
179 edge_scale_y_start_(0),
180 edge_scale_y_finish_(0),
181 glow_alpha_start_(0),
182 glow_alpha_finish_(0),
183 glow_scale_y_start_(0),
184 glow_scale_y_finish_(0),
185 state_(STATE_IDLE),
186 pull_distance_(0) {
187 } 167 }
188 168
189 EdgeEffect::~EdgeEffect() { } 169 EdgeEffect::~EdgeEffect() { }
190 170
191 bool EdgeEffect::IsFinished() const { 171 bool EdgeEffect::IsFinished() const {
192 return state_ == STATE_IDLE; 172 return state_ == STATE_IDLE;
193 } 173 }
194 174
195 void EdgeEffect::Finish() { 175 void EdgeEffect::Finish() {
196 edge_->Disable(); 176 DisableLayer(edge_.get());
197 glow_->Disable(); 177 DisableLayer(glow_.get());
198 pull_distance_ = 0; 178 pull_distance_ = 0;
199 state_ = STATE_IDLE; 179 state_ = STATE_IDLE;
200 } 180 }
201 181
202 void EdgeEffect::Pull(base::TimeTicks current_time, float delta_distance) { 182 void EdgeEffect::Pull(base::TimeTicks current_time, float delta_distance) {
203 if (state_ == STATE_PULL_DECAY && current_time - start_time_ < duration_) { 183 if (state_ == STATE_PULL_DECAY && current_time - start_time_ < duration_) {
204 return; 184 return;
205 } 185 }
206 if (state_ != STATE_PULL) { 186 if (state_ != STATE_PULL) {
207 glow_scale_y_ = kPullGlowBegin; 187 glow_scale_y_ = kPullGlowBegin;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 Edge edge, 352 Edge edge,
373 float edge_height, 353 float edge_height,
374 float glow_height, 354 float glow_height,
375 float offset) { 355 float offset) {
376 if (IsFinished()) 356 if (IsFinished())
377 return; 357 return;
378 358
379 // An empty window size, while meaningless, is also relatively harmless, and 359 // An empty window size, while meaningless, is also relatively harmless, and
380 // will simply prevent any drawing of the layers. 360 // will simply prevent any drawing of the layers.
381 if (window_size.IsEmpty()) { 361 if (window_size.IsEmpty()) {
382 edge_->Disable(); 362 DisableLayer(edge_.get());
383 glow_->Disable(); 363 DisableLayer(glow_.get());
384 return; 364 return;
385 } 365 }
386 366
387 // Glow 367 // Glow
388 const int scaled_glow_height = static_cast<int>( 368 const int scaled_glow_height = static_cast<int>(
389 std::min(glow_height * glow_scale_y_ * kGlowHeightToWidthRatio * 0.6f, 369 std::min(glow_height * glow_scale_y_ * kGlowHeightToWidthRatio * 0.6f,
390 glow_height * kMaxGlowHeight) + 0.5f); 370 glow_height * kMaxGlowHeight) + 0.5f);
391 glow_->Update(edge, window_size, offset, scaled_glow_height, glow_alpha_); 371 UpdateLayer(
372 glow_.get(), edge, window_size, offset, scaled_glow_height, glow_alpha_);
392 373
393 // Edge 374 // Edge
394 const int scaled_edge_height = static_cast<int>(edge_height * edge_scale_y_); 375 const int scaled_edge_height = static_cast<int>(edge_height * edge_scale_y_);
395 edge_->Update(edge, window_size, offset, scaled_edge_height, edge_alpha_); 376 UpdateLayer(
396 } 377 edge_.get(), edge, window_size, offset, scaled_edge_height, edge_alpha_);
397
398 void EdgeEffect::SetParent(cc::Layer* parent) {
399 edge_->SetParent(parent);
400 glow_->SetParent(parent);
401 }
402
403 // static
404 void EdgeEffect::PreloadResources(
405 ui::SystemUIResourceManager* resource_manager) {
406 DCHECK(resource_manager);
407 resource_manager->PreloadResource(
408 ui::SystemUIResourceManager::OVERSCROLL_EDGE);
409 resource_manager->PreloadResource(
410 ui::SystemUIResourceManager::OVERSCROLL_GLOW);
411 } 378 }
412 379
413 } // namespace content 380 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/edge_effect.h ('k') | content/browser/android/overscroll_glow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698