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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 const int kButtonBarHorizontalSpacing = 10; | 38 const int kButtonBarHorizontalSpacing = 10; |
39 | 39 |
40 // Use black for text labels since the bubble has white background. | 40 // Use black for text labels since the bubble has white background. |
41 const GdkColor& kLabelTextColor = ui::kGdkBlack; | 41 const GdkColor& kLabelTextColor = ui::kGdkBlack; |
42 | 42 |
43 // Implementation of SpeechRecognitionBubble for GTK. This shows a speech | 43 // Implementation of SpeechRecognitionBubble for GTK. This shows a speech |
44 // recognition bubble on screen. | 44 // recognition bubble on screen. |
45 class SpeechRecognitionBubbleGtk : public SpeechRecognitionBubbleBase, | 45 class SpeechRecognitionBubbleGtk : public SpeechRecognitionBubbleBase, |
46 public BubbleDelegateGtk { | 46 public BubbleDelegateGtk { |
47 public: | 47 public: |
48 SpeechRecognitionBubbleGtk(WebContents* web_contents, | 48 SpeechRecognitionBubbleGtk(int render_process_id, int render_view_id, |
49 Delegate* delegate, | 49 Delegate* delegate, |
50 const gfx::Rect& element_rect); | 50 const gfx::Rect& element_rect); |
51 virtual ~SpeechRecognitionBubbleGtk(); | 51 virtual ~SpeechRecognitionBubbleGtk(); |
52 | 52 |
53 private: | 53 private: |
54 // SpeechRecognitionBubbleBase: | 54 // SpeechRecognitionBubbleBase: |
55 virtual void Show() OVERRIDE; | 55 virtual void Show() OVERRIDE; |
56 virtual void Hide() OVERRIDE; | 56 virtual void Hide() OVERRIDE; |
57 virtual void UpdateLayout() OVERRIDE; | 57 virtual void UpdateLayout() OVERRIDE; |
58 virtual void UpdateImage() OVERRIDE; | 58 virtual void UpdateImage() OVERRIDE; |
(...skipping 14 matching lines...) Expand all Loading... |
73 GtkWidget* cancel_button_; | 73 GtkWidget* cancel_button_; |
74 GtkWidget* try_again_button_; | 74 GtkWidget* try_again_button_; |
75 GtkWidget* icon_; | 75 GtkWidget* icon_; |
76 GtkWidget* icon_container_; | 76 GtkWidget* icon_container_; |
77 GtkWidget* mic_settings_; | 77 GtkWidget* mic_settings_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleGtk); | 79 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleGtk); |
80 }; | 80 }; |
81 | 81 |
82 SpeechRecognitionBubbleGtk::SpeechRecognitionBubbleGtk( | 82 SpeechRecognitionBubbleGtk::SpeechRecognitionBubbleGtk( |
83 WebContents* web_contents, Delegate* delegate, | 83 int render_process_id, int render_view_id, Delegate* delegate, |
84 const gfx::Rect& element_rect) | 84 const gfx::Rect& element_rect) |
85 : SpeechRecognitionBubbleBase(web_contents), | 85 : SpeechRecognitionBubbleBase(render_process_id, render_process_id), |
86 delegate_(delegate), | 86 delegate_(delegate), |
87 bubble_(NULL), | 87 bubble_(NULL), |
88 element_rect_(element_rect), | 88 element_rect_(element_rect), |
89 did_invoke_close_(false), | 89 did_invoke_close_(false), |
90 label_(NULL), | 90 label_(NULL), |
91 cancel_button_(NULL), | 91 cancel_button_(NULL), |
92 try_again_button_(NULL), | 92 try_again_button_(NULL), |
93 icon_(NULL), | 93 icon_(NULL), |
94 icon_container_(NULL), | 94 icon_container_(NULL), |
95 mic_settings_(NULL) { | 95 mic_settings_(NULL) { |
(...skipping 14 matching lines...) Expand all Loading... |
110 void SpeechRecognitionBubbleGtk::OnTryAgainClicked(GtkWidget* widget) { | 110 void SpeechRecognitionBubbleGtk::OnTryAgainClicked(GtkWidget* widget) { |
111 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN); | 111 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN); |
112 } | 112 } |
113 | 113 |
114 void SpeechRecognitionBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) { | 114 void SpeechRecognitionBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) { |
115 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings(); | 115 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings(); |
116 Hide(); | 116 Hide(); |
117 } | 117 } |
118 | 118 |
119 void SpeechRecognitionBubbleGtk::Show() { | 119 void SpeechRecognitionBubbleGtk::Show() { |
120 if (bubble_) | 120 if (bubble_ || !GetWebContents()) |
121 return; // Nothing further to do since the bubble is already visible. | 121 return; // Nothing further to do since the bubble is already visible. |
122 | 122 |
123 // We use a vbox to arrange the controls (label, image, button bar) vertically | 123 // We use a vbox to arrange the controls (label, image, button bar) vertically |
124 // and the button bar is a hbox holding the 2 buttons (try again and cancel). | 124 // and the button bar is a hbox holding the 2 buttons (try again and cancel). |
125 // To get horizontal space around them we place this vbox with padding in a | 125 // To get horizontal space around them we place this vbox with padding in a |
126 // GtkAlignment below. | 126 // GtkAlignment below. |
127 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 127 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
128 | 128 |
129 // The icon with a some padding on the left and right. | 129 // The icon with a some padding on the left and right. |
130 icon_container_ = gtk_alignment_new(0, 0, 0, 0); | 130 icon_container_ = gtk_alignment_new(0, 0, 0, 0); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 UpdateLayout(); | 206 UpdateLayout(); |
207 } | 207 } |
208 | 208 |
209 void SpeechRecognitionBubbleGtk::Hide() { | 209 void SpeechRecognitionBubbleGtk::Hide() { |
210 if (bubble_) | 210 if (bubble_) |
211 bubble_->Close(); | 211 bubble_->Close(); |
212 } | 212 } |
213 | 213 |
214 void SpeechRecognitionBubbleGtk::UpdateLayout() { | 214 void SpeechRecognitionBubbleGtk::UpdateLayout() { |
215 if (!bubble_) | 215 if (!bubble_ || !GetWebContents()) |
216 return; | 216 return; |
217 | 217 |
218 if (display_mode() == DISPLAY_MODE_MESSAGE) { | 218 if (display_mode() == DISPLAY_MODE_MESSAGE) { |
219 // Message text and the Try Again + Cancel buttons are visible, hide the | 219 // Message text and the Try Again + Cancel buttons are visible, hide the |
220 // icon. | 220 // icon. |
221 gtk_label_set_text(GTK_LABEL(label_), | 221 gtk_label_set_text(GTK_LABEL(label_), |
222 base::UTF16ToUTF8(message_text()).c_str()); | 222 base::UTF16ToUTF8(message_text()).c_str()); |
223 gtk_widget_show(label_); | 223 gtk_widget_show(label_); |
224 gtk_widget_show(try_again_button_); | 224 gtk_widget_show(try_again_button_); |
225 if (mic_settings_) | 225 if (mic_settings_) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 void SpeechRecognitionBubbleGtk::BubbleClosing(BubbleGtk* bubble, | 286 void SpeechRecognitionBubbleGtk::BubbleClosing(BubbleGtk* bubble, |
287 bool closed_by_escape) { | 287 bool closed_by_escape) { |
288 bubble_ = NULL; | 288 bubble_ = NULL; |
289 if (!did_invoke_close_) | 289 if (!did_invoke_close_) |
290 delegate_->InfoBubbleFocusChanged(); | 290 delegate_->InfoBubbleFocusChanged(); |
291 } | 291 } |
292 | 292 |
293 } // namespace | 293 } // namespace |
294 | 294 |
295 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( | 295 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( |
296 WebContents* web_contents, | 296 int render_process_id, int render_view_id, |
297 Delegate* delegate, | 297 SpeechRecognitionBubble::Delegate* delegate, |
298 const gfx::Rect& element_rect) { | 298 const gfx::Rect& element_rect) { |
299 return new SpeechRecognitionBubbleGtk(web_contents, delegate, element_rect); | 299 return new SpeechRecognitionBubbleGtk(render_process_id, render_view_id, |
| 300 delegate, element_rect); |
300 } | 301 } |
OLD | NEW |