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

Side by Side Diff: ui/views/animation/ink_drop_animation.cc

Issue 1430153003: Moved the *PaintedLayerDelegates from ink_drop_animation.cc to ink_drop_painted_layer_delegates.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added use of BasePaintedLayerDelegate::GetCenterPoint(). Created 5 years, 1 month 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 | « no previous file | ui/views/animation/ink_drop_painted_layer_delegates.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/views/animation/ink_drop_animation.h" 5 #include "ui/views/animation/ink_drop_animation.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "third_party/skia/include/core/SkColor.h" 11 #include "third_party/skia/include/core/SkColor.h"
12 #include "third_party/skia/include/core/SkPaint.h"
13 #include "ui/base/ui_base_switches.h" 12 #include "ui/base/ui_base_switches.h"
14 #include "ui/compositor/callback_layer_animation_observer.h" 13 #include "ui/compositor/callback_layer_animation_observer.h"
15 #include "ui/compositor/layer.h" 14 #include "ui/compositor/layer.h"
16 #include "ui/compositor/layer_animation_sequence.h" 15 #include "ui/compositor/layer_animation_sequence.h"
17 #include "ui/compositor/paint_recorder.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h" 16 #include "ui/compositor/scoped_layer_animation_settings.h"
19 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/geometry/point_conversions.h"
20 #include "ui/gfx/transform_util.h" 18 #include "ui/gfx/transform_util.h"
21 #include "ui/views/animation/ink_drop_animation_observer.h" 19 #include "ui/views/animation/ink_drop_animation_observer.h"
20 #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
22 #include "ui/views/view.h" 21 #include "ui/views/view.h"
23 22
24 namespace { 23 namespace {
25 24
26 // The minimum scale factor to use when scaling rectangle layers. Smaller values 25 // The minimum scale factor to use when scaling rectangle layers. Smaller values
27 // were causing visual anomalies. 26 // were causing visual anomalies.
28 const float kMinimumRectScale = 0.0001f; 27 const float kMinimumRectScale = 0.0001f;
29 28
30 // The minimum scale factor to use when scaling circle layers. Smaller values 29 // The minimum scale factor to use when scaling circle layers. Smaller values
31 // were causing visual anomalies. 30 // were causing visual anomalies.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 gfx::Transform transform; 115 gfx::Transform transform;
117 transform.Scale(x_scale, y_scale); 116 transform.Scale(x_scale, y_scale);
118 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); 117 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y());
119 return transform; 118 return transform;
120 } 119 }
121 120
122 } // namespace 121 } // namespace
123 122
124 namespace views { 123 namespace views {
125 124
126 // Base ui::LayerDelegate stub that can be extended to paint shapes of a
127 // specific color.
128 class BasePaintedLayerDelegate : public ui::LayerDelegate {
129 public:
130 ~BasePaintedLayerDelegate() override;
131
132 SkColor color() const { return color_; }
133
134 // ui::LayerDelegate:
135 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override;
136 void OnDeviceScaleFactorChanged(float device_scale_factor) override;
137 base::Closure PrepareForLayerBoundsChange() override;
138
139 protected:
140 explicit BasePaintedLayerDelegate(SkColor color);
141
142 private:
143 // The color to paint.
144 SkColor color_;
145
146 DISALLOW_COPY_AND_ASSIGN(BasePaintedLayerDelegate);
147 };
148
149 BasePaintedLayerDelegate::BasePaintedLayerDelegate(SkColor color)
150 : color_(color) {}
151
152 BasePaintedLayerDelegate::~BasePaintedLayerDelegate() {}
153
154 void BasePaintedLayerDelegate::OnDelegatedFrameDamage(
155 const gfx::Rect& damage_rect_in_dip) {}
156
157 void BasePaintedLayerDelegate::OnDeviceScaleFactorChanged(
158 float device_scale_factor) {}
159
160 base::Closure BasePaintedLayerDelegate::PrepareForLayerBoundsChange() {
161 return base::Closure();
162 }
163
164 // A BasePaintedLayerDelegate that paints a circle of a specified color and
165 // radius.
166 class CircleLayerDelegate : public BasePaintedLayerDelegate {
167 public:
168 CircleLayerDelegate(SkColor color, int radius);
169 ~CircleLayerDelegate() override;
170
171 int radius() const { return radius_; }
172
173 // ui::LayerDelegate:
174 void OnPaintLayer(const ui::PaintContext& context) override;
175
176 private:
177 // The radius of the circle.
178 int radius_;
179
180 DISALLOW_COPY_AND_ASSIGN(CircleLayerDelegate);
181 };
182
183 CircleLayerDelegate::CircleLayerDelegate(SkColor color, int radius)
184 : BasePaintedLayerDelegate(color), radius_(radius) {}
185
186 CircleLayerDelegate::~CircleLayerDelegate() {}
187
188 void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
189 SkPaint paint;
190 paint.setColor(color());
191 paint.setFlags(SkPaint::kAntiAlias_Flag);
192 paint.setStyle(SkPaint::kFill_Style);
193
194 ui::PaintRecorder recorder(context, gfx::Size(radius_, radius_));
195 gfx::Canvas* canvas = recorder.canvas();
196
197 gfx::Point center_point = gfx::Point(radius_, radius_);
198 canvas->DrawCircle(center_point, radius_, paint);
199 }
200
201 // A BasePaintedLayerDelegate that paints a rectangle of a specified color and
202 // size.
203 class RectangleLayerDelegate : public BasePaintedLayerDelegate {
204 public:
205 RectangleLayerDelegate(SkColor color, gfx::Size size);
206 ~RectangleLayerDelegate() override;
207
208 const gfx::Size& size() const { return size_; }
209
210 // ui::LayerDelegate:
211 void OnPaintLayer(const ui::PaintContext& context) override;
212
213 private:
214 // The size of the rectangle.
215 gfx::Size size_;
216
217 DISALLOW_COPY_AND_ASSIGN(RectangleLayerDelegate);
218 };
219
220 RectangleLayerDelegate::RectangleLayerDelegate(SkColor color, gfx::Size size)
221 : BasePaintedLayerDelegate(color), size_(size) {}
222
223 RectangleLayerDelegate::~RectangleLayerDelegate() {}
224
225 void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
226 SkPaint paint;
227 paint.setColor(color());
228 paint.setFlags(SkPaint::kAntiAlias_Flag);
229 paint.setStyle(SkPaint::kFill_Style);
230
231 ui::PaintRecorder recorder(context, size_);
232 gfx::Canvas* canvas = recorder.canvas();
233 canvas->DrawRect(gfx::Rect(size_), paint);
234 }
235
236 InkDropAnimation::InkDropAnimation(const gfx::Size& large_size, 125 InkDropAnimation::InkDropAnimation(const gfx::Size& large_size,
237 int large_corner_radius, 126 int large_corner_radius,
238 const gfx::Size& small_size, 127 const gfx::Size& small_size,
239 int small_corner_radius) 128 int small_corner_radius)
240 : large_size_(large_size), 129 : large_size_(large_size),
241 large_corner_radius_(large_corner_radius), 130 large_corner_radius_(large_corner_radius),
242 small_size_(small_size), 131 small_size_(small_size),
243 small_corner_radius_(small_corner_radius), 132 small_corner_radius_(small_corner_radius),
244 circle_layer_delegate_(new CircleLayerDelegate( 133 circle_layer_delegate_(new CircleLayerDelegate(
245 kInkDropColor, 134 kInkDropColor,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // methods to calculate the complex Transforms. 323 // methods to calculate the complex Transforms.
435 324
436 const float circle_scale = std::max( 325 const float circle_scale = std::max(
437 kMinimumCircleScale, 326 kMinimumCircleScale,
438 corner_radius / static_cast<float>(circle_layer_delegate_->radius())); 327 corner_radius / static_cast<float>(circle_layer_delegate_->radius()));
439 328
440 const float circle_target_x_offset = size.width() / 2.0f - corner_radius; 329 const float circle_target_x_offset = size.width() / 2.0f - corner_radius;
441 const float circle_target_y_offset = size.height() / 2.0f - corner_radius; 330 const float circle_target_y_offset = size.height() / 2.0f - corner_radius;
442 331
443 (*transforms_out)[TOP_LEFT_CIRCLE] = CalculateCircleTransform( 332 (*transforms_out)[TOP_LEFT_CIRCLE] = CalculateCircleTransform(
444 painted_layers_[TOP_LEFT_CIRCLE]->bounds().CenterPoint(), circle_scale, 333 ToRoundedPoint(circle_layer_delegate_->GetCenterPoint()), circle_scale,
445 -circle_target_x_offset, -circle_target_y_offset); 334 -circle_target_x_offset, -circle_target_y_offset);
446 335
447 (*transforms_out)[TOP_RIGHT_CIRCLE] = CalculateCircleTransform( 336 (*transforms_out)[TOP_RIGHT_CIRCLE] = CalculateCircleTransform(
448 painted_layers_[TOP_RIGHT_CIRCLE]->bounds().CenterPoint(), circle_scale, 337 ToRoundedPoint(circle_layer_delegate_->GetCenterPoint()), circle_scale,
449 circle_target_x_offset, -circle_target_y_offset); 338 circle_target_x_offset, -circle_target_y_offset);
450 339
451 (*transforms_out)[BOTTOM_RIGHT_CIRCLE] = CalculateCircleTransform( 340 (*transforms_out)[BOTTOM_RIGHT_CIRCLE] = CalculateCircleTransform(
452 painted_layers_[BOTTOM_RIGHT_CIRCLE]->bounds().CenterPoint(), 341 ToRoundedPoint(circle_layer_delegate_->GetCenterPoint()), circle_scale,
453 circle_scale, circle_target_x_offset, circle_target_y_offset); 342 circle_target_x_offset, circle_target_y_offset);
454 343
455 (*transforms_out)[BOTTOM_LEFT_CIRCLE] = CalculateCircleTransform( 344 (*transforms_out)[BOTTOM_LEFT_CIRCLE] = CalculateCircleTransform(
456 painted_layers_[BOTTOM_LEFT_CIRCLE]->bounds().CenterPoint(), circle_scale, 345 ToRoundedPoint(circle_layer_delegate_->GetCenterPoint()), circle_scale,
457 -circle_target_x_offset, circle_target_y_offset); 346 -circle_target_x_offset, circle_target_y_offset);
458 347
459 const float rect_delegate_width = 348 const float rect_delegate_width =
460 static_cast<float>(rect_layer_delegate_->size().width()); 349 static_cast<float>(rect_layer_delegate_->size().width());
461 const float rect_delegate_height = 350 const float rect_delegate_height =
462 static_cast<float>(rect_layer_delegate_->size().height()); 351 static_cast<float>(rect_layer_delegate_->size().height());
463 352
464 (*transforms_out)[HORIZONTAL_RECT] = CalculateRectTransform( 353 (*transforms_out)[HORIZONTAL_RECT] = CalculateRectTransform(
465 painted_layers_[HORIZONTAL_RECT]->bounds().CenterPoint(), 354 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()),
466 std::max(kMinimumRectScale, size.width() / rect_delegate_width), 355 std::max(kMinimumRectScale, size.width() / rect_delegate_width),
467 std::max(kMinimumRectScale, 356 std::max(kMinimumRectScale,
468 (size.height() - 2.0f * corner_radius) / rect_delegate_height)); 357 (size.height() - 2.0f * corner_radius) / rect_delegate_height));
469 358
470 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( 359 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform(
471 painted_layers_[VERTICAL_RECT]->bounds().CenterPoint(), 360 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()),
472 std::max(kMinimumRectScale, 361 std::max(kMinimumRectScale,
473 (size.width() - 2.0f * corner_radius) / rect_delegate_width), 362 (size.width() - 2.0f * corner_radius) / rect_delegate_width),
474 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); 363 std::max(kMinimumRectScale, size.height() / rect_delegate_height));
475 } 364 }
476 365
477 void InkDropAnimation::GetCurrentTansforms( 366 void InkDropAnimation::GetCurrentTansforms(
478 InkDropTransforms* transforms_out) const { 367 InkDropTransforms* transforms_out) const {
479 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 368 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
480 (*transforms_out)[i] = painted_layers_[i]->GetTargetTransform(); 369 (*transforms_out)[i] = painted_layers_[i]->GetTargetTransform();
481 } 370 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 FOR_EACH_OBSERVER( 419 FOR_EACH_OBSERVER(
531 InkDropAnimationObserver, observers_, 420 InkDropAnimationObserver, observers_,
532 InkDropAnimationEnded(ink_drop_state, 421 InkDropAnimationEnded(ink_drop_state,
533 observer.aborted_count() 422 observer.aborted_count()
534 ? InkDropAnimationObserver::PRE_EMPTED 423 ? InkDropAnimationObserver::PRE_EMPTED
535 : InkDropAnimationObserver::SUCCESS)); 424 : InkDropAnimationObserver::SUCCESS));
536 return true; 425 return true;
537 } 426 }
538 427
539 } // namespace views 428 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/animation/ink_drop_painted_layer_delegates.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698