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

Side by Side Diff: ash/shelf/voice_interaction_overlay.cc

Issue 2951583002: Update voice interaction icon shadow (Closed)
Patch Set: missed one line when breaking out cl Created 3 years, 6 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
« no previous file with comments | « no previous file | ui/gfx/shadow_util.cc » ('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 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
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
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 gfx::Insets shadow_margin = gfx::ShadowValue::GetMargin(shadow_values_);
oshima 2017/06/21 18:14:52 nit: const
xc 2017/06/21 18:50:59 Done.
91
118 shadow_layer_.reset(new ui::Layer()); 92 shadow_layer_.reset(new ui::Layer());
119 shadow_layer_->set_delegate(this); 93 shadow_layer_->set_delegate(this);
120 shadow_layer_->SetFillsBoundsOpaquely(false); 94 shadow_layer_->SetFillsBoundsOpaquely(false);
121 shadow_layer_->SetBounds( 95 shadow_layer_->SetBounds({shadow_margin.left(), shadow_margin.top(),
122 gfx::Rect(-kBackgroundShadowSizeDip, -kBackgroundShadowSizeDip, 96 kBackgroundInitSizeDip - shadow_margin.width(),
123 kBackgroundInitSizeDip + kBackgroundShadowSizeDip * 2, 97 kBackgroundInitSizeDip - shadow_margin.height()});
124 kBackgroundInitSizeDip + kBackgroundShadowSizeDip * 2));
125 Add(shadow_layer_.get()); 98 Add(shadow_layer_.get());
126 } 99 }
127 ~VoiceInteractionIconBackground() override{}; 100 ~VoiceInteractionIconBackground() override{};
128 101
129 private: 102 private:
130 void OnPaintLayer(const ui::PaintContext& context) override { 103 void OnPaintLayer(const ui::PaintContext& context) override {
131 // Radius is based on the parent layer size, the shadow layer is expanded 104 // Radius is based on the parent layer size, the shadow layer is expanded
132 // to make room for the shadow. 105 // to make room for the shadow.
133 float radius = size().width() / 2.f; 106 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 107
140 ui::PaintRecorder recorder(context, background_with_shadow.size()); 108 ui::PaintRecorder recorder(context, shadow_layer_->size());
141 gfx::Canvas* canvas = recorder.canvas(); 109 gfx::Canvas* canvas = recorder.canvas();
142 float shadow_offset = 110
143 (shadow_layer_->size().width() - background_with_shadow.width()) / 2.f; 111 cc::PaintFlags flags;
144 canvas->DrawImageInt(background_with_shadow, shadow_offset, shadow_offset); 112 flags.setColor(SK_ColorWHITE);
113 flags.setAntiAlias(true);
114 flags.setStyle(cc::PaintFlags::kFill_Style);
115 flags.setLooper(gfx::CreateShadowDrawLooper(shadow_values_));
116 gfx::Rect shadow_bounds = shadow_layer_->bounds();
117 canvas->DrawCircle({radius - shadow_bounds.x(), radius - shadow_bounds.y()},
118 radius, flags);
145 } 119 }
146 120
147 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} 121 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
148 122
149 void OnDeviceScaleFactorChanged(float device_scale_factor) override {} 123 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
150 124
151 gfx::ShadowValues shadow_values_; 125 gfx::ShadowValues shadow_values_;
152 126
153 std::unique_ptr<ui::Layer> shadow_layer_; 127 std::unique_ptr<ui::Layer> shadow_layer_;
154 128
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 settings.SetTransitionDuration( 425 settings.SetTransitionDuration(
452 base::TimeDelta::FromMilliseconds(kFullRetractDurationMs)); 426 base::TimeDelta::FromMilliseconds(kFullRetractDurationMs));
453 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); 427 settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN);
454 428
455 background_layer_->SetTransform(transform); 429 background_layer_->SetTransform(transform);
456 background_layer_->SetOpacity(0); 430 background_layer_->SetOpacity(0);
457 } 431 }
458 } 432 }
459 433
460 } // namespace ash 434 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/shadow_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698