| 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" | |
| 25 #include "ui/views/shadow_border.h" | 24 #include "ui/views/shadow_border.h" |
| 26 | 25 |
| 27 namespace app_list { | 26 namespace app_list { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 const int kShadowOffset = 1; | 30 const int kShadowOffset = 1; |
| 32 const int kShadowBlur = 4; | 31 const int kShadowBlur = 4; |
| 33 const int kSpeechViewMaxHeight = 300; | 32 const int kSpeechViewMaxHeight = 300; |
| 34 const int kMicButtonMargin = 12; | 33 const int kMicButtonMargin = 12; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 86 |
| 88 MicButton::MicButton(views::ButtonListener* listener) | 87 MicButton::MicButton(views::ButtonListener* listener) |
| 89 : views::ImageButton(listener) {} | 88 : views::ImageButton(listener) {} |
| 90 | 89 |
| 91 MicButton::~MicButton() {} | 90 MicButton::~MicButton() {} |
| 92 | 91 |
| 93 bool MicButton::HasHitTestMask() const { | 92 bool MicButton::HasHitTestMask() const { |
| 94 return true; | 93 return true; |
| 95 } | 94 } |
| 96 | 95 |
| 97 // TODO(tdanderson): Move the implementation into views::View::HitTestRect() | |
| 98 // and delete this function. See crbug.com/377527. | |
| 99 void MicButton::GetHitTestMask(views::View::HitTestSource source, | 96 void MicButton::GetHitTestMask(views::View::HitTestSource source, |
| 100 gfx::Path* mask) const { | 97 gfx::Path* mask) const { |
| 101 const ui::EventTargeter* targeter = GetEventTargeter(); | 98 DCHECK(mask); |
| 102 CHECK(targeter); | 99 |
| 103 static_cast<const views::MaskedViewTargeter*>(targeter) | 100 // The mic button icon is a circle. |source| doesn't matter. |
| 104 ->GetHitTestMask(this, mask); | 101 gfx::Rect local_bounds = GetLocalBounds(); |
| 102 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset; |
| 103 gfx::Point center = local_bounds.CenterPoint(); |
| 104 center.set_y(center.y() + kIndicatorCenterOffsetY); |
| 105 mask->addCircle(SkIntToScalar(center.x()), |
| 106 SkIntToScalar(center.y()), |
| 107 SkIntToScalar(radius)); |
| 105 } | 108 } |
| 106 | 109 |
| 107 // Used to define the circular hit test region of a MicButton for the | |
| 108 // purposes of event targeting. | |
| 109 class MicButtonTargeter : public views::MaskedViewTargeter { | |
| 110 public: | |
| 111 explicit MicButtonTargeter(views::View* mic_button) | |
| 112 : views::MaskedViewTargeter(mic_button) {} | |
| 113 virtual ~MicButtonTargeter() {} | |
| 114 | |
| 115 private: | |
| 116 // views::MaskedViewTargeter: | |
| 117 virtual bool GetHitTestMask(const views::View* view, | |
| 118 gfx::Path* mask) const OVERRIDE { | |
| 119 DCHECK(mask); | |
| 120 DCHECK_EQ(view, masked_view()); | |
| 121 | |
| 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 | |
| 136 } // namespace | 110 } // namespace |
| 137 | 111 |
| 138 // static | 112 // static |
| 139 | 113 |
| 140 SpeechView::SpeechView(AppListViewDelegate* delegate) | 114 SpeechView::SpeechView(AppListViewDelegate* delegate) |
| 141 : delegate_(delegate), | 115 : delegate_(delegate), |
| 142 logo_(NULL) { | 116 logo_(NULL) { |
| 143 SetBorder(scoped_ptr<views::Border>( | 117 SetBorder(scoped_ptr<views::Border>( |
| 144 new views::ShadowBorder(kShadowBlur, | 118 new views::ShadowBorder(kShadowBlur, |
| 145 kShadowColor, | 119 kShadowColor, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 159 logo_->SetImage(&logo_image); | 133 logo_->SetImage(&logo_image); |
| 160 container->AddChildView(logo_); | 134 container->AddChildView(logo_); |
| 161 } | 135 } |
| 162 | 136 |
| 163 indicator_ = new SoundLevelIndicator(); | 137 indicator_ = new SoundLevelIndicator(); |
| 164 indicator_->SetVisible(false); | 138 indicator_->SetVisible(false); |
| 165 container->AddChildView(indicator_); | 139 container->AddChildView(indicator_); |
| 166 | 140 |
| 167 mic_button_ = new MicButton(this); | 141 mic_button_ = new MicButton(this); |
| 168 container->AddChildView(mic_button_); | 142 container->AddChildView(mic_button_); |
| 169 mic_button_->SetEventTargeter( | |
| 170 scoped_ptr<ui::EventTargeter>(new MicButtonTargeter(mic_button_))); | |
| 171 | 143 |
| 172 // TODO(mukai): use BoundedLabel to cap 2 lines. | 144 // TODO(mukai): use BoundedLabel to cap 2 lines. |
| 173 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 145 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 174 speech_result_ = new views::Label( | 146 speech_result_ = new views::Label( |
| 175 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); | 147 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); |
| 176 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 148 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 177 | 149 |
| 178 speech_result_->SetMultiLine(true); | 150 speech_result_->SetMultiLine(true); |
| 179 container->AddChildView(speech_result_); | 151 container->AddChildView(speech_result_); |
| 180 | 152 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 246 } |
| 275 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); | 247 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); |
| 276 speech_result_->SetEnabledColor(kHintTextColor); | 248 speech_result_->SetEnabledColor(kHintTextColor); |
| 277 | 249 |
| 278 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 250 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 279 mic_button_->SetImage(views::Button::STATE_NORMAL, | 251 mic_button_->SetImage(views::Button::STATE_NORMAL, |
| 280 bundle.GetImageSkiaNamed(resource_id)); | 252 bundle.GetImageSkiaNamed(resource_id)); |
| 281 } | 253 } |
| 282 | 254 |
| 283 } // namespace app_list | 255 } // namespace app_list |
| OLD | NEW |