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

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

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