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

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

Issue 10703110: browser/ui: Unify the enum Kind of SadTab used by SadTabViews and SabTabGtk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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/ui/gtk/sad_tab_gtk.h ('k') | chrome/browser/ui/sad_tab_helper.h » ('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) 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/sad_tab_gtk.h" 5 #include "chrome/browser/ui/gtk/sad_tab_gtk.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" 8 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
9 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 // Set text to white. 46 // Set text to white.
47 GdkColor white = ui::kGdkWhite; 47 GdkColor white = ui::kGdkWhite;
48 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &white); 48 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &white);
49 49
50 return label; 50 return label;
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 SadTabGtk::SadTabGtk(WebContents* web_contents, Kind kind) 55 SadTabGtk::SadTabGtk(WebContents* web_contents, chrome::SadTabKind kind)
56 : web_contents_(web_contents), 56 : web_contents_(web_contents),
57 kind_(kind) { 57 kind_(kind) {
58 DCHECK(web_contents_); 58 DCHECK(web_contents_);
59 59
60 // Use an event box to get the background painting correctly. 60 // Use an event box to get the background painting correctly.
61 event_box_.Own(gtk_event_box_new()); 61 event_box_.Own(gtk_event_box_new());
62 gtk_widget_modify_bg(event_box_.get(), GTK_STATE_NORMAL, 62 gtk_widget_modify_bg(event_box_.get(), GTK_STATE_NORMAL,
63 kind == CRASHED ? 63 (kind == chrome::SAD_TAB_KIND_CRASHED) ?
64 &kCrashedBackgroundColor : 64 &kCrashedBackgroundColor : &kKilledBackgroundColor);
65 &kKilledBackgroundColor);
66 // Allow ourselves to be resized arbitrarily small. 65 // Allow ourselves to be resized arbitrarily small.
67 gtk_widget_set_size_request(event_box_.get(), 0, 0); 66 gtk_widget_set_size_request(event_box_.get(), 0, 0);
68 67
69 GtkWidget* centering = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); 68 GtkWidget* centering = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
70 gtk_container_add(GTK_CONTAINER(event_box_.get()), centering); 69 gtk_container_add(GTK_CONTAINER(event_box_.get()), centering);
71 70
72 // Use a vertical box to contain icon, title, message and link. 71 // Use a vertical box to contain icon, title, message and link.
73 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); 72 GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
74 gtk_container_add(GTK_CONTAINER(centering), vbox); 73 gtk_container_add(GTK_CONTAINER(centering), vbox);
75 74
76 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 75 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
77 // Add center-aligned image. 76 // Add center-aligned image.
78 GtkWidget* image = gtk_image_new_from_pixbuf(rb.GetNativeImageNamed( 77 GtkWidget* image = gtk_image_new_from_pixbuf(rb.GetNativeImageNamed(
79 kind == CRASHED ? IDR_SAD_TAB : IDR_KILLED_TAB).ToGdkPixbuf()); 78 (kind == chrome::SAD_TAB_KIND_CRASHED) ?
79 IDR_SAD_TAB : IDR_KILLED_TAB).ToGdkPixbuf());
80 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5); 80 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5);
81 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); 81 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0);
82 82
83 // Add spacer between image and title. 83 // Add spacer between image and title.
84 GtkWidget* spacer = gtk_label_new(NULL); 84 GtkWidget* spacer = gtk_label_new(NULL);
85 gtk_label_set_markup(GTK_LABEL(spacer), "<span size=\"larger\"> </span>"); 85 gtk_label_set_markup(GTK_LABEL(spacer), "<span size=\"larger\"> </span>");
86 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); 86 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0);
87 87
88 // Add center-aligned title. 88 // Add center-aligned title.
89 GtkWidget* title = MakeWhiteMarkupLabel( 89 GtkWidget* title = MakeWhiteMarkupLabel(
90 "<span size=\"larger\" style=\"normal\"><b>%s</b></span>", 90 "<span size=\"larger\" style=\"normal\"><b>%s</b></span>",
91 l10n_util::GetStringUTF8(kind == CRASHED ? 91 l10n_util::GetStringUTF8((kind == chrome::SAD_TAB_KIND_CRASHED) ?
92 IDS_SAD_TAB_TITLE : 92 IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE));
93 IDS_KILLED_TAB_TITLE));
94 gtk_box_pack_start(GTK_BOX(vbox), title, FALSE, FALSE, 0); 93 gtk_box_pack_start(GTK_BOX(vbox), title, FALSE, FALSE, 0);
95 94
96 // Add spacer between title and message. 95 // Add spacer between title and message.
97 spacer = gtk_label_new(" "); 96 spacer = gtk_label_new(" ");
98 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); 97 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0);
99 98
100 // Add center-aligned message. 99 // Add center-aligned message.
101 GtkWidget* message = MakeWhiteMarkupLabel( 100 GtkWidget* message = MakeWhiteMarkupLabel(
102 "<span style=\"normal\">%s</span>", 101 "<span style=\"normal\">%s</span>",
103 l10n_util::GetStringUTF8(kind == CRASHED ? 102 l10n_util::GetStringUTF8((kind == chrome::SAD_TAB_KIND_CRASHED) ?
104 IDS_SAD_TAB_MESSAGE : 103 IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE));
105 IDS_KILLED_TAB_MESSAGE));
106 gtk_label_set_line_wrap(GTK_LABEL(message), TRUE); 104 gtk_label_set_line_wrap(GTK_LABEL(message), TRUE);
107 gtk_box_pack_start(GTK_BOX(vbox), message, FALSE, FALSE, 0); 105 gtk_box_pack_start(GTK_BOX(vbox), message, FALSE, FALSE, 0);
108 106
109 // Add spacer between message and link. 107 // Add spacer between message and link.
110 spacer = gtk_label_new(" "); 108 spacer = gtk_label_new(" ");
111 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0); 109 gtk_box_pack_start(GTK_BOX(vbox), spacer, FALSE, FALSE, 0);
112 110
113 if (web_contents_ != NULL) { 111 if (web_contents_) {
114 // Create the help link and alignment. 112 // Create the help link and alignment.
115 std::string link_text(l10n_util::GetStringUTF8( 113 std::string link_text(l10n_util::GetStringUTF8(
116 kind == CRASHED ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE)); 114 (kind == chrome::SAD_TAB_KIND_CRASHED) ?
115 IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE));
117 GtkWidget* link = gtk_chrome_link_button_new(link_text.c_str()); 116 GtkWidget* link = gtk_chrome_link_button_new(link_text.c_str());
118 gtk_chrome_link_button_set_normal_color(GTK_CHROME_LINK_BUTTON(link), 117 gtk_chrome_link_button_set_normal_color(GTK_CHROME_LINK_BUTTON(link),
119 &ui::kGdkWhite); 118 &ui::kGdkWhite);
120 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkButtonClickThunk), this); 119 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkButtonClickThunk), this);
121 GtkWidget* help_alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); 120 GtkWidget* help_alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
122 121
123 if (kind == CRASHED) { 122 if (kind == chrome::SAD_TAB_KIND_CRASHED) {
124 // Use a horizontal box to contain the help text and link. 123 // Use a horizontal box to contain the help text and link.
125 GtkWidget* help_hbox = gtk_hbox_new(FALSE, 0); 124 GtkWidget* help_hbox = gtk_hbox_new(FALSE, 0);
126 gtk_container_add(GTK_CONTAINER(vbox), help_hbox); 125 gtk_container_add(GTK_CONTAINER(vbox), help_hbox);
127 126
128 size_t offset = 0; 127 size_t offset = 0;
129 string16 help_text(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE, 128 string16 help_text(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE,
130 string16(), &offset)); 129 string16(), &offset));
131 std::string help_prefix_text(UTF16ToUTF8(help_text.substr(0, offset))); 130 std::string help_prefix_text(UTF16ToUTF8(help_text.substr(0, offset)));
132 std::string help_suffix_text(UTF16ToUTF8(help_text.substr(offset))); 131 std::string help_suffix_text(UTF16ToUTF8(help_text.substr(offset)));
133 132
(...skipping 16 matching lines...) Expand all
150 } 149 }
151 150
152 gtk_widget_show_all(event_box_.get()); 151 gtk_widget_show_all(event_box_.get());
153 } 152 }
154 153
155 SadTabGtk::~SadTabGtk() { 154 SadTabGtk::~SadTabGtk() {
156 event_box_.Destroy(); 155 event_box_.Destroy();
157 } 156 }
158 157
159 void SadTabGtk::OnLinkButtonClick(GtkWidget* sender) { 158 void SadTabGtk::OnLinkButtonClick(GtkWidget* sender) {
160 if (web_contents_ != NULL) { 159 if (web_contents_) {
161 GURL help_url( 160 GURL help_url((kind_ == chrome::SAD_TAB_KIND_CRASHED) ?
162 kind_ == CRASHED ? chrome::kCrashReasonURL : chrome::kKillReasonURL); 161 chrome::kCrashReasonURL : chrome::kKillReasonURL);
163 OpenURLParams params( 162 OpenURLParams params(help_url, content::Referrer(), CURRENT_TAB,
164 help_url, content::Referrer(), CURRENT_TAB, 163 content::PAGE_TRANSITION_LINK, false);
165 content::PAGE_TRANSITION_LINK, false);
166 web_contents_->OpenURL(params); 164 web_contents_->OpenURL(params);
167 } 165 }
168 } 166 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/sad_tab_gtk.h ('k') | chrome/browser/ui/sad_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698