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