OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/speech/speech_input_bubble.h" | 5 #include "chrome/browser/speech/speech_recognition_bubble.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/views/frame/browser_view.h" | 11 #include "chrome/browser/ui/views/frame/browser_view.h" |
12 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 12 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
13 #include "chrome/browser/ui/views/toolbar_view.h" | 13 #include "chrome/browser/ui/views/toolbar_view.h" |
14 #include "chrome/browser/ui/views/window.h" | 14 #include "chrome/browser/ui/views/window.h" |
15 #include "content/public/browser/resource_context.h" | 15 #include "content/public/browser/resource_context.h" |
16 #include "content/public/browser/speech_input_manager.h" | 16 #include "content/public/browser/speech_recognition_manager.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/views/bubble/bubble_delegate.h" | 23 #include "ui/views/bubble/bubble_delegate.h" |
24 #include "ui/views/controls/button/text_button.h" | 24 #include "ui/views/controls/button/text_button.h" |
25 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
26 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
27 #include "ui/views/controls/link.h" | 27 #include "ui/views/controls/link.h" |
28 #include "ui/views/controls/link_listener.h" | 28 #include "ui/views/controls/link_listener.h" |
29 #include "ui/views/layout/layout_constants.h" | 29 #include "ui/views/layout/layout_constants.h" |
30 | 30 |
31 using content::WebContents; | 31 using content::WebContents; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const int kBubbleHorizMargin = 6; | 35 const int kBubbleHorizMargin = 6; |
36 const int kBubbleVertMargin = 4; | 36 const int kBubbleVertMargin = 4; |
37 const int kBubbleHeadingVertMargin = 6; | 37 const int kBubbleHeadingVertMargin = 6; |
38 const int kIconHorizontalOffset = 27; | 38 const int kIconHorizontalOffset = 27; |
39 const int kIconVerticalOffset = -7; | 39 const int kIconVerticalOffset = -7; |
40 | 40 |
41 // This is the SpeechInputBubble content and views bubble delegate. | 41 // This is the SpeechRecognitionBubble content and views bubble delegate. |
42 class SpeechInputBubbleView | 42 class SpeechRecognitionBubbleView |
43 : public views::BubbleDelegateView, | 43 : public views::BubbleDelegateView, |
44 public views::ButtonListener, | 44 public views::ButtonListener, |
45 public views::LinkListener { | 45 public views::LinkListener { |
46 public: | 46 public: |
47 SpeechInputBubbleView(SpeechInputBubbleDelegate* delegate, | 47 SpeechRecognitionBubbleView(SpeechRecognitionBubbleDelegate* delegate, |
48 views::View* anchor_view, | 48 views::View* anchor_view, |
49 const gfx::Rect& element_rect, | 49 const gfx::Rect& element_rect, |
50 WebContents* web_contents); | 50 WebContents* web_contents); |
51 | 51 |
52 void UpdateLayout(SpeechInputBubbleBase::DisplayMode mode, | 52 void UpdateLayout(SpeechRecognitionBubbleBase::DisplayMode mode, |
53 const string16& message_text, | 53 const string16& message_text, |
54 const SkBitmap& image); | 54 const SkBitmap& image); |
55 void SetImage(const SkBitmap& image); | 55 void SetImage(const SkBitmap& image); |
56 | 56 |
57 // views::BubbleDelegateView methods. | 57 // views::BubbleDelegateView methods. |
58 virtual void OnWidgetActivationChanged(views::Widget* widget, | 58 virtual void OnWidgetActivationChanged(views::Widget* widget, |
59 bool active) OVERRIDE; | 59 bool active) OVERRIDE; |
60 virtual gfx::Rect GetAnchorRect() OVERRIDE; | 60 virtual gfx::Rect GetAnchorRect() OVERRIDE; |
61 virtual void Init() OVERRIDE; | 61 virtual void Init() OVERRIDE; |
62 | 62 |
63 // views::ButtonListener methods. | 63 // views::ButtonListener methods. |
64 virtual void ButtonPressed(views::Button* source, | 64 virtual void ButtonPressed(views::Button* source, |
65 const views::Event& event) OVERRIDE; | 65 const views::Event& event) OVERRIDE; |
66 | 66 |
67 // views::LinkListener methods. | 67 // views::LinkListener methods. |
68 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | 68 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
69 | 69 |
70 // views::View overrides. | 70 // views::View overrides. |
71 virtual gfx::Size GetPreferredSize() OVERRIDE; | 71 virtual gfx::Size GetPreferredSize() OVERRIDE; |
72 virtual void Layout() OVERRIDE; | 72 virtual void Layout() OVERRIDE; |
73 | 73 |
74 void set_notify_delegate_on_activation_change(bool notify) { | 74 void set_notify_delegate_on_activation_change(bool notify) { |
75 notify_delegate_on_activation_change_ = notify; | 75 notify_delegate_on_activation_change_ = notify; |
76 } | 76 } |
77 | 77 |
78 private: | 78 private: |
79 SpeechInputBubbleDelegate* delegate_; | 79 SpeechRecognitionBubbleDelegate* delegate_; |
80 gfx::Rect element_rect_; | 80 gfx::Rect element_rect_; |
81 WebContents* web_contents_; | 81 WebContents* web_contents_; |
82 bool notify_delegate_on_activation_change_; | 82 bool notify_delegate_on_activation_change_; |
83 views::ImageView* icon_; | 83 views::ImageView* icon_; |
84 views::Label* heading_; | 84 views::Label* heading_; |
85 views::Label* message_; | 85 views::Label* message_; |
86 views::TextButton* try_again_; | 86 views::TextButton* try_again_; |
87 views::TextButton* cancel_; | 87 views::TextButton* cancel_; |
88 views::Link* mic_settings_; | 88 views::Link* mic_settings_; |
89 SpeechInputBubbleBase::DisplayMode display_mode_; | 89 SpeechRecognitionBubbleBase::DisplayMode display_mode_; |
90 const int kIconLayoutMinWidth; | 90 const int kIconLayoutMinWidth; |
91 | 91 |
92 DISALLOW_COPY_AND_ASSIGN(SpeechInputBubbleView); | 92 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleView); |
93 }; | 93 }; |
94 | 94 |
95 SpeechInputBubbleView::SpeechInputBubbleView( | 95 SpeechRecognitionBubbleView::SpeechRecognitionBubbleView( |
96 SpeechInputBubbleDelegate* delegate, | 96 SpeechRecognitionBubbleDelegate* delegate, |
97 views::View* anchor_view, | 97 views::View* anchor_view, |
98 const gfx::Rect& element_rect, | 98 const gfx::Rect& element_rect, |
99 WebContents* web_contents) | 99 WebContents* web_contents) |
100 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 100 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
101 delegate_(delegate), | 101 delegate_(delegate), |
102 element_rect_(element_rect), | 102 element_rect_(element_rect), |
103 web_contents_(web_contents), | 103 web_contents_(web_contents), |
104 notify_delegate_on_activation_change_(true), | 104 notify_delegate_on_activation_change_(true), |
105 icon_(NULL), | 105 icon_(NULL), |
106 heading_(NULL), | 106 heading_(NULL), |
107 message_(NULL), | 107 message_(NULL), |
108 try_again_(NULL), | 108 try_again_(NULL), |
109 cancel_(NULL), | 109 cancel_(NULL), |
110 mic_settings_(NULL), | 110 mic_settings_(NULL), |
111 display_mode_(SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP), | 111 display_mode_(SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP), |
112 kIconLayoutMinWidth(ResourceBundle::GetSharedInstance().GetBitmapNamed( | 112 kIconLayoutMinWidth(ResourceBundle::GetSharedInstance().GetBitmapNamed( |
113 IDR_SPEECH_INPUT_MIC_EMPTY)->width()) { | 113 IDR_SPEECH_INPUT_MIC_EMPTY)->width()) { |
114 // The bubble lifetime is managed by its controller; closing on escape or | 114 // The bubble lifetime is managed by its controller; closing on escape or |
115 // explicitly closing on deactivation will cause unexpected behavior. | 115 // explicitly closing on deactivation will cause unexpected behavior. |
116 set_close_on_esc(false); | 116 set_close_on_esc(false); |
117 set_close_on_deactivate(false); | 117 set_close_on_deactivate(false); |
118 } | 118 } |
119 | 119 |
120 void SpeechInputBubbleView::OnWidgetActivationChanged(views::Widget* widget, | 120 void SpeechRecognitionBubbleView::OnWidgetActivationChanged( |
121 bool active) { | 121 views::Widget* widget, bool active) { |
122 if (widget == GetWidget() && !active && notify_delegate_on_activation_change_) | 122 if (widget == GetWidget() && !active && notify_delegate_on_activation_change_) |
123 delegate_->InfoBubbleFocusChanged(); | 123 delegate_->InfoBubbleFocusChanged(); |
124 BubbleDelegateView::OnWidgetActivationChanged(widget, active); | 124 BubbleDelegateView::OnWidgetActivationChanged(widget, active); |
125 } | 125 } |
126 | 126 |
127 gfx::Rect SpeechInputBubbleView::GetAnchorRect() { | 127 gfx::Rect SpeechRecognitionBubbleView::GetAnchorRect() { |
128 gfx::Rect container_rect; | 128 gfx::Rect container_rect; |
129 web_contents_->GetContainerBounds(&container_rect); | 129 web_contents_->GetContainerBounds(&container_rect); |
130 gfx::Rect anchor(element_rect_); | 130 gfx::Rect anchor(element_rect_); |
131 anchor.Offset(container_rect.origin()); | 131 anchor.Offset(container_rect.origin()); |
132 if (!container_rect.Intersects(anchor)) | 132 if (!container_rect.Intersects(anchor)) |
133 return BubbleDelegateView::GetAnchorRect(); | 133 return BubbleDelegateView::GetAnchorRect(); |
134 return anchor; | 134 return anchor; |
135 } | 135 } |
136 | 136 |
137 void SpeechInputBubbleView::Init() { | 137 void SpeechRecognitionBubbleView::Init() { |
138 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 138 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
139 const gfx::Font& font = rb.GetFont(ResourceBundle::MediumFont); | 139 const gfx::Font& font = rb.GetFont(ResourceBundle::MediumFont); |
140 | 140 |
141 heading_ = new views::Label( | 141 heading_ = new views::Label( |
142 l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_BUBBLE_HEADING)); | 142 l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_BUBBLE_HEADING)); |
143 heading_->set_border(views::Border::CreateEmptyBorder( | 143 heading_->set_border(views::Border::CreateEmptyBorder( |
144 kBubbleHeadingVertMargin, 0, kBubbleHeadingVertMargin, 0)); | 144 kBubbleHeadingVertMargin, 0, kBubbleHeadingVertMargin, 0)); |
145 heading_->SetFont(font); | 145 heading_->SetFont(font); |
146 heading_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); | 146 heading_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); |
147 heading_->SetText( | 147 heading_->SetText( |
(...skipping 17 matching lines...) Expand all Loading... |
165 try_again_ = new views::NativeTextButton( | 165 try_again_ = new views::NativeTextButton( |
166 this, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_TRY_AGAIN)); | 166 this, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_TRY_AGAIN)); |
167 AddChildView(try_again_); | 167 AddChildView(try_again_); |
168 | 168 |
169 mic_settings_ = new views::Link( | 169 mic_settings_ = new views::Link( |
170 l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_SETTINGS)); | 170 l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_SETTINGS)); |
171 mic_settings_->set_listener(this); | 171 mic_settings_->set_listener(this); |
172 AddChildView(mic_settings_); | 172 AddChildView(mic_settings_); |
173 } | 173 } |
174 | 174 |
175 void SpeechInputBubbleView::UpdateLayout( | 175 void SpeechRecognitionBubbleView::UpdateLayout( |
176 SpeechInputBubbleBase::DisplayMode mode, | 176 SpeechRecognitionBubbleBase::DisplayMode mode, |
177 const string16& message_text, | 177 const string16& message_text, |
178 const SkBitmap& image) { | 178 const SkBitmap& image) { |
179 display_mode_ = mode; | 179 display_mode_ = mode; |
180 bool is_message = (mode == SpeechInputBubbleBase::DISPLAY_MODE_MESSAGE); | 180 bool is_message = (mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_MESSAGE); |
181 icon_->SetVisible(!is_message); | 181 icon_->SetVisible(!is_message); |
182 message_->SetVisible(is_message); | 182 message_->SetVisible(is_message); |
183 mic_settings_->SetVisible(is_message); | 183 mic_settings_->SetVisible(is_message); |
184 try_again_->SetVisible(is_message); | 184 try_again_->SetVisible(is_message); |
185 cancel_->SetVisible(mode != SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP); | 185 cancel_->SetVisible( |
186 heading_->SetVisible(mode == SpeechInputBubbleBase::DISPLAY_MODE_RECORDING); | 186 mode != SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP); |
| 187 heading_->SetVisible( |
| 188 mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_RECORDING); |
187 | 189 |
188 // Clickable elements should be enabled if and only if they are visible. | 190 // Clickable elements should be enabled if and only if they are visible. |
189 mic_settings_->SetEnabled(mic_settings_->visible()); | 191 mic_settings_->SetEnabled(mic_settings_->visible()); |
190 try_again_->SetEnabled(try_again_->visible()); | 192 try_again_->SetEnabled(try_again_->visible()); |
191 cancel_->SetEnabled(cancel_->visible()); | 193 cancel_->SetEnabled(cancel_->visible()); |
192 | 194 |
193 if (is_message) { | 195 if (is_message) { |
194 message_->SetText(message_text); | 196 message_->SetText(message_text); |
195 } else { | 197 } else { |
196 SetImage(image); | 198 SetImage(image); |
197 } | 199 } |
198 | 200 |
199 if (icon_->visible()) | 201 if (icon_->visible()) |
200 icon_->ResetImageSize(); | 202 icon_->ResetImageSize(); |
201 | 203 |
202 // When moving from warming up to recording state, the size of the content | 204 // When moving from warming up to recording state, the size of the content |
203 // stays the same. So we wouldn't get a resize/layout call from the view | 205 // stays the same. So we wouldn't get a resize/layout call from the view |
204 // system and we do it ourselves. | 206 // system and we do it ourselves. |
205 if (GetPreferredSize() == size()) // |size()| here is the current size. | 207 if (GetPreferredSize() == size()) // |size()| here is the current size. |
206 Layout(); | 208 Layout(); |
207 | 209 |
208 SizeToContents(); | 210 SizeToContents(); |
209 } | 211 } |
210 | 212 |
211 void SpeechInputBubbleView::SetImage(const SkBitmap& image) { | 213 void SpeechRecognitionBubbleView::SetImage(const SkBitmap& image) { |
212 icon_->SetImage(image); | 214 icon_->SetImage(image); |
213 } | 215 } |
214 | 216 |
215 void SpeechInputBubbleView::ButtonPressed(views::Button* source, | 217 void SpeechRecognitionBubbleView::ButtonPressed(views::Button* source, |
216 const views::Event& event) { | 218 const views::Event& event) { |
217 if (source == cancel_) { | 219 if (source == cancel_) { |
218 delegate_->InfoBubbleButtonClicked(SpeechInputBubble::BUTTON_CANCEL); | 220 delegate_->InfoBubbleButtonClicked(SpeechRecognitionBubble::BUTTON_CANCEL); |
219 } else if (source == try_again_) { | 221 } else if (source == try_again_) { |
220 delegate_->InfoBubbleButtonClicked(SpeechInputBubble::BUTTON_TRY_AGAIN); | 222 delegate_->InfoBubbleButtonClicked( |
| 223 SpeechRecognitionBubble::BUTTON_TRY_AGAIN); |
221 } else { | 224 } else { |
222 NOTREACHED() << "Unknown button"; | 225 NOTREACHED() << "Unknown button"; |
223 } | 226 } |
224 } | 227 } |
225 | 228 |
226 void SpeechInputBubbleView::LinkClicked(views::Link* source, int event_flags) { | 229 void SpeechRecognitionBubbleView::LinkClicked(views::Link* source, |
| 230 int event_flags) { |
227 DCHECK_EQ(source, mic_settings_); | 231 DCHECK_EQ(source, mic_settings_); |
228 content::SpeechInputManager::GetInstance()->ShowAudioInputSettings(); | 232 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings(); |
229 } | 233 } |
230 | 234 |
231 gfx::Size SpeechInputBubbleView::GetPreferredSize() { | 235 gfx::Size SpeechRecognitionBubbleView::GetPreferredSize() { |
232 int width = heading_->GetPreferredSize().width(); | 236 int width = heading_->GetPreferredSize().width(); |
233 int control_width = cancel_->GetPreferredSize().width(); | 237 int control_width = cancel_->GetPreferredSize().width(); |
234 if (try_again_->visible()) { | 238 if (try_again_->visible()) { |
235 control_width += try_again_->GetPreferredSize().width() + | 239 control_width += try_again_->GetPreferredSize().width() + |
236 views::kRelatedButtonHSpacing; | 240 views::kRelatedButtonHSpacing; |
237 } | 241 } |
238 width = std::max(width, control_width); | 242 width = std::max(width, control_width); |
239 control_width = std::max(icon_->GetPreferredSize().width(), | 243 control_width = std::max(icon_->GetPreferredSize().width(), |
240 kIconLayoutMinWidth); | 244 kIconLayoutMinWidth); |
241 width = std::max(width, control_width); | 245 width = std::max(width, control_width); |
(...skipping 12 matching lines...) Expand all Loading... |
254 if (icon_->visible()) | 258 if (icon_->visible()) |
255 height += icon_->GetImage().height(); | 259 height += icon_->GetImage().height(); |
256 if (mic_settings_->visible()) | 260 if (mic_settings_->visible()) |
257 height += mic_settings_->GetPreferredSize().height(); | 261 height += mic_settings_->GetPreferredSize().height(); |
258 width += kBubbleHorizMargin * 2; | 262 width += kBubbleHorizMargin * 2; |
259 height += kBubbleVertMargin * 2; | 263 height += kBubbleVertMargin * 2; |
260 | 264 |
261 return gfx::Size(width, height); | 265 return gfx::Size(width, height); |
262 } | 266 } |
263 | 267 |
264 void SpeechInputBubbleView::Layout() { | 268 void SpeechRecognitionBubbleView::Layout() { |
265 int x = kBubbleHorizMargin; | 269 int x = kBubbleHorizMargin; |
266 int y = kBubbleVertMargin; | 270 int y = kBubbleVertMargin; |
267 int available_width = width() - kBubbleHorizMargin * 2; | 271 int available_width = width() - kBubbleHorizMargin * 2; |
268 int available_height = height() - kBubbleVertMargin * 2; | 272 int available_height = height() - kBubbleVertMargin * 2; |
269 | 273 |
270 if (message_->visible()) { | 274 if (message_->visible()) { |
271 DCHECK(try_again_->visible()); | 275 DCHECK(try_again_->visible()); |
272 | 276 |
273 int control_height = try_again_->GetPreferredSize().height(); | 277 int control_height = try_again_->GetPreferredSize().height(); |
274 int try_again_width = try_again_->GetPreferredSize().width(); | 278 int try_again_width = try_again_->GetPreferredSize().width(); |
(...skipping 10 matching lines...) Expand all Loading... |
285 available_width, control_height); | 289 available_width, control_height); |
286 y = kBubbleVertMargin + control_height; | 290 y = kBubbleVertMargin + control_height; |
287 | 291 |
288 control_height = mic_settings_->GetPreferredSize().height(); | 292 control_height = mic_settings_->GetPreferredSize().height(); |
289 mic_settings_->SetBounds(kBubbleHorizMargin, y, available_width, | 293 mic_settings_->SetBounds(kBubbleHorizMargin, y, available_width, |
290 control_height); | 294 control_height); |
291 } else { | 295 } else { |
292 DCHECK(icon_->visible()); | 296 DCHECK(icon_->visible()); |
293 | 297 |
294 int control_height = icon_->GetImage().height(); | 298 int control_height = icon_->GetImage().height(); |
295 if (display_mode_ == SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP) | 299 if (display_mode_ == SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP) |
296 y = (available_height - control_height) / 2; | 300 y = (available_height - control_height) / 2; |
297 icon_->SetBounds(x, y, available_width, control_height); | 301 icon_->SetBounds(x, y, available_width, control_height); |
298 y += control_height; | 302 y += control_height; |
299 | 303 |
300 if (heading_->visible()) { | 304 if (heading_->visible()) { |
301 control_height = heading_->GetPreferredSize().height(); | 305 control_height = heading_->GetPreferredSize().height(); |
302 heading_->SetBounds(x, y, available_width, control_height); | 306 heading_->SetBounds(x, y, available_width, control_height); |
303 y += control_height; | 307 y += control_height; |
304 } | 308 } |
305 | 309 |
306 if (cancel_->visible()) { | 310 if (cancel_->visible()) { |
307 control_height = cancel_->GetPreferredSize().height(); | 311 control_height = cancel_->GetPreferredSize().height(); |
308 int width = cancel_->GetPreferredSize().width(); | 312 int width = cancel_->GetPreferredSize().width(); |
309 cancel_->SetBounds(x + (available_width - width) / 2, y, width, | 313 cancel_->SetBounds(x + (available_width - width) / 2, y, width, |
310 control_height); | 314 control_height); |
311 } | 315 } |
312 } | 316 } |
313 } | 317 } |
314 | 318 |
315 // Implementation of SpeechInputBubble. | 319 // Implementation of SpeechRecognitionBubble. |
316 class SpeechInputBubbleImpl : public SpeechInputBubbleBase { | 320 class SpeechRecognitionBubbleImpl : public SpeechRecognitionBubbleBase { |
317 public: | 321 public: |
318 SpeechInputBubbleImpl(WebContents* web_contents, | 322 SpeechRecognitionBubbleImpl(WebContents* web_contents, |
319 Delegate* delegate, | 323 Delegate* delegate, |
320 const gfx::Rect& element_rect); | 324 const gfx::Rect& element_rect); |
321 virtual ~SpeechInputBubbleImpl(); | 325 virtual ~SpeechRecognitionBubbleImpl(); |
322 | 326 |
323 // SpeechInputBubble methods. | 327 // SpeechRecognitionBubble methods. |
324 virtual void Show() OVERRIDE; | 328 virtual void Show() OVERRIDE; |
325 virtual void Hide() OVERRIDE; | 329 virtual void Hide() OVERRIDE; |
326 | 330 |
327 // SpeechInputBubbleBase methods. | 331 // SpeechRecognitionBubbleBase methods. |
328 virtual void UpdateLayout() OVERRIDE; | 332 virtual void UpdateLayout() OVERRIDE; |
329 virtual void UpdateImage() OVERRIDE; | 333 virtual void UpdateImage() OVERRIDE; |
330 | 334 |
331 private: | 335 private: |
332 Delegate* delegate_; | 336 Delegate* delegate_; |
333 SpeechInputBubbleView* bubble_; | 337 SpeechRecognitionBubbleView* bubble_; |
334 gfx::Rect element_rect_; | 338 gfx::Rect element_rect_; |
335 | 339 |
336 DISALLOW_COPY_AND_ASSIGN(SpeechInputBubbleImpl); | 340 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleImpl); |
337 }; | 341 }; |
338 | 342 |
339 SpeechInputBubbleImpl::SpeechInputBubbleImpl(WebContents* web_contents, | 343 SpeechRecognitionBubbleImpl::SpeechRecognitionBubbleImpl( |
340 Delegate* delegate, | 344 WebContents* web_contents, Delegate* delegate, |
341 const gfx::Rect& element_rect) | 345 const gfx::Rect& element_rect) |
342 : SpeechInputBubbleBase(web_contents), | 346 : SpeechRecognitionBubbleBase(web_contents), |
343 delegate_(delegate), | 347 delegate_(delegate), |
344 bubble_(NULL), | 348 bubble_(NULL), |
345 element_rect_(element_rect) { | 349 element_rect_(element_rect) { |
346 } | 350 } |
347 | 351 |
348 SpeechInputBubbleImpl::~SpeechInputBubbleImpl() { | 352 SpeechRecognitionBubbleImpl::~SpeechRecognitionBubbleImpl() { |
349 if (bubble_) { | 353 if (bubble_) { |
350 bubble_->set_notify_delegate_on_activation_change(false); | 354 bubble_->set_notify_delegate_on_activation_change(false); |
351 bubble_->GetWidget()->Close(); | 355 bubble_->GetWidget()->Close(); |
352 } | 356 } |
353 } | 357 } |
354 | 358 |
355 void SpeechInputBubbleImpl::Show() { | 359 void SpeechRecognitionBubbleImpl::Show() { |
356 if (!bubble_) { | 360 if (!bubble_) { |
357 // Anchor to the location icon view, in case |element_rect| is offscreen. | 361 // Anchor to the location icon view, in case |element_rect| is offscreen. |
358 Browser* browser = Browser::GetOrCreateTabbedBrowser( | 362 Browser* browser = Browser::GetOrCreateTabbedBrowser( |
359 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); | 363 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
360 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 364 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
361 views::View* icon = browser_view->GetLocationBarView() ? | 365 views::View* icon = browser_view->GetLocationBarView() ? |
362 browser_view->GetLocationBarView()->location_icon_view() : NULL; | 366 browser_view->GetLocationBarView()->location_icon_view() : NULL; |
363 bubble_ = new SpeechInputBubbleView(delegate_, icon, element_rect_, | 367 bubble_ = new SpeechRecognitionBubbleView(delegate_, icon, element_rect_, |
364 web_contents()); | 368 web_contents()); |
365 browser::CreateViewsBubble(bubble_); | 369 browser::CreateViewsBubble(bubble_); |
366 UpdateLayout(); | 370 UpdateLayout(); |
367 } | 371 } |
368 bubble_->Show(); | 372 bubble_->Show(); |
369 } | 373 } |
370 | 374 |
371 void SpeechInputBubbleImpl::Hide() { | 375 void SpeechRecognitionBubbleImpl::Hide() { |
372 if (bubble_) | 376 if (bubble_) |
373 bubble_->GetWidget()->Hide(); | 377 bubble_->GetWidget()->Hide(); |
374 } | 378 } |
375 | 379 |
376 void SpeechInputBubbleImpl::UpdateLayout() { | 380 void SpeechRecognitionBubbleImpl::UpdateLayout() { |
377 if (bubble_) | 381 if (bubble_) |
378 bubble_->UpdateLayout(display_mode(), message_text(), icon_image()); | 382 bubble_->UpdateLayout(display_mode(), message_text(), icon_image()); |
379 } | 383 } |
380 | 384 |
381 void SpeechInputBubbleImpl::UpdateImage() { | 385 void SpeechRecognitionBubbleImpl::UpdateImage() { |
382 if (bubble_) | 386 if (bubble_) |
383 bubble_->SetImage(icon_image()); | 387 bubble_->SetImage(icon_image()); |
384 } | 388 } |
385 | 389 |
386 } // namespace | 390 } // namespace |
387 | 391 |
388 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( | 392 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( |
389 WebContents* web_contents, | 393 WebContents* web_contents, |
390 SpeechInputBubble::Delegate* delegate, | 394 SpeechRecognitionBubble::Delegate* delegate, |
391 const gfx::Rect& element_rect) { | 395 const gfx::Rect& element_rect) { |
392 return new SpeechInputBubbleImpl(web_contents, delegate, element_rect); | 396 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); |
393 } | 397 } |
OLD | NEW |