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

Side by Side Diff: chrome/browser/ui/views/sad_tab_view.cc

Issue 7610011: Update Sad Tab help text and link. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge. Created 9 years, 3 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/views/sad_tab_view.h ('k') | chrome/chrome_browser.gypi » ('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) 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/views/sad_tab_view.h" 5 #include "chrome/browser/ui/views/sad_tab_view.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/google/google_util.h" 9 #include "chrome/browser/google/google_util.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/webui/bug_report_ui.h" 11 #include "chrome/browser/ui/webui/bug_report_ui.h"
12 #include "chrome/browser/userfeedback/proto/extension.pb.h" 12 #include "chrome/browser/userfeedback/proto/extension.pb.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "content/browser/tab_contents/tab_contents.h" 14 #include "content/browser/tab_contents/tab_contents.h"
15 #include "content/browser/tab_contents/tab_contents_delegate.h"
16 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
17 #include "grit/locale_settings.h"
18 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
19 #include "third_party/skia/include/effects/SkGradientShader.h"
20 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/canvas_skia.h"
24 #include "ui/gfx/font.h" 19 #include "ui/gfx/font.h"
25 #include "ui/gfx/size.h" 20 #include "views/controls/image_view.h"
26 #include "ui/gfx/skia_util.h" 21 #include "views/controls/label.h"
27 #include "views/controls/link.h" 22 #include "views/controls/link.h"
23 #include "views/layout/grid_layout.h"
28 24
29 static const int kSadTabOffset = -64; 25 static const int kPadding = 20;
30 static const int kIconTitleSpacing = 20;
31 static const int kTitleMessageSpacing = 15;
32 static const int kMessageBottomMargin = 20;
33 static const float kMessageSize = 0.65f; 26 static const float kMessageSize = 0.65f;
34 static const SkColor kTitleColor = SK_ColorWHITE; 27 static const SkColor kTextColor = SK_ColorWHITE;
35 static const SkColor kMessageColor = SK_ColorWHITE; 28 static const SkColor kCrashColor = SkColorSetRGB(35, 48, 64);
36 static const SkColor kLinkColor = SK_ColorWHITE; 29 static const SkColor kKillColor = SkColorSetRGB(57, 48, 88);
37 static const SkColor kCrashBackgroundColor = SkColorSetRGB(35, 48, 64);
38 static const SkColor kCrashBackgroundEndColor = SkColorSetRGB(35, 48, 64);
39 // TODO(gspencer): update these colors when the UI team has picked
40 // official versions. See http://crosbug.com/10711.
41 static const SkColor kKillBackgroundColor = SkColorSetRGB(57, 48, 88);
42 static const SkColor kKillBackgroundEndColor = SkColorSetRGB(57, 48, 88);
43 static const int kMessageFlags = gfx::Canvas::MULTI_LINE |
44 gfx::Canvas::NO_ELLIPSIS | gfx::Canvas::TEXT_ALIGN_CENTER;
45 30
46 // Font size correction. 31 // Font size correction.
47 #if defined(CROS_FONTS_USING_BCI) 32 #if defined(CROS_FONTS_USING_BCI)
48 static const int kTitleFontSizeDelta = 1; 33 static const int kTitleFontSizeDelta = 1;
49 static const int kMessageFontSizeDelta = 0; 34 static const int kMessageFontSizeDelta = 0;
50 #else 35 #else
51 static const int kTitleFontSizeDelta = 2; 36 static const int kTitleFontSizeDelta = 2;
52 static const int kMessageFontSizeDelta = 1; 37 static const int kMessageFontSizeDelta = 1;
53 #endif 38 #endif
54 39
55 SadTabView::SadTabView(TabContents* tab_contents, Kind kind) 40 SadTabView::SadTabView(TabContents* tab_contents, Kind kind)
56 : tab_contents_(tab_contents), 41 : tab_contents_(tab_contents),
57 learn_more_link_(NULL),
58 feedback_link_(NULL),
59 kind_(kind), 42 kind_(kind),
60 painted_(false) { 43 painted_(false),
44 message_(NULL),
45 help_link_(NULL),
46 feedback_link_(NULL) {
61 DCHECK(tab_contents); 47 DCHECK(tab_contents);
62 48
63 // Sometimes the user will never see this tab, so keep track of the total 49 // Sometimes the user will never see this tab, so keep track of the total
64 // number of creation events to compare to display events. 50 // number of creation events to compare to display events.
65 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind); 51 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind_);
66 52
67 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 53 // Set the background color.
68 title_font_ = new gfx::Font( 54 set_background(views::Background::CreateSolidBackground(
69 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kTitleFontSizeDelta, 55 (kind_ == CRASHED) ? kCrashColor : kKillColor));
70 gfx::Font::BOLD));
71 message_font_ = new gfx::Font(
72 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kMessageFontSizeDelta));
73 sad_tab_bitmap_ = rb.GetBitmapNamed(
74 kind == CRASHED ? IDR_SAD_TAB : IDR_KILLED_TAB);
75
76 title_ = l10n_util::GetStringUTF16(
77 kind == CRASHED ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE);
78 title_width_ = title_font_->GetStringWidth(title_);
79 message_ = l10n_util::GetStringUTF16(
80 kind == CRASHED ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE);
81
82 if (tab_contents != NULL) {
83 learn_more_link_ =
84 new views::Link(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE)));
85 learn_more_link_->SetFont(*message_font_);
86 learn_more_link_->SetNormalColor(kLinkColor);
87 learn_more_link_->set_listener(this);
88 AddChildView(learn_more_link_);
89
90 if (kind == KILLED) {
91 feedback_link_ = new views::Link(
92 UTF16ToWide(l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK)));
93 feedback_link_->SetFont(*message_font_);
94 feedback_link_->SetNormalColor(kLinkColor);
95 feedback_link_->set_listener(this);
96 AddChildView(feedback_link_);
97 }
98 }
99 } 56 }
100 57
101 SadTabView::~SadTabView() {} 58 SadTabView::~SadTabView() {}
102 59
103 void SadTabView::OnPaint(gfx::Canvas* canvas) {
104 if (!painted_) {
105 // User actually saw the error, keep track for user experience stats.
106 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_);
107 painted_ = true;
108 }
109 SkPaint paint;
110 SkSafeUnref(paint.setShader(
111 gfx::CreateGradientShader(
112 0,
113 height(),
114 kind_ == CRASHED ? kCrashBackgroundColor : kKillBackgroundColor,
115 kind_ == CRASHED ?
116 kCrashBackgroundEndColor : kKillBackgroundEndColor)));
117 paint.setStyle(SkPaint::kFill_Style);
118 canvas->AsCanvasSkia()->drawRectCoords(
119 0, 0, SkIntToScalar(width()), SkIntToScalar(height()), paint);
120
121 canvas->DrawBitmapInt(*sad_tab_bitmap_, icon_bounds_.x(), icon_bounds_.y());
122
123 canvas->DrawStringInt(title_, *title_font_, kTitleColor,
124 title_bounds_.x(), title_bounds_.y(),
125 title_bounds_.width(), title_bounds_.height(),
126 gfx::Canvas::TEXT_ALIGN_CENTER);
127
128 canvas->DrawStringInt(message_, *message_font_,
129 kMessageColor, message_bounds_.x(), message_bounds_.y(),
130 message_bounds_.width(), message_bounds_.height(),
131 kMessageFlags);
132
133 if (learn_more_link_ != NULL) {
134 learn_more_link_->SetBounds(
135 learn_more_bounds_.x(), learn_more_bounds_.y(),
136 learn_more_bounds_.width(), learn_more_bounds_.height());
137 }
138 if (feedback_link_ != NULL) {
139 feedback_link_->SetBounds(
140 feedback_bounds_.x(), feedback_bounds_.y(),
141 feedback_bounds_.width(), feedback_bounds_.height());
142 }
143 }
144
145 void SadTabView::Layout() {
146 int icon_width = sad_tab_bitmap_->width();
147 int icon_height = sad_tab_bitmap_->height();
148 int icon_x = (width() - icon_width) / 2;
149 int icon_y = ((height() - icon_height) / 2) + kSadTabOffset;
150 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height);
151
152 int title_x = (width() - title_width_) / 2;
153 int title_y = icon_bounds_.bottom() + kIconTitleSpacing;
154 int title_height = title_font_->GetHeight();
155 title_bounds_.SetRect(title_x, title_y, title_width_, title_height);
156
157 int message_width = static_cast<int>(width() * kMessageSize);
158 int message_height = 0;
159 gfx::CanvasSkia::SizeStringInt(message_,
160 *message_font_, &message_width,
161 &message_height, kMessageFlags);
162 int message_x = (width() - message_width) / 2;
163 int message_y = title_bounds_.bottom() + kTitleMessageSpacing;
164 message_bounds_.SetRect(message_x, message_y, message_width, message_height);
165 int bottom = message_bounds_.bottom();
166
167 if (learn_more_link_ != NULL) {
168 gfx::Size sz = learn_more_link_->GetPreferredSize();
169 gfx::Insets insets = learn_more_link_->GetInsets();
170 learn_more_bounds_.SetRect((width() - sz.width()) / 2,
171 bottom + kTitleMessageSpacing - insets.top(),
172 sz.width(),
173 sz.height());
174 bottom = learn_more_bounds_.bottom();
175 }
176
177 if (feedback_link_ != NULL) {
178 gfx::Size sz = feedback_link_->GetPreferredSize();
179 gfx::Insets insets = feedback_link_->GetInsets();
180 feedback_bounds_.SetRect((width() - sz.width()) / 2,
181 bottom + kTitleMessageSpacing - insets.top(),
182 sz.width(),
183 sz.height());
184 }
185 }
186
187 void SadTabView::LinkClicked(views::Link* source, int event_flags) { 60 void SadTabView::LinkClicked(views::Link* source, int event_flags) {
188 if (tab_contents_ != NULL && source == learn_more_link_) { 61 if (tab_contents_ != NULL && source == help_link_) {
189 GURL help_url = 62 GURL help_url =
190 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? 63 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ?
191 chrome::kCrashReasonURL : 64 chrome::kCrashReasonURL :
192 chrome::kKillReasonURL)); 65 chrome::kKillReasonURL));
193 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); 66 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK);
194 } else if (tab_contents_ != NULL && source == feedback_link_) { 67 } else if (tab_contents_ != NULL && source == feedback_link_) {
195 browser::ShowHtmlBugReportView( 68 browser::ShowHtmlBugReportView(
196 Browser::GetBrowserForController(&tab_contents_->controller(), NULL), 69 Browser::GetBrowserForController(&tab_contents_->controller(), NULL),
197 l10n_util::GetStringUTF8(IDS_KILLED_TAB_FEEDBACK_MESSAGE), 70 l10n_util::GetStringUTF8(IDS_KILLED_TAB_FEEDBACK_MESSAGE),
198 userfeedback::ChromeOsData_ChromeOsCategory_CRASH); 71 userfeedback::ChromeOsData_ChromeOsCategory_CRASH);
199 } 72 }
200 } 73 }
74
75 void SadTabView::Layout() {
76 // Specify the maximum message width explicitly.
77 message_->SizeToFit(static_cast<int>(width() * kMessageSize));
78 View::Layout();
79 }
80
81 void SadTabView::ViewHierarchyChanged(bool is_add,
82 views::View* parent,
83 views::View* child) {
84 if (child != this || !is_add)
85 return;
86
87 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
88 SetLayoutManager(layout);
89
90 const int column_set_id = 0;
91 views::ColumnSet* columns = layout->AddColumnSet(column_set_id);
92 columns->AddPaddingColumn(1, kPadding);
93 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
94 0, views::GridLayout::USE_PREF, 0, 0);
95 columns->AddPaddingColumn(1, kPadding);
96
97 views::ImageView* image = new views::ImageView();
98 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
99 image->SetImage(
100 rb.GetBitmapNamed((kind_ == CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB));
101 layout->StartRowWithPadding(0, column_set_id, 1, kPadding);
102 layout->AddView(image);
103
104 views::Label* title = new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(
105 (kind_ == CRASHED) ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE)));
106 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
107 title->SetFont(base_font.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD));
108 title->SetColor(kTextColor);
109 layout->StartRowWithPadding(0, column_set_id, 0, kPadding);
110 layout->AddView(title);
111
112 message_ = new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(
113 (kind_ == CRASHED) ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE)));
114 message_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
115 message_->SetColor(kTextColor);
116 message_->SetMultiLine(true);
117 layout->StartRowWithPadding(0, column_set_id, 0, kPadding);
118 layout->AddView(message_);
119
120 if (tab_contents_) {
121 std::wstring help_link(UTF16ToWide(l10n_util::GetStringUTF16(
122 (kind_ == CRASHED) ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE)));
123 help_link_ = new views::Link(help_link);
124 help_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
125 help_link_->SetNormalColor(kTextColor);
126 help_link_->set_listener(this);
127
128 if (kind_ == CRASHED) {
129 size_t offset = 0;
130 string16 help_text(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE,
131 string16(), &offset));
132 views::Label* help_prefix =
133 new views::Label(UTF16ToWide(help_text.substr(0, offset)));
134 help_prefix->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
135 help_prefix->SetColor(kTextColor);
136 views::Label* help_suffix =
137 new views::Label(UTF16ToWide(help_text.substr(offset)));
138 help_suffix->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
139 help_suffix->SetColor(kTextColor);
140
141 const int help_column_set_id = 1;
142 views::ColumnSet* help_columns = layout->AddColumnSet(help_column_set_id);
143 help_columns->AddPaddingColumn(1, kPadding);
144 // Center three middle columns for the help's [prefix][link][suffix].
145 for (size_t column = 0; column < 3; column++)
146 help_columns->AddColumn(views::GridLayout::CENTER,
147 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
148 help_columns->AddPaddingColumn(1, kPadding);
149
150 layout->StartRowWithPadding(0, help_column_set_id, 0, kPadding);
151 layout->AddView(help_prefix);
152 layout->AddView(help_link_);
153 layout->AddView(help_suffix);
154 } else {
155 layout->StartRowWithPadding(0, column_set_id, 0, kPadding);
156 layout->AddView(help_link_);
157
158 feedback_link_ = new views::Link(UTF16ToWide(
159 l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK)));
160 feedback_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
161 feedback_link_->SetNormalColor(kTextColor);
162 feedback_link_->set_listener(this);
163 layout->StartRowWithPadding(0, column_set_id, 0, kPadding);
164 layout->AddView(feedback_link_);
165 }
166 }
167 layout->AddPaddingRow(1, kPadding);
168 }
169
170 void SadTabView::OnPaint(gfx::Canvas* canvas) {
171 if (!painted_) {
172 // User actually saw the error, keep track for user experience stats.
173 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_);
174 painted_ = true;
175 }
176 View::OnPaint(canvas);
177 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/sad_tab_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698