OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/views/speech_view.h" | 5 #include "ui/app_list/views/speech_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
10 #include "third_party/skia/include/core/SkPath.h" | 10 #include "third_party/skia/include/core/SkPath.h" |
11 #include "ui/app_list/app_list_model.h" | 11 #include "ui/app_list/app_list_model.h" |
12 #include "ui/app_list/app_list_view_delegate.h" | 12 #include "ui/app_list/app_list_view_delegate.h" |
13 #include "ui/app_list/speech_ui_model.h" | 13 #include "ui/app_list/speech_ui_model.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/path.h" | 17 #include "ui/gfx/path.h" |
18 #include "ui/views/animation/bounds_animator.h" | 18 #include "ui/views/animation/bounds_animator.h" |
19 #include "ui/views/background.h" | 19 #include "ui/views/background.h" |
20 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
21 #include "ui/views/controls/image_view.h" | 21 #include "ui/views/controls/image_view.h" |
22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
23 #include "ui/views/layout/fill_layout.h" | 23 #include "ui/views/layout/fill_layout.h" |
24 #include "ui/views/masked_targeter_delegate.h" | |
24 #include "ui/views/shadow_border.h" | 25 #include "ui/views/shadow_border.h" |
25 | 26 |
26 namespace app_list { | 27 namespace app_list { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const int kShadowOffset = 1; | 31 const int kShadowOffset = 1; |
31 const int kShadowBlur = 4; | 32 const int kShadowBlur = 4; |
32 const int kSpeechViewMaxHeight = 300; | 33 const int kSpeechViewMaxHeight = 300; |
33 const int kMicButtonMargin = 12; | 34 const int kMicButtonMargin = 12; |
(...skipping 28 matching lines...) Expand all Loading... | |
62 SoundLevelIndicator::~SoundLevelIndicator() {} | 63 SoundLevelIndicator::~SoundLevelIndicator() {} |
63 | 64 |
64 void SoundLevelIndicator::OnPaint(gfx::Canvas* canvas) { | 65 void SoundLevelIndicator::OnPaint(gfx::Canvas* canvas) { |
65 SkPaint paint; | 66 SkPaint paint; |
66 paint.setStyle(SkPaint::kFill_Style); | 67 paint.setStyle(SkPaint::kFill_Style); |
67 paint.setColor(kSoundLevelIndicatorColor); | 68 paint.setColor(kSoundLevelIndicatorColor); |
68 paint.setAntiAlias(true); | 69 paint.setAntiAlias(true); |
69 canvas->DrawCircle(bounds().CenterPoint(), width() / 2, paint); | 70 canvas->DrawCircle(bounds().CenterPoint(), width() / 2, paint); |
70 } | 71 } |
71 | 72 |
72 // MicButton is an image button with circular hit area. | 73 // MicButton is an image button with a circular hit test mask. |
73 class MicButton : public views::ImageButton { | 74 class MicButton : public views::ImageButton, |
75 public views::MaskedTargeterDelegate { | |
74 public: | 76 public: |
75 explicit MicButton(views::ButtonListener* listener); | 77 explicit MicButton(views::ButtonListener* listener); |
76 virtual ~MicButton(); | 78 virtual ~MicButton(); |
77 | 79 |
78 private: | 80 private: |
79 // Overridden from views::View: | 81 // views::MaskedTargeterDelegate: |
80 virtual bool HasHitTestMask() const OVERRIDE; | 82 virtual bool GetHitTestMask(gfx::Path* mask) const OVERRIDE; |
81 virtual void GetHitTestMaskDeprecated(views::View::HitTestSource source, | |
82 gfx::Path* mask) const OVERRIDE; | |
83 | 83 |
84 DISALLOW_COPY_AND_ASSIGN(MicButton); | 84 DISALLOW_COPY_AND_ASSIGN(MicButton); |
85 }; | 85 }; |
86 | 86 |
87 MicButton::MicButton(views::ButtonListener* listener) | 87 MicButton::MicButton(views::ButtonListener* listener) |
88 : views::ImageButton(listener) {} | 88 : views::ImageButton(listener) {} |
89 | 89 |
90 MicButton::~MicButton() {} | 90 MicButton::~MicButton() {} |
91 | 91 |
92 bool MicButton::HasHitTestMask() const { | 92 bool MicButton::GetHitTestMask(gfx::Path* mask) const { |
93 return true; | |
94 } | |
95 | |
96 void MicButton::GetHitTestMaskDeprecated(views::View::HitTestSource source, | |
97 gfx::Path* mask) const { | |
98 DCHECK(mask); | 93 DCHECK(mask); |
99 | 94 |
100 // The mic button icon is a circle. |source| doesn't matter. | 95 // The mic button icon is a circle. |
101 gfx::Rect local_bounds = GetLocalBounds(); | 96 gfx::Rect local_bounds = GetLocalBounds(); |
102 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset; | 97 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset; |
103 gfx::Point center = local_bounds.CenterPoint(); | 98 gfx::Point center = local_bounds.CenterPoint(); |
104 center.set_y(center.y() + kIndicatorCenterOffsetY); | 99 center.set_y(center.y() + kIndicatorCenterOffsetY); |
105 mask->addCircle(SkIntToScalar(center.x()), | 100 mask->addCircle(SkIntToScalar(center.x()), |
106 SkIntToScalar(center.y()), | 101 SkIntToScalar(center.y()), |
107 SkIntToScalar(radius)); | 102 SkIntToScalar(radius)); |
103 return true; | |
108 } | 104 } |
109 | 105 |
110 } // namespace | 106 } // namespace |
111 | 107 |
112 // static | 108 // static |
113 | 109 |
114 SpeechView::SpeechView(AppListViewDelegate* delegate) | 110 SpeechView::SpeechView(AppListViewDelegate* delegate) |
115 : delegate_(delegate), | 111 : delegate_(delegate), |
116 logo_(NULL) { | 112 logo_(NULL) { |
117 SetBorder(scoped_ptr<views::Border>( | 113 SetBorder(scoped_ptr<views::Border>( |
(...skipping 15 matching lines...) Expand all Loading... | |
133 logo_->SetImage(&logo_image); | 129 logo_->SetImage(&logo_image); |
134 container->AddChildView(logo_); | 130 container->AddChildView(logo_); |
135 } | 131 } |
136 | 132 |
137 indicator_ = new SoundLevelIndicator(); | 133 indicator_ = new SoundLevelIndicator(); |
138 indicator_->SetVisible(false); | 134 indicator_->SetVisible(false); |
139 container->AddChildView(indicator_); | 135 container->AddChildView(indicator_); |
140 | 136 |
141 mic_button_ = new MicButton(this); | 137 mic_button_ = new MicButton(this); |
142 container->AddChildView(mic_button_); | 138 container->AddChildView(mic_button_); |
139 mic_button_->SetEventTargeter(scoped_ptr<views::ViewTargeter>( | |
140 new views::ViewTargeter(static_cast<MicButton*>(mic_button_)))); | |
sky
2014/07/10 15:46:00
I'm not a fan of the static_cast here. Could you c
tdanderson
2014/07/10 16:53:45
Done.
| |
143 | 141 |
144 // TODO(mukai): use BoundedLabel to cap 2 lines. | 142 // TODO(mukai): use BoundedLabel to cap 2 lines. |
145 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 143 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
146 speech_result_ = new views::Label( | 144 speech_result_ = new views::Label( |
147 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); | 145 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); |
148 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 146 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
149 | 147 |
150 speech_result_->SetMultiLine(true); | 148 speech_result_->SetMultiLine(true); |
151 container->AddChildView(speech_result_); | 149 container->AddChildView(speech_result_); |
152 | 150 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 } | 244 } |
247 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); | 245 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); |
248 speech_result_->SetEnabledColor(kHintTextColor); | 246 speech_result_->SetEnabledColor(kHintTextColor); |
249 | 247 |
250 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 248 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
251 mic_button_->SetImage(views::Button::STATE_NORMAL, | 249 mic_button_->SetImage(views::Button::STATE_NORMAL, |
252 bundle.GetImageSkiaNamed(resource_id)); | 250 bundle.GetImageSkiaNamed(resource_id)); |
253 } | 251 } |
254 | 252 |
255 } // namespace app_list | 253 } // namespace app_list |
OLD | NEW |