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 "ui/app_list/app_list_model.h" | 11 #include "ui/app_list/app_list_model.h" |
11 #include "ui/app_list/app_list_view_delegate.h" | 12 #include "ui/app_list/app_list_view_delegate.h" |
12 #include "ui/app_list/speech_ui_model.h" | 13 #include "ui/app_list/speech_ui_model.h" |
13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/path.h" |
16 #include "ui/views/animation/bounds_animator.h" | 18 #include "ui/views/animation/bounds_animator.h" |
17 #include "ui/views/background.h" | 19 #include "ui/views/background.h" |
18 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
19 #include "ui/views/controls/image_view.h" | 21 #include "ui/views/controls/image_view.h" |
20 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
21 #include "ui/views/layout/fill_layout.h" | 23 #include "ui/views/layout/fill_layout.h" |
22 #include "ui/views/shadow_border.h" | 24 #include "ui/views/shadow_border.h" |
23 | 25 |
24 namespace app_list { | 26 namespace app_list { |
25 | 27 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 70 } |
69 | 71 |
70 // MicButton is an image button with circular hit area. | 72 // MicButton is an image button with circular hit area. |
71 class MicButton : public views::ImageButton { | 73 class MicButton : public views::ImageButton { |
72 public: | 74 public: |
73 explicit MicButton(views::ButtonListener* listener); | 75 explicit MicButton(views::ButtonListener* listener); |
74 virtual ~MicButton(); | 76 virtual ~MicButton(); |
75 | 77 |
76 private: | 78 private: |
77 // Overridden from views::View: | 79 // Overridden from views::View: |
78 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE; | 80 virtual bool HasHitTestMask() const OVERRIDE; |
| 81 virtual void GetHitTestMask(views::View::HitTestSource source, |
| 82 gfx::Path* mask) const OVERRIDE; |
79 | 83 |
80 DISALLOW_COPY_AND_ASSIGN(MicButton); | 84 DISALLOW_COPY_AND_ASSIGN(MicButton); |
81 }; | 85 }; |
82 | 86 |
83 MicButton::MicButton(views::ButtonListener* listener) | 87 MicButton::MicButton(views::ButtonListener* listener) |
84 : views::ImageButton(listener) {} | 88 : views::ImageButton(listener) {} |
85 | 89 |
86 MicButton::~MicButton() {} | 90 MicButton::~MicButton() {} |
87 | 91 |
88 bool MicButton::HitTestRect(const gfx::Rect& rect) const { | 92 bool MicButton::HasHitTestMask() const { |
89 if (!views::ImageButton::HitTestRect(rect)) | 93 return true; |
90 return false; | 94 } |
91 | 95 |
| 96 void MicButton::GetHitTestMask(views::View::HitTestSource source, |
| 97 gfx::Path* mask) const { |
| 98 // The mic button icon is a circle. |source| doesn't matter. |
92 gfx::Rect local_bounds = GetLocalBounds(); | 99 gfx::Rect local_bounds = GetLocalBounds(); |
93 int radius = local_bounds.width() / 2; | 100 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset; |
94 return (rect.origin() - local_bounds.CenterPoint()).LengthSquared() < | 101 gfx::Point center = local_bounds.CenterPoint(); |
95 radius * radius; | 102 center.set_y(center.y() + kIndicatorCenterOffsetY); |
| 103 mask->addCircle(SkIntToScalar(center.x()), |
| 104 SkIntToScalar(center.y()), |
| 105 SkIntToScalar(radius)); |
96 } | 106 } |
97 | 107 |
98 } // namespace | 108 } // namespace |
99 | 109 |
100 // static | 110 // static |
101 | 111 |
102 SpeechView::SpeechView(AppListViewDelegate* delegate) | 112 SpeechView::SpeechView(AppListViewDelegate* delegate) |
103 : delegate_(delegate), | 113 : delegate_(delegate), |
104 logo_(NULL) { | 114 logo_(NULL) { |
105 SetBorder(scoped_ptr<views::Border>( | 115 SetBorder(scoped_ptr<views::Border>( |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 resource_id = IDR_APP_LIST_SPEECH_MIC_ON; | 239 resource_id = IDR_APP_LIST_SPEECH_MIC_ON; |
230 else if (new_state == SPEECH_RECOGNITION_IN_SPEECH) | 240 else if (new_state == SPEECH_RECOGNITION_IN_SPEECH) |
231 resource_id = IDR_APP_LIST_SPEECH_MIC_RECORDING; | 241 resource_id = IDR_APP_LIST_SPEECH_MIC_RECORDING; |
232 | 242 |
233 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 243 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
234 mic_button_->SetImage(views::Button::STATE_NORMAL, | 244 mic_button_->SetImage(views::Button::STATE_NORMAL, |
235 bundle.GetImageSkiaNamed(resource_id)); | 245 bundle.GetImageSkiaNamed(resource_id)); |
236 } | 246 } |
237 | 247 |
238 } // namespace app_list | 248 } // namespace app_list |
OLD | NEW |