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

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

Issue 1390113006: Added material design mouse hover feedback support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed the diff delta to depend on correct branch. Created 5 years, 2 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
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"
20 #include "ui/gfx/transform_util.h" 17 #include "ui/gfx/transform_util.h"
21 #include "ui/views/animation/ink_drop_animation_observer.h" 18 #include "ui/views/animation/ink_drop_animation_observer.h"
22 #include "ui/views/view.h" 19 #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
23 20
24 namespace { 21 namespace {
25 22
26 // The minimum scale factor to use when scaling rectangle layers. Smaller values 23 // The minimum scale factor to use when scaling rectangle layers. Smaller values
27 // were causing visual anomalies. 24 // were causing visual anomalies.
28 const float kMinimumRectScale = 0.0001f; 25 const float kMinimumRectScale = 0.0001f;
29 26
30 // The minimum scale factor to use when scaling circle layers. Smaller values 27 // The minimum scale factor to use when scaling circle layers. Smaller values
31 // were causing visual anomalies. 28 // were causing visual anomalies.
32 const float kMinimumCircleScale = 0.001f; 29 const float kMinimumCircleScale = 0.001f;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 gfx::Transform transform; 113 gfx::Transform transform;
117 transform.Scale(x_scale, y_scale); 114 transform.Scale(x_scale, y_scale);
118 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); 115 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y());
119 return transform; 116 return transform;
120 } 117 }
121 118
122 } // namespace 119 } // namespace
123 120
124 namespace views { 121 namespace views {
125 122
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, 123 InkDropAnimation::InkDropAnimation(const gfx::Size& large_size,
237 int large_corner_radius, 124 int large_corner_radius,
238 const gfx::Size& small_size, 125 const gfx::Size& small_size,
239 int small_corner_radius) 126 int small_corner_radius)
240 : large_size_(large_size), 127 : large_size_(large_size),
241 large_corner_radius_(large_corner_radius), 128 large_corner_radius_(large_corner_radius),
242 small_size_(small_size), 129 small_size_(small_size),
243 small_corner_radius_(small_corner_radius), 130 small_corner_radius_(small_corner_radius),
244 circle_layer_delegate_(new CircleLayerDelegate( 131 circle_layer_delegate_(new CircleLayerDelegate(
245 kInkDropColor, 132 kInkDropColor,
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 FOR_EACH_OBSERVER( 417 FOR_EACH_OBSERVER(
531 InkDropAnimationObserver, observers_, 418 InkDropAnimationObserver, observers_,
532 InkDropAnimationEnded(ink_drop_state, 419 InkDropAnimationEnded(ink_drop_state,
533 observer.aborted_count() 420 observer.aborted_count()
534 ? InkDropAnimationObserver::PRE_EMPTED 421 ? InkDropAnimationObserver::PRE_EMPTED
535 : InkDropAnimationObserver::SUCCESS)); 422 : InkDropAnimationObserver::SUCCESS));
536 return true; 423 return true;
537 } 424 }
538 425
539 } // namespace views 426 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698