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_recognition_bubble.h" | 5 #include "chrome/browser/speech/speech_recognition_bubble.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 virtual void Init() OVERRIDE; | 57 virtual void Init() OVERRIDE; |
58 | 58 |
59 // views::ButtonListener methods. | 59 // views::ButtonListener methods. |
60 virtual void ButtonPressed(views::Button* source, | 60 virtual void ButtonPressed(views::Button* source, |
61 const ui::Event& event) OVERRIDE; | 61 const ui::Event& event) OVERRIDE; |
62 | 62 |
63 // views::LinkListener methods. | 63 // views::LinkListener methods. |
64 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | 64 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
65 | 65 |
66 // views::View overrides. | 66 // views::View overrides. |
67 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
67 virtual gfx::Size GetPreferredSize() OVERRIDE; | 68 virtual gfx::Size GetPreferredSize() OVERRIDE; |
68 virtual void Layout() OVERRIDE; | 69 virtual void Layout() OVERRIDE; |
69 | 70 |
70 void set_notify_delegate_on_activation_change(bool notify) { | 71 void set_notify_delegate_on_activation_change(bool notify) { |
71 notify_delegate_on_activation_change_ = notify; | 72 notify_delegate_on_activation_change_ = notify; |
72 } | 73 } |
73 | 74 |
74 private: | 75 private: |
75 SpeechRecognitionBubbleDelegate* delegate_; | 76 SpeechRecognitionBubbleDelegate* delegate_; |
76 gfx::Rect element_rect_; | 77 gfx::Rect element_rect_; |
(...skipping 25 matching lines...) Expand all Loading... | |
102 heading_(NULL), | 103 heading_(NULL), |
103 message_(NULL), | 104 message_(NULL), |
104 try_again_(NULL), | 105 try_again_(NULL), |
105 cancel_(NULL), | 106 cancel_(NULL), |
106 mic_settings_(NULL), | 107 mic_settings_(NULL), |
107 display_mode_(SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP), | 108 display_mode_(SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP), |
108 kIconLayoutMinWidth(ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 109 kIconLayoutMinWidth(ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
109 IDR_SPEECH_INPUT_MIC_EMPTY)->width()) { | 110 IDR_SPEECH_INPUT_MIC_EMPTY)->width()) { |
110 // The bubble lifetime is managed by its controller; closing on escape or | 111 // The bubble lifetime is managed by its controller; closing on escape or |
111 // explicitly closing on deactivation will cause unexpected behavior. | 112 // explicitly closing on deactivation will cause unexpected behavior. |
112 set_close_on_esc(false); | 113 set_close_on_esc(false); |
msw
2014/02/20 18:30:20
Why not just remove this line? Many bubbles close
Elliot Glaysher
2014/02/20 18:59:18
Might have to figure out why closing on escape is
msw
2014/02/20 21:57:24
Ah, right... that comment is probably still valid,
| |
113 set_close_on_deactivate(false); | 114 set_close_on_deactivate(false); |
114 } | 115 } |
115 | 116 |
116 void SpeechRecognitionBubbleView::OnWidgetActivationChanged( | 117 void SpeechRecognitionBubbleView::OnWidgetActivationChanged( |
117 views::Widget* widget, bool active) { | 118 views::Widget* widget, bool active) { |
118 if (widget == GetWidget() && !active && notify_delegate_on_activation_change_) | 119 if (widget == GetWidget() && !active && notify_delegate_on_activation_change_) |
119 delegate_->InfoBubbleFocusChanged(); | 120 delegate_->InfoBubbleFocusChanged(); |
120 BubbleDelegateView::OnWidgetActivationChanged(widget, active); | 121 BubbleDelegateView::OnWidgetActivationChanged(widget, active); |
121 } | 122 } |
122 | 123 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 NOTREACHED() << "Unknown button"; | 219 NOTREACHED() << "Unknown button"; |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
222 void SpeechRecognitionBubbleView::LinkClicked(views::Link* source, | 223 void SpeechRecognitionBubbleView::LinkClicked(views::Link* source, |
223 int event_flags) { | 224 int event_flags) { |
224 DCHECK_EQ(mic_settings_, source); | 225 DCHECK_EQ(mic_settings_, source); |
225 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings(); | 226 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings(); |
226 } | 227 } |
227 | 228 |
229 bool SpeechRecognitionBubbleView::AcceleratorPressed( | |
230 const ui::Accelerator& accelerator) { | |
231 // The accelerator is added by BubbleDelegateView. | |
232 if (accelerator.key_code() == ui::VKEY_ESCAPE) { | |
233 delegate_->InfoBubbleButtonClicked(SpeechRecognitionBubble::BUTTON_CANCEL); | |
234 return true; | |
235 } | |
236 | |
237 return false; | |
msw
2014/02/20 21:57:24
This should be: return BubbleDelegateView::Acceler
| |
238 } | |
239 | |
228 gfx::Size SpeechRecognitionBubbleView::GetPreferredSize() { | 240 gfx::Size SpeechRecognitionBubbleView::GetPreferredSize() { |
229 int width = heading_->GetPreferredSize().width(); | 241 int width = heading_->GetPreferredSize().width(); |
230 int control_width = cancel_->GetPreferredSize().width(); | 242 int control_width = cancel_->GetPreferredSize().width(); |
231 if (try_again_->visible()) { | 243 if (try_again_->visible()) { |
232 control_width += try_again_->GetPreferredSize().width() + | 244 control_width += try_again_->GetPreferredSize().width() + |
233 views::kRelatedButtonHSpacing; | 245 views::kRelatedButtonHSpacing; |
234 } | 246 } |
235 width = std::max(width, control_width); | 247 width = std::max(width, control_width); |
236 control_width = std::max(icon_->GetPreferredSize().width(), | 248 control_width = std::max(icon_->GetPreferredSize().width(), |
237 kIconLayoutMinWidth); | 249 kIconLayoutMinWidth); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 } | 407 } |
396 | 408 |
397 } // namespace | 409 } // namespace |
398 | 410 |
399 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( | 411 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( |
400 WebContents* web_contents, | 412 WebContents* web_contents, |
401 SpeechRecognitionBubble::Delegate* delegate, | 413 SpeechRecognitionBubble::Delegate* delegate, |
402 const gfx::Rect& element_rect) { | 414 const gfx::Rect& element_rect) { |
403 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); | 415 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); |
404 } | 416 } |
OLD | NEW |