Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(666)

Side by Side Diff: chrome/browser/gtk/sad_tab_gtk.cc

Issue 6053012: This adds a "killed tab" page and pages reload when killed on ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed indent Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/sad_tab_gtk.h ('k') | chrome/browser/renderer_host/site_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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/gtk/sad_tab_gtk.h" 5 #include "chrome/browser/gtk/sad_tab_gtk.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "chrome/browser/google/google_util.h" 11 #include "chrome/browser/google/google_util.h"
12 #include "chrome/browser/gtk/gtk_chrome_link_button.h" 12 #include "chrome/browser/gtk/gtk_chrome_link_button.h"
13 #include "chrome/browser/gtk/gtk_util.h" 13 #include "chrome/browser/gtk/gtk_util.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 14 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 #include "grit/locale_settings.h" 17 #include "grit/locale_settings.h"
18 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
19 19
20 namespace { 20 namespace {
21 21
22 // Background color of the content (a grayish blue). 22 // Background color of the content (a grayish blue) for a crashed tab.
23 const GdkColor kBackgroundColor = GDK_COLOR_RGB(35, 48, 64); 23 const GdkColor kCrashedBackgroundColor = GDK_COLOR_RGB(35, 48, 64);
24
25 // Background color of the content (a grayish purple) for a killed
26 // tab. TODO(gspencer): update this for the "real" color when the UI
27 // team provides one. See http://crosbug.com/10711
28 const GdkColor kKilledBackgroundColor = GDK_COLOR_RGB(57, 48, 88);
24 29
25 // Construct a centered GtkLabel with a white foreground. 30 // Construct a centered GtkLabel with a white foreground.
26 // |format| is a printf-style format containing a %s; 31 // |format| is a printf-style format containing a %s;
27 // |str| is substituted into the format. 32 // |str| is substituted into the format.
28 GtkWidget* MakeWhiteMarkupLabel(const char* format, const std::string& str) { 33 GtkWidget* MakeWhiteMarkupLabel(const char* format, const std::string& str) {
29 GtkWidget* label = gtk_label_new(NULL); 34 GtkWidget* label = gtk_label_new(NULL);
30 char* markup = g_markup_printf_escaped(format, str.c_str()); 35 char* markup = g_markup_printf_escaped(format, str.c_str());
36 UpdateLabelMarkup(label, format, str);
31 gtk_label_set_markup(GTK_LABEL(label), markup); 37 gtk_label_set_markup(GTK_LABEL(label), markup);
32 g_free(markup); 38 g_free(markup);
33 39
34 // Center align and justify it. 40 // Center align and justify it.
35 gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5); 41 gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
36 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER); 42 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
37 43
38 // Set text to white. 44 // Set text to white.
39 GdkColor white = gtk_util::kGdkWhite; 45 GdkColor white = gtk_util::kGdkWhite;
40 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &white); 46 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &white);
41 47
42 return label; 48 return label;
43 } 49 }
44 50
45 } // namespace 51 } // namespace
46 52
47 SadTabGtk::SadTabGtk(TabContents* tab_contents) 53 SadTabGtk::SadTabGtk(TabContents* tab_contents, Kind kind)
48 : tab_contents_(tab_contents) { 54 : tab_contents_(tab_contents),
55 kind_(kind) {
49 DCHECK(tab_contents_); 56 DCHECK(tab_contents_);
50 57
51 // Use an event box to get the background painting correctly. 58 // Use an event box to get the background painting correctly.
52 event_box_.Own(gtk_event_box_new()); 59 event_box_.Own(gtk_event_box_new());
53 gtk_widget_modify_bg(event_box_.get(), GTK_STATE_NORMAL, &kBackgroundColor); 60 gtk_widget_modify_bg(event_box_.get(), GTK_STATE_NORMAL,
61 kind == CRASHED ?
62 &kCrashedBackgroundColor :
63 &kKilledBackgroundColor);
54 // Allow ourselves to be resized arbitrarily small. 64 // Allow ourselves to be resized arbitrarily small.
55 gtk_widget_set_size_request(event_box_.get(), 0, 0); 65 gtk_widget_set_size_request(event_box_.get(), 0, 0);
56 66
57 GtkWidget* centering = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); 67 GtkWidget* centering = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
58 gtk_container_add(GTK_CONTAINER(event_box_.get()), centering); 68 gtk_container_add(GTK_CONTAINER(event_box_.get()), centering);
59 69
60 // Use a vertical box to contain icon, title, message and link. 70 // Use a vertical box to contain icon, title, message and link.
61 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); 71 GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
62 gtk_container_add(GTK_CONTAINER(centering), vbox); 72 gtk_container_add(GTK_CONTAINER(centering), vbox);
63 73
64 // Add center-aligned image. 74 // Add center-aligned image.
65 GtkWidget* image = gtk_image_new_from_pixbuf( 75 GtkWidget* image = gtk_image_new_from_pixbuf(
66 ResourceBundle::GetSharedInstance().GetPixbufNamed(IDR_SAD_TAB)); 76 ResourceBundle::GetSharedInstance().GetPixbufNamed(kind == CRASHED ?
77 IDR_SAD_TAB :
78 IDR_KILLED_TAB));
67 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5); 79 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5);
68 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); 80 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0);
69 81
70 // Add spacer between image and title. 82 // Add spacer between image and title.
71 GtkWidget* spacer = gtk_label_new(NULL); 83 GtkWidget* spacer = gtk_label_new(NULL);
72 gtk_label_set_markup(GTK_LABEL(spacer), "<span size=\"larger\"> </span>"); 84 gtk_label_set_markup(GTK_LABEL(spacer), "<span size=\"larger\"> </span>");
73 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); 85 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0);
74 86
75 // Add center-aligned title. 87 // Add center-aligned title.
76 GtkWidget* title = MakeWhiteMarkupLabel( 88 GtkWidget* title = MakeWhiteMarkupLabel(
77 "<span size=\"larger\" style=\"normal\"><b>%s</b></span>", 89 "<span size=\"larger\" style=\"normal\"><b>%s</b></span>",
78 l10n_util::GetStringUTF8(IDS_SAD_TAB_TITLE)); 90 l10n_util::GetStringUTF8(kind == CRASHED ?
91 IDS_SAD_TAB_TITLE :
92 IDS_KILLED_TAB_TITLE));
79 gtk_box_pack_start(GTK_BOX(vbox), title, FALSE, FALSE, 0); 93 gtk_box_pack_start(GTK_BOX(vbox), title, FALSE, FALSE, 0);
80 94
81 // Add spacer between title and message. 95 // Add spacer between title and message.
82 spacer = gtk_label_new(" "); 96 spacer = gtk_label_new(" ");
83 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); 97 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0);
84 98
85 // Add center-aligned message. 99 // Add center-aligned message.
86 GtkWidget* message = 100 GtkWidget* message = MakeWhiteMarkupLabel(
87 MakeWhiteMarkupLabel("<span style=\"normal\">%s</span>", 101 "<span style=\"normal\">%s</span>",
88 l10n_util::GetStringUTF8(IDS_SAD_TAB_MESSAGE)); 102 l10n_util::GetStringUTF8(kind == CRASHED ?
103 IDS_SAD_TAB_MESSAGE :
104 IDS_KILLED_TAB_MESSAGE));
89 gtk_label_set_line_wrap(GTK_LABEL(message), TRUE); 105 gtk_label_set_line_wrap(GTK_LABEL(message), TRUE);
90 gtk_box_pack_start(GTK_BOX(vbox), message, FALSE, FALSE, 0); 106 gtk_box_pack_start(GTK_BOX(vbox), message, FALSE, FALSE, 0);
91 107
92 // Add spacer between message and link. 108 // Add spacer between message and link.
93 spacer = gtk_label_new(" "); 109 spacer = gtk_label_new(" ");
94 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); 110 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0);
95 111
96 if (tab_contents_ != NULL) { 112 if (tab_contents_ != NULL) {
97 // Add the learn-more link and center-align it in an alignment. 113 // Add the learn-more link and center-align it in an alignment.
98 GtkWidget* link = gtk_chrome_link_button_new( 114 GtkWidget* link = gtk_chrome_link_button_new(
99 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); 115 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str());
100 gtk_chrome_link_button_set_normal_color(GTK_CHROME_LINK_BUTTON(link), 116 gtk_chrome_link_button_set_normal_color(GTK_CHROME_LINK_BUTTON(link),
101 &gtk_util::kGdkWhite); 117 &gtk_util::kGdkWhite);
102 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkButtonClickThunk), this); 118 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkButtonClickThunk), this);
103 GtkWidget* link_alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); 119 GtkWidget* link_alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
104 gtk_container_add(GTK_CONTAINER(link_alignment), link); 120 gtk_container_add(GTK_CONTAINER(link_alignment), link);
105 gtk_box_pack_start(GTK_BOX(vbox), link_alignment, FALSE, FALSE, 0); 121 gtk_box_pack_start(GTK_BOX(vbox), link_alignment, FALSE, FALSE, 0);
106 } 122 }
107 123
108 gtk_widget_show_all(event_box_.get()); 124 gtk_widget_show_all(event_box_.get());
109 } 125 }
110 126
111 SadTabGtk::~SadTabGtk() { 127 SadTabGtk::~SadTabGtk() {
112 event_box_.Destroy(); 128 event_box_.Destroy();
113 } 129 }
114 130
115 void SadTabGtk::OnLinkButtonClick(GtkWidget* sender) { 131 void SadTabGtk::OnLinkButtonClick(GtkWidget* sender) {
116 if (tab_contents_ != NULL) { 132 if (tab_contents_ != NULL) {
117 GURL help_url = 133 GURL help_url =
118 google_util::AppendGoogleLocaleParam(GURL(chrome::kCrashReasonURL)); 134 google_util::AppendGoogleLocaleParam(GURL(
135 kind_ == CRASHED ?
136 chrome::kCrashReasonURL :
137 chrome::kKillReasonURL));
119 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); 138 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK);
120 } 139 }
121 } 140 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/sad_tab_gtk.h ('k') | chrome/browser/renderer_host/site_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698