OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "ash/shelf/voice_interaction_overlay.h" | 5 #include "ash/shelf/voice_interaction_overlay.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "ash/public/cpp/shelf_types.h" | 12 #include "ash/public/cpp/shelf_types.h" |
12 #include "ash/resources/vector_icons/vector_icons.h" | 13 #include "ash/resources/vector_icons/vector_icons.h" |
13 #include "ash/shelf/app_list_button.h" | 14 #include "ash/shelf/app_list_button.h" |
14 #include "ash/shelf/ink_drop_button_listener.h" | 15 #include "ash/shelf/ink_drop_button_listener.h" |
15 #include "ash/shelf/shelf.h" | 16 #include "ash/shelf/shelf.h" |
16 #include "ash/shelf/shelf_constants.h" | 17 #include "ash/shelf/shelf_constants.h" |
17 #include "ash/shelf/shelf_view.h" | 18 #include "ash/shelf/shelf_view.h" |
18 #include "ash/shell.h" | 19 #include "ash/shell.h" |
19 #include "ash/strings/grit/ash_strings.h" | 20 #include "ash/strings/grit/ash_strings.h" |
20 #include "ash/system/tray/tray_popup_utils.h" | 21 #include "ash/system/tray/tray_popup_utils.h" |
21 #include "base/command_line.h" | 22 #include "base/command_line.h" |
22 #include "base/memory/ptr_util.h" | 23 #include "base/memory/ptr_util.h" |
23 #include "base/metrics/user_metrics.h" | 24 #include "base/metrics/user_metrics.h" |
24 #include "base/metrics/user_metrics_action.h" | 25 #include "base/metrics/user_metrics_action.h" |
25 #include "chromeos/chromeos_switches.h" | 26 #include "chromeos/chromeos_switches.h" |
26 #include "ui/accessibility/ax_node_data.h" | 27 #include "ui/accessibility/ax_node_data.h" |
27 #include "ui/app_list/presenter/app_list.h" | 28 #include "ui/app_list/presenter/app_list.h" |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/compositor/callback_layer_animation_observer.h" | |
29 #include "ui/compositor/layer_animation_element.h" | 31 #include "ui/compositor/layer_animation_element.h" |
30 #include "ui/compositor/layer_animation_observer.h" | 32 #include "ui/compositor/layer_animation_observer.h" |
31 #include "ui/compositor/layer_animation_sequence.h" | 33 #include "ui/compositor/layer_animation_sequence.h" |
32 #include "ui/compositor/layer_animator.h" | 34 #include "ui/compositor/layer_animator.h" |
33 #include "ui/compositor/paint_context.h" | 35 #include "ui/compositor/paint_context.h" |
34 #include "ui/compositor/paint_recorder.h" | 36 #include "ui/compositor/paint_recorder.h" |
35 #include "ui/compositor/scoped_layer_animation_settings.h" | 37 #include "ui/compositor/scoped_layer_animation_settings.h" |
36 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
37 #include "ui/gfx/image/canvas_image_source.h" | 39 #include "ui/gfx/image/canvas_image_source.h" |
38 #include "ui/gfx/image/image_skia.h" | 40 #include "ui/gfx/image/image_skia.h" |
39 #include "ui/gfx/image/image_skia_operations.h" | 41 #include "ui/gfx/image/image_skia_operations.h" |
40 #include "ui/gfx/paint_vector_icon.h" | 42 #include "ui/gfx/paint_vector_icon.h" |
41 #include "ui/gfx/scoped_canvas.h" | 43 #include "ui/gfx/scoped_canvas.h" |
42 #include "ui/gfx/skia_paint_util.h" | 44 #include "ui/gfx/skia_paint_util.h" |
43 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 45 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
44 #include "ui/views/animation/ink_drop_impl.h" | 46 #include "ui/views/animation/ink_drop_impl.h" |
45 #include "ui/views/animation/ink_drop_mask.h" | 47 #include "ui/views/animation/ink_drop_mask.h" |
48 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" | |
46 #include "ui/views/painter.h" | 49 #include "ui/views/painter.h" |
47 #include "ui/views/widget/widget.h" | 50 #include "ui/views/widget/widget.h" |
48 | 51 |
49 namespace ash { | 52 namespace ash { |
50 namespace { | 53 namespace { |
51 constexpr int kFullExpandDurationMs = 450; | 54 constexpr int kFullExpandDurationMs = 450; |
52 constexpr int kFullRetractDurationMs = 300; | 55 constexpr int kFullRetractDurationMs = 300; |
53 constexpr int kFullBurstDurationMs = 200; | 56 constexpr int kFullBurstDurationMs = 200; |
54 | 57 |
55 constexpr float kRippleCircleInitRadiusDip = 40.f; | 58 constexpr float kRippleCircleInitRadiusDip = 40.f; |
56 constexpr float kRippleCircleStartRadiusDip = 1.f; | 59 constexpr float kRippleCircleStartRadiusDip = 1.f; |
57 constexpr float kRippleCircleRadiusDip = 77.f; | 60 constexpr float kRippleCircleRadiusDip = 77.f; |
58 constexpr float kRippleCircleBurstRadiusDip = 96.f; | 61 constexpr float kRippleCircleBurstRadiusDip = 96.f; |
59 constexpr SkColor kRippleColor = SK_ColorWHITE; | 62 constexpr SkColor kRippleColor = SK_ColorWHITE; |
60 constexpr int kRippleExpandDurationMs = 400; | 63 constexpr int kRippleExpandDurationMs = 400; |
61 constexpr int kRippleOpacityDurationMs = 100; | 64 constexpr int kRippleOpacityDurationMs = 100; |
62 constexpr int kRippleOpacityRetractDurationMs = 200; | 65 constexpr int kRippleOpacityRetractDurationMs = 200; |
63 constexpr float kRippleOpacity = 0.2f; | 66 constexpr float kRippleOpacity = 0.2f; |
64 | 67 |
65 constexpr float kIconInitSizeDip = 24.f; | 68 constexpr float kIconInitSizeDip = 48.f; |
66 constexpr float kIconStartSizeDip = 4.f; | 69 constexpr float kIconStartSizeDip = 4.f; |
67 constexpr float kIconSizeDip = 24.f; | 70 constexpr float kIconSizeDip = 24.f; |
71 constexpr float kIconEndSizeDip = 48.f; | |
68 constexpr float kIconOffsetDip = 56.f; | 72 constexpr float kIconOffsetDip = 56.f; |
69 constexpr float kIconOpacity = 1.f; | 73 constexpr float kIconOpacity = 1.f; |
70 constexpr int kIconBurstDurationMs = 100; | |
71 | 74 |
72 constexpr float kBackgroundInitSizeDip = 48.f; | 75 constexpr float kBackgroundInitSizeDip = 48.f; |
73 constexpr float kBackgroundStartSizeDip = 10.f; | 76 constexpr float kBackgroundStartSizeDip = 10.f; |
74 constexpr float kBackgroundSizeDip = 48.f; | 77 constexpr float kBackgroundSizeDip = 48.f; |
75 constexpr int kBackgroundOpacityDurationMs = 200; | 78 constexpr int kBackgroundOpacityDurationMs = 200; |
76 constexpr float kBackgroundShadowElevationDip = 24.f; | 79 constexpr float kBackgroundShadowElevationDip = 24.f; |
80 // TODO(xiaohuic): this is 2x device size, 1x actually have a different size. | |
81 // Need to figure out a way to dynamically change sizes. | |
82 constexpr float kBackgroundLargeWidthDip = 352.5f; | |
83 constexpr float kBackgroundLargeHeightDip = 540.0f; | |
84 constexpr float kBackgroundCornerRadiusDip = 2.f; | |
85 constexpr float kBackgroundPaddingDip = 6.f; | |
86 constexpr int kBackgroundMorphDurationMs = 300; | |
87 | |
88 constexpr int kHideDurationMs = 200; | |
89 | |
90 // The minimum scale factor to use when scaling rectangle layers. Smaller values | |
91 // were causing visual anomalies. | |
92 constexpr float kMinimumRectScale = 0.0001f; | |
93 | |
94 // The minimum scale factor to use when scaling circle layers. Smaller values | |
95 // were causing visual anomalies. | |
96 constexpr float kMinimumCircleScale = 0.001f; | |
97 | |
98 class VoiceInteractionIcon : public ui::Layer, public ui::LayerDelegate { | |
99 public: | |
100 VoiceInteractionIcon() { | |
101 set_name("VoiceInteractionOverlay:ICON_LAYER"); | |
102 SetBounds(gfx::Rect(0, 0, kIconInitSizeDip, kIconInitSizeDip)); | |
103 SetFillsBoundsOpaquely(false); | |
104 SetMasksToBounds(false); | |
105 set_delegate(this); | |
106 } | |
107 | |
108 private: | |
109 // ui::LayerDelegate: | |
110 void OnPaintLayer(const ui::PaintContext& context) override { | |
111 ui::PaintRecorder recorder(context, size()); | |
112 gfx::PaintVectorIcon(recorder.canvas(), kShelfVoiceInteractionIcon, | |
113 kIconInitSizeDip, 0); | |
114 } | |
115 | |
116 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | |
117 | |
118 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(VoiceInteractionIcon); | |
121 }; | |
122 } // namespace | |
77 | 123 |
78 class VoiceInteractionIconBackground : public ui::Layer, | 124 class VoiceInteractionIconBackground : public ui::Layer, |
79 public ui::LayerDelegate { | 125 public ui::LayerDelegate { |
80 public: | 126 public: |
81 VoiceInteractionIconBackground() : Layer(ui::LAYER_NOT_DRAWN) { | 127 VoiceInteractionIconBackground() |
128 : Layer(ui::LAYER_NOT_DRAWN), | |
129 large_size_( | |
130 gfx::Size(kBackgroundLargeWidthDip, kBackgroundLargeHeightDip)), | |
131 small_size_(gfx::Size(kBackgroundSizeDip, kBackgroundSizeDip)), | |
132 center_point_( | |
133 gfx::PointF(kBackgroundSizeDip / 2, kBackgroundSizeDip / 2)), | |
134 circle_layer_delegate_(base::MakeUnique<views::CircleLayerDelegate>( | |
135 SK_ColorWHITE, | |
136 kBackgroundSizeDip / 2)), | |
137 rect_layer_delegate_(base::MakeUnique<views::RectangleLayerDelegate>( | |
138 SK_ColorWHITE, | |
139 gfx::SizeF(small_size_))) { | |
82 set_name("VoiceInteractionOverlay:BACKGROUND_LAYER"); | 140 set_name("VoiceInteractionOverlay:BACKGROUND_LAYER"); |
83 SetBounds(gfx::Rect(0, 0, kBackgroundInitSizeDip, kBackgroundInitSizeDip)); | 141 SetBounds(gfx::Rect(0, 0, kBackgroundInitSizeDip, kBackgroundInitSizeDip)); |
84 SetFillsBoundsOpaquely(false); | 142 SetFillsBoundsOpaquely(false); |
85 SetMasksToBounds(false); | 143 SetMasksToBounds(false); |
86 | 144 |
145 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | |
146 AddPaintLayer(static_cast<PaintedShape>(i)); | |
147 | |
87 shadow_values_ = | 148 shadow_values_ = |
88 gfx::ShadowValue::MakeMdShadowValues(kBackgroundShadowElevationDip); | 149 gfx::ShadowValue::MakeMdShadowValues(kBackgroundShadowElevationDip); |
89 const gfx::Insets shadow_margin = | 150 const gfx::Insets shadow_margin = |
90 gfx::ShadowValue::GetMargin(shadow_values_); | 151 gfx::ShadowValue::GetMargin(shadow_values_); |
91 | 152 |
92 shadow_layer_.reset(new ui::Layer()); | 153 shadow_layer_.reset(new ui::Layer()); |
93 shadow_layer_->set_delegate(this); | 154 shadow_layer_->set_delegate(this); |
94 shadow_layer_->SetFillsBoundsOpaquely(false); | 155 shadow_layer_->SetFillsBoundsOpaquely(false); |
95 shadow_layer_->SetBounds( | 156 shadow_layer_->SetBounds( |
96 gfx::Rect(shadow_margin.left(), shadow_margin.top(), | 157 gfx::Rect(shadow_margin.left(), shadow_margin.top(), |
97 kBackgroundInitSizeDip - shadow_margin.width(), | 158 kBackgroundInitSizeDip - shadow_margin.width(), |
98 kBackgroundInitSizeDip - shadow_margin.height())); | 159 kBackgroundInitSizeDip - shadow_margin.height())); |
99 Add(shadow_layer_.get()); | 160 Add(shadow_layer_.get()); |
100 } | 161 } |
101 ~VoiceInteractionIconBackground() override{}; | 162 ~VoiceInteractionIconBackground() override{}; |
102 | 163 |
164 void AnimateToLarge(const gfx::PointF& new_center, | |
165 ui::LayerAnimationObserver* animation_observer) { | |
166 PaintedShapeTransforms transforms; | |
167 // Setup the painted layers to be the small round size and show it | |
168 CalculateCircleTransforms(small_size_, &transforms); | |
169 SetTransforms(transforms); | |
170 SetPaintedLayersVisible(true); | |
171 | |
172 // Hide the shadow layer | |
173 shadow_layer_->SetVisible(false); | |
174 | |
175 center_point_ = new_center; | |
176 // Animate the painted layers to the large rectangle size | |
177 CalculateRectTransforms(large_size_, kBackgroundCornerRadiusDip, | |
178 &transforms); | |
179 | |
180 AnimateToTransforms( | |
181 transforms, | |
182 base::TimeDelta::FromMilliseconds(kBackgroundMorphDurationMs), | |
183 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | |
184 gfx::Tween::LINEAR_OUT_SLOW_IN, animation_observer); | |
185 } | |
186 | |
187 void ResetShape() { | |
188 // This reverts to the original small round shape. | |
189 shadow_layer_->SetVisible(true); | |
190 SetPaintedLayersVisible(false); | |
191 center_point_.SetPoint(small_size_.width() / 2.f, | |
192 small_size_.height() / 2.f); | |
193 } | |
194 | |
103 private: | 195 private: |
196 // Enumeration of the different shapes that compose the background. | |
197 enum PaintedShape { | |
198 TOP_LEFT_CIRCLE = 0, | |
199 TOP_RIGHT_CIRCLE, | |
200 BOTTOM_RIGHT_CIRCLE, | |
201 BOTTOM_LEFT_CIRCLE, | |
202 HORIZONTAL_RECT, | |
203 VERTICAL_RECT, | |
204 // The total number of shapes, not an actual shape. | |
205 PAINTED_SHAPE_COUNT | |
oshima
2017/07/08 00:05:32
Okay, sorry I wasn't clear. I'd say this is option
| |
206 }; | |
207 | |
208 typedef gfx::Transform PaintedShapeTransforms[PAINTED_SHAPE_COUNT]; | |
209 | |
210 void AddPaintLayer(PaintedShape painted_shape) { | |
211 ui::LayerDelegate* delegate = nullptr; | |
212 switch (painted_shape) { | |
213 case TOP_LEFT_CIRCLE: | |
214 case TOP_RIGHT_CIRCLE: | |
215 case BOTTOM_RIGHT_CIRCLE: | |
216 case BOTTOM_LEFT_CIRCLE: | |
217 delegate = circle_layer_delegate_.get(); | |
218 break; | |
219 case HORIZONTAL_RECT: | |
220 case VERTICAL_RECT: | |
221 delegate = rect_layer_delegate_.get(); | |
222 break; | |
223 case PAINTED_SHAPE_COUNT: | |
224 NOTREACHED() << "PAINTED_SHAPE_COUNT is not an actual shape type."; | |
225 break; | |
226 } | |
227 | |
228 ui::Layer* layer = new ui::Layer(); | |
229 Add(layer); | |
230 | |
231 layer->SetBounds(gfx::Rect(small_size_)); | |
232 layer->SetFillsBoundsOpaquely(false); | |
233 layer->set_delegate(delegate); | |
234 layer->SetVisible(true); | |
235 layer->SetOpacity(1.0); | |
236 layer->SetMasksToBounds(false); | |
237 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape)); | |
238 | |
239 painted_layers_[static_cast<int>(painted_shape)].reset(layer); | |
240 } | |
241 | |
242 void SetTransforms(const PaintedShapeTransforms transforms) { | |
243 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | |
244 painted_layers_[i]->SetTransform(transforms[i]); | |
245 } | |
246 | |
247 void SetPaintedLayersVisible(bool visible) { | |
248 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | |
249 painted_layers_[i]->SetVisible(visible); | |
250 } | |
251 | |
252 void CalculateCircleTransforms(const gfx::Size& size, | |
253 PaintedShapeTransforms* transforms_out) const { | |
254 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f, | |
255 transforms_out); | |
256 } | |
257 | |
258 void CalculateRectTransforms(const gfx::Size& desired_size, | |
259 float corner_radius, | |
260 PaintedShapeTransforms* transforms_out) const { | |
261 DCHECK_GE(desired_size.width() / 2.0f, corner_radius) | |
262 << "The circle's diameter should not be greater than the total width."; | |
263 DCHECK_GE(desired_size.height() / 2.0f, corner_radius) | |
264 << "The circle's diameter should not be greater than the total height."; | |
265 | |
266 gfx::SizeF size(desired_size); | |
267 // This function can be called before the layer's been added to a view, | |
268 // either at construction time or in tests. | |
269 if (GetCompositor()) { | |
270 // Modify |desired_size| so that the ripple aligns to pixel bounds. | |
271 const float dsf = GetCompositor()->device_scale_factor(); | |
272 gfx::RectF ripple_bounds((gfx::PointF(center_point_)), gfx::SizeF()); | |
273 ripple_bounds.Inset(-gfx::InsetsF(desired_size.height() / 2.0f, | |
274 desired_size.width() / 2.0f)); | |
275 ripple_bounds.Scale(dsf); | |
276 ripple_bounds = gfx::RectF(gfx::ToEnclosingRect(ripple_bounds)); | |
277 ripple_bounds.Scale(1.0f / dsf); | |
278 size = ripple_bounds.size(); | |
279 } | |
280 | |
281 // The shapes are drawn such that their center points are not at the origin. | |
282 // Thus we use the CalculateCircleTransform() and CalculateRectTransform() | |
283 // methods to calculate the complex Transforms. | |
284 | |
285 const float circle_scale = std::max( | |
286 kMinimumCircleScale, | |
287 corner_radius / static_cast<float>(circle_layer_delegate_->radius())); | |
288 | |
289 const float circle_target_x_offset = size.width() / 2.0f - corner_radius; | |
290 const float circle_target_y_offset = size.height() / 2.0f - corner_radius; | |
291 | |
292 (*transforms_out)[TOP_LEFT_CIRCLE] = CalculateCircleTransform( | |
293 circle_scale, -circle_target_x_offset, -circle_target_y_offset); | |
294 (*transforms_out)[TOP_RIGHT_CIRCLE] = CalculateCircleTransform( | |
295 circle_scale, circle_target_x_offset, -circle_target_y_offset); | |
296 (*transforms_out)[BOTTOM_RIGHT_CIRCLE] = CalculateCircleTransform( | |
297 circle_scale, circle_target_x_offset, circle_target_y_offset); | |
298 (*transforms_out)[BOTTOM_LEFT_CIRCLE] = CalculateCircleTransform( | |
299 circle_scale, -circle_target_x_offset, circle_target_y_offset); | |
300 | |
301 const float rect_delegate_width = rect_layer_delegate_->size().width(); | |
302 const float rect_delegate_height = rect_layer_delegate_->size().height(); | |
303 | |
304 (*transforms_out)[HORIZONTAL_RECT] = CalculateRectTransform( | |
305 std::max(kMinimumRectScale, size.width() / rect_delegate_width), | |
306 std::max(kMinimumRectScale, (size.height() - 2.0f * corner_radius) / | |
307 rect_delegate_height)); | |
308 | |
309 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( | |
310 std::max(kMinimumRectScale, | |
311 (size.width() - 2.0f * corner_radius) / rect_delegate_width), | |
312 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); | |
313 } | |
314 | |
315 gfx::Transform CalculateCircleTransform(float scale, | |
316 float target_center_x, | |
317 float target_center_y) const { | |
318 gfx::Transform transform; | |
319 // Offset for the center point of the ripple. | |
320 transform.Translate(center_point_.x(), center_point_.y()); | |
321 // Move circle to target. | |
322 transform.Translate(target_center_x, target_center_y); | |
323 transform.Scale(scale, scale); | |
324 // Align center point of the painted circle. | |
325 const gfx::Vector2dF circle_center_offset = | |
326 circle_layer_delegate_->GetCenteringOffset(); | |
327 transform.Translate(-circle_center_offset.x(), -circle_center_offset.y()); | |
328 return transform; | |
329 } | |
330 | |
331 gfx::Transform CalculateRectTransform(float x_scale, float y_scale) const { | |
332 gfx::Transform transform; | |
333 transform.Translate(center_point_.x(), center_point_.y()); | |
334 transform.Scale(x_scale, y_scale); | |
335 const gfx::Vector2dF rect_center_offset = | |
336 rect_layer_delegate_->GetCenteringOffset(); | |
337 transform.Translate(-rect_center_offset.x(), -rect_center_offset.y()); | |
338 return transform; | |
339 } | |
340 | |
341 void AnimateToTransforms( | |
342 const PaintedShapeTransforms transforms, | |
343 base::TimeDelta duration, | |
344 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | |
345 gfx::Tween::Type tween, | |
346 ui::LayerAnimationObserver* animation_observer) { | |
347 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { | |
348 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); | |
349 ui::ScopedLayerAnimationSettings animation(animator); | |
350 animation.SetPreemptionStrategy(preemption_strategy); | |
351 animation.SetTweenType(tween); | |
352 std::unique_ptr<ui::LayerAnimationElement> element = | |
353 ui::LayerAnimationElement::CreateTransformElement(transforms[i], | |
354 duration); | |
355 ui::LayerAnimationSequence* sequence = | |
356 new ui::LayerAnimationSequence(std::move(element)); | |
357 | |
358 if (animation_observer) | |
359 sequence->AddObserver(animation_observer); | |
360 | |
361 animator->StartAnimation(sequence); | |
362 } | |
363 } | |
364 | |
365 std::string ToLayerName(PaintedShape painted_shape) { | |
366 switch (painted_shape) { | |
367 case TOP_LEFT_CIRCLE: | |
368 return "TOP_LEFT_CIRCLE"; | |
369 case TOP_RIGHT_CIRCLE: | |
370 return "TOP_RIGHT_CIRCLE"; | |
371 case BOTTOM_RIGHT_CIRCLE: | |
372 return "BOTTOM_RIGHT_CIRCLE"; | |
373 case BOTTOM_LEFT_CIRCLE: | |
374 return "BOTTOM_LEFT_CIRCLE"; | |
375 case HORIZONTAL_RECT: | |
376 return "HORIZONTAL_RECT"; | |
377 case VERTICAL_RECT: | |
378 return "VERTICAL_RECT"; | |
379 case PAINTED_SHAPE_COUNT: | |
380 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used."; | |
381 return "PAINTED_SHAPE_COUNT"; | |
382 } | |
383 return "UNKNOWN"; | |
384 } | |
385 | |
104 void OnPaintLayer(const ui::PaintContext& context) override { | 386 void OnPaintLayer(const ui::PaintContext& context) override { |
105 // Radius is based on the parent layer size, the shadow layer is expanded | 387 // Radius is based on the parent layer size, the shadow layer is expanded |
106 // to make room for the shadow. | 388 // to make room for the shadow. |
107 float radius = size().width() / 2.f; | 389 float radius = size().width() / 2.f; |
108 | 390 |
109 ui::PaintRecorder recorder(context, shadow_layer_->size()); | 391 ui::PaintRecorder recorder(context, shadow_layer_->size()); |
110 gfx::Canvas* canvas = recorder.canvas(); | 392 gfx::Canvas* canvas = recorder.canvas(); |
111 | 393 |
112 cc::PaintFlags flags; | 394 cc::PaintFlags flags; |
113 flags.setColor(SK_ColorWHITE); | 395 flags.setColor(SK_ColorWHITE); |
114 flags.setAntiAlias(true); | 396 flags.setAntiAlias(true); |
115 flags.setStyle(cc::PaintFlags::kFill_Style); | 397 flags.setStyle(cc::PaintFlags::kFill_Style); |
116 flags.setLooper(gfx::CreateShadowDrawLooper(shadow_values_)); | 398 flags.setLooper(gfx::CreateShadowDrawLooper(shadow_values_)); |
117 gfx::Rect shadow_bounds = shadow_layer_->bounds(); | 399 gfx::Rect shadow_bounds = shadow_layer_->bounds(); |
118 canvas->DrawCircle( | 400 canvas->DrawCircle( |
119 gfx::PointF(radius - shadow_bounds.x(), radius - shadow_bounds.y()), | 401 gfx::PointF(radius - shadow_bounds.x(), radius - shadow_bounds.y()), |
120 radius, flags); | 402 radius, flags); |
121 } | 403 } |
122 | 404 |
123 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 405 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
124 | 406 |
125 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 407 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
126 | 408 |
409 // ui::Layers for all of the painted shape layers that compose the morphing | |
410 // shape. | |
411 std::unique_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT]; | |
412 | |
413 const gfx::Size large_size_; | |
414 | |
415 const gfx::Size small_size_; | |
416 | |
417 // The center point of the painted shape. | |
418 gfx::PointF center_point_; | |
419 | |
420 // ui::LayerDelegate to paint circles for all the circle layers. | |
421 std::unique_ptr<views::CircleLayerDelegate> circle_layer_delegate_; | |
422 | |
423 // ui::LayerDelegate to paint rectangles for all the rectangle layers. | |
424 std::unique_ptr<views::RectangleLayerDelegate> rect_layer_delegate_; | |
425 | |
127 gfx::ShadowValues shadow_values_; | 426 gfx::ShadowValues shadow_values_; |
128 | 427 |
129 std::unique_ptr<ui::Layer> shadow_layer_; | 428 std::unique_ptr<ui::Layer> shadow_layer_; |
130 | 429 |
131 DISALLOW_COPY_AND_ASSIGN(VoiceInteractionIconBackground); | 430 DISALLOW_COPY_AND_ASSIGN(VoiceInteractionIconBackground); |
132 }; | 431 }; |
133 | 432 |
134 class VoiceInteractionIcon : public ui::Layer, public ui::LayerDelegate { | |
135 public: | |
136 VoiceInteractionIcon() { | |
137 set_name("VoiceInteractionOverlay:ICON_LAYER"); | |
138 SetBounds(gfx::Rect(0, 0, kIconInitSizeDip, kIconInitSizeDip)); | |
139 SetFillsBoundsOpaquely(false); | |
140 SetMasksToBounds(false); | |
141 set_delegate(this); | |
142 } | |
143 | |
144 private: | |
145 void OnPaintLayer(const ui::PaintContext& context) override { | |
146 ui::PaintRecorder recorder(context, size()); | |
147 gfx::PaintVectorIcon(recorder.canvas(), kShelfVoiceInteractionIcon, | |
148 kIconInitSizeDip, 0); | |
149 } | |
150 | |
151 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | |
152 | |
153 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(VoiceInteractionIcon); | |
156 }; | |
157 } // namespace | |
158 | |
159 VoiceInteractionOverlay::VoiceInteractionOverlay(AppListButton* host_view) | 433 VoiceInteractionOverlay::VoiceInteractionOverlay(AppListButton* host_view) |
160 : ripple_layer_(new ui::Layer()), | 434 : ripple_layer_(base::MakeUnique<ui::Layer>()), |
161 icon_layer_(new VoiceInteractionIcon()), | 435 icon_layer_(base::MakeUnique<VoiceInteractionIcon>()), |
162 background_layer_(new VoiceInteractionIconBackground()), | 436 background_layer_(base::MakeUnique<VoiceInteractionIconBackground>()), |
163 host_view_(host_view), | 437 host_view_(host_view), |
164 is_bursting_(false), | 438 is_bursting_(false), |
439 show_icon_(false), | |
440 should_hide_animation_(false), | |
165 circle_layer_delegate_(kRippleColor, kRippleCircleInitRadiusDip) { | 441 circle_layer_delegate_(kRippleColor, kRippleCircleInitRadiusDip) { |
166 SetPaintToLayer(ui::LAYER_NOT_DRAWN); | 442 SetPaintToLayer(ui::LAYER_NOT_DRAWN); |
167 layer()->set_name("VoiceInteractionOverlay:ROOT_LAYER"); | 443 layer()->set_name("VoiceInteractionOverlay:ROOT_LAYER"); |
168 layer()->SetMasksToBounds(false); | 444 layer()->SetMasksToBounds(false); |
169 | 445 |
170 ripple_layer_->SetBounds(gfx::Rect(0, 0, kRippleCircleInitRadiusDip * 2, | 446 ripple_layer_->SetBounds(gfx::Rect(0, 0, kRippleCircleInitRadiusDip * 2, |
171 kRippleCircleInitRadiusDip * 2)); | 447 kRippleCircleInitRadiusDip * 2)); |
172 ripple_layer_->set_delegate(&circle_layer_delegate_); | 448 ripple_layer_->set_delegate(&circle_layer_delegate_); |
173 ripple_layer_->SetFillsBoundsOpaquely(false); | 449 ripple_layer_->SetFillsBoundsOpaquely(false); |
174 ripple_layer_->SetMasksToBounds(true); | 450 ripple_layer_->SetMasksToBounds(true); |
175 ripple_layer_->set_name("VoiceInteractionOverlay:PAINTED_LAYER"); | 451 ripple_layer_->set_name("VoiceInteractionOverlay:PAINTED_LAYER"); |
176 layer()->Add(ripple_layer_.get()); | 452 layer()->Add(ripple_layer_.get()); |
177 | 453 |
178 layer()->Add(background_layer_.get()); | 454 layer()->Add(background_layer_.get()); |
179 | 455 |
180 layer()->Add(icon_layer_.get()); | 456 layer()->Add(icon_layer_.get()); |
181 } | 457 } |
182 | 458 |
183 VoiceInteractionOverlay::~VoiceInteractionOverlay() {} | 459 VoiceInteractionOverlay::~VoiceInteractionOverlay() {} |
184 | 460 |
185 void VoiceInteractionOverlay::StartAnimation() { | 461 void VoiceInteractionOverlay::StartAnimation(bool show_icon) { |
186 is_bursting_ = false; | 462 is_bursting_ = false; |
463 show_icon_ = show_icon; | |
187 SetVisible(true); | 464 SetVisible(true); |
188 | 465 |
189 // Setup ripple initial state. | 466 // Setup ripple initial state. |
190 ripple_layer_->SetOpacity(0); | 467 ripple_layer_->SetOpacity(0); |
191 | 468 |
192 SkMScalar scale_factor = | 469 SkMScalar scale_factor = |
193 kRippleCircleStartRadiusDip / kRippleCircleInitRadiusDip; | 470 kRippleCircleStartRadiusDip / kRippleCircleInitRadiusDip; |
194 gfx::Transform transform; | 471 gfx::Transform transform; |
195 | 472 |
196 const gfx::Point center = host_view_->GetCenterPoint(); | 473 const gfx::Point center = host_view_->GetCenterPoint(); |
(...skipping 15 matching lines...) Expand all Loading... | |
212 base::TimeDelta::FromMilliseconds(kRippleExpandDurationMs)); | 489 base::TimeDelta::FromMilliseconds(kRippleExpandDurationMs)); |
213 settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN_2); | 490 settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN_2); |
214 | 491 |
215 ripple_layer_->SetTransform(transform); | 492 ripple_layer_->SetTransform(transform); |
216 | 493 |
217 settings.SetTransitionDuration( | 494 settings.SetTransitionDuration( |
218 base::TimeDelta::FromMilliseconds(kRippleOpacityDurationMs)); | 495 base::TimeDelta::FromMilliseconds(kRippleOpacityDurationMs)); |
219 ripple_layer_->SetOpacity(kRippleOpacity); | 496 ripple_layer_->SetOpacity(kRippleOpacity); |
220 } | 497 } |
221 | 498 |
222 // We need to determine the animation direction based on shelf alignment. | 499 icon_layer_->SetOpacity(0); |
223 ShelfAlignment alignment = | 500 background_layer_->SetOpacity(0); |
224 Shelf::ForWindow(host_view_->GetWidget()->GetNativeWindow())->alignment(); | 501 if (!show_icon_) |
502 return; | |
225 | 503 |
226 // Setup icon initial state. | 504 // Setup icon initial state. |
227 icon_layer_->SetOpacity(0); | |
228 transform.MakeIdentity(); | 505 transform.MakeIdentity(); |
229 | |
230 transform.Translate(center.x() - kIconStartSizeDip / 2.f, | 506 transform.Translate(center.x() - kIconStartSizeDip / 2.f, |
231 center.y() - kIconStartSizeDip / 2.f); | 507 center.y() - kIconStartSizeDip / 2.f); |
232 | 508 |
233 scale_factor = kIconStartSizeDip / kIconInitSizeDip; | 509 scale_factor = kIconStartSizeDip / kIconInitSizeDip; |
234 transform.Scale(scale_factor, scale_factor); | 510 transform.Scale(scale_factor, scale_factor); |
235 icon_layer_->SetTransform(transform); | 511 icon_layer_->SetTransform(transform); |
236 | 512 |
237 // Setup icon animation. | 513 // Setup icon animation. |
238 scale_factor = kIconSizeDip / kIconInitSizeDip; | 514 scale_factor = kIconSizeDip / kIconInitSizeDip; |
239 transform.MakeIdentity(); | 515 transform.MakeIdentity(); |
240 if (alignment == SHELF_ALIGNMENT_BOTTOM || | 516 transform.Translate(center.x() - kIconSizeDip / 2 + kIconOffsetDip, |
241 alignment == SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 517 center.y() - kIconSizeDip / 2 - kIconOffsetDip); |
242 transform.Translate(center.x() - kIconSizeDip / 2 + kIconOffsetDip, | |
243 center.y() - kIconSizeDip / 2 - kIconOffsetDip); | |
244 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { | |
245 transform.Translate(center.x() - kIconSizeDip / 2 - kIconOffsetDip, | |
246 center.y() - kIconSizeDip / 2 + kIconOffsetDip); | |
247 } else { | |
248 DCHECK_EQ(alignment, SHELF_ALIGNMENT_LEFT); | |
249 transform.Translate(center.x() - kIconSizeDip / 2 + kIconOffsetDip, | |
250 center.y() - kIconSizeDip / 2 + kIconOffsetDip); | |
251 } | |
252 transform.Scale(scale_factor, scale_factor); | 518 transform.Scale(scale_factor, scale_factor); |
253 | 519 |
254 { | 520 { |
255 ui::ScopedLayerAnimationSettings settings(icon_layer_->GetAnimator()); | 521 ui::ScopedLayerAnimationSettings settings(icon_layer_->GetAnimator()); |
256 settings.SetTransitionDuration( | 522 settings.SetTransitionDuration( |
257 base::TimeDelta::FromMilliseconds(kFullExpandDurationMs)); | 523 base::TimeDelta::FromMilliseconds(kFullExpandDurationMs)); |
258 settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN_2); | 524 settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN_2); |
259 | 525 |
260 icon_layer_->SetTransform(transform); | 526 icon_layer_->SetTransform(transform); |
261 icon_layer_->SetOpacity(kIconOpacity); | 527 icon_layer_->SetOpacity(kIconOpacity); |
262 } | 528 } |
263 | 529 |
264 // Setup background initial state. | 530 // Setup background initial state. |
265 background_layer_->SetOpacity(0); | 531 background_layer_->ResetShape(); |
266 | 532 |
267 transform.MakeIdentity(); | 533 transform.MakeIdentity(); |
268 transform.Translate(center.x() - kBackgroundStartSizeDip / 2.f, | 534 transform.Translate(center.x() - kBackgroundStartSizeDip / 2.f, |
269 center.y() - kBackgroundStartSizeDip / 2.f); | 535 center.y() - kBackgroundStartSizeDip / 2.f); |
270 | 536 |
271 scale_factor = kBackgroundStartSizeDip / kBackgroundInitSizeDip; | 537 scale_factor = kBackgroundStartSizeDip / kBackgroundInitSizeDip; |
272 transform.Scale(scale_factor, scale_factor); | 538 transform.Scale(scale_factor, scale_factor); |
273 background_layer_->SetTransform(transform); | 539 background_layer_->SetTransform(transform); |
274 | 540 |
275 // Setup background animation. | 541 // Setup background animation. |
276 scale_factor = kBackgroundSizeDip / kBackgroundInitSizeDip; | 542 scale_factor = kBackgroundSizeDip / kBackgroundInitSizeDip; |
277 transform.MakeIdentity(); | 543 transform.MakeIdentity(); |
278 if (alignment == SHELF_ALIGNMENT_BOTTOM || | 544 transform.Translate(center.x() - kBackgroundSizeDip / 2 + kIconOffsetDip, |
279 alignment == SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 545 center.y() - kBackgroundSizeDip / 2 - kIconOffsetDip); |
280 transform.Translate(center.x() - kBackgroundSizeDip / 2 + kIconOffsetDip, | |
281 center.y() - kBackgroundSizeDip / 2 - kIconOffsetDip); | |
282 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { | |
283 transform.Translate(center.x() - kBackgroundSizeDip / 2 - kIconOffsetDip, | |
284 center.y() - kBackgroundSizeDip / 2 + kIconOffsetDip); | |
285 } else { | |
286 DCHECK_EQ(alignment, SHELF_ALIGNMENT_LEFT); | |
287 transform.Translate(center.x() - kBackgroundSizeDip / 2 + kIconOffsetDip, | |
288 center.y() - kBackgroundSizeDip / 2 + kIconOffsetDip); | |
289 } | |
290 transform.Scale(scale_factor, scale_factor); | 546 transform.Scale(scale_factor, scale_factor); |
291 | 547 |
292 { | 548 { |
293 ui::ScopedLayerAnimationSettings settings(background_layer_->GetAnimator()); | 549 ui::ScopedLayerAnimationSettings settings(background_layer_->GetAnimator()); |
294 settings.SetTransitionDuration( | 550 settings.SetTransitionDuration( |
295 base::TimeDelta::FromMilliseconds(kFullExpandDurationMs)); | 551 base::TimeDelta::FromMilliseconds(kFullExpandDurationMs)); |
296 settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN_2); | 552 settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN_2); |
297 | 553 |
298 background_layer_->SetTransform(transform); | 554 background_layer_->SetTransform(transform); |
299 } | 555 } |
300 | 556 |
301 { | 557 { |
302 ui::ScopedLayerAnimationSettings settings(background_layer_->GetAnimator()); | 558 ui::ScopedLayerAnimationSettings settings(background_layer_->GetAnimator()); |
303 settings.SetTransitionDuration( | 559 settings.SetTransitionDuration( |
304 base::TimeDelta::FromMilliseconds(kBackgroundOpacityDurationMs)); | 560 base::TimeDelta::FromMilliseconds(kBackgroundOpacityDurationMs)); |
305 settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN_2); | 561 settings.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN_2); |
306 | 562 |
307 background_layer_->SetOpacity(1); | 563 background_layer_->SetOpacity(1); |
308 } | 564 } |
309 } | 565 } |
310 | 566 |
311 void VoiceInteractionOverlay::BurstAnimation() { | 567 void VoiceInteractionOverlay::BurstAnimation() { |
312 is_bursting_ = true; | 568 is_bursting_ = true; |
569 should_hide_animation_ = false; | |
313 | 570 |
314 gfx::Point center = host_view_->GetCenterPoint(); | 571 gfx::Point center = host_view_->GetCenterPoint(); |
572 gfx::Transform transform; | |
315 | 573 |
316 // Setup ripple animations. | 574 // Setup ripple animations. |
317 { | 575 { |
318 SkMScalar scale_factor = | 576 SkMScalar scale_factor = |
319 kRippleCircleBurstRadiusDip / kRippleCircleInitRadiusDip; | 577 kRippleCircleBurstRadiusDip / kRippleCircleInitRadiusDip; |
320 std::unique_ptr<gfx::Transform> transform(new gfx::Transform()); | 578 transform.Translate(center.x() - kRippleCircleBurstRadiusDip, |
321 transform->Translate(center.x() - kRippleCircleBurstRadiusDip, | 579 center.y() - kRippleCircleBurstRadiusDip); |
322 center.y() - kRippleCircleBurstRadiusDip); | 580 transform.Scale(scale_factor, scale_factor); |
323 transform->Scale(scale_factor, scale_factor); | |
324 | 581 |
325 ui::ScopedLayerAnimationSettings settings(ripple_layer_->GetAnimator()); | 582 ui::ScopedLayerAnimationSettings settings(ripple_layer_->GetAnimator()); |
326 settings.SetTransitionDuration( | 583 settings.SetTransitionDuration( |
327 base::TimeDelta::FromMilliseconds(kFullBurstDurationMs)); | 584 base::TimeDelta::FromMilliseconds(kFullBurstDurationMs)); |
328 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); | 585 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); |
586 settings.SetPreemptionStrategy( | |
587 ui::LayerAnimator::PreemptionStrategy::ENQUEUE_NEW_ANIMATION); | |
329 | 588 |
330 ripple_layer_->SetTransform(*transform.get()); | 589 ripple_layer_->SetTransform(transform); |
331 ripple_layer_->SetOpacity(0); | 590 ripple_layer_->SetOpacity(0); |
332 } | 591 } |
333 | 592 |
593 if (!show_icon_) | |
594 return; | |
595 | |
334 // Setup icon animation. | 596 // Setup icon animation. |
597 // TODO(xiaohuic): Currently the animation does not support RTL. | |
335 { | 598 { |
336 ui::ScopedLayerAnimationSettings settings(icon_layer_->GetAnimator()); | 599 ui::ScopedLayerAnimationSettings settings(icon_layer_->GetAnimator()); |
337 settings.SetTransitionDuration( | 600 settings.SetTransitionDuration( |
338 base::TimeDelta::FromMilliseconds(kIconBurstDurationMs)); | 601 base::TimeDelta::FromMilliseconds(kBackgroundMorphDurationMs)); |
602 settings.SetPreemptionStrategy( | |
603 ui::LayerAnimator::PreemptionStrategy::ENQUEUE_NEW_ANIMATION); | |
339 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); | 604 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); |
340 | 605 |
341 icon_layer_->SetOpacity(0); | 606 transform.MakeIdentity(); |
607 transform.Translate(kBackgroundLargeWidthDip / 2 + kBackgroundPaddingDip - | |
608 kIconEndSizeDip / 2, | |
609 -kBackgroundLargeHeightDip / 2 - kBackgroundPaddingDip - | |
610 kIconEndSizeDip / 2); | |
611 SkMScalar scale_factor = kIconEndSizeDip / kIconInitSizeDip; | |
612 transform.Scale(scale_factor, scale_factor); | |
613 | |
614 icon_layer_->SetTransform(transform); | |
342 } | 615 } |
343 | 616 |
344 // Setup background animation. | 617 // Setup background animation. |
345 { | 618 ui::CallbackLayerAnimationObserver* observer = |
346 ui::ScopedLayerAnimationSettings settings(background_layer_->GetAnimator()); | 619 new ui::CallbackLayerAnimationObserver( |
347 settings.SetTransitionDuration( | 620 base::Bind(&VoiceInteractionOverlay::AnimationEndedCallback, |
348 base::TimeDelta::FromMilliseconds(kIconBurstDurationMs)); | 621 base::Unretained(this))); |
349 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); | 622 // Transform to new shape. |
623 // We want to animate from the background's current position into a larger | |
624 // size. The animation moves the background's center point while morphing from | |
625 // circle to a rectangle. | |
626 float x_offset = center.x() - kBackgroundSizeDip / 2 + kIconOffsetDip; | |
627 float y_offset = center.y() - kBackgroundSizeDip / 2 - kIconOffsetDip; | |
350 | 628 |
351 background_layer_->SetOpacity(0); | 629 background_layer_->AnimateToLarge( |
352 } | 630 gfx::PointF( |
631 kBackgroundLargeWidthDip / 2 + kBackgroundPaddingDip - x_offset, | |
632 -kBackgroundLargeHeightDip / 2 - kBackgroundPaddingDip - y_offset), | |
633 observer); | |
634 observer->SetActive(); | |
353 } | 635 } |
354 | 636 |
355 void VoiceInteractionOverlay::EndAnimation() { | 637 void VoiceInteractionOverlay::EndAnimation() { |
356 if (is_bursting_) { | 638 if (is_bursting_) { |
357 // Too late, user action already fired, we have to finish what's started. | 639 // Too late, user action already fired, we have to finish what's started. |
358 return; | 640 return; |
359 } | 641 } |
360 | 642 |
361 // Play reverse animation | 643 // Play reverse animation |
362 // Setup ripple animations. | 644 // Setup ripple animations. |
(...skipping 14 matching lines...) Expand all Loading... | |
377 base::TimeDelta::FromMilliseconds(kFullRetractDurationMs)); | 659 base::TimeDelta::FromMilliseconds(kFullRetractDurationMs)); |
378 settings.SetTweenType(gfx::Tween::SLOW_OUT_LINEAR_IN); | 660 settings.SetTweenType(gfx::Tween::SLOW_OUT_LINEAR_IN); |
379 | 661 |
380 ripple_layer_->SetTransform(transform); | 662 ripple_layer_->SetTransform(transform); |
381 | 663 |
382 settings.SetTransitionDuration( | 664 settings.SetTransitionDuration( |
383 base::TimeDelta::FromMilliseconds(kRippleOpacityRetractDurationMs)); | 665 base::TimeDelta::FromMilliseconds(kRippleOpacityRetractDurationMs)); |
384 ripple_layer_->SetOpacity(0); | 666 ripple_layer_->SetOpacity(0); |
385 } | 667 } |
386 | 668 |
669 if (!show_icon_) | |
670 return; | |
671 | |
387 // Setup icon animation. | 672 // Setup icon animation. |
388 transform.MakeIdentity(); | 673 transform.MakeIdentity(); |
389 | 674 |
390 transform.Translate(center.x() - kIconStartSizeDip / 2.f, | 675 transform.Translate(center.x() - kIconStartSizeDip / 2.f, |
391 center.y() - kIconStartSizeDip / 2.f); | 676 center.y() - kIconStartSizeDip / 2.f); |
392 | 677 |
393 scale_factor = kIconStartSizeDip / kIconInitSizeDip; | 678 scale_factor = kIconStartSizeDip / kIconInitSizeDip; |
394 transform.Scale(scale_factor, scale_factor); | 679 transform.Scale(scale_factor, scale_factor); |
395 | 680 |
396 { | 681 { |
(...skipping 23 matching lines...) Expand all Loading... | |
420 IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 705 IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
421 settings.SetTransitionDuration( | 706 settings.SetTransitionDuration( |
422 base::TimeDelta::FromMilliseconds(kFullRetractDurationMs)); | 707 base::TimeDelta::FromMilliseconds(kFullRetractDurationMs)); |
423 settings.SetTweenType(gfx::Tween::SLOW_OUT_LINEAR_IN); | 708 settings.SetTweenType(gfx::Tween::SLOW_OUT_LINEAR_IN); |
424 | 709 |
425 background_layer_->SetTransform(transform); | 710 background_layer_->SetTransform(transform); |
426 background_layer_->SetOpacity(0); | 711 background_layer_->SetOpacity(0); |
427 } | 712 } |
428 } | 713 } |
429 | 714 |
715 void VoiceInteractionOverlay::HideAnimation() { | |
716 is_bursting_ = false; | |
717 | |
718 if (background_layer_->GetAnimator()->is_animating()) { | |
719 // Wait for current animation to finish | |
720 should_hide_animation_ = true; | |
721 return; | |
722 } | |
723 should_hide_animation_ = false; | |
724 | |
725 // Setup ripple animations. | |
726 { | |
727 ui::ScopedLayerAnimationSettings settings(ripple_layer_->GetAnimator()); | |
728 settings.SetTransitionDuration( | |
729 base::TimeDelta::FromMilliseconds(kHideDurationMs)); | |
730 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); | |
731 settings.SetPreemptionStrategy( | |
732 ui::LayerAnimator::PreemptionStrategy::ENQUEUE_NEW_ANIMATION); | |
733 | |
734 ripple_layer_->SetOpacity(0); | |
735 } | |
736 | |
737 // Setup icon animation. | |
738 { | |
739 ui::ScopedLayerAnimationSettings settings(icon_layer_->GetAnimator()); | |
740 settings.SetTransitionDuration( | |
741 base::TimeDelta::FromMilliseconds(kHideDurationMs)); | |
742 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); | |
743 settings.SetPreemptionStrategy( | |
744 ui::LayerAnimator::PreemptionStrategy::ENQUEUE_NEW_ANIMATION); | |
745 | |
746 icon_layer_->SetOpacity(0); | |
747 } | |
748 | |
749 // Setup background animation. | |
750 { | |
751 ui::ScopedLayerAnimationSettings settings(background_layer_->GetAnimator()); | |
752 settings.SetTransitionDuration( | |
753 base::TimeDelta::FromMilliseconds(kHideDurationMs)); | |
754 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); | |
755 settings.SetPreemptionStrategy( | |
756 ui::LayerAnimator::PreemptionStrategy::ENQUEUE_NEW_ANIMATION); | |
757 | |
758 background_layer_->SetOpacity(0); | |
759 } | |
760 } | |
761 | |
762 bool VoiceInteractionOverlay::AnimationEndedCallback( | |
763 const ui::CallbackLayerAnimationObserver& observer) { | |
764 if (should_hide_animation_) | |
765 HideAnimation(); | |
766 | |
767 return true; | |
768 } | |
769 | |
430 } // namespace ash | 770 } // namespace ash |
OLD | NEW |