| 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" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 GList* vbox_list = | 256 GList* vbox_list = |
| 257 gtk_container_get_children(GTK_CONTAINER(extensions_vbox_)); | 257 gtk_container_get_children(GTK_CONTAINER(extensions_vbox_)); |
| 258 GtkWidget* hbox = static_cast<GtkWidget*>(g_list_nth_data(vbox_list, index)); | 258 GtkWidget* hbox = static_cast<GtkWidget*>(g_list_nth_data(vbox_list, index)); |
| 259 | 259 |
| 260 RemoveThrobber(); | 260 RemoveThrobber(); |
| 261 gtk_widget_show_all(hbox); | 261 gtk_widget_show_all(hbox); |
| 262 g_list_free(vbox_list); | 262 g_list_free(vbox_list); |
| 263 SetWidgetsEnabled(true); | 263 SetWidgetsEnabled(true); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void WebIntentPickerGtk::OnInlineDispositionAutoResize(const gfx::Size& size) { |
| 267 gtk_widget_set_size_request(tab_contents_container_->widget(), |
| 268 size.width(), size.height()); |
| 269 } |
| 270 |
| 266 void WebIntentPickerGtk::OnModelChanged(WebIntentPickerModel* model) { | 271 void WebIntentPickerGtk::OnModelChanged(WebIntentPickerModel* model) { |
| 267 if (waiting_dialog_.get() && !model->IsWaitingForSuggestions()) { | 272 if (waiting_dialog_.get() && !model->IsWaitingForSuggestions()) { |
| 268 waiting_dialog_.reset(); | 273 waiting_dialog_.reset(); |
| 269 InitMainContents(); | 274 InitMainContents(); |
| 270 } | 275 } |
| 271 UpdateInstalledServices(); | 276 UpdateInstalledServices(); |
| 272 UpdateCWSLabel(); | 277 UpdateCWSLabel(); |
| 273 UpdateSuggestedExtensions(); | 278 UpdateSuggestedExtensions(); |
| 274 SetActionString(header_label_text_); | 279 SetActionString(header_label_text_); |
| 275 } | 280 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 299 | 304 |
| 300 tab_contents_container_.reset(new TabContentsContainerGtk(NULL)); | 305 tab_contents_container_.reset(new TabContentsContainerGtk(NULL)); |
| 301 tab_contents_container_->SetTab(inline_disposition_tab_contents_.get()); | 306 tab_contents_container_->SetTab(inline_disposition_tab_contents_.get()); |
| 302 | 307 |
| 303 inline_disposition_tab_contents_->web_contents()->GetController().LoadURL( | 308 inline_disposition_tab_contents_->web_contents()->GetController().LoadURL( |
| 304 url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 309 url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 305 std::string()); | 310 std::string()); |
| 306 | 311 |
| 307 // Replace the picker contents with the inline disposition. | 312 // Replace the picker contents with the inline disposition. |
| 308 ClearContents(); | 313 ClearContents(); |
| 314 gtk_widget_set_size_request(contents_, -1, -1); |
| 315 window_->BackgroundColorChanged(); |
| 309 | 316 |
| 310 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); | 317 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
| 311 GtkThemeService* theme_service = GetThemeService(tab_contents_); | 318 GtkThemeService* theme_service = GetThemeService(tab_contents_); |
| 312 | 319 |
| 313 GtkWidget* service_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); | 320 GtkWidget* service_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 314 // TODO(gbillock): Eventually get the service icon button here. | 321 // TODO(gbillock): Eventually get the service icon button here. |
| 315 | 322 |
| 316 // Intent action label. | 323 // Intent action label. |
| 317 GtkWidget* action_label = theme_service->BuildLabel( | 324 GtkWidget* action_label = gtk_label_new(UTF16ToUTF8(title).c_str()); |
| 318 UTF16ToUTF8(title), ui::kGdkBlack); | |
| 319 gtk_util::ForceFontSizePixels(action_label, kMainContentPixelSize); | 325 gtk_util::ForceFontSizePixels(action_label, kMainContentPixelSize); |
| 326 // Hardcode color; don't allow theming. |
| 327 gtk_util::SetLabelColor(action_label, &ui::kGdkBlack); |
| 320 | 328 |
| 321 GtkWidget* label_alignment = gtk_alignment_new(0, 0.5f, 0, 0); | 329 GtkWidget* label_alignment = gtk_alignment_new(0, 0.5f, 0, 0); |
| 322 gtk_container_add(GTK_CONTAINER(label_alignment), action_label); | 330 gtk_container_add(GTK_CONTAINER(label_alignment), action_label); |
| 323 GtkWidget* indent_label = gtk_util::IndentWidget(label_alignment); | 331 GtkWidget* indent_label = gtk_util::IndentWidget(label_alignment); |
| 324 | 332 |
| 325 gtk_box_pack_start(GTK_BOX(service_hbox), indent_label, FALSE, TRUE, 0); | 333 gtk_box_pack_start(GTK_BOX(service_hbox), indent_label, FALSE, TRUE, 0); |
| 326 | 334 |
| 327 // Add link for "choose another service" if other suggestions are available | 335 // Add link for "choose another service" if other suggestions are available |
| 328 // or if more than one (the current) service is installed. | 336 // or if more than one (the current) service is installed. |
| 329 if (model_->GetInstalledServiceCount() > 1 || | 337 if (model_->GetInstalledServiceCount() > 1 || |
| 330 model_->GetSuggestedExtensionCount()) { | 338 model_->GetSuggestedExtensionCount()) { |
| 331 GtkWidget* use_alternate_link = theme_service->BuildChromeLinkButton( | 339 GtkWidget* use_alternate_link = theme_service->BuildChromeLinkButton( |
| 332 l10n_util::GetStringUTF8( | 340 l10n_util::GetStringUTF8( |
| 333 IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE).c_str()); | 341 IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE).c_str()); |
| 334 gtk_chrome_link_button_set_use_gtk_theme( | 342 gtk_chrome_link_button_set_use_gtk_theme( |
| 335 GTK_CHROME_LINK_BUTTON(use_alternate_link), | 343 GTK_CHROME_LINK_BUTTON(use_alternate_link), |
| 336 theme_service->UsingNativeTheme()); | 344 theme_service->UsingNativeTheme()); |
| 337 gtk_util::ForceFontSizePixels( | 345 gtk_util::ForceFontSizePixels( |
| 338 GTK_CHROME_LINK_BUTTON(use_alternate_link)->label, | 346 GTK_CHROME_LINK_BUTTON(use_alternate_link)->label, |
| 339 kMainContentPixelSize); | 347 kMainContentPixelSize); |
| 340 g_signal_connect(use_alternate_link, "clicked", | 348 g_signal_connect(use_alternate_link, "clicked", |
| 341 G_CALLBACK(OnChooseAnotherServiceClickThunk), this); | 349 G_CALLBACK(OnChooseAnotherServiceClickThunk), this); |
| 342 GtkWidget* link_alignment = gtk_alignment_new(0, 0.5f, 0, 0); | 350 GtkWidget* link_alignment = gtk_alignment_new(0, 0.5f, 0, 0); |
| 343 gtk_container_add(GTK_CONTAINER(link_alignment), use_alternate_link); | 351 gtk_container_add(GTK_CONTAINER(link_alignment), use_alternate_link); |
| 344 gtk_box_pack_start(GTK_BOX(service_hbox), link_alignment, TRUE, TRUE, 0); | 352 gtk_box_pack_start(GTK_BOX(service_hbox), link_alignment, TRUE, TRUE, 0); |
| 345 } | 353 } |
| 346 AddCloseButton(service_hbox); | 354 AddCloseButton(service_hbox); |
| 347 | 355 |
| 348 // The header box | 356 // The header box |
| 349 gtk_box_pack_start(GTK_BOX(vbox), service_hbox, TRUE, TRUE, 0); | 357 gtk_container_add(GTK_CONTAINER(vbox), service_hbox); |
| 350 | |
| 351 // The separator between the icon/title/close and the inline renderer. | |
| 352 gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, TRUE, 0); | |
| 353 | 358 |
| 354 // hbox for the web contents, so we can have spacing on the borders. | 359 // hbox for the web contents, so we can have spacing on the borders. |
| 355 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | 360 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 356 gtk_alignment_set_padding( | 361 gtk_alignment_set_padding( |
| 357 GTK_ALIGNMENT(alignment), 0, ui::kContentAreaBorder, | 362 GTK_ALIGNMENT(alignment), 0, ui::kContentAreaBorder, |
| 358 ui::kContentAreaBorder, ui::kContentAreaBorder); | 363 ui::kContentAreaBorder, ui::kContentAreaBorder); |
| 359 gtk_container_add(GTK_CONTAINER(alignment), | 364 gtk_container_add(GTK_CONTAINER(alignment), |
| 360 tab_contents_container_->widget()); | 365 tab_contents_container_->widget()); |
| 361 gtk_box_pack_end(GTK_BOX(vbox), alignment, TRUE, TRUE, 0); | 366 gtk_container_add(GTK_CONTAINER(vbox), alignment); |
| 362 gtk_container_add(GTK_CONTAINER(contents_), vbox); | 367 gtk_container_add(GTK_CONTAINER(contents_), vbox); |
| 363 | 368 |
| 364 gfx::Size size = GetMinInlineDispositionSize(); | 369 gfx::Size size = GetMinInlineDispositionSize(); |
| 365 gtk_widget_set_size_request(tab_contents_container_->widget(), | 370 gtk_widget_set_size_request(tab_contents_container_->widget(), |
| 366 size.width(), size.height()); | 371 size.width(), size.height()); |
| 367 gtk_widget_show_all(contents_); | 372 gtk_widget_show_all(contents_); |
| 368 } | 373 } |
| 369 | 374 |
| 370 void WebIntentPickerGtk::OnInlineDispositionAutoResize(const gfx::Size& size) { | |
| 371 gtk_widget_set_size_request(tab_contents_container_->widget(), | |
| 372 size.width(), size.height()); | |
| 373 } | |
| 374 | |
| 375 void WebIntentPickerGtk::OnPendingAsyncCompleted() { | 375 void WebIntentPickerGtk::OnPendingAsyncCompleted() { |
| 376 // Requests to both the WebIntentService and the Chrome Web Store have | 376 // Requests to both the WebIntentService and the Chrome Web Store have |
| 377 // completed. If there are any services, installed or suggested, there's | 377 // completed. If there are any services, installed or suggested, there's |
| 378 // nothing to do. | 378 // nothing to do. |
| 379 if (model_->GetInstalledServiceCount() || | 379 if (model_->GetInstalledServiceCount() || |
| 380 model_->GetSuggestedExtensionCount()) | 380 model_->GetSuggestedExtensionCount()) |
| 381 return; | 381 return; |
| 382 | 382 |
| 383 // If there are no installed or suggested services at this point, | 383 // If there are no installed or suggested services at this point, |
| 384 // inform the user about it. | 384 // inform the user about it. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 GtkWidget* WebIntentPickerGtk::GetFocusWidget() { | 421 GtkWidget* WebIntentPickerGtk::GetFocusWidget() { |
| 422 return contents_; | 422 return contents_; |
| 423 } | 423 } |
| 424 | 424 |
| 425 void WebIntentPickerGtk::DeleteDelegate() { | 425 void WebIntentPickerGtk::DeleteDelegate() { |
| 426 // The delegate is deleted when the contents widget is destroyed. See | 426 // The delegate is deleted when the contents widget is destroyed. See |
| 427 // OnDestroy. | 427 // OnDestroy. |
| 428 delegate_->OnClosing(); | 428 delegate_->OnClosing(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 bool WebIntentPickerGtk::GetBackgroundColor(GdkColor* color) { |
| 432 if (tab_contents_container_.get()) { |
| 433 *color = ui::kGdkWhite; |
| 434 return true; |
| 435 } |
| 436 |
| 437 return false; |
| 438 } |
| 439 |
| 431 bool WebIntentPickerGtk::ShouldHaveBorderPadding() const { | 440 bool WebIntentPickerGtk::ShouldHaveBorderPadding() const { |
| 432 return false; | 441 return false; |
| 433 } | 442 } |
| 434 | 443 |
| 435 void WebIntentPickerGtk::Observe(int type, | 444 void WebIntentPickerGtk::Observe(int type, |
| 436 const content::NotificationSource& source, | 445 const content::NotificationSource& source, |
| 437 const content::NotificationDetails& details) { | 446 const content::NotificationDetails& details) { |
| 438 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); | 447 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
| 439 if (header_label_) { | 448 if (header_label_) { |
| 440 GtkThemeService* theme_service = GetThemeService(tab_contents_); | 449 GtkThemeService* theme_service = GetThemeService(tab_contents_); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 extensions_vbox_ = NULL; | 636 extensions_vbox_ = NULL; |
| 628 } | 637 } |
| 629 | 638 |
| 630 void WebIntentPickerGtk::ResetContents() { | 639 void WebIntentPickerGtk::ResetContents() { |
| 631 ClearContents(); | 640 ClearContents(); |
| 632 | 641 |
| 633 // Reset potential inline disposition data. | 642 // Reset potential inline disposition data. |
| 634 inline_disposition_delegate_.reset(NULL); | 643 inline_disposition_delegate_.reset(NULL); |
| 635 tab_contents_container_.reset(NULL); | 644 tab_contents_container_.reset(NULL); |
| 636 inline_disposition_tab_contents_.reset(NULL); | 645 inline_disposition_tab_contents_.reset(NULL); |
| 646 window_->BackgroundColorChanged(); |
| 637 | 647 |
| 638 // Re-initialize picker widgets and data. | 648 // Re-initialize picker widgets and data. |
| 639 InitMainContents(); | 649 InitMainContents(); |
| 640 UpdateInstalledServices(); | 650 UpdateInstalledServices(); |
| 641 UpdateCWSLabel(); | 651 UpdateCWSLabel(); |
| 642 UpdateSuggestedExtensions(); | 652 UpdateSuggestedExtensions(); |
| 643 SetActionString(header_label_text_); | 653 SetActionString(header_label_text_); |
| 644 | 654 |
| 645 gtk_widget_show_all(contents_); | 655 gtk_widget_show_all(contents_); |
| 646 } | 656 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 return alignment; | 826 return alignment; |
| 817 } | 827 } |
| 818 | 828 |
| 819 void WebIntentPickerGtk::RemoveThrobber() { | 829 void WebIntentPickerGtk::RemoveThrobber() { |
| 820 GtkWidget* alignment = gtk_widget_get_parent(throbber_->widget()); | 830 GtkWidget* alignment = gtk_widget_get_parent(throbber_->widget()); |
| 821 DCHECK(alignment); | 831 DCHECK(alignment); |
| 822 gtk_container_remove(GTK_CONTAINER(alignment), throbber_->widget()); | 832 gtk_container_remove(GTK_CONTAINER(alignment), throbber_->widget()); |
| 823 gtk_widget_destroy(alignment); | 833 gtk_widget_destroy(alignment); |
| 824 throbber_->Stop(); | 834 throbber_->Stop(); |
| 825 } | 835 } |
| OLD | NEW |