Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_layer.h" | |
| 10 #include "ui/base/android/system_ui_resource_manager.h" | |
| 8 | 11 |
| 9 namespace content { | 12 namespace content { |
| 10 | 13 |
| 11 namespace { | 14 namespace { |
| 12 | 15 |
| 13 enum State { | 16 enum State { |
| 14 STATE_IDLE = 0, | 17 STATE_IDLE = 0, |
| 15 STATE_PULL, | 18 STATE_PULL, |
| 16 STATE_ABSORB, | 19 STATE_ABSORB, |
| 17 STATE_RECEDE, | 20 STATE_RECEDE, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 DCHECK(layer); | 137 DCHECK(layer); |
| 135 layer->SetIsDrawable(true); | 138 layer->SetIsDrawable(true); |
| 136 gfx::Size bounds = ComputeBounds(edge, window_size, height); | 139 gfx::Size bounds = ComputeBounds(edge, window_size, height); |
| 137 layer->SetTransformOrigin( | 140 layer->SetTransformOrigin( |
| 138 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); | 141 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); |
| 139 layer->SetTransform(ComputeTransform(edge, window_size, offset, height)); | 142 layer->SetTransform(ComputeTransform(edge, window_size, offset, height)); |
| 140 layer->SetBounds(bounds); | 143 layer->SetBounds(bounds); |
| 141 layer->SetOpacity(Clamp(opacity, 0.f, 1.f)); | 144 layer->SetOpacity(Clamp(opacity, 0.f, 1.f)); |
| 142 } | 145 } |
| 143 | 146 |
| 144 } // namespace | 147 } // namespace |
| 145 | 148 |
| 146 EdgeEffect::EdgeEffect(scoped_refptr<cc::Layer> edge, | 149 class EdgeEffect::EffectLayer : public ui::SystemUIResourceLayer { |
| 147 scoped_refptr<cc::Layer> glow) | 150 public: |
| 148 : edge_(edge) | 151 static scoped_ptr<EffectLayer> Create( |
| 149 , glow_(glow) | 152 ui::SystemUIResourceManager::Type type, |
| 150 , edge_alpha_(0) | 153 ui::SystemUIResourceManager* resource_manager) { |
| 151 , edge_scale_y_(0) | 154 return make_scoped_ptr(new EffectLayer(type, resource_manager)); |
| 152 , glow_alpha_(0) | 155 } |
| 153 , glow_scale_y_(0) | 156 |
| 154 , edge_alpha_start_(0) | 157 virtual ~EffectLayer() { |
| 155 , edge_alpha_finish_(0) | 158 resource_manager_->Unsubscribe(type_, this); |
| 156 , edge_scale_y_start_(0) | 159 ui_resource_layer_->RemoveFromParent(); |
| 157 , edge_scale_y_finish_(0) | 160 } |
| 158 , glow_alpha_start_(0) | 161 |
| 159 , glow_alpha_finish_(0) | 162 // ui::SystemUIResourceLayer implementation. |
| 160 , glow_scale_y_start_(0) | 163 virtual void SetUIResourceId(cc::UIResourceId id) OVERRIDE { |
| 161 , glow_scale_y_finish_(0) | 164 ui_resource_id_ = id; |
| 162 , state_(STATE_IDLE) | 165 ui_resource_layer_->SetUIResourceId(id); |
| 163 , pull_distance_(0) { | 166 } |
| 167 | |
| 168 cc::Layer* layer() { return ui_resource_layer_.get(); } | |
| 169 | |
| 170 void SetParent(cc::Layer* parent) { | |
| 171 if (ui_resource_layer_->parent() != parent) | |
| 172 parent->AddChild(ui_resource_layer_); | |
|
jdduke (slow)
2014/07/28 20:45:38
Do we need a null check on |parent|? Otherwise we
| |
| 173 ui_resource_layer_->SetUIResourceId(ui_resource_id_); | |
| 174 } | |
| 175 | |
| 176 private: | |
| 177 EffectLayer(ui::SystemUIResourceManager::Type type, | |
| 178 ui::SystemUIResourceManager* resource_manager) | |
| 179 : ui_resource_id_(0), | |
| 180 ui_resource_layer_(cc::UIResourceLayer::Create()), | |
| 181 type_(type), | |
| 182 resource_manager_(resource_manager) { | |
| 183 resource_manager_->Subscribe(type_, this); | |
| 184 } | |
| 185 | |
| 186 cc::UIResourceId ui_resource_id_; | |
| 187 scoped_refptr<cc::UIResourceLayer> ui_resource_layer_; | |
| 188 ui::SystemUIResourceManager::Type type_; | |
| 189 ui::SystemUIResourceManager* resource_manager_; | |
| 190 | |
| 191 DISALLOW_COPY_AND_ASSIGN(EffectLayer); | |
| 192 }; | |
| 193 | |
| 194 EdgeEffect::EdgeEffect(ui::SystemUIResourceManager* resource_manager) | |
| 195 : edge_alpha_(0), | |
| 196 edge_scale_y_(0), | |
| 197 glow_alpha_(0), | |
| 198 glow_scale_y_(0), | |
| 199 edge_alpha_start_(0), | |
| 200 edge_alpha_finish_(0), | |
| 201 edge_scale_y_start_(0), | |
| 202 edge_scale_y_finish_(0), | |
| 203 glow_alpha_start_(0), | |
| 204 glow_alpha_finish_(0), | |
| 205 glow_scale_y_start_(0), | |
| 206 glow_scale_y_finish_(0), | |
| 207 state_(STATE_IDLE), | |
| 208 pull_distance_(0) { | |
| 209 edge_ = EffectLayer::Create(ui::SystemUIResourceManager::OVERSCROLL_EDGE, | |
| 210 resource_manager); | |
| 211 glow_ = EffectLayer::Create(ui::SystemUIResourceManager::OVERSCROLL_GLOW, | |
| 212 resource_manager); | |
| 164 // Prevent the provided layers from drawing until the effect is activated. | 213 // Prevent the provided layers from drawing until the effect is activated. |
| 165 DisableLayer(edge_.get()); | 214 DisableLayer(edge_->layer()); |
| 166 DisableLayer(glow_.get()); | 215 DisableLayer(glow_->layer()); |
| 167 } | 216 } |
| 168 | 217 |
| 169 EdgeEffect::~EdgeEffect() { } | 218 EdgeEffect::~EdgeEffect() { } |
| 170 | 219 |
| 171 bool EdgeEffect::IsFinished() const { | 220 bool EdgeEffect::IsFinished() const { |
| 172 return state_ == STATE_IDLE; | 221 return state_ == STATE_IDLE; |
| 173 } | 222 } |
| 174 | 223 |
| 175 void EdgeEffect::Finish() { | 224 void EdgeEffect::Finish() { |
| 176 DisableLayer(edge_.get()); | 225 DisableLayer(edge_->layer()); |
| 177 DisableLayer(glow_.get()); | 226 DisableLayer(glow_->layer()); |
| 178 pull_distance_ = 0; | 227 pull_distance_ = 0; |
| 179 state_ = STATE_IDLE; | 228 state_ = STATE_IDLE; |
| 180 } | 229 } |
| 181 | 230 |
| 182 void EdgeEffect::Pull(base::TimeTicks current_time, float delta_distance) { | 231 void EdgeEffect::Pull(base::TimeTicks current_time, float delta_distance) { |
| 183 if (state_ == STATE_PULL_DECAY && current_time - start_time_ < duration_) { | 232 if (state_ == STATE_PULL_DECAY && current_time - start_time_ < duration_) { |
| 184 return; | 233 return; |
| 185 } | 234 } |
| 186 if (state_ != STATE_PULL) { | 235 if (state_ != STATE_PULL) { |
| 187 glow_scale_y_ = kPullGlowBegin; | 236 glow_scale_y_ = kPullGlowBegin; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 Edge edge, | 401 Edge edge, |
| 353 float edge_height, | 402 float edge_height, |
| 354 float glow_height, | 403 float glow_height, |
| 355 float offset) { | 404 float offset) { |
| 356 if (IsFinished()) | 405 if (IsFinished()) |
| 357 return; | 406 return; |
| 358 | 407 |
| 359 // An empty window size, while meaningless, is also relatively harmless, and | 408 // An empty window size, while meaningless, is also relatively harmless, and |
| 360 // will simply prevent any drawing of the layers. | 409 // will simply prevent any drawing of the layers. |
| 361 if (window_size.IsEmpty()) { | 410 if (window_size.IsEmpty()) { |
| 362 DisableLayer(edge_.get()); | 411 DisableLayer(edge_->layer()); |
| 363 DisableLayer(glow_.get()); | 412 DisableLayer(glow_->layer()); |
| 364 return; | 413 return; |
| 365 } | 414 } |
| 366 | 415 |
| 367 // Glow | 416 // Glow |
| 368 const int scaled_glow_height = static_cast<int>( | 417 const int scaled_glow_height = static_cast<int>( |
| 369 std::min(glow_height * glow_scale_y_ * kGlowHeightToWidthRatio * 0.6f, | 418 std::min(glow_height * glow_scale_y_ * kGlowHeightToWidthRatio * 0.6f, |
| 370 glow_height * kMaxGlowHeight) + 0.5f); | 419 glow_height * kMaxGlowHeight) + 0.5f); |
| 371 UpdateLayer( | 420 UpdateLayer(glow_->layer(), |
| 372 glow_.get(), edge, window_size, offset, scaled_glow_height, glow_alpha_); | 421 edge, |
| 422 window_size, | |
| 423 offset, | |
| 424 scaled_glow_height, | |
| 425 glow_alpha_); | |
| 373 | 426 |
| 374 // Edge | 427 // Edge |
| 375 const int scaled_edge_height = static_cast<int>(edge_height * edge_scale_y_); | 428 const int scaled_edge_height = static_cast<int>(edge_height * edge_scale_y_); |
| 376 UpdateLayer( | 429 UpdateLayer(edge_->layer(), |
| 377 edge_.get(), edge, window_size, offset, scaled_edge_height, edge_alpha_); | 430 edge, |
| 431 window_size, | |
| 432 offset, | |
| 433 scaled_edge_height, | |
| 434 edge_alpha_); | |
| 435 } | |
| 436 | |
| 437 void EdgeEffect::SetParent(cc::Layer* parent) { | |
| 438 edge_->SetParent(parent); | |
| 439 glow_->SetParent(parent); | |
| 378 } | 440 } |
| 379 | 441 |
| 380 } // namespace content | 442 } // namespace content |
| OLD | NEW |