Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: ui/app_list/views/speech_view.cc

Issue 302653002: Introduce the MicButtonTargeter class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/views/masked_view_targeter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
103 gfx::Point center = local_bounds.CenterPoint(); 106 MicButton* b = const_cast<MicButton*>(this);
xiyuan 2014/05/28 23:01:44 const_cast makes me nervous. Does it make sense t
tdanderson 2014/05/29 19:55:18 Done.
104 center.set_y(center.y() + kIndicatorCenterOffsetY); 107 static_cast<const views::MaskedViewTargeter*>(targeter)
105 mask->addCircle(SkIntToScalar(center.x()), 108 ->GetHitTestMask(b, mask);
106 SkIntToScalar(center.y()),
107 SkIntToScalar(radius));
108 } 109 }
109 110
111 // Used to define the circular hit test region of a MicButton for the
112 // purposes of event targeting.
113 class MicButtonTargeter : public views::MaskedViewTargeter {
114 public:
115 explicit MicButtonTargeter(views::View* mic_button)
116 : views::MaskedViewTargeter(mic_button) {}
117 virtual ~MicButtonTargeter() {}
118
119 private:
120 // views::MaskedViewTargeter:
121 virtual bool GetHitTestMask(views::View* view,
122 gfx::Path* mask) const OVERRIDE {
123 // The mic button icon is a circle.
124 gfx::Rect local_bounds = view->GetLocalBounds();
125 int radius = local_bounds.width() / 2 + kIndicatorRadiusMinOffset;
126 gfx::Point center = local_bounds.CenterPoint();
127 center.set_y(center.y() + kIndicatorCenterOffsetY);
128 mask->addCircle(SkIntToScalar(center.x()),
129 SkIntToScalar(center.y()),
130 SkIntToScalar(radius));
131 return true;
132 }
133
134 DISALLOW_COPY_AND_ASSIGN(MicButtonTargeter);
135 };
136
110 } // namespace 137 } // namespace
111 138
112 // static 139 // static
113 140
114 SpeechView::SpeechView(AppListViewDelegate* delegate) 141 SpeechView::SpeechView(AppListViewDelegate* delegate)
115 : delegate_(delegate), 142 : delegate_(delegate),
116 logo_(NULL) { 143 logo_(NULL) {
117 SetBorder(scoped_ptr<views::Border>( 144 SetBorder(scoped_ptr<views::Border>(
118 new views::ShadowBorder(kShadowBlur, 145 new views::ShadowBorder(kShadowBlur,
119 kShadowColor, 146 kShadowColor,
(...skipping 13 matching lines...) Expand all
133 logo_->SetImage(&logo_image); 160 logo_->SetImage(&logo_image);
134 container->AddChildView(logo_); 161 container->AddChildView(logo_);
135 } 162 }
136 163
137 indicator_ = new SoundLevelIndicator(); 164 indicator_ = new SoundLevelIndicator();
138 indicator_->SetVisible(false); 165 indicator_->SetVisible(false);
139 container->AddChildView(indicator_); 166 container->AddChildView(indicator_);
140 167
141 mic_button_ = new MicButton(this); 168 mic_button_ = new MicButton(this);
142 container->AddChildView(mic_button_); 169 container->AddChildView(mic_button_);
170 mic_button_->SetEventTargeter(
171 scoped_ptr<ui::EventTargeter>(new MicButtonTargeter(mic_button_)));
143 172
144 // TODO(mukai): use BoundedLabel to cap 2 lines. 173 // TODO(mukai): use BoundedLabel to cap 2 lines.
145 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 174 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
146 speech_result_ = new views::Label( 175 speech_result_ = new views::Label(
147 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); 176 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont));
148 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 177 speech_result_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
149 178
150 speech_result_->SetMultiLine(true); 179 speech_result_->SetMultiLine(true);
151 container->AddChildView(speech_result_); 180 container->AddChildView(speech_result_);
152 181
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 resource_id = IDR_APP_LIST_SPEECH_MIC_ON; 270 resource_id = IDR_APP_LIST_SPEECH_MIC_ON;
242 else if (new_state == SPEECH_RECOGNITION_IN_SPEECH) 271 else if (new_state == SPEECH_RECOGNITION_IN_SPEECH)
243 resource_id = IDR_APP_LIST_SPEECH_MIC_RECORDING; 272 resource_id = IDR_APP_LIST_SPEECH_MIC_RECORDING;
244 273
245 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 274 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
246 mic_button_->SetImage(views::Button::STATE_NORMAL, 275 mic_button_->SetImage(views::Button::STATE_NORMAL,
247 bundle.GetImageSkiaNamed(resource_id)); 276 bundle.GetImageSkiaNamed(resource_id));
248 } 277 }
249 278
250 } // namespace app_list 279 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | ui/views/masked_view_targeter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698