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/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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 static const int kMessageFontSizeDelta = 0; | 34 static const int kMessageFontSizeDelta = 0; |
35 #else | 35 #else |
36 static const int kTitleFontSizeDelta = 2; | 36 static const int kTitleFontSizeDelta = 2; |
37 static const int kMessageFontSizeDelta = 1; | 37 static const int kMessageFontSizeDelta = 1; |
38 #endif | 38 #endif |
39 | 39 |
40 SadTabView::SadTabView(TabContents* tab_contents, Kind kind) | 40 SadTabView::SadTabView(TabContents* tab_contents, Kind kind) |
41 : tab_contents_(tab_contents), | 41 : tab_contents_(tab_contents), |
42 kind_(kind), | 42 kind_(kind), |
43 painted_(false), | 43 painted_(false), |
| 44 base_font_(ResourceBundle::GetSharedInstance().GetFont( |
| 45 ResourceBundle::BaseFont)), |
44 message_(NULL), | 46 message_(NULL), |
45 help_link_(NULL), | 47 help_link_(NULL), |
46 feedback_link_(NULL) { | 48 feedback_link_(NULL) { |
47 DCHECK(tab_contents); | 49 DCHECK(tab_contents); |
48 | 50 |
49 // Sometimes the user will never see this tab, so keep track of the total | 51 // Sometimes the user will never see this tab, so keep track of the total |
50 // number of creation events to compare to display events. | 52 // number of creation events to compare to display events. |
51 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind_); | 53 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind_); |
52 | 54 |
53 // Set the background color. | 55 // Set the background color. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 SetLayoutManager(layout); | 90 SetLayoutManager(layout); |
89 | 91 |
90 const int column_set_id = 0; | 92 const int column_set_id = 0; |
91 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); | 93 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); |
92 columns->AddPaddingColumn(1, kPadding); | 94 columns->AddPaddingColumn(1, kPadding); |
93 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | 95 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
94 0, views::GridLayout::USE_PREF, 0, 0); | 96 0, views::GridLayout::USE_PREF, 0, 0); |
95 columns->AddPaddingColumn(1, kPadding); | 97 columns->AddPaddingColumn(1, kPadding); |
96 | 98 |
97 views::ImageView* image = new views::ImageView(); | 99 views::ImageView* image = new views::ImageView(); |
98 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 100 image->SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed( |
99 image->SetImage( | 101 (kind_ == CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB)); |
100 rb.GetBitmapNamed((kind_ == CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB)); | |
101 layout->StartRowWithPadding(0, column_set_id, 1, kPadding); | 102 layout->StartRowWithPadding(0, column_set_id, 1, kPadding); |
102 layout->AddView(image); | 103 layout->AddView(image); |
103 | 104 |
104 views::Label* title = new views::Label(l10n_util::GetStringUTF16( | 105 views::Label* title = CreateLabel(l10n_util::GetStringUTF16( |
105 (kind_ == CRASHED) ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE)); | 106 (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)); |
107 title->SetFont(base_font.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD)); | |
108 title->SetColor(kTextColor); | |
109 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 108 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
110 layout->AddView(title); | 109 layout->AddView(title); |
111 | 110 |
112 message_ = new views::Label(l10n_util::GetStringUTF16( | 111 message_ = CreateLabel(l10n_util::GetStringUTF16( |
113 (kind_ == CRASHED) ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE)); | 112 (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); | 113 message_->SetMultiLine(true); |
117 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 114 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
118 layout->AddView(message_); | 115 layout->AddView(message_); |
119 | 116 |
120 if (tab_contents_) { | 117 if (tab_contents_) { |
121 string16 help_link(l10n_util::GetStringUTF16( | 118 help_link_ = CreateLink(l10n_util::GetStringUTF16( |
122 (kind_ == CRASHED) ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE)); | 119 (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 | 120 |
128 if (kind_ == CRASHED) { | 121 if (kind_ == CRASHED) { |
129 size_t offset = 0; | 122 size_t offset = 0; |
130 string16 help_text(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE, | 123 string16 help_text(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE, |
131 string16(), &offset)); | 124 string16(), &offset)); |
132 views::Label* help_prefix = | 125 views::Label* help_prefix = CreateLabel(help_text.substr(0, offset)); |
133 new views::Label(help_text.substr(0, offset)); | 126 views::Label* help_suffix = CreateLabel(help_text.substr(offset)); |
134 help_prefix->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); | |
135 help_prefix->SetColor(kTextColor); | |
136 views::Label* help_suffix = new views::Label(help_text.substr(offset)); | |
137 help_suffix->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); | |
138 help_suffix->SetColor(kTextColor); | |
139 | 127 |
140 const int help_column_set_id = 1; | 128 const int help_column_set_id = 1; |
141 views::ColumnSet* help_columns = layout->AddColumnSet(help_column_set_id); | 129 views::ColumnSet* help_columns = layout->AddColumnSet(help_column_set_id); |
142 help_columns->AddPaddingColumn(1, kPadding); | 130 help_columns->AddPaddingColumn(1, kPadding); |
143 // Center three middle columns for the help's [prefix][link][suffix]. | 131 // Center three middle columns for the help's [prefix][link][suffix]. |
144 for (size_t column = 0; column < 3; column++) | 132 for (size_t column = 0; column < 3; column++) |
145 help_columns->AddColumn(views::GridLayout::CENTER, | 133 help_columns->AddColumn(views::GridLayout::CENTER, |
146 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | 134 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); |
147 help_columns->AddPaddingColumn(1, kPadding); | 135 help_columns->AddPaddingColumn(1, kPadding); |
148 | 136 |
149 layout->StartRowWithPadding(0, help_column_set_id, 0, kPadding); | 137 layout->StartRowWithPadding(0, help_column_set_id, 0, kPadding); |
150 layout->AddView(help_prefix); | 138 layout->AddView(help_prefix); |
151 layout->AddView(help_link_); | 139 layout->AddView(help_link_); |
152 layout->AddView(help_suffix); | 140 layout->AddView(help_suffix); |
153 } else { | 141 } else { |
154 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 142 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
155 layout->AddView(help_link_); | 143 layout->AddView(help_link_); |
156 | 144 |
157 feedback_link_ = new views::Link( | 145 feedback_link_ = CreateLink( |
158 l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK)); | 146 l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK)); |
159 feedback_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); | |
160 feedback_link_->SetNormalColor(kTextColor); | |
161 feedback_link_->set_listener(this); | |
162 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); | 147 layout->StartRowWithPadding(0, column_set_id, 0, kPadding); |
163 layout->AddView(feedback_link_); | 148 layout->AddView(feedback_link_); |
164 } | 149 } |
165 } | 150 } |
166 layout->AddPaddingRow(1, kPadding); | 151 layout->AddPaddingRow(1, kPadding); |
167 } | 152 } |
168 | 153 |
169 void SadTabView::OnPaint(gfx::Canvas* canvas) { | 154 void SadTabView::OnPaint(gfx::Canvas* canvas) { |
170 if (!painted_) { | 155 if (!painted_) { |
171 // User actually saw the error, keep track for user experience stats. | 156 // User actually saw the error, keep track for user experience stats. |
172 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_); | 157 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_); |
173 painted_ = true; | 158 painted_ = true; |
174 } | 159 } |
175 View::OnPaint(canvas); | 160 View::OnPaint(canvas); |
176 } | 161 } |
| 162 |
| 163 views::Label* SadTabView::CreateLabel(const string16& text) { |
| 164 views::Label* label = new views::Label(text); |
| 165 label->SetFont(base_font_.DeriveFont(kMessageFontSizeDelta)); |
| 166 label->SetBackgroundColor(background()->get_color()); |
| 167 label->SetEnabledColor(kTextColor); |
| 168 return label; |
| 169 } |
| 170 |
| 171 views::Link* SadTabView::CreateLink(const string16& text) { |
| 172 views::Link* link = new views::Link(text); |
| 173 link->SetFont(base_font_.DeriveFont(kMessageFontSizeDelta)); |
| 174 link->SetBackgroundColor(background()->get_color()); |
| 175 link->SetEnabledColor(kTextColor); |
| 176 link->set_listener(this); |
| 177 return link; |
| 178 } |
OLD | NEW |