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