| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gtk/sad_tab_gtk.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "app/l10n_util.h" | |
| 10 #include "app/resource_bundle.h" | |
| 11 #include "chrome/browser/google/google_util.h" | |
| 12 #include "chrome/browser/gtk/gtk_chrome_link_button.h" | |
| 13 #include "chrome/browser/gtk/gtk_util.h" | |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 15 #include "chrome/common/url_constants.h" | |
| 16 #include "grit/generated_resources.h" | |
| 17 #include "grit/locale_settings.h" | |
| 18 #include "grit/theme_resources.h" | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 // Background color of the content (a grayish blue). | |
| 23 const GdkColor kBackgroundColor = GDK_COLOR_RGB(35, 48, 64); | |
| 24 | |
| 25 // Construct a centered GtkLabel with a white foreground. | |
| 26 // |format| is a printf-style format containing a %s; | |
| 27 // |str| is substituted into the format. | |
| 28 GtkWidget* MakeWhiteMarkupLabel(const char* format, const std::string& str) { | |
| 29 GtkWidget* label = gtk_label_new(NULL); | |
| 30 char* markup = g_markup_printf_escaped(format, str.c_str()); | |
| 31 gtk_label_set_markup(GTK_LABEL(label), markup); | |
| 32 g_free(markup); | |
| 33 | |
| 34 // Center align and justify it. | |
| 35 gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5); | |
| 36 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER); | |
| 37 | |
| 38 // Set text to white. | |
| 39 GdkColor white = gtk_util::kGdkWhite; | |
| 40 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &white); | |
| 41 | |
| 42 return label; | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 47 SadTabGtk::SadTabGtk(TabContents* tab_contents) | |
| 48 : tab_contents_(tab_contents) { | |
| 49 DCHECK(tab_contents_); | |
| 50 | |
| 51 // Use an event box to get the background painting correctly. | |
| 52 event_box_.Own(gtk_event_box_new()); | |
| 53 gtk_widget_modify_bg(event_box_.get(), GTK_STATE_NORMAL, &kBackgroundColor); | |
| 54 // Allow ourselves to be resized arbitrarily small. | |
| 55 gtk_widget_set_size_request(event_box_.get(), 0, 0); | |
| 56 | |
| 57 GtkWidget* centering = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); | |
| 58 gtk_container_add(GTK_CONTAINER(event_box_.get()), centering); | |
| 59 | |
| 60 // Use a vertical box to contain icon, title, message and link. | |
| 61 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | |
| 62 gtk_container_add(GTK_CONTAINER(centering), vbox); | |
| 63 | |
| 64 // Add center-aligned image. | |
| 65 GtkWidget* image = gtk_image_new_from_pixbuf( | |
| 66 ResourceBundle::GetSharedInstance().GetPixbufNamed(IDR_SAD_TAB)); | |
| 67 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5); | |
| 68 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); | |
| 69 | |
| 70 // Add spacer between image and title. | |
| 71 GtkWidget* spacer = gtk_label_new(NULL); | |
| 72 gtk_label_set_markup(GTK_LABEL(spacer), "<span size=\"larger\"> </span>"); | |
| 73 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); | |
| 74 | |
| 75 // Add center-aligned title. | |
| 76 GtkWidget* title = MakeWhiteMarkupLabel( | |
| 77 "<span size=\"larger\" style=\"normal\"><b>%s</b></span>", | |
| 78 l10n_util::GetStringUTF8(IDS_SAD_TAB_TITLE)); | |
| 79 gtk_box_pack_start(GTK_BOX(vbox), title, FALSE, FALSE, 0); | |
| 80 | |
| 81 // Add spacer between title and message. | |
| 82 spacer = gtk_label_new(" "); | |
| 83 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); | |
| 84 | |
| 85 // Add center-aligned message. | |
| 86 GtkWidget* message = | |
| 87 MakeWhiteMarkupLabel("<span style=\"normal\">%s</span>", | |
| 88 l10n_util::GetStringUTF8(IDS_SAD_TAB_MESSAGE)); | |
| 89 gtk_label_set_line_wrap(GTK_LABEL(message), TRUE); | |
| 90 gtk_box_pack_start(GTK_BOX(vbox), message, FALSE, FALSE, 0); | |
| 91 | |
| 92 // Add spacer between message and link. | |
| 93 spacer = gtk_label_new(" "); | |
| 94 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); | |
| 95 | |
| 96 if (tab_contents_ != NULL) { | |
| 97 // Add the learn-more link and center-align it in an alignment. | |
| 98 GtkWidget* link = gtk_chrome_link_button_new( | |
| 99 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); | |
| 100 gtk_chrome_link_button_set_normal_color(GTK_CHROME_LINK_BUTTON(link), | |
| 101 >k_util::kGdkWhite); | |
| 102 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkButtonClickThunk), this); | |
| 103 GtkWidget* link_alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); | |
| 104 gtk_container_add(GTK_CONTAINER(link_alignment), link); | |
| 105 gtk_box_pack_start(GTK_BOX(vbox), link_alignment, FALSE, FALSE, 0); | |
| 106 } | |
| 107 | |
| 108 gtk_widget_show_all(event_box_.get()); | |
| 109 } | |
| 110 | |
| 111 SadTabGtk::~SadTabGtk() { | |
| 112 event_box_.Destroy(); | |
| 113 } | |
| 114 | |
| 115 void SadTabGtk::OnLinkButtonClick(GtkWidget* sender) { | |
| 116 if (tab_contents_ != NULL) { | |
| 117 GURL help_url = | |
| 118 google_util::AppendGoogleLocaleParam(GURL(chrome::kCrashReasonURL)); | |
| 119 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); | |
| 120 } | |
| 121 } | |
| OLD | NEW |