OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_input_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_theme_service.h" | 14 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
15 #include "chrome/browser/ui/gtk/gtk_util.h" | 15 #include "chrome/browser/ui/gtk/gtk_util.h" |
16 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 16 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
| 17 #include "content/browser/resource_context.h" |
17 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
20 #include "media/audio/audio_manager.h" | 21 #include "media/audio/audio_manager.h" |
21 #include "ui/base/gtk/gtk_hig_constants.h" | 22 #include "ui/base/gtk/gtk_hig_constants.h" |
22 #include "ui/base/gtk/owned_widget_gtk.h" | 23 #include "ui/base/gtk/owned_widget_gtk.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/gfx/gtk_util.h" | 26 #include "ui/gfx/gtk_util.h" |
26 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 101 |
101 void SpeechInputBubbleGtk::OnCancelClicked(GtkWidget* widget) { | 102 void SpeechInputBubbleGtk::OnCancelClicked(GtkWidget* widget) { |
102 delegate_->InfoBubbleButtonClicked(BUTTON_CANCEL); | 103 delegate_->InfoBubbleButtonClicked(BUTTON_CANCEL); |
103 } | 104 } |
104 | 105 |
105 void SpeechInputBubbleGtk::OnTryAgainClicked(GtkWidget* widget) { | 106 void SpeechInputBubbleGtk::OnTryAgainClicked(GtkWidget* widget) { |
106 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN); | 107 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN); |
107 } | 108 } |
108 | 109 |
109 void SpeechInputBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) { | 110 void SpeechInputBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) { |
110 AudioManager::GetAudioManager()->ShowAudioInputSettings(); | 111 Profile* profile = |
| 112 Profile::FromBrowserContext(tab_contents()->browser_context()); |
| 113 profile->GetResourceContext().audio_manager()->ShowAudioInputSettings(); |
111 Hide(); | 114 Hide(); |
112 } | 115 } |
113 | 116 |
114 void SpeechInputBubbleGtk::Show() { | 117 void SpeechInputBubbleGtk::Show() { |
115 if (bubble_) | 118 if (bubble_) |
116 return; // Nothing further to do since the bubble is already visible. | 119 return; // Nothing further to do since the bubble is already visible. |
117 | 120 |
118 // 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 |
119 // 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). |
120 // 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 |
121 // GtkAlignment below. | 124 // GtkAlignment below. |
122 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 125 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
123 | 126 |
124 // The icon with a some padding on the left and right. | 127 // The icon with a some padding on the left and right. |
125 icon_container_ = gtk_alignment_new(0, 0, 0, 0); | 128 icon_container_ = gtk_alignment_new(0, 0, 0, 0); |
126 icon_ = gtk_image_new(); | 129 icon_ = gtk_image_new(); |
127 gtk_container_add(GTK_CONTAINER(icon_container_), icon_); | 130 gtk_container_add(GTK_CONTAINER(icon_container_), icon_); |
128 gtk_box_pack_start(GTK_BOX(vbox), icon_container_, FALSE, FALSE, | 131 gtk_box_pack_start(GTK_BOX(vbox), icon_container_, FALSE, FALSE, |
129 kBubbleControlVerticalSpacing); | 132 kBubbleControlVerticalSpacing); |
130 | 133 |
131 label_ = gtk_label_new(NULL); | 134 label_ = gtk_label_new(NULL); |
132 gtk_util::SetLabelColor(label_, &kLabelTextColor); | 135 gtk_util::SetLabelColor(label_, &kLabelTextColor); |
133 gtk_box_pack_start(GTK_BOX(vbox), label_, FALSE, FALSE, | 136 gtk_box_pack_start(GTK_BOX(vbox), label_, FALSE, FALSE, |
134 kBubbleControlVerticalSpacing); | 137 kBubbleControlVerticalSpacing); |
135 | 138 |
136 if (AudioManager::GetAudioManager()->CanShowAudioInputSettings()) { | 139 Profile* profile = Profile::FromBrowserContext( |
| 140 tab_contents()->browser_context()); |
| 141 scoped_refptr<AudioManager> audio_manager = |
| 142 profile->GetResourceContext().audio_manager(); |
| 143 if (audio_manager->CanShowAudioInputSettings()) { |
137 mic_settings_ = gtk_chrome_link_button_new( | 144 mic_settings_ = gtk_chrome_link_button_new( |
138 l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_MIC_SETTINGS).c_str()); | 145 l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_MIC_SETTINGS).c_str()); |
139 gtk_box_pack_start(GTK_BOX(vbox), mic_settings_, FALSE, FALSE, | 146 gtk_box_pack_start(GTK_BOX(vbox), mic_settings_, FALSE, FALSE, |
140 kBubbleControlVerticalSpacing); | 147 kBubbleControlVerticalSpacing); |
141 g_signal_connect(mic_settings_, "clicked", | 148 g_signal_connect(mic_settings_, "clicked", |
142 G_CALLBACK(&OnMicSettingsClickedThunk), this); | 149 G_CALLBACK(&OnMicSettingsClickedThunk), this); |
143 } | 150 } |
144 | 151 |
| 152 |
145 GtkWidget* button_bar = gtk_hbox_new(FALSE, kButtonBarHorizontalSpacing); | 153 GtkWidget* button_bar = gtk_hbox_new(FALSE, kButtonBarHorizontalSpacing); |
146 gtk_box_pack_start(GTK_BOX(vbox), button_bar, FALSE, FALSE, | 154 gtk_box_pack_start(GTK_BOX(vbox), button_bar, FALSE, FALSE, |
147 kBubbleControlVerticalSpacing); | 155 kBubbleControlVerticalSpacing); |
148 | 156 |
149 cancel_button_ = gtk_button_new_with_label( | 157 cancel_button_ = gtk_button_new_with_label( |
150 l10n_util::GetStringUTF8(IDS_CANCEL).c_str()); | 158 l10n_util::GetStringUTF8(IDS_CANCEL).c_str()); |
151 gtk_box_pack_start(GTK_BOX(button_bar), cancel_button_, TRUE, FALSE, 0); | 159 gtk_box_pack_start(GTK_BOX(button_bar), cancel_button_, TRUE, FALSE, 0); |
152 g_signal_connect(cancel_button_, "clicked", | 160 g_signal_connect(cancel_button_, "clicked", |
153 G_CALLBACK(&OnCancelClickedThunk), this); | 161 G_CALLBACK(&OnCancelClickedThunk), this); |
154 | 162 |
155 try_again_button_ = gtk_button_new_with_label( | 163 try_again_button_ = gtk_button_new_with_label( |
156 l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_TRY_AGAIN).c_str()); | 164 l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_TRY_AGAIN).c_str()); |
157 gtk_box_pack_start(GTK_BOX(button_bar), try_again_button_, TRUE, FALSE, 0); | 165 gtk_box_pack_start(GTK_BOX(button_bar), try_again_button_, TRUE, FALSE, 0); |
158 g_signal_connect(try_again_button_, "clicked", | 166 g_signal_connect(try_again_button_, "clicked", |
159 G_CALLBACK(&OnTryAgainClickedThunk), this); | 167 G_CALLBACK(&OnTryAgainClickedThunk), this); |
160 | 168 |
161 GtkWidget* content = gtk_alignment_new(0, 0, 0, 0); | 169 GtkWidget* content = gtk_alignment_new(0, 0, 0, 0); |
162 gtk_alignment_set_padding(GTK_ALIGNMENT(content), | 170 gtk_alignment_set_padding(GTK_ALIGNMENT(content), |
163 kBubbleControlVerticalSpacing, kBubbleControlVerticalSpacing, | 171 kBubbleControlVerticalSpacing, kBubbleControlVerticalSpacing, |
164 kBubbleControlHorizontalSpacing, kBubbleControlHorizontalSpacing); | 172 kBubbleControlHorizontalSpacing, kBubbleControlHorizontalSpacing); |
165 gtk_container_add(GTK_CONTAINER(content), vbox); | 173 gtk_container_add(GTK_CONTAINER(content), vbox); |
166 | 174 |
167 Profile* profile = | |
168 Profile::FromBrowserContext(tab_contents()->browser_context()); | |
169 GtkThemeService* theme_provider = GtkThemeService::GetFrom(profile); | 175 GtkThemeService* theme_provider = GtkThemeService::GetFrom(profile); |
170 GtkWidget* reference_widget = tab_contents()->GetNativeView(); | 176 GtkWidget* reference_widget = tab_contents()->GetNativeView(); |
171 gfx::Rect container_rect; | 177 gfx::Rect container_rect; |
172 tab_contents()->GetContainerBounds(&container_rect); | 178 tab_contents()->GetContainerBounds(&container_rect); |
173 gfx::Rect target_rect(element_rect_.right() - kBubbleTargetOffsetX, | 179 gfx::Rect target_rect(element_rect_.right() - kBubbleTargetOffsetX, |
174 element_rect_.bottom(), 1, 1); | 180 element_rect_.bottom(), 1, 1); |
175 | 181 |
176 if (target_rect.x() < 0 || target_rect.y() < 0 || | 182 if (target_rect.x() < 0 || target_rect.y() < 0 || |
177 target_rect.x() > container_rect.width() || | 183 target_rect.x() > container_rect.width() || |
178 target_rect.y() > container_rect.height()) { | 184 target_rect.y() > container_rect.height()) { |
179 // Target is not in screen view, so point to wrench. | 185 // Target is not in screen view, so point to wrench. |
180 Browser* browser = | 186 Browser* browser = |
181 Browser::GetOrCreateTabbedBrowser(profile); | 187 Browser::GetOrCreateTabbedBrowser(profile); |
182 BrowserWindowGtk* browser_window = | 188 BrowserWindowGtk* browser_window = |
183 BrowserWindowGtk::GetBrowserWindowForNativeWindow( | 189 BrowserWindowGtk::GetBrowserWindowForNativeWindow( |
184 browser->window()->GetNativeHandle()); | 190 browser->window()->GetNativeHandle()); |
185 reference_widget = browser_window->GetToolbar()->GetLocationBarView() | 191 reference_widget = browser_window->GetToolbar()->GetLocationBarView() |
186 ->location_icon_widget(); | 192 ->location_icon_widget(); |
187 target_rect = gtk_util::WidgetBounds(reference_widget); | 193 target_rect = gtk_util::WidgetBounds(reference_widget); |
188 } | 194 } |
189 bubble_ = BubbleGtk::Show(reference_widget, | 195 bubble_ = BubbleGtk::Show(reference_widget, |
190 &target_rect, | 196 &target_rect, |
191 content, | 197 content, |
192 BubbleGtk::ARROW_LOCATION_TOP_LEFT, | 198 BubbleGtk::ARROW_LOCATION_TOP_LEFT, |
193 false, // match_system_theme | 199 false, // match_system_theme |
194 true, // grab_input | 200 true, // grab_input |
195 theme_provider, | 201 theme_provider, |
196 this); | 202 this); |
197 | 203 |
198 UpdateLayout(); | 204 UpdateLayout(); |
199 } | 205 } |
200 | 206 |
201 void SpeechInputBubbleGtk::Hide() { | 207 void SpeechInputBubbleGtk::Hide() { |
202 if (bubble_) | 208 if (bubble_) |
203 bubble_->Close(); | 209 bubble_->Close(); |
204 } | 210 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 289 } |
284 | 290 |
285 } // namespace | 291 } // namespace |
286 | 292 |
287 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( | 293 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( |
288 TabContents* tab_contents, | 294 TabContents* tab_contents, |
289 Delegate* delegate, | 295 Delegate* delegate, |
290 const gfx::Rect& element_rect) { | 296 const gfx::Rect& element_rect) { |
291 return new SpeechInputBubbleGtk(tab_contents, delegate, element_rect); | 297 return new SpeechInputBubbleGtk(tab_contents, delegate, element_rect); |
292 } | 298 } |
OLD | NEW |