| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/favicon/favicon_service.h" | 12 #include "chrome/browser/favicon/favicon_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" | 16 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
| 16 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 17 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 17 #include "chrome/browser/ui/gtk/custom_button.h" | 18 #include "chrome/browser/ui/gtk/custom_button.h" |
| 18 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 19 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 19 #include "chrome/browser/ui/gtk/gtk_util.h" | 20 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 20 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 21 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
| 21 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" | 22 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" |
| 22 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 23 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 23 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" | 24 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" |
| 25 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 25 #include "content/browser/renderer_host/render_view_host.h" | 27 #include "content/browser/renderer_host/render_view_host.h" |
| 26 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" | 28 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" |
| 27 #include "content/public/browser/notification_registrar.h" | 29 #include "content/public/browser/notification_registrar.h" |
| 28 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
| 29 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
| 30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_contents_view.h" | 33 #include "content/public/browser/web_contents_view.h" |
| 32 #include "googleurl/src/gurl.h" | 34 #include "googleurl/src/gurl.h" |
| 33 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| 34 #include "grit/theme_resources.h" | |
| 35 #include "grit/theme_resources_standard.h" | |
| 36 #include "grit/ui_resources.h" | |
| 37 #include "ui/base/gtk/gtk_hig_constants.h" | 36 #include "ui/base/gtk/gtk_hig_constants.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 40 #include "ui/gfx/gtk_util.h" | 39 #include "ui/gfx/gtk_util.h" |
| 41 #include "ui/gfx/image/image.h" | 40 #include "ui/gfx/image/image.h" |
| 42 | 41 |
| 43 using content::WebContents; | 42 using content::WebContents; |
| 44 | 43 |
| 45 namespace { | 44 namespace { |
| 46 | 45 |
| 47 // The width in pixels of the area between the icon on the left and the close | 46 // The width in pixels of the area between the icon on the left and the close |
| 48 // button on the right. | 47 // button on the right. |
| 49 const int kMainContentWidth = 300; | 48 const int kMainContentWidth = 300; |
| 50 | 49 |
| 51 // The length in pixels of the label at the bottom of the picker. Text longer | 50 // The length in pixels of the label at the bottom of the picker. Text longer |
| 52 // than this width will wrap. | 51 // than this width will wrap. |
| 53 const int kWebStoreLabelLength = 300; | 52 const int kWebStoreLabelLength = 300; |
| 54 | 53 |
| 55 // The pixel size of the label at the bottom of the picker. | 54 // The pixel size of the label at the bottom of the picker. |
| 56 const int kWebStoreLabelPixelSize = 11; | 55 const int kWebStoreLabelPixelSize = 11; |
| 57 | 56 |
| 58 // How much to scale the the buttons up from their favicon size. | |
| 59 const int kServiceButtonScale = 3; | |
| 60 | |
| 61 GtkThemeService *GetThemeService(TabContentsWrapper* wrapper) { | 57 GtkThemeService *GetThemeService(TabContentsWrapper* wrapper) { |
| 62 return GtkThemeService::GetFrom(wrapper->profile()); | 58 return GtkThemeService::GetFrom(wrapper->profile()); |
| 63 } | 59 } |
| 64 | 60 |
| 65 // Set the image of |button| to |pixbuf|, and scale the button up by | 61 // Set the image of |button| to |pixbuf|. |
| 66 // |kServiceButtonScale|. | |
| 67 void SetServiceButtonImage(GtkWidget* button, GdkPixbuf* pixbuf) { | 62 void SetServiceButtonImage(GtkWidget* button, GdkPixbuf* pixbuf) { |
| 68 int width = gdk_pixbuf_get_width(pixbuf); | 63 gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(pixbuf)); |
| 69 int height = gdk_pixbuf_get_height(pixbuf); | 64 gtk_button_set_image_position(GTK_BUTTON(button), GTK_POS_LEFT); |
| 70 gtk_button_set_image(GTK_BUTTON(button), | |
| 71 gtk_image_new_from_pixbuf(pixbuf)); | |
| 72 gtk_widget_set_size_request(button, | |
| 73 width * kServiceButtonScale, | |
| 74 height * kServiceButtonScale); | |
| 75 } | 65 } |
| 76 | 66 |
| 77 } // namespace | 67 } // namespace |
| 78 | 68 |
| 79 // static | 69 // static |
| 80 WebIntentPicker* WebIntentPicker::Create(Browser* browser, | 70 WebIntentPicker* WebIntentPicker::Create(Browser* browser, |
| 81 TabContentsWrapper* wrapper, | 71 TabContentsWrapper* wrapper, |
| 82 WebIntentPickerDelegate* delegate) { | 72 WebIntentPickerDelegate* delegate, |
| 83 return new WebIntentPickerGtk(browser, wrapper, delegate); | 73 WebIntentPickerModel* model) { |
| 74 return new WebIntentPickerGtk(browser, wrapper, delegate, model); |
| 84 } | 75 } |
| 85 | 76 |
| 86 WebIntentPickerGtk::WebIntentPickerGtk(Browser* browser, | 77 WebIntentPickerGtk::WebIntentPickerGtk(Browser* browser, |
| 87 TabContentsWrapper* wrapper, | 78 TabContentsWrapper* wrapper, |
| 88 WebIntentPickerDelegate* delegate) | 79 WebIntentPickerDelegate* delegate, |
| 80 WebIntentPickerModel* model) |
| 89 : wrapper_(wrapper), | 81 : wrapper_(wrapper), |
| 90 delegate_(delegate), | 82 delegate_(delegate), |
| 83 model_(model), |
| 91 contents_(NULL), | 84 contents_(NULL), |
| 92 button_hbox_(NULL), | 85 button_vbox_(NULL), |
| 93 bubble_(NULL), | 86 bubble_(NULL), |
| 94 browser_(browser) { | 87 browser_(browser) { |
| 95 DCHECK(delegate_ != NULL); | 88 DCHECK(delegate_ != NULL); |
| 96 DCHECK(browser); | 89 DCHECK(browser); |
| 97 DCHECK(browser->window()); | 90 DCHECK(browser->window()); |
| 91 |
| 92 model_->set_observer(this); |
| 93 |
| 98 BrowserWindowGtk* browser_window = | 94 BrowserWindowGtk* browser_window = |
| 99 BrowserWindowGtk::GetBrowserWindowForNativeWindow( | 95 BrowserWindowGtk::GetBrowserWindowForNativeWindow( |
| 100 browser->window()->GetNativeHandle()); | 96 browser->window()->GetNativeHandle()); |
| 101 | 97 |
| 102 GtkWidget* anchor = browser_window-> | 98 GtkWidget* anchor = browser_window-> |
| 103 GetToolbar()->GetLocationBarView()->location_icon_widget(); | 99 GetToolbar()->GetLocationBarView()->location_icon_widget(); |
| 104 | 100 |
| 105 InitContents(); | 101 InitContents(); |
| 106 | 102 |
| 107 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ? | 103 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ? |
| 108 BubbleGtk::ARROW_LOCATION_TOP_RIGHT : | 104 BubbleGtk::ARROW_LOCATION_TOP_RIGHT : |
| 109 BubbleGtk::ARROW_LOCATION_TOP_LEFT; | 105 BubbleGtk::ARROW_LOCATION_TOP_LEFT; |
| 110 bubble_ = BubbleGtk::Show(anchor, | 106 bubble_ = BubbleGtk::Show(anchor, |
| 111 NULL, // |rect| | 107 NULL, // |rect| |
| 112 contents_, | 108 contents_, |
| 113 arrow_location, | 109 arrow_location, |
| 114 true, // |match_system_theme| | 110 true, // |match_system_theme| |
| 115 true, // |grab_input| | 111 true, // |grab_input| |
| 116 GetThemeService(wrapper), | 112 GetThemeService(wrapper), |
| 117 this); // |delegate| | 113 this); // |delegate| |
| 118 } | 114 } |
| 119 | 115 |
| 120 WebIntentPickerGtk::~WebIntentPickerGtk() { | 116 WebIntentPickerGtk::~WebIntentPickerGtk() { |
| 121 DCHECK(bubble_ == NULL) << "Should have closed window before destroying."; | 117 DCHECK(bubble_ == NULL) << "Should have closed window before destroying."; |
| 122 } | 118 } |
| 123 | 119 |
| 124 void WebIntentPickerGtk::SetServiceURLs(const std::vector<GURL>& urls) { | 120 void WebIntentPickerGtk::OnModelChanged(WebIntentPickerModel* model) { |
| 125 for (size_t i = 0; i < urls.size(); ++i) { | 121 gtk_util::RemoveAllChildren(button_vbox_); |
| 122 |
| 123 for (size_t i = 0; i < model->GetItemCount(); ++i) { |
| 124 const WebIntentPickerModel::Item& item = model->GetItemAt(i); |
| 125 |
| 126 GtkWidget* button = gtk_button_new(); | 126 GtkWidget* button = gtk_button_new(); |
| 127 gtk_widget_set_tooltip_text(button, urls[i].spec().c_str()); | 127 |
| 128 gtk_box_pack_start(GTK_BOX(button_hbox_), button, FALSE, FALSE, 0); | 128 gtk_widget_set_tooltip_text(button, item.url.spec().c_str()); |
| 129 gtk_button_set_label(GTK_BUTTON(button), UTF16ToUTF8(item.title).c_str()); |
| 130 |
| 131 gtk_box_pack_start(GTK_BOX(button_vbox_), button, FALSE, FALSE, 0); |
| 129 g_signal_connect(button, | 132 g_signal_connect(button, |
| 130 "clicked", | 133 "clicked", |
| 131 G_CALLBACK(OnServiceButtonClickThunk), | 134 G_CALLBACK(OnServiceButtonClickThunk), |
| 132 this); | 135 this); |
| 136 |
| 137 SetServiceButtonImage(button, item.favicon.ToGdkPixbuf()); |
| 133 } | 138 } |
| 134 | 139 |
| 135 // Add the '+' button, to use the Chrome Web Store. | 140 gtk_widget_show_all(button_vbox_); |
| 136 GtkWidget* plus_button = gtk_button_new(); | |
| 137 gtk_widget_set_tooltip_text( | |
| 138 plus_button, | |
| 139 l10n_util::GetStringUTF8(IDS_FIND_MORE_INTENT_HANDLER_TOOLTIP).c_str()); | |
| 140 gtk_box_pack_start(GTK_BOX(button_hbox_), plus_button, FALSE, FALSE, 0); | |
| 141 | |
| 142 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 143 GdkPixbuf* icon_pixbuf = rb.GetNativeImageNamed(IDR_SIDETABS_NEW_TAB); | |
| 144 SetServiceButtonImage(plus_button, icon_pixbuf); | |
| 145 | |
| 146 gtk_widget_show_all(button_hbox_); | |
| 147 } | 141 } |
| 148 | 142 |
| 149 void WebIntentPickerGtk::SetServiceIcon(size_t index, const SkBitmap& icon) { | 143 void WebIntentPickerGtk::OnFaviconChanged(WebIntentPickerModel* model, |
| 150 if (icon.empty()) | 144 size_t index) { |
| 151 return; | 145 const WebIntentPickerModel::Item& item = model->GetItemAt(index); |
| 152 | |
| 153 GtkWidget* button = GetServiceButton(index); | 146 GtkWidget* button = GetServiceButton(index); |
| 154 | 147 SetServiceButtonImage(button, item.favicon.ToGdkPixbuf()); |
| 155 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); | |
| 156 SetServiceButtonImage(button, icon_pixbuf); | |
| 157 g_object_unref(icon_pixbuf); | |
| 158 } | 148 } |
| 159 | 149 |
| 160 void WebIntentPickerGtk::SetDefaultServiceIcon(size_t index) { | 150 void WebIntentPickerGtk::OnInlineDisposition(WebIntentPickerModel* model) { |
| 161 GtkWidget* button = GetServiceButton(index); | 151 const WebIntentPickerModel::Item& item = model->GetItemAt( |
| 152 model->inline_disposition_index()); |
| 153 const GURL& url = item.url; |
| 162 | 154 |
| 163 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 155 content::WebContents* web_contents = content::WebContents::Create( |
| 164 GdkPixbuf* icon_pixbuf = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON); | |
| 165 SetServiceButtonImage(button, icon_pixbuf); | |
| 166 } | |
| 167 | |
| 168 void WebIntentPickerGtk::Close() { | |
| 169 bubble_->Close(); | |
| 170 bubble_ = NULL; | |
| 171 if (inline_disposition_tab_contents_.get()) | |
| 172 inline_disposition_tab_contents_->web_contents()->OnCloseStarted(); | |
| 173 } | |
| 174 | |
| 175 void WebIntentPickerGtk::BubbleClosing(BubbleGtk* bubble, | |
| 176 bool closed_by_escape) { | |
| 177 delegate_->OnClosing(); | |
| 178 } | |
| 179 | |
| 180 void WebIntentPickerGtk::OnCloseButtonClick(GtkWidget* button) { | |
| 181 delegate_->OnCancelled(); | |
| 182 delegate_->OnClosing(); | |
| 183 } | |
| 184 | |
| 185 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) { | |
| 186 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_hbox_)); | |
| 187 gint index = g_list_index(button_list, button); | |
| 188 DCHECK(index != -1); | |
| 189 | |
| 190 delegate_->OnServiceChosen(static_cast<size_t>(index)); | |
| 191 } | |
| 192 | |
| 193 void WebIntentPickerGtk::InitContents() { | |
| 194 GtkThemeService* theme_service = GetThemeService(wrapper_); | |
| 195 | |
| 196 contents_ = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); | |
| 197 gtk_container_set_border_width(GTK_CONTAINER(contents_), | |
| 198 ui::kContentAreaBorder); | |
| 199 | |
| 200 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 201 GdkPixbuf* image_pixbuf = rb.GetNativeImageNamed(IDR_PAGEINFO_INFO); | |
| 202 GtkWidget* image = gtk_image_new_from_pixbuf(image_pixbuf); | |
| 203 gtk_box_pack_start(GTK_BOX(contents_), image, FALSE, FALSE, 0); | |
| 204 gtk_misc_set_alignment(GTK_MISC(image), 0, 0); | |
| 205 | |
| 206 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); | |
| 207 | |
| 208 GtkWidget* label = theme_service->BuildLabel( | |
| 209 l10n_util::GetStringUTF8(IDS_CHOOSE_INTENT_HANDLER_MESSAGE).c_str(), | |
| 210 ui::kGdkBlack); | |
| 211 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); | |
| 212 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
| 213 | |
| 214 gtk_widget_set_size_request(vbox, kMainContentWidth, -1); | |
| 215 | |
| 216 button_hbox_ = gtk_hbox_new(FALSE, ui::kControlSpacing); | |
| 217 gtk_box_pack_start(GTK_BOX(vbox), button_hbox_, TRUE, TRUE, 0); | |
| 218 | |
| 219 GtkWidget* cws_label = theme_service->BuildLabel( | |
| 220 l10n_util::GetStringUTF8(IDS_FIND_MORE_INTENT_HANDLER_MESSAGE).c_str(), | |
| 221 ui::kGdkBlack); | |
| 222 gtk_box_pack_start(GTK_BOX(vbox), cws_label, TRUE, TRUE, 0); | |
| 223 gtk_misc_set_alignment(GTK_MISC(cws_label), 0, 0); | |
| 224 gtk_util::SetLabelWidth(cws_label, kWebStoreLabelLength); | |
| 225 gtk_util::ForceFontSizePixels(cws_label, kWebStoreLabelPixelSize); | |
| 226 | |
| 227 gtk_box_pack_start(GTK_BOX(contents_), vbox, TRUE, TRUE, 0); | |
| 228 | |
| 229 close_button_.reset( | |
| 230 CustomDrawButton::CloseButton(GetThemeService(wrapper_))); | |
| 231 g_signal_connect(close_button_->widget(), | |
| 232 "clicked", | |
| 233 G_CALLBACK(OnCloseButtonClickThunk), | |
| 234 this); | |
| 235 gtk_widget_set_can_focus(close_button_->widget(), FALSE); | |
| 236 | |
| 237 GtkWidget* close_vbox = gtk_vbox_new(FALSE, 0); | |
| 238 gtk_box_pack_start(GTK_BOX(close_vbox), close_button_->widget(), FALSE, FALSE, | |
| 239 0); | |
| 240 gtk_box_pack_end(GTK_BOX(contents_), close_vbox, FALSE, FALSE, 0); | |
| 241 } | |
| 242 | |
| 243 void RemoveAllHelper(GtkWidget* widget, gpointer data) { | |
| 244 GtkWidget* parent = gtk_widget_get_parent(widget); | |
| 245 gtk_container_remove(GTK_CONTAINER(parent), widget); | |
| 246 } | |
| 247 | |
| 248 WebContents* WebIntentPickerGtk::SetInlineDisposition(const GURL& url) { | |
| 249 WebContents* web_contents = WebContents::Create( | |
| 250 browser_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 156 browser_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 251 inline_disposition_tab_contents_.reset(new TabContentsWrapper(web_contents)); | 157 inline_disposition_tab_contents_.reset(new TabContentsWrapper(web_contents)); |
| 252 inline_disposition_delegate_.reset(new InlineDispositionDelegate); | 158 inline_disposition_delegate_.reset(new InlineDispositionDelegate); |
| 253 web_contents->SetDelegate(inline_disposition_delegate_.get()); | 159 web_contents->SetDelegate(inline_disposition_delegate_.get()); |
| 254 tab_contents_container_.reset(new TabContentsContainerGtk(NULL)); | 160 tab_contents_container_.reset(new TabContentsContainerGtk(NULL)); |
| 255 tab_contents_container_->SetTab(inline_disposition_tab_contents_.get()); | 161 tab_contents_container_->SetTab(inline_disposition_tab_contents_.get()); |
| 256 | 162 |
| 257 inline_disposition_tab_contents_->web_contents()->GetController().LoadURL( | 163 inline_disposition_tab_contents_->web_contents()->GetController().LoadURL( |
| 258 url, content::Referrer(), content::PAGE_TRANSITION_START_PAGE, | 164 url, content::Referrer(), content::PAGE_TRANSITION_START_PAGE, |
| 259 std::string()); | 165 std::string()); |
| 260 | 166 |
| 261 // Replace the bubble picker contents with the inline disposition. | 167 // Replace the bubble picker contents with the inline disposition. |
| 262 | 168 |
| 263 gtk_container_foreach(GTK_CONTAINER(contents_), RemoveAllHelper, NULL); | 169 gtk_util::RemoveAllChildren(contents_); |
| 264 | 170 |
| 265 GtkWidget* service_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); | 171 GtkWidget* service_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 266 // TODO(gbillock): Eventually get the service icon button here. | 172 // TODO(gbillock): Eventually get the service icon button here. |
| 267 // Maybe add a title or something too? | 173 // Maybe add a title or something too? |
| 268 close_button_.reset( | 174 close_button_.reset( |
| 269 CustomDrawButton::CloseButton(GetThemeService(wrapper_))); | 175 CustomDrawButton::CloseButton(GetThemeService(wrapper_))); |
| 270 g_signal_connect(close_button_->widget(), | 176 g_signal_connect(close_button_->widget(), |
| 271 "clicked", | 177 "clicked", |
| 272 G_CALLBACK(OnCloseButtonClickThunk), | 178 G_CALLBACK(OnCloseButtonClickThunk), |
| 273 this); | 179 this); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 290 | 196 |
| 291 // TODO(gbillock): This size calculation needs more thought. | 197 // TODO(gbillock): This size calculation needs more thought. |
| 292 // Move up to WebIntentPicker? | 198 // Move up to WebIntentPicker? |
| 293 gfx::Size tab_size = wrapper_->web_contents()->GetView()->GetContainerSize(); | 199 gfx::Size tab_size = wrapper_->web_contents()->GetView()->GetContainerSize(); |
| 294 int width = std::max(tab_size.width()/2, kMainContentWidth); | 200 int width = std::max(tab_size.width()/2, kMainContentWidth); |
| 295 int height = std::max(tab_size.height()/2, kMainContentWidth); | 201 int height = std::max(tab_size.height()/2, kMainContentWidth); |
| 296 gtk_widget_set_size_request(tab_contents_container_->widget(), | 202 gtk_widget_set_size_request(tab_contents_container_->widget(), |
| 297 width, height); | 203 width, height); |
| 298 gtk_widget_show_all(contents_); | 204 gtk_widget_show_all(contents_); |
| 299 | 205 |
| 300 return inline_disposition_tab_contents_->web_contents(); | 206 delegate_->OnInlineDispositionWebContentsCreated(web_contents); |
| 207 } |
| 208 |
| 209 void WebIntentPickerGtk::Close() { |
| 210 bubble_->Close(); |
| 211 if (inline_disposition_tab_contents_.get()) |
| 212 inline_disposition_tab_contents_->web_contents()->OnCloseStarted(); |
| 213 } |
| 214 |
| 215 void WebIntentPickerGtk::BubbleClosing(BubbleGtk* bubble, |
| 216 bool closed_by_escape) { |
| 217 delegate_->OnClosing(); |
| 218 } |
| 219 |
| 220 void WebIntentPickerGtk::OnCloseButtonClick(GtkWidget* button) { |
| 221 delegate_->OnCancelled(); |
| 222 delegate_->OnClosing(); |
| 223 } |
| 224 |
| 225 void WebIntentPickerGtk::OnDestroy(GtkWidget* button) { |
| 226 // Destroy this object when the BubbleGtk is destroyed. It can't be "delete |
| 227 // this" because this function happens in a callback. |
| 228 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 229 model_->set_observer(NULL); |
| 230 bubble_ = NULL; |
| 231 } |
| 232 |
| 233 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) { |
| 234 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_vbox_)); |
| 235 gint index = g_list_index(button_list, button); |
| 236 DCHECK(index != -1); |
| 237 |
| 238 const WebIntentPickerModel::Item& item = model_->GetItemAt(index); |
| 239 |
| 240 delegate_->OnServiceChosen(static_cast<size_t>(index), item.disposition); |
| 241 } |
| 242 |
| 243 void WebIntentPickerGtk::InitContents() { |
| 244 GtkThemeService* theme_service = GetThemeService(wrapper_); |
| 245 |
| 246 // Main contents vbox. |
| 247 contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); |
| 248 gtk_container_set_border_width(GTK_CONTAINER(contents_), |
| 249 ui::kContentAreaBorder); |
| 250 gtk_widget_set_size_request(contents_, kMainContentWidth, -1); |
| 251 |
| 252 // Hbox containing label and close button. |
| 253 GtkWidget* header_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 254 gtk_box_pack_start(GTK_BOX(contents_), header_hbox, TRUE, TRUE, 0); |
| 255 |
| 256 GtkWidget* label = theme_service->BuildLabel( |
| 257 l10n_util::GetStringUTF8(IDS_CHOOSE_INTENT_HANDLER_MESSAGE).c_str(), |
| 258 ui::kGdkBlack); |
| 259 gtk_box_pack_start(GTK_BOX(header_hbox), label, TRUE, TRUE, 0); |
| 260 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
| 261 |
| 262 close_button_.reset( |
| 263 CustomDrawButton::CloseButton(GetThemeService(wrapper_))); |
| 264 g_signal_connect(close_button_->widget(), |
| 265 "clicked", |
| 266 G_CALLBACK(OnCloseButtonClickThunk), |
| 267 this); |
| 268 gtk_widget_set_can_focus(close_button_->widget(), FALSE); |
| 269 gtk_box_pack_end(GTK_BOX(header_hbox), close_button_->widget(), |
| 270 FALSE, FALSE, 0); |
| 271 |
| 272 // Vbox containing all service buttons. |
| 273 button_vbox_ = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 274 gtk_box_pack_start(GTK_BOX(contents_), button_vbox_, TRUE, TRUE, 0); |
| 275 |
| 276 // Chrome Web Store label. |
| 277 GtkWidget* cws_label = theme_service->BuildLabel( |
| 278 l10n_util::GetStringUTF8(IDS_FIND_MORE_INTENT_HANDLER_MESSAGE).c_str(), |
| 279 ui::kGdkBlack); |
| 280 gtk_box_pack_start(GTK_BOX(contents_), cws_label, TRUE, TRUE, 0); |
| 281 gtk_misc_set_alignment(GTK_MISC(cws_label), 0, 0); |
| 282 gtk_util::SetLabelWidth(cws_label, kWebStoreLabelLength); |
| 283 gtk_util::ForceFontSizePixels(cws_label, kWebStoreLabelPixelSize); |
| 284 |
| 285 g_signal_connect(contents_, "destroy", G_CALLBACK(&OnDestroyThunk), this); |
| 301 } | 286 } |
| 302 | 287 |
| 303 GtkWidget* WebIntentPickerGtk::GetServiceButton(size_t index) { | 288 GtkWidget* WebIntentPickerGtk::GetServiceButton(size_t index) { |
| 304 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_hbox_)); | 289 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_vbox_)); |
| 305 GtkWidget* button = GTK_WIDGET(g_list_nth_data(button_list, index)); | 290 GtkWidget* button = GTK_WIDGET(g_list_nth_data(button_list, index)); |
| 306 DCHECK(button != NULL); | 291 DCHECK(button != NULL); |
| 307 | 292 |
| 308 return button; | 293 return button; |
| 309 } | 294 } |
| 310 | 295 |
| 311 // WebIntentPickerGtk::InlineDispositionDelegate | 296 // WebIntentPickerGtk::InlineDispositionDelegate |
| 312 | 297 |
| 313 WebIntentPickerGtk::InlineDispositionDelegate::InlineDispositionDelegate() {} | 298 WebIntentPickerGtk::InlineDispositionDelegate::InlineDispositionDelegate() {} |
| 314 WebIntentPickerGtk::InlineDispositionDelegate::~InlineDispositionDelegate() {} | 299 WebIntentPickerGtk::InlineDispositionDelegate::~InlineDispositionDelegate() {} |
| 315 | 300 |
| 316 | |
| 317 bool WebIntentPickerGtk::InlineDispositionDelegate::IsPopupOrPanel( | 301 bool WebIntentPickerGtk::InlineDispositionDelegate::IsPopupOrPanel( |
| 318 const WebContents* source) const { | 302 const WebContents* source) const { |
| 319 return true; | 303 return true; |
| 320 } | 304 } |
| 321 | 305 |
| 322 bool WebIntentPickerGtk::InlineDispositionDelegate:: | 306 bool WebIntentPickerGtk::InlineDispositionDelegate:: |
| 323 ShouldAddNavigationToHistory( | 307 ShouldAddNavigationToHistory( |
| 324 const history::HistoryAddPageArgs& add_page_args, | 308 const history::HistoryAddPageArgs& add_page_args, |
| 325 content::NavigationType navigation_type) { | 309 content::NavigationType navigation_type) { |
| 326 return false; | 310 return false; |
| 327 } | 311 } |
| OLD | NEW |