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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "ui/compositor/layer_animator.h" | 32 #include "ui/compositor/layer_animator.h" |
33 #include "ui/compositor/paint_context.h" | 33 #include "ui/compositor/paint_context.h" |
34 #include "ui/compositor/paint_recorder.h" | 34 #include "ui/compositor/paint_recorder.h" |
35 #include "ui/compositor/scoped_layer_animation_settings.h" | 35 #include "ui/compositor/scoped_layer_animation_settings.h" |
36 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
37 #include "ui/gfx/image/canvas_image_source.h" | 37 #include "ui/gfx/image/canvas_image_source.h" |
38 #include "ui/gfx/image/image_skia.h" | 38 #include "ui/gfx/image/image_skia.h" |
39 #include "ui/gfx/image/image_skia_operations.h" | 39 #include "ui/gfx/image/image_skia_operations.h" |
40 #include "ui/gfx/paint_vector_icon.h" | 40 #include "ui/gfx/paint_vector_icon.h" |
41 #include "ui/gfx/scoped_canvas.h" | 41 #include "ui/gfx/scoped_canvas.h" |
| 42 #include "ui/gfx/skia_paint_util.h" |
42 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 43 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
43 #include "ui/views/animation/ink_drop_impl.h" | 44 #include "ui/views/animation/ink_drop_impl.h" |
44 #include "ui/views/animation/ink_drop_mask.h" | 45 #include "ui/views/animation/ink_drop_mask.h" |
45 #include "ui/views/painter.h" | 46 #include "ui/views/painter.h" |
46 #include "ui/views/widget/widget.h" | 47 #include "ui/views/widget/widget.h" |
47 | 48 |
48 namespace ash { | 49 namespace ash { |
49 namespace { | 50 namespace { |
50 constexpr int kFullExpandDurationMs = 650; | 51 constexpr int kFullExpandDurationMs = 650; |
51 constexpr int kFullRetractDurationMs = 300; | 52 constexpr int kFullRetractDurationMs = 300; |
(...skipping 14 matching lines...) Expand all Loading... |
66 constexpr float kIconSizeDip = 24.f; | 67 constexpr float kIconSizeDip = 24.f; |
67 constexpr float kIconOffsetDip = 56.f; | 68 constexpr float kIconOffsetDip = 56.f; |
68 constexpr float kIconOpacity = 1.f; | 69 constexpr float kIconOpacity = 1.f; |
69 constexpr int kIconBurstDurationMs = 100; | 70 constexpr int kIconBurstDurationMs = 100; |
70 | 71 |
71 constexpr float kBackgroundInitSizeDip = 48.f; | 72 constexpr float kBackgroundInitSizeDip = 48.f; |
72 constexpr float kBackgroundStartSizeDip = 10.f; | 73 constexpr float kBackgroundStartSizeDip = 10.f; |
73 constexpr float kBackgroundSizeDip = 48.f; | 74 constexpr float kBackgroundSizeDip = 48.f; |
74 constexpr int kBackgroundStartDelayMs = 100; | 75 constexpr int kBackgroundStartDelayMs = 100; |
75 constexpr int kBackgroundOpacityDurationMs = 200; | 76 constexpr int kBackgroundOpacityDurationMs = 200; |
76 constexpr float kBackgroundShadowSizeDip = 12; | 77 constexpr float kBackgroundShadowElevationDip = 24.f; |
77 | |
78 class CircleImageSource : public gfx::CanvasImageSource { | |
79 public: | |
80 CircleImageSource(float radius, float padding) | |
81 : CanvasImageSource( | |
82 gfx::Size((radius + padding) * 2, (radius + padding) * 2), | |
83 false), | |
84 radius_(radius), | |
85 padding_(padding) {} | |
86 ~CircleImageSource() override {} | |
87 | |
88 private: | |
89 void Draw(gfx::Canvas* canvas) override { | |
90 cc::PaintFlags flags; | |
91 flags.setColor(SK_ColorWHITE); | |
92 flags.setAntiAlias(true); | |
93 flags.setStyle(cc::PaintFlags::kFill_Style); | |
94 canvas->DrawCircle(gfx::PointF(radius_ + padding_, radius_ + padding_), | |
95 radius_, flags); | |
96 } | |
97 | |
98 float radius_; | |
99 float padding_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(CircleImageSource); | |
102 }; | |
103 | 78 |
104 class VoiceInteractionIconBackground : public ui::Layer, | 79 class VoiceInteractionIconBackground : public ui::Layer, |
105 public ui::LayerDelegate { | 80 public ui::LayerDelegate { |
106 public: | 81 public: |
107 VoiceInteractionIconBackground() | 82 VoiceInteractionIconBackground() : Layer(ui::LAYER_NOT_DRAWN) { |
108 : Layer(ui::LAYER_NOT_DRAWN), | |
109 shadow_values_(1, | |
110 gfx::ShadowValue(gfx::Vector2d(0, 0), | |
111 kBackgroundShadowSizeDip, | |
112 SkColorSetARGB(0x54, 0, 0, 0))) { | |
113 set_name("VoiceInteractionOverlay:BACKGROUND_LAYER"); | 83 set_name("VoiceInteractionOverlay:BACKGROUND_LAYER"); |
114 SetBounds(gfx::Rect(0, 0, kBackgroundInitSizeDip, kBackgroundInitSizeDip)); | 84 SetBounds(gfx::Rect(0, 0, kBackgroundInitSizeDip, kBackgroundInitSizeDip)); |
115 SetFillsBoundsOpaquely(false); | 85 SetFillsBoundsOpaquely(false); |
116 SetMasksToBounds(false); | 86 SetMasksToBounds(false); |
117 | 87 |
| 88 shadow_values_ = |
| 89 gfx::ShadowValue::MakeMdShadowValues(kBackgroundShadowElevationDip); |
| 90 const gfx::Insets shadow_margin = |
| 91 gfx::ShadowValue::GetMargin(shadow_values_); |
| 92 |
118 shadow_layer_.reset(new ui::Layer()); | 93 shadow_layer_.reset(new ui::Layer()); |
119 shadow_layer_->set_delegate(this); | 94 shadow_layer_->set_delegate(this); |
120 shadow_layer_->SetFillsBoundsOpaquely(false); | 95 shadow_layer_->SetFillsBoundsOpaquely(false); |
121 shadow_layer_->SetBounds( | 96 shadow_layer_->SetBounds( |
122 gfx::Rect(-kBackgroundShadowSizeDip, -kBackgroundShadowSizeDip, | 97 gfx::Rect(shadow_margin.left(), shadow_margin.top(), |
123 kBackgroundInitSizeDip + kBackgroundShadowSizeDip * 2, | 98 kBackgroundInitSizeDip - shadow_margin.width(), |
124 kBackgroundInitSizeDip + kBackgroundShadowSizeDip * 2)); | 99 kBackgroundInitSizeDip - shadow_margin.height())); |
125 Add(shadow_layer_.get()); | 100 Add(shadow_layer_.get()); |
126 } | 101 } |
127 ~VoiceInteractionIconBackground() override{}; | 102 ~VoiceInteractionIconBackground() override{}; |
128 | 103 |
129 private: | 104 private: |
130 void OnPaintLayer(const ui::PaintContext& context) override { | 105 void OnPaintLayer(const ui::PaintContext& context) override { |
131 // Radius is based on the parent layer size, the shadow layer is expanded | 106 // Radius is based on the parent layer size, the shadow layer is expanded |
132 // to make room for the shadow. | 107 // to make room for the shadow. |
133 float radius = size().width() / 2.f; | 108 float radius = size().width() / 2.f; |
134 CircleImageSource* circle_image = | |
135 new CircleImageSource(radius, kBackgroundShadowSizeDip); | |
136 gfx::ImageSkia background_with_shadow = | |
137 gfx::ImageSkiaOperations::CreateImageWithDropShadow( | |
138 gfx::ImageSkia(circle_image, circle_image->size()), shadow_values_); | |
139 | 109 |
140 ui::PaintRecorder recorder(context, background_with_shadow.size()); | 110 ui::PaintRecorder recorder(context, shadow_layer_->size()); |
141 gfx::Canvas* canvas = recorder.canvas(); | 111 gfx::Canvas* canvas = recorder.canvas(); |
142 float shadow_offset = | 112 |
143 (shadow_layer_->size().width() - background_with_shadow.width()) / 2.f; | 113 cc::PaintFlags flags; |
144 canvas->DrawImageInt(background_with_shadow, shadow_offset, shadow_offset); | 114 flags.setColor(SK_ColorWHITE); |
| 115 flags.setAntiAlias(true); |
| 116 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 117 flags.setLooper(gfx::CreateShadowDrawLooper(shadow_values_)); |
| 118 gfx::Rect shadow_bounds = shadow_layer_->bounds(); |
| 119 canvas->DrawCircle({radius - shadow_bounds.x(), radius - shadow_bounds.y()}, |
| 120 radius, flags); |
145 } | 121 } |
146 | 122 |
147 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 123 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
148 | 124 |
149 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} | 125 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
150 | 126 |
151 gfx::ShadowValues shadow_values_; | 127 gfx::ShadowValues shadow_values_; |
152 | 128 |
153 std::unique_ptr<ui::Layer> shadow_layer_; | 129 std::unique_ptr<ui::Layer> shadow_layer_; |
154 | 130 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 settings.SetTransitionDuration( | 427 settings.SetTransitionDuration( |
452 base::TimeDelta::FromMilliseconds(kFullRetractDurationMs)); | 428 base::TimeDelta::FromMilliseconds(kFullRetractDurationMs)); |
453 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); | 429 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); |
454 | 430 |
455 background_layer_->SetTransform(transform); | 431 background_layer_->SetTransform(transform); |
456 background_layer_->SetOpacity(0); | 432 background_layer_->SetOpacity(0); |
457 } | 433 } |
458 } | 434 } |
459 | 435 |
460 } // namespace ash | 436 } // namespace ash |
OLD | NEW |