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

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: Use views::GridLayout, address Cocoa comments. 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
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) {
sky 2011/09/01 03:38:55 Initialize all the new fields you're adding. In fa
msw 2011/09/01 16:27:42 Done.
61 DCHECK(tab_contents); 44 DCHECK(tab_contents);
62 45
63 // Sometimes the user will never see this tab, so keep track of the total 46 // Sometimes the user will never see this tab, so keep track of the total
64 // number of creation events to compare to display events. 47 // number of creation events to compare to display events.
65 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind); 48 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind_);
66 49
67 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 50 // Set the background color.
68 title_font_ = new gfx::Font( 51 set_background(views::Background::CreateSolidBackground(
69 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kTitleFontSizeDelta, 52 (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 } 53 }
100 54
101 SadTabView::~SadTabView() {} 55 SadTabView::~SadTabView() {}
102 56
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) { 57 void SadTabView::LinkClicked(views::Link* source, int event_flags) {
188 if (tab_contents_ != NULL && source == learn_more_link_) { 58 if (tab_contents_ != NULL && source == help_link_) {
189 GURL help_url = 59 GURL help_url =
190 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? 60 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ?
191 chrome::kCrashReasonURL : 61 chrome::kCrashReasonURL :
192 chrome::kKillReasonURL)); 62 chrome::kKillReasonURL));
193 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); 63 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK);
194 } else if (tab_contents_ != NULL && source == feedback_link_) { 64 } else if (tab_contents_ != NULL && source == feedback_link_) {
195 browser::ShowHtmlBugReportView( 65 browser::ShowHtmlBugReportView(
196 Browser::GetBrowserForController(&tab_contents_->controller(), NULL), 66 Browser::GetBrowserForController(&tab_contents_->controller(), NULL),
197 l10n_util::GetStringUTF8(IDS_KILLED_TAB_FEEDBACK_MESSAGE), 67 l10n_util::GetStringUTF8(IDS_KILLED_TAB_FEEDBACK_MESSAGE),
198 userfeedback::ChromeOsData_ChromeOsCategory_CRASH); 68 userfeedback::ChromeOsData_ChromeOsCategory_CRASH);
199 } 69 }
200 } 70 }
71
72 void SadTabView::Layout() {
73 // Specify the maximum message width explicitly.
74 message_->SizeToFit(static_cast<int>(width() * kMessageSize));
sky 2011/09/01 03:38:55 Is this needed? I suspect you don't need it or to
msw 2011/09/01 16:27:42 I wasn't able to get the text to SizeToFit expande
sky 2011/09/01 17:27:47 I believe that's because the column message_ ends
75 View::Layout();
76 }
77
78 void SadTabView::ViewHierarchyChanged(bool is_add,
79 views::View* parent,
80 views::View* child) {
81 if (child != this || !is_add)
82 return;
83
84 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
85 SetLayoutManager(layout);
86
87 const int column_set_id = 0;
88 views::ColumnSet* columns = layout->AddColumnSet(column_set_id);
89 columns->AddPaddingColumn(1, kPadding);
90 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
91 0, views::GridLayout::USE_PREF, 0, 0);
92 columns->AddPaddingColumn(1, kPadding);
93
94 image_ = new views::ImageView();
95 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
96 image_->SetImage(
97 rb.GetBitmapNamed((kind_ == CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB));
98 layout->StartRowWithPadding(0, column_set_id, 1, kPadding);
99 layout->AddView(image_);
100
101 title_ = new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(
102 (kind_ == CRASHED) ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE)));
103 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
104 title_->SetFont(base_font.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD));
105 title_->SetColor(kTextColor);
106 layout->StartRowWithPadding(0, column_set_id, 0, kPadding);
107 layout->AddView(title_);
108
109 message_ = new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(
110 (kind_ == CRASHED) ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE)));
111 message_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
112 message_->SetColor(kTextColor);
113 message_->SetMultiLine(true);
114 layout->StartRowWithPadding(0, column_set_id, 0, kPadding);
115 layout->AddView(message_);
116
117 if (tab_contents_) {
118 std::wstring help_link(UTF16ToWide(l10n_util::GetStringUTF16(
119 (kind_ == CRASHED) ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE)));
120 help_link_ = new views::Link(help_link);
121 help_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
122 help_link_->SetNormalColor(kTextColor);
123 help_link_->set_listener(this);
124
125 if (kind_ == CRASHED) {
126 size_t offset = 0;
127 string16 help_text(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE,
128 string16(), &offset));
129 help_prefix_ = new views::Label(UTF16ToWide(help_text.substr(0, offset)));
130 help_prefix_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
131 help_prefix_->SetColor(kTextColor);
132 help_suffix_ = new views::Label(UTF16ToWide(help_text.substr(offset)));
133 help_suffix_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
134 help_suffix_->SetColor(kTextColor);
135
136 const int help_column_set_id = 1;
137 views::ColumnSet* help_columns = layout->AddColumnSet(help_column_set_id);
138 help_columns->AddPaddingColumn(1, kPadding);
139 // Center three middle columns for the help's [prefix][link][suffix].
140 for (size_t column = 0; column < 3; column++)
141 help_columns->AddColumn(views::GridLayout::CENTER,
142 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
143 help_columns->AddPaddingColumn(1, kPadding);
144
145 layout->StartRowWithPadding(0, help_column_set_id, 0, kPadding);
146 layout->AddView(help_prefix_);
147 layout->AddView(help_link_);
148 layout->AddView(help_suffix_);
149 } else {
150 layout->StartRowWithPadding(0, column_set_id, 0, kPadding);
151 layout->AddView(help_link_);
152
153 feedback_link_ = new views::Link(UTF16ToWide(
154 l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK)));
155 feedback_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta));
156 feedback_link_->SetNormalColor(kTextColor);
157 feedback_link_->set_listener(this);
158 layout->StartRowWithPadding(0, column_set_id, 0, kPadding);
159 layout->AddView(feedback_link_);
160 }
161 }
162 layout->AddPaddingRow(1, kPadding);
163 }
164
165 void SadTabView::OnPaint(gfx::Canvas* canvas) {
166 if (!painted_) {
167 // User actually saw the error, keep track for user experience stats.
168 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_);
169 painted_ = true;
170 }
171 View::OnPaint(canvas);
172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698