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/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #if defined(CROS_FONTS_USING_BCI) | 44 #if defined(CROS_FONTS_USING_BCI) |
45 static const int kTitleFontSizeDelta = 1; | 45 static const int kTitleFontSizeDelta = 1; |
46 static const int kMessageFontSizeDelta = 0; | 46 static const int kMessageFontSizeDelta = 0; |
47 #else | 47 #else |
48 static const int kTitleFontSizeDelta = 2; | 48 static const int kTitleFontSizeDelta = 2; |
49 static const int kMessageFontSizeDelta = 1; | 49 static const int kMessageFontSizeDelta = 1; |
50 #endif | 50 #endif |
51 | 51 |
52 SadTabView::SadTabView(TabContents* tab_contents, Kind kind) | 52 SadTabView::SadTabView(TabContents* tab_contents, Kind kind) |
53 : tab_contents_(tab_contents), | 53 : tab_contents_(tab_contents), |
54 learn_more_link_(NULL), | 54 help_link_(NULL), |
55 kind_(kind), | 55 kind_(kind), |
56 painted_(false) { | 56 painted_(false) { |
57 DCHECK(tab_contents); | 57 DCHECK(tab_contents); |
58 | 58 |
59 // Sometimes the user will never see this tab, so keep track of the total | 59 // Sometimes the user will never see this tab, so keep track of the total |
60 // number of creation events to compare to display events. | 60 // number of creation events to compare to display events. |
61 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind); | 61 UMA_HISTOGRAM_COUNTS("SadTab.Created", kind); |
62 | 62 |
63 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 63 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
64 title_font_ = new gfx::Font( | 64 title_font_ = new gfx::Font( |
65 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kTitleFontSizeDelta, | 65 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kTitleFontSizeDelta, |
66 gfx::Font::BOLD)); | 66 gfx::Font::BOLD)); |
67 message_font_ = new gfx::Font( | 67 message_font_ = new gfx::Font( |
68 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kMessageFontSizeDelta)); | 68 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kMessageFontSizeDelta)); |
69 sad_tab_bitmap_ = rb.GetBitmapNamed( | 69 sad_tab_bitmap_ = rb.GetBitmapNamed( |
70 kind == CRASHED ? IDR_SAD_TAB : IDR_KILLED_TAB); | 70 kind == CRASHED ? IDR_SAD_TAB : IDR_KILLED_TAB); |
71 | 71 |
72 title_ = l10n_util::GetStringUTF16( | 72 title_ = l10n_util::GetStringUTF16( |
73 kind == CRASHED ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE); | 73 kind == CRASHED ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE); |
74 title_width_ = title_font_->GetStringWidth(title_); | 74 title_width_ = title_font_->GetStringWidth(title_); |
75 message_ = l10n_util::GetStringUTF16( | 75 message_ = l10n_util::GetStringUTF16( |
76 kind == CRASHED ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE); | 76 kind == CRASHED ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE); |
77 | 77 |
78 if (tab_contents != NULL) { | 78 if (tab_contents != NULL) { |
79 learn_more_link_ = | 79 if (kind == CRASHED) { |
80 new views::Link(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE))); | 80 size_t offset = 0; |
81 learn_more_link_->SetFont(*message_font_); | 81 string16 help(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE, |
82 learn_more_link_->SetNormalColor(kLinkColor); | 82 string16(), &offset)); |
83 learn_more_link_->set_listener(this); | 83 help_prefix_ = help.substr(0, offset); |
84 AddChildView(learn_more_link_); | 84 help_suffix_ = help.substr(offset); |
| 85 } |
| 86 help_link_ = new views::Link(UTF16ToWide(l10n_util::GetStringUTF16( |
| 87 kind == CRASHED ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE))); |
| 88 help_link_->SetFont(*message_font_); |
| 89 help_link_->SetNormalColor(kLinkColor); |
| 90 help_link_->set_listener(this); |
| 91 AddChildView(help_link_); |
85 } | 92 } |
86 } | 93 } |
87 | 94 |
88 SadTabView::~SadTabView() {} | 95 SadTabView::~SadTabView() {} |
89 | 96 |
90 void SadTabView::OnPaint(gfx::Canvas* canvas) { | 97 void SadTabView::OnPaint(gfx::Canvas* canvas) { |
91 if (!painted_) { | 98 if (!painted_) { |
92 // User actually saw the error, keep track for user experience stats. | 99 // User actually saw the error, keep track for user experience stats. |
93 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_); | 100 UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_); |
94 painted_ = true; | 101 painted_ = true; |
(...skipping 15 matching lines...) Expand all Loading... |
110 canvas->DrawStringInt(title_, *title_font_, kTitleColor, | 117 canvas->DrawStringInt(title_, *title_font_, kTitleColor, |
111 title_bounds_.x(), title_bounds_.y(), | 118 title_bounds_.x(), title_bounds_.y(), |
112 title_bounds_.width(), title_bounds_.height(), | 119 title_bounds_.width(), title_bounds_.height(), |
113 gfx::Canvas::TEXT_ALIGN_CENTER); | 120 gfx::Canvas::TEXT_ALIGN_CENTER); |
114 | 121 |
115 canvas->DrawStringInt(message_, *message_font_, | 122 canvas->DrawStringInt(message_, *message_font_, |
116 kMessageColor, message_bounds_.x(), message_bounds_.y(), | 123 kMessageColor, message_bounds_.x(), message_bounds_.y(), |
117 message_bounds_.width(), message_bounds_.height(), | 124 message_bounds_.width(), message_bounds_.height(), |
118 kMessageFlags); | 125 kMessageFlags); |
119 | 126 |
120 if (learn_more_link_ != NULL) | 127 if (help_link_ != NULL) { |
121 learn_more_link_->SetBounds(link_bounds_.x(), link_bounds_.y(), | 128 if (kind_ == CRASHED) { |
122 link_bounds_.width(), link_bounds_.height()); | 129 canvas->DrawStringInt(help_prefix_, *message_font_, kMessageColor, |
| 130 help_prefix_bounds_.x(), help_prefix_bounds_.y(), |
| 131 help_prefix_bounds_.width(), help_prefix_bounds_.height(), |
| 132 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 133 |
| 134 canvas->DrawStringInt(help_suffix_, *message_font_, kMessageColor, |
| 135 help_suffix_bounds_.x(), help_suffix_bounds_.y(), |
| 136 help_suffix_bounds_.width(), help_suffix_bounds_.height(), |
| 137 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 138 } |
| 139 help_link_->SetBounds(help_link_bounds_.x(), help_link_bounds_.y(), |
| 140 help_link_bounds_.width(), help_link_bounds_.height()); |
| 141 } |
123 } | 142 } |
124 | 143 |
125 void SadTabView::Layout() { | 144 void SadTabView::Layout() { |
126 int icon_width = sad_tab_bitmap_->width(); | 145 int icon_width = sad_tab_bitmap_->width(); |
127 int icon_height = sad_tab_bitmap_->height(); | 146 int icon_height = sad_tab_bitmap_->height(); |
128 int icon_x = (width() - icon_width) / 2; | 147 int icon_x = (width() - icon_width) / 2; |
129 int icon_y = ((height() - icon_height) / 2) + kSadTabOffset; | 148 int icon_y = ((height() - icon_height) / 2) + kSadTabOffset; |
130 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); | 149 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); |
131 | 150 |
132 int title_x = (width() - title_width_) / 2; | 151 int title_x = (width() - title_width_) / 2; |
133 int title_y = icon_bounds_.bottom() + kIconTitleSpacing; | 152 int title_y = icon_bounds_.bottom() + kIconTitleSpacing; |
134 int title_height = title_font_->GetHeight(); | 153 int title_height = title_font_->GetHeight(); |
135 title_bounds_.SetRect(title_x, title_y, title_width_, title_height); | 154 title_bounds_.SetRect(title_x, title_y, title_width_, title_height); |
136 | 155 |
137 int message_width = static_cast<int>(width() * kMessageSize); | 156 int message_width = static_cast<int>(width() * kMessageSize); |
138 int message_height = 0; | 157 int message_height = 0; |
139 gfx::CanvasSkia::SizeStringInt(message_, | 158 gfx::CanvasSkia::SizeStringInt(message_, |
140 *message_font_, &message_width, | 159 *message_font_, &message_width, |
141 &message_height, kMessageFlags); | 160 &message_height, kMessageFlags); |
142 int message_x = (width() - message_width) / 2; | 161 int message_x = (width() - message_width) / 2; |
143 int message_y = title_bounds_.bottom() + kTitleMessageSpacing; | 162 int message_y = title_bounds_.bottom() + kTitleMessageSpacing; |
144 message_bounds_.SetRect(message_x, message_y, message_width, message_height); | 163 message_bounds_.SetRect(message_x, message_y, message_width, message_height); |
145 | 164 |
146 if (learn_more_link_ != NULL) { | 165 if (help_link_ != NULL) { |
147 gfx::Size sz = learn_more_link_->GetPreferredSize(); | 166 gfx::Size link_size = help_link_->GetPreferredSize(); |
148 gfx::Insets insets = learn_more_link_->GetInsets(); | 167 gfx::Insets link_insets = help_link_->GetInsets(); |
149 link_bounds_.SetRect((width() - sz.width()) / 2, | 168 int y = message_bounds_.bottom() + kTitleMessageSpacing; |
150 message_bounds_.bottom() + kTitleMessageSpacing - | 169 if (kind_ == CRASHED) { |
151 insets.top(), sz.width(), sz.height()); | 170 // Layout [HELP PREFIX][HELP LINK][HELP SUFFIX] centered. |
| 171 int help_height = message_font_->GetHeight(); |
| 172 int prefix_width = message_font_->GetStringWidth(help_prefix_); |
| 173 int suffix_width = message_font_->GetStringWidth(help_suffix_); |
| 174 int offset = width() - link_size.width() - prefix_width - suffix_width; |
| 175 offset /= 2; |
| 176 help_prefix_bounds_.SetRect(offset, y, prefix_width, help_height); |
| 177 offset += prefix_width; |
| 178 help_link_bounds_.SetRect(offset, y - link_insets.top(), |
| 179 link_size.width(), link_size.height()); |
| 180 offset += link_size.width(); |
| 181 help_suffix_bounds_.SetRect(offset, y, suffix_width, help_height); |
| 182 } else { |
| 183 help_link_bounds_.SetRect((width() - link_size.width()) / 2, |
| 184 y - link_insets.top(), link_size.width(), link_size.height()); |
| 185 } |
152 } | 186 } |
153 } | 187 } |
154 | 188 |
155 void SadTabView::LinkClicked(views::Link* source, int event_flags) { | 189 void SadTabView::LinkClicked(views::Link* source, int event_flags) { |
156 if (tab_contents_ != NULL && source == learn_more_link_) { | 190 if (tab_contents_ != NULL && source == help_link_) { |
157 GURL help_url = | 191 GURL help_url = |
158 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? | 192 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? |
159 chrome::kCrashReasonURL : | 193 chrome::kCrashReasonURL : |
160 chrome::kKillReasonURL)); | 194 chrome::kKillReasonURL)); |
161 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 195 tab_contents_->OpenURL(help_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
162 } | 196 } |
163 } | 197 } |
OLD | NEW |