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 "base/utf_string_conversions.h" | 7 #include "base/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/gtk/browser_toolbar_gtk.h" | 10 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
11 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 11 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
12 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" | 12 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
13 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 13 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
14 #include "chrome/browser/ui/gtk/gtk_util.h" | 14 #include "chrome/browser/ui/gtk/gtk_util.h" |
15 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 15 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
16 #include "chrome/browser/ui/gtk/theme_service_gtk.h" | 16 #include "chrome/browser/ui/gtk/theme_service_gtk.h" |
17 #include "content/public/browser/resource_context.h" | 17 #include "content/public/browser/resource_context.h" |
18 #include "content/public/browser/speech_input_manager.h" | 18 #include "content/public/browser/speech_recognition_manager.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
22 #include "ui/base/gtk/gtk_hig_constants.h" | 22 #include "ui/base/gtk/gtk_hig_constants.h" |
23 #include "ui/base/gtk/owned_widget_gtk.h" | 23 #include "ui/base/gtk/owned_widget_gtk.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/gtk_util.h" | 26 #include "ui/gfx/gtk_util.h" |
27 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
28 | 28 |
29 using content::WebContents; | 29 using content::WebContents; |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const int kBubbleControlVerticalSpacing = 5; | 33 const int kBubbleControlVerticalSpacing = 5; |
34 const int kBubbleControlHorizontalSpacing = 20; | 34 const int kBubbleControlHorizontalSpacing = 20; |
35 const int kIconHorizontalPadding = 10; | 35 const int kIconHorizontalPadding = 10; |
36 const int kButtonBarHorizontalSpacing = 10; | 36 const int kButtonBarHorizontalSpacing = 10; |
37 | 37 |
38 // Use black for text labels since the bubble has white background. | 38 // Use black for text labels since the bubble has white background. |
39 const GdkColor& kLabelTextColor = ui::kGdkBlack; | 39 const GdkColor& kLabelTextColor = ui::kGdkBlack; |
40 | 40 |
41 // Implementation of SpeechInputBubble for GTK. This shows a speech input bubble | 41 // Implementation of SpeechRecognitionBubble for GTK. This shows a speech |
42 // on screen. | 42 // recognition bubble on screen. |
43 class SpeechInputBubbleGtk : public SpeechInputBubbleBase, | 43 class SpeechRecognitionBubbleGtk : public SpeechRecognitionBubbleBase, |
44 public BubbleDelegateGtk { | 44 public BubbleDelegateGtk { |
45 public: | 45 public: |
46 SpeechInputBubbleGtk(WebContents* web_contents, | 46 SpeechRecognitionBubbleGtk(WebContents* web_contents, |
47 Delegate* delegate, | 47 Delegate* delegate, |
48 const gfx::Rect& element_rect); | 48 const gfx::Rect& element_rect); |
49 ~SpeechInputBubbleGtk(); | 49 ~SpeechRecognitionBubbleGtk(); |
50 | 50 |
51 private: | 51 private: |
52 // SpeechInputBubbleBase: | 52 // SpeechRecognitionBubbleBase: |
53 virtual void Show() OVERRIDE; | 53 virtual void Show() OVERRIDE; |
54 virtual void Hide() OVERRIDE; | 54 virtual void Hide() OVERRIDE; |
55 virtual void UpdateLayout() OVERRIDE; | 55 virtual void UpdateLayout() OVERRIDE; |
56 virtual void UpdateImage() OVERRIDE; | 56 virtual void UpdateImage() OVERRIDE; |
57 | 57 |
58 // BubbleDelegateGtk: | 58 // BubbleDelegateGtk: |
59 virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; | 59 virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; |
60 | 60 |
61 CHROMEGTK_CALLBACK_0(SpeechInputBubbleGtk, void, OnCancelClicked); | 61 CHROMEGTK_CALLBACK_0(SpeechRecognitionBubbleGtk, void, OnCancelClicked); |
62 CHROMEGTK_CALLBACK_0(SpeechInputBubbleGtk, void, OnTryAgainClicked); | 62 CHROMEGTK_CALLBACK_0(SpeechRecognitionBubbleGtk, void, OnTryAgainClicked); |
63 CHROMEGTK_CALLBACK_0(SpeechInputBubbleGtk, void, OnMicSettingsClicked); | 63 CHROMEGTK_CALLBACK_0(SpeechRecognitionBubbleGtk, void, OnMicSettingsClicked); |
64 | 64 |
65 Delegate* delegate_; | 65 Delegate* delegate_; |
66 BubbleGtk* bubble_; | 66 BubbleGtk* bubble_; |
67 gfx::Rect element_rect_; | 67 gfx::Rect element_rect_; |
68 bool did_invoke_close_; | 68 bool did_invoke_close_; |
69 | 69 |
70 GtkWidget* label_; | 70 GtkWidget* label_; |
71 GtkWidget* cancel_button_; | 71 GtkWidget* cancel_button_; |
72 GtkWidget* try_again_button_; | 72 GtkWidget* try_again_button_; |
73 GtkWidget* icon_; | 73 GtkWidget* icon_; |
74 GtkWidget* icon_container_; | 74 GtkWidget* icon_container_; |
75 GtkWidget* mic_settings_; | 75 GtkWidget* mic_settings_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(SpeechInputBubbleGtk); | 77 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleGtk); |
78 }; | 78 }; |
79 | 79 |
80 SpeechInputBubbleGtk::SpeechInputBubbleGtk(WebContents* web_contents, | 80 SpeechRecognitionBubbleGtk::SpeechRecognitionBubbleGtk( |
81 Delegate* delegate, | 81 WebContents* web_contents, Delegate* delegate, |
82 const gfx::Rect& element_rect) | 82 const gfx::Rect& element_rect) |
83 : SpeechInputBubbleBase(web_contents), | 83 : SpeechRecognitionBubbleBase(web_contents), |
84 delegate_(delegate), | 84 delegate_(delegate), |
85 bubble_(NULL), | 85 bubble_(NULL), |
86 element_rect_(element_rect), | 86 element_rect_(element_rect), |
87 did_invoke_close_(false), | 87 did_invoke_close_(false), |
88 label_(NULL), | 88 label_(NULL), |
89 cancel_button_(NULL), | 89 cancel_button_(NULL), |
90 try_again_button_(NULL), | 90 try_again_button_(NULL), |
91 icon_(NULL), | 91 icon_(NULL), |
92 icon_container_(NULL), | 92 icon_container_(NULL), |
93 mic_settings_(NULL) { | 93 mic_settings_(NULL) { |
94 } | 94 } |
95 | 95 |
96 SpeechInputBubbleGtk::~SpeechInputBubbleGtk() { | 96 SpeechRecognitionBubbleGtk::~SpeechRecognitionBubbleGtk() { |
97 // The |Close| call below invokes our |BubbleClosing| method. Since we were | 97 // The |Close| call below invokes our |BubbleClosing| method. Since we were |
98 // destroyed by the caller we don't need to call them back, hence set this | 98 // destroyed by the caller we don't need to call them back, hence set this |
99 // flag here. | 99 // flag here. |
100 did_invoke_close_ = true; | 100 did_invoke_close_ = true; |
101 Hide(); | 101 Hide(); |
102 } | 102 } |
103 | 103 |
104 void SpeechInputBubbleGtk::OnCancelClicked(GtkWidget* widget) { | 104 void SpeechRecognitionBubbleGtk::OnCancelClicked(GtkWidget* widget) { |
105 delegate_->InfoBubbleButtonClicked(BUTTON_CANCEL); | 105 delegate_->InfoBubbleButtonClicked(BUTTON_CANCEL); |
106 } | 106 } |
107 | 107 |
108 void SpeechInputBubbleGtk::OnTryAgainClicked(GtkWidget* widget) { | 108 void SpeechRecognitionBubbleGtk::OnTryAgainClicked(GtkWidget* widget) { |
109 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN); | 109 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN); |
110 } | 110 } |
111 | 111 |
112 void SpeechInputBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) { | 112 void SpeechRecognitionBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) { |
113 content::SpeechInputManager::GetInstance()->ShowAudioInputSettings(); | 113 content::SpeechRecognitionManager::GetInstance()->ShowAudioInputSettings(); |
114 Hide(); | 114 Hide(); |
115 } | 115 } |
116 | 116 |
117 void SpeechInputBubbleGtk::Show() { | 117 void SpeechRecognitionBubbleGtk::Show() { |
118 if (bubble_) | 118 if (bubble_) |
119 return; // Nothing further to do since the bubble is already visible. | 119 return; // Nothing further to do since the bubble is already visible. |
120 | 120 |
121 // We use a vbox to arrange the controls (label, image, button bar) vertically | 121 // We use a vbox to arrange the controls (label, image, button bar) vertically |
122 // and the button bar is a hbox holding the 2 buttons (try again and cancel). | 122 // and the button bar is a hbox holding the 2 buttons (try again and cancel). |
123 // To get horizontal space around them we place this vbox with padding in a | 123 // To get horizontal space around them we place this vbox with padding in a |
124 // GtkAlignment below. | 124 // GtkAlignment below. |
125 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 125 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
126 | 126 |
127 // The icon with a some padding on the left and right. | 127 // The icon with a some padding on the left and right. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 content, | 199 content, |
200 BubbleGtk::ARROW_LOCATION_TOP_LEFT, | 200 BubbleGtk::ARROW_LOCATION_TOP_LEFT, |
201 false, // match_system_theme | 201 false, // match_system_theme |
202 true, // grab_input | 202 true, // grab_input |
203 theme_provider, | 203 theme_provider, |
204 this); | 204 this); |
205 | 205 |
206 UpdateLayout(); | 206 UpdateLayout(); |
207 } | 207 } |
208 | 208 |
209 void SpeechInputBubbleGtk::Hide() { | 209 void SpeechRecognitionBubbleGtk::Hide() { |
210 if (bubble_) | 210 if (bubble_) |
211 bubble_->Close(); | 211 bubble_->Close(); |
212 } | 212 } |
213 | 213 |
214 void SpeechInputBubbleGtk::UpdateLayout() { | 214 void SpeechRecognitionBubbleGtk::UpdateLayout() { |
215 if (!bubble_) | 215 if (!bubble_) |
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 UTF16ToUTF8(message_text()).c_str()); | 222 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_); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 diff_width / 2, diff_width - diff_width / 2); | 266 diff_width / 2, diff_width - diff_width / 2); |
267 } else { | 267 } else { |
268 // Reset the padding done above. | 268 // Reset the padding done above. |
269 gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container_), 0, 0, | 269 gtk_alignment_set_padding(GTK_ALIGNMENT(icon_container_), 0, 0, |
270 kIconHorizontalPadding, kIconHorizontalPadding); | 270 kIconHorizontalPadding, kIconHorizontalPadding); |
271 gtk_widget_show(cancel_button_); | 271 gtk_widget_show(cancel_button_); |
272 } | 272 } |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 void SpeechInputBubbleGtk::UpdateImage() { | 276 void SpeechRecognitionBubbleGtk::UpdateImage() { |
277 SkBitmap image = icon_image(); | 277 SkBitmap image = icon_image(); |
278 if (image.isNull() || !bubble_) | 278 if (image.isNull() || !bubble_) |
279 return; | 279 return; |
280 | 280 |
281 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&image); | 281 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&image); |
282 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); | 282 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); |
283 g_object_unref(pixbuf); | 283 g_object_unref(pixbuf); |
284 } | 284 } |
285 | 285 |
286 void SpeechInputBubbleGtk::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 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( | 295 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( |
296 WebContents* web_contents, | 296 WebContents* web_contents, |
297 Delegate* delegate, | 297 Delegate* delegate, |
298 const gfx::Rect& element_rect) { | 298 const gfx::Rect& element_rect) { |
299 return new SpeechInputBubbleGtk(web_contents, delegate, element_rect); | 299 return new SpeechRecognitionBubbleGtk(web_contents, delegate, element_rect); |
300 } | 300 } |
OLD | NEW |