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" | |
21 #include "ui/views/controls/image_view.h" | 20 #include "ui/views/controls/image_view.h" |
22 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
23 #include "ui/views/layout/fill_layout.h" | 22 #include "ui/views/layout/fill_layout.h" |
24 #include "ui/views/shadow_border.h" | 23 #include "ui/views/shadow_border.h" |
25 | 24 |
26 namespace app_list { | 25 namespace app_list { |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 const int kShadowOffset = 1; | 29 const int kShadowOffset = 1; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 SoundLevelIndicator::~SoundLevelIndicator() {} | 61 SoundLevelIndicator::~SoundLevelIndicator() {} |
63 | 62 |
64 void SoundLevelIndicator::OnPaint(gfx::Canvas* canvas) { | 63 void SoundLevelIndicator::OnPaint(gfx::Canvas* canvas) { |
65 SkPaint paint; | 64 SkPaint paint; |
66 paint.setStyle(SkPaint::kFill_Style); | 65 paint.setStyle(SkPaint::kFill_Style); |
67 paint.setColor(kSoundLevelIndicatorColor); | 66 paint.setColor(kSoundLevelIndicatorColor); |
68 paint.setAntiAlias(true); | 67 paint.setAntiAlias(true); |
69 canvas->DrawCircle(bounds().CenterPoint(), width() / 2, paint); | 68 canvas->DrawCircle(bounds().CenterPoint(), width() / 2, paint); |
70 } | 69 } |
71 | 70 |
72 // MicButton is an image button with circular hit area. | 71 } // namespace |
73 class MicButton : public views::ImageButton { | |
74 public: | |
75 explicit MicButton(views::ButtonListener* listener); | |
76 virtual ~MicButton(); | |
77 | |
78 private: | |
79 // Overridden from views::View: | |
80 virtual bool HasHitTestMask() const OVERRIDE; | |
81 virtual void GetHitTestMaskDeprecated(views::View::HitTestSource source, | |
82 gfx::Path* mask) const OVERRIDE; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(MicButton); | |
85 }; | |
86 | 72 |
87 MicButton::MicButton(views::ButtonListener* listener) | 73 MicButton::MicButton(views::ButtonListener* listener) |
88 : views::ImageButton(listener) {} | 74 : views::ImageButton(listener) {} |
89 | 75 |
90 MicButton::~MicButton() {} | 76 MicButton::~MicButton() {} |
91 | 77 |
92 bool MicButton::HasHitTestMask() const { | 78 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); | 79 DCHECK(mask); |
99 | 80 |
100 // The mic button icon is a circle. |source| doesn't matter. | 81 // The mic button icon is a circle. |
101 gfx::Rect local_bounds = GetLocalBounds(); | 82 gfx::Rect local_bounds = GetLocalBounds(); |
102 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset; | 83 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset; |
103 gfx::Point center = local_bounds.CenterPoint(); | 84 gfx::Point center = local_bounds.CenterPoint(); |
104 center.set_y(center.y() + kIndicatorCenterOffsetY); | 85 center.set_y(center.y() + kIndicatorCenterOffsetY); |
105 mask->addCircle(SkIntToScalar(center.x()), | 86 mask->addCircle(SkIntToScalar(center.x()), |
106 SkIntToScalar(center.y()), | 87 SkIntToScalar(center.y()), |
107 SkIntToScalar(radius)); | 88 SkIntToScalar(radius)); |
| 89 return true; |
108 } | 90 } |
109 | 91 |
110 } // namespace | |
111 | |
112 // static | 92 // static |
113 | 93 |
114 SpeechView::SpeechView(AppListViewDelegate* delegate) | 94 SpeechView::SpeechView(AppListViewDelegate* delegate) |
115 : delegate_(delegate), | 95 : delegate_(delegate), |
116 logo_(NULL) { | 96 logo_(NULL) { |
117 SetBorder(scoped_ptr<views::Border>( | 97 SetBorder(scoped_ptr<views::Border>( |
118 new views::ShadowBorder(kShadowBlur, | 98 new views::ShadowBorder(kShadowBlur, |
119 kShadowColor, | 99 kShadowColor, |
120 kShadowOffset, // Vertical offset. | 100 kShadowOffset, // Vertical offset. |
121 0))); | 101 0))); |
(...skipping 11 matching lines...) Expand all Loading... |
133 logo_->SetImage(&logo_image); | 113 logo_->SetImage(&logo_image); |
134 container->AddChildView(logo_); | 114 container->AddChildView(logo_); |
135 } | 115 } |
136 | 116 |
137 indicator_ = new SoundLevelIndicator(); | 117 indicator_ = new SoundLevelIndicator(); |
138 indicator_->SetVisible(false); | 118 indicator_->SetVisible(false); |
139 container->AddChildView(indicator_); | 119 container->AddChildView(indicator_); |
140 | 120 |
141 mic_button_ = new MicButton(this); | 121 mic_button_ = new MicButton(this); |
142 container->AddChildView(mic_button_); | 122 container->AddChildView(mic_button_); |
| 123 mic_button_->SetEventTargeter( |
| 124 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(mic_button_))); |
143 | 125 |
144 // TODO(mukai): use BoundedLabel to cap 2 lines. | 126 // TODO(mukai): use BoundedLabel to cap 2 lines. |
145 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 127 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
146 speech_result_ = new views::Label( | 128 speech_result_ = new views::Label( |
147 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); | 129 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); |
148 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 130 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
149 | 131 |
150 speech_result_->SetMultiLine(true); | 132 speech_result_->SetMultiLine(true); |
151 container->AddChildView(speech_result_); | 133 container->AddChildView(speech_result_); |
152 | 134 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 228 } |
247 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); | 229 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); |
248 speech_result_->SetEnabledColor(kHintTextColor); | 230 speech_result_->SetEnabledColor(kHintTextColor); |
249 | 231 |
250 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 232 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
251 mic_button_->SetImage(views::Button::STATE_NORMAL, | 233 mic_button_->SetImage(views::Button::STATE_NORMAL, |
252 bundle.GetImageSkiaNamed(resource_id)); | 234 bundle.GetImageSkiaNamed(resource_id)); |
253 } | 235 } |
254 | 236 |
255 } // namespace app_list | 237 } // namespace app_list |
OLD | NEW |