Index: chrome/browser/ui/views/sad_tab_view.cc |
diff --git a/chrome/browser/ui/views/sad_tab_view.cc b/chrome/browser/ui/views/sad_tab_view.cc |
index b63879c8680c432a464e1ee402b0d6fea07997fa..ee869b167fdaa1449d894df49e8b5007e22a6e2c 100644 |
--- a/chrome/browser/ui/views/sad_tab_view.cc |
+++ b/chrome/browser/ui/views/sad_tab_view.cc |
@@ -12,36 +12,27 @@ |
#include "chrome/browser/userfeedback/proto/extension.pb.h" |
#include "chrome/common/url_constants.h" |
#include "content/browser/tab_contents/tab_contents.h" |
-#include "content/browser/tab_contents/tab_contents_delegate.h" |
#include "grit/generated_resources.h" |
-#include "grit/locale_settings.h" |
#include "grit/theme_resources.h" |
-#include "third_party/skia/include/effects/SkGradientShader.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/resource/resource_bundle.h" |
-#include "ui/gfx/canvas.h" |
-#include "ui/gfx/canvas_skia.h" |
#include "ui/gfx/font.h" |
-#include "ui/gfx/size.h" |
-#include "ui/gfx/skia_util.h" |
#include "views/controls/link.h" |
+#include "views/controls/label.h" |
+#include "views/controls/image_view.h" |
+#include "views/layout/box_layout.h" |
+#include "views/layout/center_layout.h" |
static const int kSadTabOffset = -64; |
-static const int kIconTitleSpacing = 20; |
-static const int kTitleMessageSpacing = 15; |
-static const int kMessageBottomMargin = 20; |
+static const int kSpacing = 20; |
static const float kMessageSize = 0.65f; |
-static const SkColor kTitleColor = SK_ColorWHITE; |
-static const SkColor kMessageColor = SK_ColorWHITE; |
-static const SkColor kLinkColor = SK_ColorWHITE; |
-static const SkColor kCrashBackgroundColor = SkColorSetRGB(35, 48, 64); |
-static const SkColor kCrashBackgroundEndColor = SkColorSetRGB(35, 48, 64); |
+static const SkColor kTextColor = SK_ColorWHITE; |
+static const SkColor kCrashColor1 = SkColorSetRGB(35, 48, 64); |
+static const SkColor kCrashColor2 = SkColorSetRGB(35, 48, 64); |
// TODO(gspencer): update these colors when the UI team has picked |
// official versions. See http://crosbug.com/10711. |
-static const SkColor kKillBackgroundColor = SkColorSetRGB(57, 48, 88); |
-static const SkColor kKillBackgroundEndColor = SkColorSetRGB(57, 48, 88); |
-static const int kMessageFlags = gfx::Canvas::MULTI_LINE | |
- gfx::Canvas::NO_ELLIPSIS | gfx::Canvas::TEXT_ALIGN_CENTER; |
+static const SkColor kKillColor1 = SkColorSetRGB(57, 48, 88); |
+static const SkColor kKillColor2 = SkColorSetRGB(57, 48, 88); |
// Font size correction. |
#if defined(CROS_FONTS_USING_BCI) |
@@ -54,46 +45,99 @@ static const int kMessageFontSizeDelta = 1; |
SadTabView::SadTabView(TabContents* tab_contents, Kind kind) |
: tab_contents_(tab_contents), |
- learn_more_link_(NULL), |
- feedback_link_(NULL), |
kind_(kind), |
- painted_(false) { |
+ painted_(false), |
+ contents_view_(new views::View()), |
+ image_(new views::ImageView()), |
+ title_(new views::Label()), |
+ message_view_(new views::View()), |
+ message_(new views::Label()) { |
DCHECK(tab_contents); |
// Sometimes the user will never see this tab, so keep track of the total |
// number of creation events to compare to display events. |
UMA_HISTOGRAM_COUNTS("SadTab.Created", kind); |
+ // Set the background gradient. |
+ SkColor color1 = (kind == CRASHED) ? kCrashColor1 : kKillColor1; |
+ SkColor color2 = (kind == CRASHED) ? kCrashColor2 : kKillColor2; |
+ set_background( |
+ views::Background::CreateVerticalGradientBackground(color1, color2)); |
+ |
+ // Center the actual contents in |contents_view_| within the SadTabView. |
+ SetLayoutManager(new views::CenterLayout()); |
+ contents_view_->SetLayoutManager( |
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, kSpacing)); |
+ AddChildView(contents_view_.get()); |
+ |
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
- title_font_ = new gfx::Font( |
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kTitleFontSizeDelta, |
- gfx::Font::BOLD)); |
- message_font_ = new gfx::Font( |
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kMessageFontSizeDelta)); |
- sad_tab_bitmap_ = rb.GetBitmapNamed( |
- kind == CRASHED ? IDR_SAD_TAB : IDR_KILLED_TAB); |
- |
- title_ = l10n_util::GetStringUTF16( |
- kind == CRASHED ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE); |
- title_width_ = title_font_->GetStringWidth(title_); |
- message_ = l10n_util::GetStringUTF16( |
- kind == CRASHED ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE); |
- |
- if (tab_contents != NULL) { |
- learn_more_link_ = |
- new views::Link(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE))); |
- learn_more_link_->SetFont(*message_font_); |
- learn_more_link_->SetNormalColor(kLinkColor); |
- learn_more_link_->set_listener(this); |
- AddChildView(learn_more_link_); |
- |
- if (kind == KILLED) { |
- feedback_link_ = new views::Link( |
- UTF16ToWide(l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK))); |
- feedback_link_->SetFont(*message_font_); |
- feedback_link_->SetNormalColor(kLinkColor); |
+ const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
+ |
+ int image_id = (kind == CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB; |
+ image_->SetImage(rb.GetBitmapNamed(image_id)); |
+ contents_view_->AddChildView(image_.get()); |
+ |
+ int title_id = (kind == CRASHED) ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE; |
+ title_->SetText(UTF16ToWide(l10n_util::GetStringUTF16(title_id))); |
+ title_->SetFont(base_font.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD)); |
+ title_->SetColor(kTextColor); |
+ contents_view_->AddChildView(title_.get()); |
+ |
+ int msg_id = (kind == CRASHED) ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE; |
+ message_->SetText(UTF16ToWide(l10n_util::GetStringUTF16(msg_id))); |
+ message_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); |
+ message_->SetColor(kTextColor); |
+ message_->SetMultiLine(true); |
+ // Center the label horizontally for when it's less wide than other views. |
+ // Otherwise, the box layout will expand the label to the full sad tab width. |
+ message_view_->SetLayoutManager(new views::CenterLayout()); |
+ message_view_->AddChildView(message_.get()); |
+ contents_view_->AddChildView(message_view_.get()); |
+ |
+ if (tab_contents) { |
+ size_t link_id = (kind == CRASHED) ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE; |
+ std::wstring help_link(UTF16ToWide(l10n_util::GetStringUTF16(link_id))); |
+ help_link_.reset(new views::Link(help_link)); |
+ help_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); |
+ help_link_->SetNormalColor(kTextColor); |
+ help_link_->set_listener(this); |
+ |
+ if (kind == CRASHED) { |
+ // |help_view_| centers |help_contents_view_|. |
+ help_view_.reset(new views::View()); |
+ help_view_->SetLayoutManager(new views::CenterLayout()); |
+ contents_view_->AddChildView(help_view_.get()); |
+ |
+ // |help_contents_view_| lays out [HELP PREFIX][HELP LINK][HELP SUFFIX]. |
+ help_contents_view_.reset(new views::View()); |
+ help_contents_view_->SetLayoutManager( |
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
+ help_view_->AddChildView(help_contents_view_.get()); |
+ |
+ size_t offset = 0; |
+ int help_id = IDS_SAD_TAB_HELP_MESSAGE; |
+ string16 help(l10n_util::GetStringFUTF16(help_id, string16(), &offset)); |
+ |
+ help_prefix_.reset(new views::Label(UTF16ToWide(help.substr(0, offset)))); |
+ help_prefix_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); |
+ help_prefix_->SetColor(kTextColor); |
+ help_contents_view_->AddChildView(help_prefix_.get()); |
+ |
+ help_contents_view_->AddChildView(help_link_.get()); |
+ |
+ help_suffix_.reset(new views::Label(UTF16ToWide(help.substr(offset)))); |
+ help_suffix_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); |
+ help_suffix_->SetColor(kTextColor); |
+ help_contents_view_->AddChildView(help_suffix_.get()); |
+ } else { |
+ contents_view_->AddChildView(help_link_.get()); |
+ |
+ feedback_link_.reset(new views::Link(UTF16ToWide( |
+ l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK)))); |
+ feedback_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); |
+ feedback_link_->SetNormalColor(kTextColor); |
feedback_link_->set_listener(this); |
- AddChildView(feedback_link_); |
+ contents_view_->AddChildView(feedback_link_.get()); |
} |
} |
} |
@@ -106,86 +150,19 @@ void SadTabView::OnPaint(gfx::Canvas* canvas) { |
UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_); |
painted_ = true; |
} |
- SkPaint paint; |
- SkSafeUnref(paint.setShader( |
- gfx::CreateGradientShader( |
- 0, |
- height(), |
- kind_ == CRASHED ? kCrashBackgroundColor : kKillBackgroundColor, |
- kind_ == CRASHED ? |
- kCrashBackgroundEndColor : kKillBackgroundEndColor))); |
- paint.setStyle(SkPaint::kFill_Style); |
- canvas->AsCanvasSkia()->drawRectCoords( |
- 0, 0, SkIntToScalar(width()), SkIntToScalar(height()), paint); |
- |
- canvas->DrawBitmapInt(*sad_tab_bitmap_, icon_bounds_.x(), icon_bounds_.y()); |
- |
- canvas->DrawStringInt(title_, *title_font_, kTitleColor, |
- title_bounds_.x(), title_bounds_.y(), |
- title_bounds_.width(), title_bounds_.height(), |
- gfx::Canvas::TEXT_ALIGN_CENTER); |
- |
- canvas->DrawStringInt(message_, *message_font_, |
- kMessageColor, message_bounds_.x(), message_bounds_.y(), |
- message_bounds_.width(), message_bounds_.height(), |
- kMessageFlags); |
- |
- if (learn_more_link_ != NULL) { |
- learn_more_link_->SetBounds( |
- learn_more_bounds_.x(), learn_more_bounds_.y(), |
- learn_more_bounds_.width(), learn_more_bounds_.height()); |
- } |
- if (feedback_link_ != NULL) { |
- feedback_link_->SetBounds( |
- feedback_bounds_.x(), feedback_bounds_.y(), |
- feedback_bounds_.width(), feedback_bounds_.height()); |
- } |
+ View::OnPaint(canvas); |
} |
-void SadTabView::Layout() { |
- int icon_width = sad_tab_bitmap_->width(); |
- int icon_height = sad_tab_bitmap_->height(); |
- int icon_x = (width() - icon_width) / 2; |
- int icon_y = ((height() - icon_height) / 2) + kSadTabOffset; |
- icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); |
- |
- int title_x = (width() - title_width_) / 2; |
- int title_y = icon_bounds_.bottom() + kIconTitleSpacing; |
- int title_height = title_font_->GetHeight(); |
- title_bounds_.SetRect(title_x, title_y, title_width_, title_height); |
- |
- int message_width = static_cast<int>(width() * kMessageSize); |
- int message_height = 0; |
- gfx::CanvasSkia::SizeStringInt(message_, |
- *message_font_, &message_width, |
- &message_height, kMessageFlags); |
- int message_x = (width() - message_width) / 2; |
- int message_y = title_bounds_.bottom() + kTitleMessageSpacing; |
- message_bounds_.SetRect(message_x, message_y, message_width, message_height); |
- int bottom = message_bounds_.bottom(); |
- |
- if (learn_more_link_ != NULL) { |
- gfx::Size sz = learn_more_link_->GetPreferredSize(); |
- gfx::Insets insets = learn_more_link_->GetInsets(); |
- learn_more_bounds_.SetRect((width() - sz.width()) / 2, |
- bottom + kTitleMessageSpacing - insets.top(), |
- sz.width(), |
- sz.height()); |
- bottom = learn_more_bounds_.bottom(); |
- } |
- if (feedback_link_ != NULL) { |
- gfx::Size sz = feedback_link_->GetPreferredSize(); |
- gfx::Insets insets = feedback_link_->GetInsets(); |
- feedback_bounds_.SetRect((width() - sz.width()) / 2, |
- bottom + kTitleMessageSpacing - insets.top(), |
- sz.width(), |
- sz.height()); |
- } |
+void SadTabView::Layout() { |
+ // Specify the maximum message width explicitly. |
+ message_->SizeToFit(static_cast<int>(width() * kMessageSize)); |
+ View::Layout(); |
} |
+ |
void SadTabView::LinkClicked(views::Link* source, int event_flags) { |
- if (tab_contents_ != NULL && source == learn_more_link_) { |
+ if (tab_contents_ != NULL && source == help_link_.get()) { |
GURL help_url = |
google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? |
chrome::kCrashReasonURL : |