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/sad_tab_gtk.h" | 5 #include "chrome/browser/ui/gtk/sad_tab_gtk.h" |
6 | 6 |
7 #include <string> | 7 #include "base/utf_string_conversions.h" |
8 | |
9 #include "chrome/browser/google/google_util.h" | 8 #include "chrome/browser/google/google_util.h" |
10 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 9 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
11 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
12 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
13 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
14 #include "grit/locale_settings.h" | 13 #include "grit/locale_settings.h" |
15 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
16 #include "ui/base/gtk/gtk_hig_constants.h" | 15 #include "ui/base/gtk/gtk_hig_constants.h" |
17 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 IDS_SAD_TAB_MESSAGE : | 101 IDS_SAD_TAB_MESSAGE : |
103 IDS_KILLED_TAB_MESSAGE)); | 102 IDS_KILLED_TAB_MESSAGE)); |
104 gtk_label_set_line_wrap(GTK_LABEL(message), TRUE); | 103 gtk_label_set_line_wrap(GTK_LABEL(message), TRUE); |
105 gtk_box_pack_start(GTK_BOX(vbox), message, FALSE, FALSE, 0); | 104 gtk_box_pack_start(GTK_BOX(vbox), message, FALSE, FALSE, 0); |
106 | 105 |
107 // Add spacer between message and link. | 106 // Add spacer between message and link. |
108 spacer = gtk_label_new(" "); | 107 spacer = gtk_label_new(" "); |
109 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); | 108 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); |
110 | 109 |
111 if (tab_contents_ != NULL) { | 110 if (tab_contents_ != NULL) { |
112 // Add the learn-more link and center-align it in an alignment. | 111 // Create the help link and alignment. |
113 GtkWidget* link = gtk_chrome_link_button_new( | 112 std::string link_text(l10n_util::GetStringUTF8( |
114 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); | 113 kind == CRASHED ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE)); |
| 114 GtkWidget* link = gtk_chrome_link_button_new(link_text.c_str()); |
115 gtk_chrome_link_button_set_normal_color(GTK_CHROME_LINK_BUTTON(link), | 115 gtk_chrome_link_button_set_normal_color(GTK_CHROME_LINK_BUTTON(link), |
116 &ui::kGdkWhite); | 116 &ui::kGdkWhite); |
117 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkButtonClickThunk), this); | 117 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkButtonClickThunk), this); |
118 GtkWidget* link_alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); | 118 GtkWidget* help_alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); |
119 gtk_container_add(GTK_CONTAINER(link_alignment), link); | 119 |
120 gtk_box_pack_start(GTK_BOX(vbox), link_alignment, FALSE, FALSE, 0); | 120 if (kind == CRASHED) { |
| 121 // Use a horizontal box to contain the help text and link. |
| 122 GtkWidget* help_hbox = gtk_hbox_new(FALSE, 0); |
| 123 gtk_container_add(GTK_CONTAINER(vbox), help_hbox); |
| 124 |
| 125 size_t offset = 0; |
| 126 string16 help_text(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE, |
| 127 string16(), &offset)); |
| 128 std::string help_prefix_text(UTF16ToUTF8(help_text.substr(0, offset))); |
| 129 std::string help_suffix_text(UTF16ToUTF8(help_text.substr(offset))); |
| 130 |
| 131 GtkWidget* help_prefix = MakeWhiteMarkupLabel( |
| 132 "<span style=\"normal\">%s</span>", help_prefix_text); |
| 133 GtkWidget* help_suffix = MakeWhiteMarkupLabel( |
| 134 "<span style=\"normal\">%s</span>", help_suffix_text); |
| 135 |
| 136 // Add the help link and text to the horizontal box. |
| 137 gtk_box_pack_start(GTK_BOX(help_hbox), help_prefix, FALSE, FALSE, 0); |
| 138 GtkWidget* link_alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); |
| 139 gtk_container_add(GTK_CONTAINER(link_alignment), link); |
| 140 gtk_box_pack_start(GTK_BOX(help_hbox), link_alignment, FALSE, FALSE, 0); |
| 141 gtk_box_pack_start(GTK_BOX(help_hbox), help_suffix, FALSE, FALSE, 0); |
| 142 } else { |
| 143 // Add just the help link to a centered alignment. |
| 144 gtk_container_add(GTK_CONTAINER(help_alignment), link); |
| 145 } |
| 146 gtk_box_pack_start(GTK_BOX(vbox), help_alignment, FALSE, FALSE, 0); |
121 } | 147 } |
122 | 148 |
123 gtk_widget_show_all(event_box_.get()); | 149 gtk_widget_show_all(event_box_.get()); |
124 } | 150 } |
125 | 151 |
126 SadTabGtk::~SadTabGtk() { | 152 SadTabGtk::~SadTabGtk() { |
127 event_box_.Destroy(); | 153 event_box_.Destroy(); |
128 } | 154 } |
129 | 155 |
130 void SadTabGtk::OnLinkButtonClick(GtkWidget* sender) { | 156 void SadTabGtk::OnLinkButtonClick(GtkWidget* sender) { |
131 if (tab_contents_ != NULL) { | 157 if (tab_contents_ != NULL) { |
132 GURL help_url = | 158 GURL help_url = |
133 google_util::AppendGoogleLocaleParam(GURL( | 159 google_util::AppendGoogleLocaleParam(GURL( |
134 kind_ == CRASHED ? | 160 kind_ == CRASHED ? |
135 chrome::kCrashReasonURL : | 161 chrome::kCrashReasonURL : |
136 chrome::kKillReasonURL)); | 162 chrome::kKillReasonURL)); |
137 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 163 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
138 } | 164 } |
139 } | 165 } |
OLD | NEW |