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

Side by Side Diff: chrome/browser/ui/views/speech_recognition_bubble_views.cc

Issue 167283005: Close SpeechRecognitionBubble on pressing the Escape key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comment. Created 6 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 23 matching lines...) Expand all
100 notify_delegate_on_activation_change_(true), 101 notify_delegate_on_activation_change_(true),
101 icon_(NULL), 102 icon_(NULL),
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; explicitly closing
111 // explicitly closing on deactivation will cause unexpected behavior. 112 // on deactivation will cause unexpected behavior.
113 set_close_on_deactivate(false);
114 // Prevent default behavior of bubble closure on escape key and handle
115 // it in the AcceleratorPressed() to avoid an unexpected behavior.
112 set_close_on_esc(false); 116 set_close_on_esc(false);
113 set_close_on_deactivate(false);
114 } 117 }
115 118
116 void SpeechRecognitionBubbleView::OnWidgetActivationChanged( 119 void SpeechRecognitionBubbleView::OnWidgetActivationChanged(
117 views::Widget* widget, bool active) { 120 views::Widget* widget, bool active) {
118 if (widget == GetWidget() && !active && notify_delegate_on_activation_change_) 121 if (widget == GetWidget() && !active && notify_delegate_on_activation_change_)
119 delegate_->InfoBubbleFocusChanged(); 122 delegate_->InfoBubbleFocusChanged();
120 BubbleDelegateView::OnWidgetActivationChanged(widget, active); 123 BubbleDelegateView::OnWidgetActivationChanged(widget, active);
121 } 124 }
122 125
123 gfx::Rect SpeechRecognitionBubbleView::GetAnchorRect() { 126 gfx::Rect SpeechRecognitionBubbleView::GetAnchorRect() {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 NOTREACHED() << "Unknown button"; 221 NOTREACHED() << "Unknown button";
219 } 222 }
220 } 223 }
221 224
222 void SpeechRecognitionBubbleView::LinkClicked(views::Link* source, 225 void SpeechRecognitionBubbleView::LinkClicked(views::Link* source,
223 int event_flags) { 226 int event_flags) {
224 DCHECK_EQ(mic_settings_, source); 227 DCHECK_EQ(mic_settings_, source);
225 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings(); 228 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings();
226 } 229 }
227 230
231 bool SpeechRecognitionBubbleView::AcceleratorPressed(
232 const ui::Accelerator& accelerator) {
233 // The accelerator is added by BubbleDelegateView.
234 if (accelerator.key_code() == ui::VKEY_ESCAPE) {
235 delegate_->InfoBubbleButtonClicked(SpeechRecognitionBubble::BUTTON_CANCEL);
236 return true;
237 }
238
239 return BubbleDelegateView::AcceleratorPressed(accelerator);
240 }
241
228 gfx::Size SpeechRecognitionBubbleView::GetPreferredSize() { 242 gfx::Size SpeechRecognitionBubbleView::GetPreferredSize() {
229 int width = heading_->GetPreferredSize().width(); 243 int width = heading_->GetPreferredSize().width();
230 int control_width = cancel_->GetPreferredSize().width(); 244 int control_width = cancel_->GetPreferredSize().width();
231 if (try_again_->visible()) { 245 if (try_again_->visible()) {
232 control_width += try_again_->GetPreferredSize().width() + 246 control_width += try_again_->GetPreferredSize().width() +
233 views::kRelatedButtonHSpacing; 247 views::kRelatedButtonHSpacing;
234 } 248 }
235 width = std::max(width, control_width); 249 width = std::max(width, control_width);
236 control_width = std::max(icon_->GetPreferredSize().width(), 250 control_width = std::max(icon_->GetPreferredSize().width(),
237 kIconLayoutMinWidth); 251 kIconLayoutMinWidth);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 409 }
396 410
397 } // namespace 411 } // namespace
398 412
399 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( 413 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble(
400 WebContents* web_contents, 414 WebContents* web_contents,
401 SpeechRecognitionBubble::Delegate* delegate, 415 SpeechRecognitionBubble::Delegate* delegate,
402 const gfx::Rect& element_rect) { 416 const gfx::Rect& element_rect) {
403 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); 417 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect);
404 } 418 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698