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/ui/gtk/web_intent_picker_gtk.h" | 5 #include "chrome/browser/ui/gtk/web_intent_picker_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/favicon/favicon_service.h" | 11 #include "chrome/browser/favicon/favicon_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/tab_contents/tab_util.h" | 13 #include "chrome/browser/tab_contents/tab_util.h" |
14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" | 16 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
17 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 17 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
18 #include "chrome/browser/ui/gtk/custom_button.h" | 18 #include "chrome/browser/ui/gtk/custom_button.h" |
19 #include "chrome/browser/ui/gtk/event_utils.h" | 19 #include "chrome/browser/ui/gtk/event_utils.h" |
20 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 20 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
21 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 21 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
22 #include "chrome/browser/ui/gtk/gtk_util.h" | 22 #include "chrome/browser/ui/gtk/gtk_util.h" |
23 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 23 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
24 #include "chrome/browser/ui/gtk/throbber_gtk.h" | 24 #include "chrome/browser/ui/gtk/throbber_gtk.h" |
25 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 25 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
26 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" | 26 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" |
27 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | 27 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
29 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
30 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
31 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
32 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
33 #include "content/public/browser/render_widget_host_view.h" | 32 #include "content/public/browser/render_widget_host_view.h" |
34 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
35 #include "content/public/browser/web_contents_view.h" | 34 #include "content/public/browser/web_contents_view.h" |
36 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
37 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
38 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
(...skipping 18 matching lines...) Expand all Loading... |
57 const int kMainContentPixelSize = 13; | 56 const int kMainContentPixelSize = 13; |
58 | 57 |
59 // Indices of the extension row widgets. | 58 // Indices of the extension row widgets. |
60 enum { | 59 enum { |
61 kIconIndex, | 60 kIconIndex, |
62 kTitleLinkIndex, | 61 kTitleLinkIndex, |
63 kStarsIndex, | 62 kStarsIndex, |
64 kInstallButtonIndex, | 63 kInstallButtonIndex, |
65 }; | 64 }; |
66 | 65 |
67 GtkThemeService *GetThemeService(TabContents* tab_contents) { | 66 GtkThemeService *GetThemeService(WebContents* web_contents) { |
68 return GtkThemeService::GetFrom(tab_contents->profile()); | 67 Profile* profile = |
| 68 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 69 return GtkThemeService::GetFrom(profile); |
69 } | 70 } |
70 | 71 |
71 // Set the image of |button| to |pixbuf|. | 72 // Set the image of |button| to |pixbuf|. |
72 void SetServiceButtonImage(GtkWidget* button, GdkPixbuf* pixbuf) { | 73 void SetServiceButtonImage(GtkWidget* button, GdkPixbuf* pixbuf) { |
73 gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(pixbuf)); | 74 gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(pixbuf)); |
74 gtk_button_set_image_position(GTK_BUTTON(button), GTK_POS_LEFT); | 75 gtk_button_set_image_position(GTK_BUTTON(button), GTK_POS_LEFT); |
75 } | 76 } |
76 | 77 |
77 void SetWidgetFontSizeCallback(GtkWidget* widget, gpointer data) { | 78 void SetWidgetFontSizeCallback(GtkWidget* widget, gpointer data) { |
78 if (GTK_IS_LABEL(widget)) { | 79 if (GTK_IS_LABEL(widget)) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 kMainContentPixelSize, kDialogSpacing, 0, 0); | 189 kMainContentPixelSize, kDialogSpacing, 0, 0); |
189 gtk_container_add(GTK_CONTAINER(label_alignment), message_label); | 190 gtk_container_add(GTK_CONTAINER(label_alignment), message_label); |
190 gtk_box_pack_start(GTK_BOX(vbox), label_alignment, TRUE, TRUE, 0); | 191 gtk_box_pack_start(GTK_BOX(vbox), label_alignment, TRUE, TRUE, 0); |
191 | 192 |
192 // TODO(groby): use IDR_SPEECH_INPUT_SPINNER. Pending fix for ThrobberGtk. | 193 // TODO(groby): use IDR_SPEECH_INPUT_SPINNER. Pending fix for ThrobberGtk. |
193 // Animate throbber | 194 // Animate throbber |
194 throbber->Start(); | 195 throbber->Start(); |
195 } | 196 } |
196 | 197 |
197 // static | 198 // static |
198 WebIntentPicker* WebIntentPicker::Create(content::WebContents* web_contents, | 199 WebIntentPicker* WebIntentPicker::Create(WebContents* web_contents, |
199 WebIntentPickerDelegate* delegate, | 200 WebIntentPickerDelegate* delegate, |
200 WebIntentPickerModel* model) { | 201 WebIntentPickerModel* model) { |
201 TabContents* tab_contents = TabContents::FromWebContents(web_contents); | 202 return new WebIntentPickerGtk(web_contents, delegate, model); |
202 return new WebIntentPickerGtk(tab_contents, delegate, model); | |
203 } | 203 } |
204 | 204 |
205 WebIntentPickerGtk::WebIntentPickerGtk(TabContents* tab_contents, | 205 WebIntentPickerGtk::WebIntentPickerGtk(WebContents* web_contents, |
206 WebIntentPickerDelegate* delegate, | 206 WebIntentPickerDelegate* delegate, |
207 WebIntentPickerModel* model) | 207 WebIntentPickerModel* model) |
208 : tab_contents_(tab_contents), | 208 : web_contents_(web_contents), |
209 delegate_(delegate), | 209 delegate_(delegate), |
210 model_(model), | 210 model_(model), |
211 contents_(NULL), | 211 contents_(NULL), |
212 header_label_(NULL), | 212 header_label_(NULL), |
213 button_vbox_(NULL), | 213 button_vbox_(NULL), |
214 cws_label_(NULL), | 214 cws_label_(NULL), |
215 extensions_vbox_(NULL), | 215 extensions_vbox_(NULL), |
216 service_hbox_(NULL), | 216 service_hbox_(NULL), |
217 window_(NULL) { | 217 window_(NULL) { |
218 DCHECK(delegate_ != NULL); | 218 DCHECK(delegate_ != NULL); |
219 | 219 |
220 model_->set_observer(this); | 220 model_->set_observer(this); |
221 InitContents(); | 221 InitContents(); |
222 UpdateInstalledServices(); | 222 UpdateInstalledServices(); |
223 UpdateCWSLabel(); | 223 UpdateCWSLabel(); |
224 UpdateSuggestedExtensions(); | 224 UpdateSuggestedExtensions(); |
225 | 225 |
226 GtkThemeService* theme_service = GetThemeService(tab_contents); | 226 GtkThemeService* theme_service = GetThemeService(web_contents); |
227 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 227 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
228 content::Source<ThemeService>(theme_service)); | 228 content::Source<ThemeService>(theme_service)); |
229 theme_service->InitThemesFor(this); | 229 theme_service->InitThemesFor(this); |
230 | 230 |
231 window_ = new ConstrainedWindowGtk(tab_contents->web_contents(), this); | 231 window_ = new ConstrainedWindowGtk(web_contents, this); |
232 | 232 |
233 if (model_->IsInlineDisposition()) | 233 if (model_->IsInlineDisposition()) |
234 OnInlineDisposition(string16(), model_->inline_disposition_url()); | 234 OnInlineDisposition(string16(), model_->inline_disposition_url()); |
235 } | 235 } |
236 | 236 |
237 WebIntentPickerGtk::~WebIntentPickerGtk() { | 237 WebIntentPickerGtk::~WebIntentPickerGtk() { |
238 } | 238 } |
239 | 239 |
240 void WebIntentPickerGtk::Close() { | 240 void WebIntentPickerGtk::Close() { |
241 window_->CloseConstrainedWindow(); | 241 window_->CloseConstrainedWindow(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 286 |
287 void WebIntentPickerGtk::OnExtensionIconChanged( | 287 void WebIntentPickerGtk::OnExtensionIconChanged( |
288 WebIntentPickerModel* model, | 288 WebIntentPickerModel* model, |
289 const std::string& extension_id) { | 289 const std::string& extension_id) { |
290 UpdateSuggestedExtensions(); | 290 UpdateSuggestedExtensions(); |
291 } | 291 } |
292 | 292 |
293 void WebIntentPickerGtk::OnInlineDisposition(const string16&, | 293 void WebIntentPickerGtk::OnInlineDisposition(const string16&, |
294 const GURL& url) { | 294 const GURL& url) { |
295 DCHECK(delegate_); | 295 DCHECK(delegate_); |
| 296 Profile* profile = |
| 297 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
296 inline_disposition_web_contents_.reset( | 298 inline_disposition_web_contents_.reset( |
297 delegate_->CreateWebContentsForInlineDisposition( | 299 delegate_->CreateWebContentsForInlineDisposition(profile, url)); |
298 tab_contents_->profile(), url)); | 300 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
299 Browser* browser = chrome::FindBrowserWithWebContents( | |
300 tab_contents_->web_contents()); | |
301 inline_disposition_delegate_.reset( | 301 inline_disposition_delegate_.reset( |
302 new WebIntentInlineDispositionDelegate( | 302 new WebIntentInlineDispositionDelegate( |
303 this, inline_disposition_web_contents_.get(), browser)); | 303 this, inline_disposition_web_contents_.get(), browser)); |
304 | 304 |
305 inline_disposition_web_contents_->GetController().LoadURL( | 305 inline_disposition_web_contents_->GetController().LoadURL( |
306 url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 306 url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
307 std::string()); | 307 std::string()); |
308 | 308 |
309 // Replace the picker contents with the inline disposition. | 309 // Replace the picker contents with the inline disposition. |
310 ClearContents(); | 310 ClearContents(); |
311 gtk_widget_set_size_request(contents_, -1, -1); | 311 gtk_widget_set_size_request(contents_, -1, -1); |
312 window_->BackgroundColorChanged(); | 312 window_->BackgroundColorChanged(); |
313 | 313 |
314 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 314 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
315 GtkThemeService* theme_service = GetThemeService(tab_contents_); | 315 GtkThemeService* theme_service = GetThemeService(web_contents_); |
316 | 316 |
317 service_hbox_ = gtk_hbox_new(FALSE, ui::kControlSpacing); | 317 service_hbox_ = gtk_hbox_new(FALSE, ui::kControlSpacing); |
318 // TODO(gbillock): Eventually get the service icon button here. | 318 // TODO(gbillock): Eventually get the service icon button here. |
319 | 319 |
320 // Intent action label. | 320 // Intent action label. |
321 const WebIntentPickerModel::InstalledService* service = | 321 const WebIntentPickerModel::InstalledService* service = |
322 model_->GetInstalledServiceWithURL(url); | 322 model_->GetInstalledServiceWithURL(url); |
323 GtkWidget* action_label = gtk_label_new(UTF16ToUTF8(service->title).c_str()); | 323 GtkWidget* action_label = gtk_label_new(UTF16ToUTF8(service->title).c_str()); |
324 gtk_util::ForceFontSizePixels(action_label, kMainContentPixelSize); | 324 gtk_util::ForceFontSizePixels(action_label, kMainContentPixelSize); |
325 // Hardcode color; don't allow theming. | 325 // Hardcode color; don't allow theming. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 371 |
372 gfx::Size size = GetMinInlineDispositionSize(); | 372 gfx::Size size = GetMinInlineDispositionSize(); |
373 gtk_widget_set_size_request(web_contents_widget, | 373 gtk_widget_set_size_request(web_contents_widget, |
374 size.width(), size.height()); | 374 size.width(), size.height()); |
375 gtk_widget_show_all(contents_); | 375 gtk_widget_show_all(contents_); |
376 | 376 |
377 inline_disposition_delegate_->SetRenderViewSizeLimits(); | 377 inline_disposition_delegate_->SetRenderViewSizeLimits(); |
378 inline_disposition_web_contents_->GetView()->SetInitialFocus(); | 378 inline_disposition_web_contents_->GetView()->SetInitialFocus(); |
379 host_signals_.reset(new ui::GtkSignalRegistrar()); | 379 host_signals_.reset(new ui::GtkSignalRegistrar()); |
380 host_signals_->Connect( | 380 host_signals_->Connect( |
381 tab_contents_->web_contents()->GetRenderViewHost()->GetView()-> | 381 web_contents_->GetRenderViewHost()->GetView()->GetNativeView(), |
382 GetNativeView(), | |
383 "size-allocate", | 382 "size-allocate", |
384 G_CALLBACK(OnHostContentsSizeAllocateThunk), this); | 383 G_CALLBACK(OnHostContentsSizeAllocateThunk), this); |
385 } | 384 } |
386 | 385 |
387 void WebIntentPickerGtk::OnInlineDispositionAutoResize(const gfx::Size& size) { | 386 void WebIntentPickerGtk::OnInlineDispositionAutoResize(const gfx::Size& size) { |
388 gfx::NativeView web_contents_widget = | 387 gfx::NativeView web_contents_widget = |
389 inline_disposition_web_contents_->GetView()->GetNativeView(); | 388 inline_disposition_web_contents_->GetView()->GetNativeView(); |
390 gtk_widget_set_size_request(web_contents_widget, size.width(), size.height()); | 389 gtk_widget_set_size_request(web_contents_widget, size.width(), size.height()); |
391 } | 390 } |
392 | 391 |
393 gfx::Size WebIntentPickerGtk::GetMaxInlineDispositionSize() { | 392 gfx::Size WebIntentPickerGtk::GetMaxInlineDispositionSize() { |
394 gfx::Rect tab_bounds(tab_contents_->web_contents()->GetRenderViewHost()-> | 393 gfx::Rect tab_bounds(web_contents_->GetRenderViewHost()-> |
395 GetView()->GetNativeView()->allocation); | 394 GetView()->GetNativeView()->allocation); |
396 GtkRequisition req = {}; | 395 GtkRequisition req = {}; |
397 if (service_hbox_) | 396 if (service_hbox_) |
398 gtk_widget_size_request(service_hbox_, &req); | 397 gtk_widget_size_request(service_hbox_, &req); |
399 | 398 |
400 tab_bounds.Inset(2 * ui::kContentAreaBorder, | 399 tab_bounds.Inset(2 * ui::kContentAreaBorder, |
401 2 * ui::kContentAreaBorder + req.height); | 400 2 * ui::kContentAreaBorder + req.height); |
402 return tab_bounds.size(); | 401 return tab_bounds.size(); |
403 } | 402 } |
404 | 403 |
(...skipping 17 matching lines...) Expand all Loading... |
422 | 421 |
423 // Replace the dialog header. | 422 // Replace the dialog header. |
424 DCHECK(header_label_); | 423 DCHECK(header_label_); |
425 gtk_label_set_text( | 424 gtk_label_set_text( |
426 GTK_LABEL(header_label_), | 425 GTK_LABEL(header_label_), |
427 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_NO_SERVICES_TITLE).c_str()); | 426 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_NO_SERVICES_TITLE).c_str()); |
428 | 427 |
429 // Add the message text. | 428 // Add the message text. |
430 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); | 429 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
431 gtk_box_pack_start(GTK_BOX(sub_contents), hbox, TRUE, TRUE, 0); | 430 gtk_box_pack_start(GTK_BOX(sub_contents), hbox, TRUE, TRUE, 0); |
432 GtkThemeService* theme_service = GetThemeService(tab_contents_); | 431 GtkThemeService* theme_service = GetThemeService(web_contents_); |
433 GtkWidget* no_service_label = theme_service->BuildLabel( | 432 GtkWidget* no_service_label = theme_service->BuildLabel( |
434 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_NO_SERVICES).c_str(), | 433 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_NO_SERVICES).c_str(), |
435 ui::kGdkBlack); | 434 ui::kGdkBlack); |
436 gtk_label_set_line_wrap(GTK_LABEL(no_service_label), TRUE); | 435 gtk_label_set_line_wrap(GTK_LABEL(no_service_label), TRUE); |
437 gtk_misc_set_alignment(GTK_MISC(no_service_label), 0, 0); | 436 gtk_misc_set_alignment(GTK_MISC(no_service_label), 0, 0); |
438 // Set the label width to the size of |sub_contents|, which we don't have | 437 // Set the label width to the size of |sub_contents|, which we don't have |
439 // access to yet, by calculating the main content width minus borders. | 438 // access to yet, by calculating the main content width minus borders. |
440 gtk_util::SetLabelWidth(no_service_label, | 439 gtk_util::SetLabelWidth(no_service_label, |
441 kWindowMinWidth - 2 * ui::kContentAreaBorder); | 440 kWindowMinWidth - 2 * ui::kContentAreaBorder); |
442 gtk_box_pack_start(GTK_BOX(hbox), no_service_label, TRUE, TRUE, 0); | 441 gtk_box_pack_start(GTK_BOX(hbox), no_service_label, TRUE, TRUE, 0); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 | 473 |
475 bool WebIntentPickerGtk::ShouldHaveBorderPadding() const { | 474 bool WebIntentPickerGtk::ShouldHaveBorderPadding() const { |
476 return false; | 475 return false; |
477 } | 476 } |
478 | 477 |
479 void WebIntentPickerGtk::Observe(int type, | 478 void WebIntentPickerGtk::Observe(int type, |
480 const content::NotificationSource& source, | 479 const content::NotificationSource& source, |
481 const content::NotificationDetails& details) { | 480 const content::NotificationDetails& details) { |
482 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); | 481 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
483 if (header_label_) { | 482 if (header_label_) { |
484 GtkThemeService* theme_service = GetThemeService(tab_contents_); | 483 GtkThemeService* theme_service = GetThemeService(web_contents_); |
485 if (theme_service->UsingNativeTheme()) | 484 if (theme_service->UsingNativeTheme()) |
486 gtk_util::UndoForceFontSize(header_label_); | 485 gtk_util::UndoForceFontSize(header_label_); |
487 else | 486 else |
488 gtk_util::ForceFontSizePixels(header_label_, kHeaderLabelPixelSize); | 487 gtk_util::ForceFontSizePixels(header_label_, kHeaderLabelPixelSize); |
489 } | 488 } |
490 UpdateInstalledServices(); | 489 UpdateInstalledServices(); |
491 UpdateSuggestedExtensions(); | 490 UpdateSuggestedExtensions(); |
492 } | 491 } |
493 | 492 |
494 void WebIntentPickerGtk::OnDestroy(GtkWidget* button) { | 493 void WebIntentPickerGtk::OnDestroy(GtkWidget* button) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 | 571 |
573 const WebIntentPickerModel::InstalledService& installed_service = | 572 const WebIntentPickerModel::InstalledService& installed_service = |
574 model_->GetInstalledServiceAt(index); | 573 model_->GetInstalledServiceAt(index); |
575 | 574 |
576 delegate_->OnServiceChosen(installed_service.url, | 575 delegate_->OnServiceChosen(installed_service.url, |
577 installed_service.disposition, | 576 installed_service.disposition, |
578 WebIntentPickerDelegate::kEnableDefaults); | 577 WebIntentPickerDelegate::kEnableDefaults); |
579 } | 578 } |
580 | 579 |
581 void WebIntentPickerGtk::InitContents() { | 580 void WebIntentPickerGtk::InitContents() { |
582 GtkThemeService* theme_service = GetThemeService(tab_contents_); | 581 GtkThemeService* theme_service = GetThemeService(web_contents_); |
583 | 582 |
584 // Main contents vbox. | 583 // Main contents vbox. |
585 if (!contents_) { | 584 if (!contents_) { |
586 contents_ = gtk_vbox_new(FALSE, 0); | 585 contents_ = gtk_vbox_new(FALSE, 0); |
587 g_signal_connect(contents_, "destroy", G_CALLBACK(&OnDestroyThunk), this); | 586 g_signal_connect(contents_, "destroy", G_CALLBACK(&OnDestroyThunk), this); |
588 } | 587 } |
589 | 588 |
590 gtk_widget_set_size_request(contents_, kWindowMinWidth, -1); | 589 gtk_widget_set_size_request(contents_, kWindowMinWidth, -1); |
591 | 590 |
592 if (model_ && model_->IsWaitingForSuggestions()) { | 591 if (model_ && model_->IsWaitingForSuggestions()) { |
593 ClearContents(); | 592 ClearContents(); |
594 AddCloseButton(contents_); | 593 AddCloseButton(contents_); |
595 waiting_dialog_.reset(new WaitingDialog(theme_service)); | 594 waiting_dialog_.reset(new WaitingDialog(theme_service)); |
596 gtk_box_pack_start(GTK_BOX(contents_), waiting_dialog_->widget(), | 595 gtk_box_pack_start(GTK_BOX(contents_), waiting_dialog_->widget(), |
597 TRUE, TRUE, 0); | 596 TRUE, TRUE, 0); |
598 } else { | 597 } else { |
599 InitMainContents(); | 598 InitMainContents(); |
600 } | 599 } |
601 } | 600 } |
602 | 601 |
603 void WebIntentPickerGtk::InitMainContents() { | 602 void WebIntentPickerGtk::InitMainContents() { |
604 GtkThemeService* theme_service = GetThemeService(tab_contents_); | 603 GtkThemeService* theme_service = GetThemeService(web_contents_); |
605 | 604 |
606 ClearContents(); | 605 ClearContents(); |
607 | 606 |
608 AddCloseButton(contents_); | 607 AddCloseButton(contents_); |
609 GtkWidget* sub_contents = CreateSubContents(contents_); | 608 GtkWidget* sub_contents = CreateSubContents(contents_); |
610 | 609 |
611 AddTitle(sub_contents); | 610 AddTitle(sub_contents); |
612 | 611 |
613 // Add separation between the installed services list and the app suggestions. | 612 // Add separation between the installed services list and the app suggestions. |
614 GtkWidget* button_alignment = gtk_alignment_new(0.5, 0, 0, 0); | 613 GtkWidget* button_alignment = gtk_alignment_new(0.5, 0, 0, 0); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 return sub_contents; | 712 return sub_contents; |
714 } | 713 } |
715 | 714 |
716 void WebIntentPickerGtk::AddCloseButton(GtkWidget* containingBox) { | 715 void WebIntentPickerGtk::AddCloseButton(GtkWidget* containingBox) { |
717 | 716 |
718 // Hbox containing the close button. | 717 // Hbox containing the close button. |
719 GtkWidget* close_hbox = gtk_hbox_new(FALSE, 0); | 718 GtkWidget* close_hbox = gtk_hbox_new(FALSE, 0); |
720 gtk_box_pack_start(GTK_BOX(containingBox), close_hbox, TRUE, TRUE, 0); | 719 gtk_box_pack_start(GTK_BOX(containingBox), close_hbox, TRUE, TRUE, 0); |
721 | 720 |
722 close_button_.reset( | 721 close_button_.reset( |
723 CustomDrawButton::CloseButton(GetThemeService(tab_contents_))); | 722 CustomDrawButton::CloseButton(GetThemeService(web_contents_))); |
724 g_signal_connect(close_button_->widget(), "clicked", | 723 g_signal_connect(close_button_->widget(), "clicked", |
725 G_CALLBACK(OnCloseButtonClickThunk), this); | 724 G_CALLBACK(OnCloseButtonClickThunk), this); |
726 gtk_widget_set_can_focus(close_button_->widget(), FALSE); | 725 gtk_widget_set_can_focus(close_button_->widget(), FALSE); |
727 gtk_box_pack_end(GTK_BOX(close_hbox), close_button_->widget(), | 726 gtk_box_pack_end(GTK_BOX(close_hbox), close_button_->widget(), |
728 FALSE, FALSE, 0); | 727 FALSE, FALSE, 0); |
729 } | 728 } |
730 | 729 |
731 void WebIntentPickerGtk::AddTitle(GtkWidget* containingBox) { | 730 void WebIntentPickerGtk::AddTitle(GtkWidget* containingBox) { |
732 // Hbox containing the header label. | 731 // Hbox containing the header label. |
733 GtkWidget* header_hbox = gtk_hbox_new(FALSE, 0); | 732 GtkWidget* header_hbox = gtk_hbox_new(FALSE, 0); |
734 gtk_box_pack_start(GTK_BOX(containingBox), header_hbox, TRUE, TRUE, 0); | 733 gtk_box_pack_start(GTK_BOX(containingBox), header_hbox, TRUE, TRUE, 0); |
735 | 734 |
736 // Label text will be set in the call to SetActionString(). | 735 // Label text will be set in the call to SetActionString(). |
737 header_label_ = GetThemeService(tab_contents_)->BuildLabel( | 736 header_label_ = GetThemeService(web_contents_)->BuildLabel( |
738 std::string(), ui::kGdkBlack); | 737 std::string(), ui::kGdkBlack); |
739 gtk_util::ForceFontSizePixels(header_label_, kHeaderLabelPixelSize); | 738 gtk_util::ForceFontSizePixels(header_label_, kHeaderLabelPixelSize); |
740 gtk_box_pack_start(GTK_BOX(header_hbox), header_label_, TRUE, TRUE, 0); | 739 gtk_box_pack_start(GTK_BOX(header_hbox), header_label_, TRUE, TRUE, 0); |
741 gtk_misc_set_alignment(GTK_MISC(header_label_), 0, 0); | 740 gtk_misc_set_alignment(GTK_MISC(header_label_), 0, 0); |
742 } | 741 } |
743 | 742 |
744 void WebIntentPickerGtk::UpdateInstalledServices() { | 743 void WebIntentPickerGtk::UpdateInstalledServices() { |
745 if (!button_vbox_) | 744 if (!button_vbox_) |
746 return; | 745 return; |
747 | 746 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 | 785 |
787 std::string label_text = UTF16ToUTF8(model_->GetSuggestionsLinkText()); | 786 std::string label_text = UTF16ToUTF8(model_->GetSuggestionsLinkText()); |
788 gtk_label_set_text(GTK_LABEL(cws_label_), label_text.c_str()); | 787 gtk_label_set_text(GTK_LABEL(cws_label_), label_text.c_str()); |
789 gtk_widget_set_visible(cws_label_, !label_text.empty()); | 788 gtk_widget_set_visible(cws_label_, !label_text.empty()); |
790 } | 789 } |
791 | 790 |
792 void WebIntentPickerGtk::UpdateSuggestedExtensions() { | 791 void WebIntentPickerGtk::UpdateSuggestedExtensions() { |
793 if (!extensions_vbox_) | 792 if (!extensions_vbox_) |
794 return; | 793 return; |
795 | 794 |
796 GtkThemeService* theme_service = GetThemeService(tab_contents_); | 795 GtkThemeService* theme_service = GetThemeService(web_contents_); |
797 | 796 |
798 gtk_util::RemoveAllChildren(extensions_vbox_); | 797 gtk_util::RemoveAllChildren(extensions_vbox_); |
799 | 798 |
800 if (model_->GetSuggestedExtensionCount() == 0) { | 799 if (model_->GetSuggestedExtensionCount() == 0) { |
801 gtk_widget_hide(gtk_widget_get_parent(extensions_vbox_)); | 800 gtk_widget_hide(gtk_widget_get_parent(extensions_vbox_)); |
802 return; | 801 return; |
803 } | 802 } |
804 | 803 |
805 gtk_widget_show(gtk_widget_get_parent(extensions_vbox_)); | 804 gtk_widget_show(gtk_widget_get_parent(extensions_vbox_)); |
806 | 805 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 return alignment; | 871 return alignment; |
873 } | 872 } |
874 | 873 |
875 void WebIntentPickerGtk::RemoveThrobber() { | 874 void WebIntentPickerGtk::RemoveThrobber() { |
876 GtkWidget* alignment = gtk_widget_get_parent(throbber_->widget()); | 875 GtkWidget* alignment = gtk_widget_get_parent(throbber_->widget()); |
877 DCHECK(alignment); | 876 DCHECK(alignment); |
878 gtk_container_remove(GTK_CONTAINER(alignment), throbber_->widget()); | 877 gtk_container_remove(GTK_CONTAINER(alignment), throbber_->widget()); |
879 gtk_widget_destroy(alignment); | 878 gtk_widget_destroy(alignment); |
880 throbber_->Stop(); | 879 throbber_->Stop(); |
881 } | 880 } |
OLD | NEW |