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

Side by Side Diff: chrome/browser/speech/speech_input_bubble_gtk.cc

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 years 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 | Annotate | Revision Log
OLDNEW
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"
18 #include "content/browser/speech/speech_input_manager.h"
17 #include "content/browser/tab_contents/tab_contents.h" 19 #include "content/browser/tab_contents/tab_contents.h"
18 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
20 #include "media/audio/audio_manager.h" 22 #include "media/audio/audio_manager.h"
21 #include "ui/base/gtk/gtk_hig_constants.h" 23 #include "ui/base/gtk/gtk_hig_constants.h"
22 #include "ui/base/gtk/owned_widget_gtk.h" 24 #include "ui/base/gtk/owned_widget_gtk.h"
23 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/gtk_util.h" 27 #include "ui/gfx/gtk_util.h"
26 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 102
101 void SpeechInputBubbleGtk::OnCancelClicked(GtkWidget* widget) { 103 void SpeechInputBubbleGtk::OnCancelClicked(GtkWidget* widget) {
102 delegate_->InfoBubbleButtonClicked(BUTTON_CANCEL); 104 delegate_->InfoBubbleButtonClicked(BUTTON_CANCEL);
103 } 105 }
104 106
105 void SpeechInputBubbleGtk::OnTryAgainClicked(GtkWidget* widget) { 107 void SpeechInputBubbleGtk::OnTryAgainClicked(GtkWidget* widget) {
106 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN); 108 delegate_->InfoBubbleButtonClicked(BUTTON_TRY_AGAIN);
107 } 109 }
108 110
109 void SpeechInputBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) { 111 void SpeechInputBubbleGtk::OnMicSettingsClicked(GtkWidget* widget) {
110 AudioManager::GetAudioManager()->ShowAudioInputSettings(); 112 speech_input::SpeechInputManager::ShowAudioInputSettingsFromUI(
113 &tab_contents()->browser_context()->GetResourceContext());
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
142 // TODO(tommi): The audio_manager property can only be accessed from the
143 // IO thread, so we can't call CanShowAudioInputSettings directly here if
144 // we can show the input settings. For now, we always show the link (like
145 // we do on other platforms).
146 if (true) {
137 mic_settings_ = gtk_chrome_link_button_new( 147 mic_settings_ = gtk_chrome_link_button_new(
138 l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_MIC_SETTINGS).c_str()); 148 l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_MIC_SETTINGS).c_str());
139 gtk_box_pack_start(GTK_BOX(vbox), mic_settings_, FALSE, FALSE, 149 gtk_box_pack_start(GTK_BOX(vbox), mic_settings_, FALSE, FALSE,
140 kBubbleControlVerticalSpacing); 150 kBubbleControlVerticalSpacing);
141 g_signal_connect(mic_settings_, "clicked", 151 g_signal_connect(mic_settings_, "clicked",
142 G_CALLBACK(&OnMicSettingsClickedThunk), this); 152 G_CALLBACK(&OnMicSettingsClickedThunk), this);
143 } 153 }
144 154
145 GtkWidget* button_bar = gtk_hbox_new(FALSE, kButtonBarHorizontalSpacing); 155 GtkWidget* button_bar = gtk_hbox_new(FALSE, kButtonBarHorizontalSpacing);
146 gtk_box_pack_start(GTK_BOX(vbox), button_bar, FALSE, FALSE, 156 gtk_box_pack_start(GTK_BOX(vbox), button_bar, FALSE, FALSE,
(...skipping 10 matching lines...) Expand all
157 gtk_box_pack_start(GTK_BOX(button_bar), try_again_button_, TRUE, FALSE, 0); 167 gtk_box_pack_start(GTK_BOX(button_bar), try_again_button_, TRUE, FALSE, 0);
158 g_signal_connect(try_again_button_, "clicked", 168 g_signal_connect(try_again_button_, "clicked",
159 G_CALLBACK(&OnTryAgainClickedThunk), this); 169 G_CALLBACK(&OnTryAgainClickedThunk), this);
160 170
161 GtkWidget* content = gtk_alignment_new(0, 0, 0, 0); 171 GtkWidget* content = gtk_alignment_new(0, 0, 0, 0);
162 gtk_alignment_set_padding(GTK_ALIGNMENT(content), 172 gtk_alignment_set_padding(GTK_ALIGNMENT(content),
163 kBubbleControlVerticalSpacing, kBubbleControlVerticalSpacing, 173 kBubbleControlVerticalSpacing, kBubbleControlVerticalSpacing,
164 kBubbleControlHorizontalSpacing, kBubbleControlHorizontalSpacing); 174 kBubbleControlHorizontalSpacing, kBubbleControlHorizontalSpacing);
165 gtk_container_add(GTK_CONTAINER(content), vbox); 175 gtk_container_add(GTK_CONTAINER(content), vbox);
166 176
167 Profile* profile =
168 Profile::FromBrowserContext(tab_contents()->browser_context());
169 GtkThemeService* theme_provider = GtkThemeService::GetFrom(profile); 177 GtkThemeService* theme_provider = GtkThemeService::GetFrom(profile);
170 GtkWidget* reference_widget = tab_contents()->GetNativeView(); 178 GtkWidget* reference_widget = tab_contents()->GetNativeView();
171 gfx::Rect container_rect; 179 gfx::Rect container_rect;
172 tab_contents()->GetContainerBounds(&container_rect); 180 tab_contents()->GetContainerBounds(&container_rect);
173 gfx::Rect target_rect(element_rect_.right() - kBubbleTargetOffsetX, 181 gfx::Rect target_rect(element_rect_.right() - kBubbleTargetOffsetX,
174 element_rect_.bottom(), 1, 1); 182 element_rect_.bottom(), 1, 1);
175 183
176 if (target_rect.x() < 0 || target_rect.y() < 0 || 184 if (target_rect.x() < 0 || target_rect.y() < 0 ||
177 target_rect.x() > container_rect.width() || 185 target_rect.x() > container_rect.width() ||
178 target_rect.y() > container_rect.height()) { 186 target_rect.y() > container_rect.height()) {
179 // Target is not in screen view, so point to wrench. 187 // Target is not in screen view, so point to wrench.
180 Browser* browser = 188 Browser* browser =
181 Browser::GetOrCreateTabbedBrowser(profile); 189 Browser::GetOrCreateTabbedBrowser(profile);
182 BrowserWindowGtk* browser_window = 190 BrowserWindowGtk* browser_window =
183 BrowserWindowGtk::GetBrowserWindowForNativeWindow( 191 BrowserWindowGtk::GetBrowserWindowForNativeWindow(
184 browser->window()->GetNativeHandle()); 192 browser->window()->GetNativeHandle());
185 reference_widget = browser_window->GetToolbar()->GetLocationBarView() 193 reference_widget = browser_window->GetToolbar()->GetLocationBarView()
186 ->location_icon_widget(); 194 ->location_icon_widget();
187 target_rect = gtk_util::WidgetBounds(reference_widget); 195 target_rect = gtk_util::WidgetBounds(reference_widget);
188 } 196 }
189 bubble_ = BubbleGtk::Show(reference_widget, 197 bubble_ = BubbleGtk::Show(reference_widget,
190 &target_rect, 198 &target_rect,
191 content, 199 content,
192 BubbleGtk::ARROW_LOCATION_TOP_LEFT, 200 BubbleGtk::ARROW_LOCATION_TOP_LEFT,
193 false, // match_system_theme 201 false, // match_system_theme
194 true, // grab_input 202 true, // grab_input
195 theme_provider, 203 theme_provider,
196 this); 204 this);
197 205
198 UpdateLayout(); 206 UpdateLayout();
199 } 207 }
200 208
201 void SpeechInputBubbleGtk::Hide() { 209 void SpeechInputBubbleGtk::Hide() {
202 if (bubble_) 210 if (bubble_)
203 bubble_->Close(); 211 bubble_->Close();
204 } 212 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 291 }
284 292
285 } // namespace 293 } // namespace
286 294
287 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( 295 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble(
288 TabContents* tab_contents, 296 TabContents* tab_contents,
289 Delegate* delegate, 297 Delegate* delegate,
290 const gfx::Rect& element_rect) { 298 const gfx::Rect& element_rect) {
291 return new SpeechInputBubbleGtk(tab_contents, delegate, element_rect); 299 return new SpeechInputBubbleGtk(tab_contents, delegate, element_rect);
292 } 300 }
OLDNEW
« no previous file with comments | « chrome/browser/speech/chrome_speech_input_manager.cc ('k') | chrome/browser/speech/speech_input_bubble_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698