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 "content/browser/android/overscroll_glow.h" |
8 | 9 |
9 namespace content { | 10 namespace content { |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 enum State { | 14 enum State { |
14 STATE_IDLE = 0, | 15 STATE_IDLE = 0, |
15 STATE_PULL, | 16 STATE_PULL, |
16 STATE_ABSORB, | 17 STATE_ABSORB, |
17 STATE_RECEDE, | 18 STATE_RECEDE, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 gfx::Size bounds = ComputeBounds(edge, window_size, height); | 137 gfx::Size bounds = ComputeBounds(edge, window_size, height); |
137 layer->SetTransformOrigin( | 138 layer->SetTransformOrigin( |
138 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); | 139 gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0)); |
139 layer->SetTransform(ComputeTransform(edge, window_size, offset, height)); | 140 layer->SetTransform(ComputeTransform(edge, window_size, offset, height)); |
140 layer->SetBounds(bounds); | 141 layer->SetBounds(bounds); |
141 layer->SetOpacity(Clamp(opacity, 0.f, 1.f)); | 142 layer->SetOpacity(Clamp(opacity, 0.f, 1.f)); |
142 } | 143 } |
143 | 144 |
144 } // namespace | 145 } // namespace |
145 | 146 |
146 EdgeEffect::EdgeEffect(scoped_refptr<cc::Layer> edge, | 147 EdgeEffect::EdgeEffect(scoped_ptr<OverscrollGlowLayerWrapper> edge, |
147 scoped_refptr<cc::Layer> glow) | 148 scoped_ptr<OverscrollGlowLayerWrapper> glow) |
148 : edge_(edge) | 149 : edge_(edge.Pass()), |
149 , glow_(glow) | 150 glow_(glow.Pass()), |
150 , edge_alpha_(0) | 151 edge_alpha_(0), |
151 , edge_scale_y_(0) | 152 edge_scale_y_(0), |
152 , glow_alpha_(0) | 153 glow_alpha_(0), |
153 , glow_scale_y_(0) | 154 glow_scale_y_(0), |
154 , edge_alpha_start_(0) | 155 edge_alpha_start_(0), |
155 , edge_alpha_finish_(0) | 156 edge_alpha_finish_(0), |
156 , edge_scale_y_start_(0) | 157 edge_scale_y_start_(0), |
157 , edge_scale_y_finish_(0) | 158 edge_scale_y_finish_(0), |
158 , glow_alpha_start_(0) | 159 glow_alpha_start_(0), |
159 , glow_alpha_finish_(0) | 160 glow_alpha_finish_(0), |
160 , glow_scale_y_start_(0) | 161 glow_scale_y_start_(0), |
161 , glow_scale_y_finish_(0) | 162 glow_scale_y_finish_(0), |
162 , state_(STATE_IDLE) | 163 state_(STATE_IDLE), |
163 , pull_distance_(0) { | 164 pull_distance_(0) { |
164 // Prevent the provided layers from drawing until the effect is activated. | 165 // Prevent the provided layers from drawing until the effect is activated. |
165 DisableLayer(edge_.get()); | 166 DisableLayer(edge_->layer()); |
166 DisableLayer(glow_.get()); | 167 DisableLayer(glow_->layer()); |
167 } | 168 } |
168 | 169 |
169 EdgeEffect::~EdgeEffect() { } | 170 EdgeEffect::~EdgeEffect() { } |
170 | 171 |
171 bool EdgeEffect::IsFinished() const { | 172 bool EdgeEffect::IsFinished() const { |
172 return state_ == STATE_IDLE; | 173 return state_ == STATE_IDLE; |
173 } | 174 } |
174 | 175 |
175 void EdgeEffect::Finish() { | 176 void EdgeEffect::Finish() { |
176 DisableLayer(edge_.get()); | 177 DisableLayer(edge_->layer()); |
177 DisableLayer(glow_.get()); | 178 DisableLayer(glow_->layer()); |
178 pull_distance_ = 0; | 179 pull_distance_ = 0; |
179 state_ = STATE_IDLE; | 180 state_ = STATE_IDLE; |
180 } | 181 } |
181 | 182 |
182 void EdgeEffect::Pull(base::TimeTicks current_time, float delta_distance) { | 183 void EdgeEffect::Pull(base::TimeTicks current_time, float delta_distance) { |
183 if (state_ == STATE_PULL_DECAY && current_time - start_time_ < duration_) { | 184 if (state_ == STATE_PULL_DECAY && current_time - start_time_ < duration_) { |
184 return; | 185 return; |
185 } | 186 } |
186 if (state_ != STATE_PULL) { | 187 if (state_ != STATE_PULL) { |
187 glow_scale_y_ = kPullGlowBegin; | 188 glow_scale_y_ = kPullGlowBegin; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 Edge edge, | 353 Edge edge, |
353 float edge_height, | 354 float edge_height, |
354 float glow_height, | 355 float glow_height, |
355 float offset) { | 356 float offset) { |
356 if (IsFinished()) | 357 if (IsFinished()) |
357 return; | 358 return; |
358 | 359 |
359 // An empty window size, while meaningless, is also relatively harmless, and | 360 // An empty window size, while meaningless, is also relatively harmless, and |
360 // will simply prevent any drawing of the layers. | 361 // will simply prevent any drawing of the layers. |
361 if (window_size.IsEmpty()) { | 362 if (window_size.IsEmpty()) { |
362 DisableLayer(edge_.get()); | 363 DisableLayer(edge_->layer()); |
363 DisableLayer(glow_.get()); | 364 DisableLayer(glow_->layer()); |
364 return; | 365 return; |
365 } | 366 } |
366 | 367 |
367 // Glow | 368 // Glow |
368 const int scaled_glow_height = static_cast<int>( | 369 const int scaled_glow_height = static_cast<int>( |
369 std::min(glow_height * glow_scale_y_ * kGlowHeightToWidthRatio * 0.6f, | 370 std::min(glow_height * glow_scale_y_ * kGlowHeightToWidthRatio * 0.6f, |
370 glow_height * kMaxGlowHeight) + 0.5f); | 371 glow_height * kMaxGlowHeight) + 0.5f); |
371 UpdateLayer( | 372 UpdateLayer(glow_->layer(), |
372 glow_.get(), edge, window_size, offset, scaled_glow_height, glow_alpha_); | 373 edge, |
| 374 window_size, |
| 375 offset, |
| 376 scaled_glow_height, |
| 377 glow_alpha_); |
373 | 378 |
374 // Edge | 379 // Edge |
375 const int scaled_edge_height = static_cast<int>(edge_height * edge_scale_y_); | 380 const int scaled_edge_height = static_cast<int>(edge_height * edge_scale_y_); |
376 UpdateLayer( | 381 UpdateLayer(edge_->layer(), |
377 edge_.get(), edge, window_size, offset, scaled_edge_height, edge_alpha_); | 382 edge, |
| 383 window_size, |
| 384 offset, |
| 385 scaled_edge_height, |
| 386 edge_alpha_); |
378 } | 387 } |
379 | 388 |
380 } // namespace content | 389 } // namespace content |
OLD | NEW |