| 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/ui/gtk/web_intent_picker_gtk.h" | 5 #include "chrome/browser/ui/gtk/web_intent_picker_gtk.h" |
| 6 | 6 |
| 7 #include "chrome/browser/favicon/favicon_service.h" | 7 #include "chrome/browser/favicon/favicon_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/gtk/custom_button.h" | 9 #include "chrome/browser/ui/gtk/custom_button.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 11 #include "chrome/browser/ui/gtk/gtk_util.h" | 11 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 12 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 12 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 13 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" | 13 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
| 16 #include "content/common/content_notification_types.h" | 16 #include "content/common/content_notification_types.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 #include "grit/ui_resources.h" | 19 #include "grit/ui_resources.h" |
| 20 #include "ui/base/gtk/gtk_hig_constants.h" | 20 #include "ui/base/gtk/gtk_hig_constants.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/gfx/gtk_util.h" | 23 #include "ui/gfx/gtk_util.h" |
| 24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 GtkThemeService *GetThemeService(TabContents* tab_contents) { | 28 GtkThemeService *GetThemeService(TabContentsWrapper* wrapper) { |
| 29 Profile* profile = Profile::FromBrowserContext( | 29 return GtkThemeService::GetFrom(wrapper->profile()); |
| 30 tab_contents->browser_context()); | |
| 31 return GtkThemeService::GetFrom(profile); | |
| 32 } | 30 } |
| 33 | 31 |
| 34 } // namespace | 32 } // namespace |
| 35 | 33 |
| 36 // static | 34 // static |
| 37 WebIntentPicker* WebIntentPicker::Create(TabContents* tab_contents, | 35 WebIntentPicker* WebIntentPicker::Create(TabContentsWrapper* wrapper, |
| 38 WebIntentPickerDelegate* delegate) { | 36 WebIntentPickerDelegate* delegate) { |
| 39 return new WebIntentPickerGtk(tab_contents, delegate); | 37 return new WebIntentPickerGtk(wrapper, delegate); |
| 40 } | 38 } |
| 41 | 39 |
| 42 WebIntentPickerGtk::WebIntentPickerGtk(TabContents* tab_contents, | 40 WebIntentPickerGtk::WebIntentPickerGtk(TabContentsWrapper* wrapper, |
| 43 WebIntentPickerDelegate* delegate) | 41 WebIntentPickerDelegate* delegate) |
| 44 : tab_contents_(tab_contents), | 42 : wrapper_(wrapper), |
| 45 delegate_(delegate), | 43 delegate_(delegate), |
| 46 window_(NULL) { | 44 window_(NULL) { |
| 47 DCHECK(delegate_ != NULL); | 45 DCHECK(delegate_ != NULL); |
| 48 root_.Own(gtk_vbox_new(FALSE, ui::kContentAreaBorder)); | 46 root_.Own(gtk_vbox_new(FALSE, ui::kContentAreaBorder)); |
| 49 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); | 47 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
| 50 GtkWidget* label = gtk_label_new( | 48 GtkWidget* label = gtk_label_new( |
| 51 l10n_util::GetStringUTF8(IDS_CHOOSE_INTENT_HANDLER_MESSAGE).c_str()); | 49 l10n_util::GetStringUTF8(IDS_CHOOSE_INTENT_HANDLER_MESSAGE).c_str()); |
| 52 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | 50 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); |
| 53 | 51 |
| 54 close_button_.reset( | 52 close_button_.reset( |
| 55 CustomDrawButton::CloseButton(GetThemeService(tab_contents_))); | 53 CustomDrawButton::CloseButton(GetThemeService(wrapper_))); |
| 56 g_signal_connect(close_button_->widget(), | 54 g_signal_connect(close_button_->widget(), |
| 57 "clicked", | 55 "clicked", |
| 58 G_CALLBACK(OnCloseButtonClickThunk), | 56 G_CALLBACK(OnCloseButtonClickThunk), |
| 59 this); | 57 this); |
| 60 gtk_widget_set_can_focus(close_button_->widget(), FALSE); | 58 gtk_widget_set_can_focus(close_button_->widget(), FALSE); |
| 61 gtk_box_pack_end(GTK_BOX(hbox), close_button_->widget(), FALSE, FALSE, 0); | 59 gtk_box_pack_end(GTK_BOX(hbox), close_button_->widget(), FALSE, FALSE, 0); |
| 62 | 60 |
| 63 gtk_box_pack_start(GTK_BOX(root_.get()), hbox, FALSE, FALSE, 0); | 61 gtk_box_pack_start(GTK_BOX(root_.get()), hbox, FALSE, FALSE, 0); |
| 64 | 62 |
| 65 button_hbox_ = gtk_hbox_new(FALSE, ui::kContentAreaBorder); | 63 button_hbox_ = gtk_hbox_new(FALSE, ui::kContentAreaBorder); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 GtkButton* button = GTK_BUTTON(g_list_nth_data(button_list, index)); | 100 GtkButton* button = GTK_BUTTON(g_list_nth_data(button_list, index)); |
| 103 DCHECK(button != NULL) << "Invalid index."; | 101 DCHECK(button != NULL) << "Invalid index."; |
| 104 | 102 |
| 105 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 103 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 106 GdkPixbuf* icon_pixbuf = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON); | 104 GdkPixbuf* icon_pixbuf = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON); |
| 107 gtk_button_set_image(button, gtk_image_new_from_pixbuf(icon_pixbuf)); | 105 gtk_button_set_image(button, gtk_image_new_from_pixbuf(icon_pixbuf)); |
| 108 } | 106 } |
| 109 | 107 |
| 110 void WebIntentPickerGtk::Show() { | 108 void WebIntentPickerGtk::Show() { |
| 111 DCHECK(window_ == NULL) << "Show already called."; | 109 DCHECK(window_ == NULL) << "Show already called."; |
| 112 window_ = new ConstrainedWindowGtk(tab_contents_, this); | 110 window_ = new ConstrainedWindowGtk(wrapper_->tab_contents(), this); |
| 113 } | 111 } |
| 114 | 112 |
| 115 void WebIntentPickerGtk::Close() { | 113 void WebIntentPickerGtk::Close() { |
| 116 DCHECK(window_ != NULL) << "Show not called."; | 114 DCHECK(window_ != NULL) << "Show not called."; |
| 117 window_->CloseConstrainedWindow(); | 115 window_->CloseConstrainedWindow(); |
| 118 window_ = NULL; | 116 window_ = NULL; |
| 119 } | 117 } |
| 120 | 118 |
| 121 GtkWidget* WebIntentPickerGtk::GetWidgetRoot() { | 119 GtkWidget* WebIntentPickerGtk::GetWidgetRoot() { |
| 122 return root_.get(); | 120 return root_.get(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 delegate_->OnCancelled(); | 132 delegate_->OnCancelled(); |
| 135 } | 133 } |
| 136 | 134 |
| 137 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) { | 135 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) { |
| 138 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_hbox_)); | 136 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_hbox_)); |
| 139 gint index = g_list_index(button_list, button); | 137 gint index = g_list_index(button_list, button); |
| 140 DCHECK(index != -1); | 138 DCHECK(index != -1); |
| 141 | 139 |
| 142 delegate_->OnServiceChosen(static_cast<size_t>(index)); | 140 delegate_->OnServiceChosen(static_cast<size_t>(index)); |
| 143 } | 141 } |
| OLD | NEW |