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_view_targeter.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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 89 |
89 MicButton::MicButton(views::ButtonListener* listener) | 90 MicButton::MicButton(views::ButtonListener* listener) |
90 : views::ImageButton(listener) {} | 91 : views::ImageButton(listener) {} |
91 | 92 |
92 MicButton::~MicButton() {} | 93 MicButton::~MicButton() {} |
93 | 94 |
94 bool MicButton::HasHitTestMask() const { | 95 bool MicButton::HasHitTestMask() const { |
95 return true; | 96 return true; |
96 } | 97 } |
97 | 98 |
| 99 // TODO(tdanderson): Move the implementation into views::View::HitTestRect() |
| 100 // and delete this function. See crbug.com/377527. |
98 void MicButton::GetHitTestMask(views::View::HitTestSource source, | 101 void MicButton::GetHitTestMask(views::View::HitTestSource source, |
99 gfx::Path* mask) const { | 102 gfx::Path* mask) const { |
100 // The mic button icon is a circle. |source| doesn't matter. | 103 const ui::EventTargeter* targeter = GetEventTargeter(); |
101 gfx::Rect local_bounds = GetLocalBounds(); | 104 CHECK(targeter); |
102 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset; | 105 static_cast<const views::MaskedViewTargeter*>(targeter) |
103 gfx::Point center = local_bounds.CenterPoint(); | 106 ->GetHitTestMask(this, mask); |
104 center.set_y(center.y() + kIndicatorCenterOffsetY); | |
105 mask->addCircle(SkIntToScalar(center.x()), | |
106 SkIntToScalar(center.y()), | |
107 SkIntToScalar(radius)); | |
108 } | 107 } |
109 | 108 |
| 109 // Used to define the circular hit test region of a MicButton for the |
| 110 // purposes of event targeting. |
| 111 class MicButtonTargeter : public views::MaskedViewTargeter { |
| 112 public: |
| 113 explicit MicButtonTargeter(views::View* mic_button) |
| 114 : views::MaskedViewTargeter(mic_button) {} |
| 115 virtual ~MicButtonTargeter() {} |
| 116 |
| 117 private: |
| 118 // views::MaskedViewTargeter: |
| 119 virtual bool GetHitTestMask(const views::View* view, |
| 120 gfx::Path* mask) const OVERRIDE { |
| 121 // The mic button icon is a circle. |
| 122 gfx::Rect local_bounds = view->GetLocalBounds(); |
| 123 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset; |
| 124 gfx::Point center = local_bounds.CenterPoint(); |
| 125 center.set_y(center.y() + kIndicatorCenterOffsetY); |
| 126 mask->addCircle(SkIntToScalar(center.x()), |
| 127 SkIntToScalar(center.y()), |
| 128 SkIntToScalar(radius)); |
| 129 return true; |
| 130 } |
| 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(MicButtonTargeter); |
| 133 }; |
| 134 |
110 } // namespace | 135 } // namespace |
111 | 136 |
112 // static | 137 // static |
113 | 138 |
114 SpeechView::SpeechView(AppListViewDelegate* delegate) | 139 SpeechView::SpeechView(AppListViewDelegate* delegate) |
115 : delegate_(delegate), | 140 : delegate_(delegate), |
116 logo_(NULL) { | 141 logo_(NULL) { |
117 SetBorder(scoped_ptr<views::Border>( | 142 SetBorder(scoped_ptr<views::Border>( |
118 new views::ShadowBorder(kShadowBlur, | 143 new views::ShadowBorder(kShadowBlur, |
119 kShadowColor, | 144 kShadowColor, |
(...skipping 13 matching lines...) Expand all Loading... |
133 logo_->SetImage(&logo_image); | 158 logo_->SetImage(&logo_image); |
134 container->AddChildView(logo_); | 159 container->AddChildView(logo_); |
135 } | 160 } |
136 | 161 |
137 indicator_ = new SoundLevelIndicator(); | 162 indicator_ = new SoundLevelIndicator(); |
138 indicator_->SetVisible(false); | 163 indicator_->SetVisible(false); |
139 container->AddChildView(indicator_); | 164 container->AddChildView(indicator_); |
140 | 165 |
141 mic_button_ = new MicButton(this); | 166 mic_button_ = new MicButton(this); |
142 container->AddChildView(mic_button_); | 167 container->AddChildView(mic_button_); |
| 168 mic_button_->SetEventTargeter( |
| 169 scoped_ptr<ui::EventTargeter>(new MicButtonTargeter(mic_button_))); |
143 | 170 |
144 // TODO(mukai): use BoundedLabel to cap 2 lines. | 171 // TODO(mukai): use BoundedLabel to cap 2 lines. |
145 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 172 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
146 speech_result_ = new views::Label( | 173 speech_result_ = new views::Label( |
147 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); | 174 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); |
148 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 175 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
149 | 176 |
150 speech_result_->SetMultiLine(true); | 177 speech_result_->SetMultiLine(true); |
151 container->AddChildView(speech_result_); | 178 container->AddChildView(speech_result_); |
152 | 179 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 resource_id = IDR_APP_LIST_SPEECH_MIC_ON; | 268 resource_id = IDR_APP_LIST_SPEECH_MIC_ON; |
242 else if (new_state == SPEECH_RECOGNITION_IN_SPEECH) | 269 else if (new_state == SPEECH_RECOGNITION_IN_SPEECH) |
243 resource_id = IDR_APP_LIST_SPEECH_MIC_RECORDING; | 270 resource_id = IDR_APP_LIST_SPEECH_MIC_RECORDING; |
244 | 271 |
245 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 272 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
246 mic_button_->SetImage(views::Button::STATE_NORMAL, | 273 mic_button_->SetImage(views::Button::STATE_NORMAL, |
247 bundle.GetImageSkiaNamed(resource_id)); | 274 bundle.GetImageSkiaNamed(resource_id)); |
248 } | 275 } |
249 | 276 |
250 } // namespace app_list | 277 } // namespace app_list |
OLD | NEW |