Chromium Code Reviews| 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 speech_input::SpeechInputManager::ShowAudioInputSettingsFromUI( |
| 112 &tab_contents_->browser_context()->GetResourceContext()); | |
| 111 Hide(); | 113 Hide(); |
| 112 } | 114 } |
| 113 | 115 |
| 114 void SpeechInputBubbleGtk::Show() { | 116 void SpeechInputBubbleGtk::Show() { |
| 115 if (bubble_) | 117 if (bubble_) |
| 116 return; // Nothing further to do since the bubble is already visible. | 118 return; // Nothing further to do since the bubble is already visible. |
| 117 | 119 |
| 118 // We use a vbox to arrange the controls (label, image, button bar) vertically | 120 // 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). | 121 // 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 | 122 // To get horizontal space around them we place this vbox with padding in a |
| 121 // GtkAlignment below. | 123 // GtkAlignment below. |
| 122 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 124 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
| 123 | 125 |
| 124 // The icon with a some padding on the left and right. | 126 // The icon with a some padding on the left and right. |
| 125 icon_container_ = gtk_alignment_new(0, 0, 0, 0); | 127 icon_container_ = gtk_alignment_new(0, 0, 0, 0); |
| 126 icon_ = gtk_image_new(); | 128 icon_ = gtk_image_new(); |
| 127 gtk_container_add(GTK_CONTAINER(icon_container_), icon_); | 129 gtk_container_add(GTK_CONTAINER(icon_container_), icon_); |
| 128 gtk_box_pack_start(GTK_BOX(vbox), icon_container_, FALSE, FALSE, | 130 gtk_box_pack_start(GTK_BOX(vbox), icon_container_, FALSE, FALSE, |
| 129 kBubbleControlVerticalSpacing); | 131 kBubbleControlVerticalSpacing); |
| 130 | 132 |
| 131 label_ = gtk_label_new(NULL); | 133 label_ = gtk_label_new(NULL); |
| 132 gtk_util::SetLabelColor(label_, &kLabelTextColor); | 134 gtk_util::SetLabelColor(label_, &kLabelTextColor); |
| 133 gtk_box_pack_start(GTK_BOX(vbox), label_, FALSE, FALSE, | 135 gtk_box_pack_start(GTK_BOX(vbox), label_, FALSE, FALSE, |
| 134 kBubbleControlVerticalSpacing); | 136 kBubbleControlVerticalSpacing); |
| 135 | 137 |
| 136 if (AudioManager::GetAudioManager()->CanShowAudioInputSettings()) { | 138 Profile* profile = Profile::FromBrowserContext( |
| 139 tab_contents()->browser_context()); | |
| 140 | |
| 141 // TODO(tommi): The audio_manager property can only be accessed from the | |
|
Satish
2011/12/09 11:46:19
We do this check only for linux because the code t
tommi (sloooow) - chröme
2011/12/09 13:24:07
OK, thanks for the background.
I'll take care of i
| |
| 142 // IO thread, so we can't call CanShowAudioInputSettings directly here if | |
| 143 // we can show the input settings. For now, we always show the link (like | |
| 144 // we do on other platforms). | |
| 145 if (true) { | |
| 137 mic_settings_ = gtk_chrome_link_button_new( | 146 mic_settings_ = gtk_chrome_link_button_new( |
| 138 l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_MIC_SETTINGS).c_str()); | 147 l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_MIC_SETTINGS).c_str()); |
| 139 gtk_box_pack_start(GTK_BOX(vbox), mic_settings_, FALSE, FALSE, | 148 gtk_box_pack_start(GTK_BOX(vbox), mic_settings_, FALSE, FALSE, |
| 140 kBubbleControlVerticalSpacing); | 149 kBubbleControlVerticalSpacing); |
| 141 g_signal_connect(mic_settings_, "clicked", | 150 g_signal_connect(mic_settings_, "clicked", |
| 142 G_CALLBACK(&OnMicSettingsClickedThunk), this); | 151 G_CALLBACK(&OnMicSettingsClickedThunk), this); |
| 143 } | 152 } |
| 144 | 153 |
| 145 GtkWidget* button_bar = gtk_hbox_new(FALSE, kButtonBarHorizontalSpacing); | 154 GtkWidget* button_bar = gtk_hbox_new(FALSE, kButtonBarHorizontalSpacing); |
| 146 gtk_box_pack_start(GTK_BOX(vbox), button_bar, FALSE, FALSE, | 155 gtk_box_pack_start(GTK_BOX(vbox), button_bar, FALSE, FALSE, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 157 gtk_box_pack_start(GTK_BOX(button_bar), try_again_button_, TRUE, FALSE, 0); | 166 gtk_box_pack_start(GTK_BOX(button_bar), try_again_button_, TRUE, FALSE, 0); |
| 158 g_signal_connect(try_again_button_, "clicked", | 167 g_signal_connect(try_again_button_, "clicked", |
| 159 G_CALLBACK(&OnTryAgainClickedThunk), this); | 168 G_CALLBACK(&OnTryAgainClickedThunk), this); |
| 160 | 169 |
| 161 GtkWidget* content = gtk_alignment_new(0, 0, 0, 0); | 170 GtkWidget* content = gtk_alignment_new(0, 0, 0, 0); |
| 162 gtk_alignment_set_padding(GTK_ALIGNMENT(content), | 171 gtk_alignment_set_padding(GTK_ALIGNMENT(content), |
| 163 kBubbleControlVerticalSpacing, kBubbleControlVerticalSpacing, | 172 kBubbleControlVerticalSpacing, kBubbleControlVerticalSpacing, |
| 164 kBubbleControlHorizontalSpacing, kBubbleControlHorizontalSpacing); | 173 kBubbleControlHorizontalSpacing, kBubbleControlHorizontalSpacing); |
| 165 gtk_container_add(GTK_CONTAINER(content), vbox); | 174 gtk_container_add(GTK_CONTAINER(content), vbox); |
| 166 | 175 |
| 167 Profile* profile = | |
| 168 Profile::FromBrowserContext(tab_contents()->browser_context()); | |
| 169 GtkThemeService* theme_provider = GtkThemeService::GetFrom(profile); | 176 GtkThemeService* theme_provider = GtkThemeService::GetFrom(profile); |
| 170 GtkWidget* reference_widget = tab_contents()->GetNativeView(); | 177 GtkWidget* reference_widget = tab_contents()->GetNativeView(); |
| 171 gfx::Rect container_rect; | 178 gfx::Rect container_rect; |
| 172 tab_contents()->GetContainerBounds(&container_rect); | 179 tab_contents()->GetContainerBounds(&container_rect); |
| 173 gfx::Rect target_rect(element_rect_.right() - kBubbleTargetOffsetX, | 180 gfx::Rect target_rect(element_rect_.right() - kBubbleTargetOffsetX, |
| 174 element_rect_.bottom(), 1, 1); | 181 element_rect_.bottom(), 1, 1); |
| 175 | 182 |
| 176 if (target_rect.x() < 0 || target_rect.y() < 0 || | 183 if (target_rect.x() < 0 || target_rect.y() < 0 || |
| 177 target_rect.x() > container_rect.width() || | 184 target_rect.x() > container_rect.width() || |
| 178 target_rect.y() > container_rect.height()) { | 185 target_rect.y() > container_rect.height()) { |
| 179 // Target is not in screen view, so point to wrench. | 186 // Target is not in screen view, so point to wrench. |
| 180 Browser* browser = | 187 Browser* browser = |
| 181 Browser::GetOrCreateTabbedBrowser(profile); | 188 Browser::GetOrCreateTabbedBrowser(profile); |
| 182 BrowserWindowGtk* browser_window = | 189 BrowserWindowGtk* browser_window = |
| 183 BrowserWindowGtk::GetBrowserWindowForNativeWindow( | 190 BrowserWindowGtk::GetBrowserWindowForNativeWindow( |
| 184 browser->window()->GetNativeHandle()); | 191 browser->window()->GetNativeHandle()); |
| 185 reference_widget = browser_window->GetToolbar()->GetLocationBarView() | 192 reference_widget = browser_window->GetToolbar()->GetLocationBarView() |
| 186 ->location_icon_widget(); | 193 ->location_icon_widget(); |
| 187 target_rect = gtk_util::WidgetBounds(reference_widget); | 194 target_rect = gtk_util::WidgetBounds(reference_widget); |
| 188 } | 195 } |
| 189 bubble_ = BubbleGtk::Show(reference_widget, | 196 bubble_ = BubbleGtk::Show(reference_widget, |
| 190 &target_rect, | 197 &target_rect, |
| 191 content, | 198 content, |
| 192 BubbleGtk::ARROW_LOCATION_TOP_LEFT, | 199 BubbleGtk::ARROW_LOCATION_TOP_LEFT, |
| 193 false, // match_system_theme | 200 false, // match_system_theme |
| 194 true, // grab_input | 201 true, // grab_input |
| 195 theme_provider, | 202 theme_provider, |
| 196 this); | 203 this); |
| 197 | 204 |
| 198 UpdateLayout(); | 205 UpdateLayout(); |
| 199 } | 206 } |
| 200 | 207 |
| 201 void SpeechInputBubbleGtk::Hide() { | 208 void SpeechInputBubbleGtk::Hide() { |
| 202 if (bubble_) | 209 if (bubble_) |
| 203 bubble_->Close(); | 210 bubble_->Close(); |
| 204 } | 211 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 } | 290 } |
| 284 | 291 |
| 285 } // namespace | 292 } // namespace |
| 286 | 293 |
| 287 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( | 294 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( |
| 288 TabContents* tab_contents, | 295 TabContents* tab_contents, |
| 289 Delegate* delegate, | 296 Delegate* delegate, |
| 290 const gfx::Rect& element_rect) { | 297 const gfx::Rect& element_rect) { |
| 291 return new SpeechInputBubbleGtk(tab_contents, delegate, element_rect); | 298 return new SpeechInputBubbleGtk(tab_contents, delegate, element_rect); |
| 292 } | 299 } |
| OLD | NEW |