Chromium Code Reviews| 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..371df466305dd083034b96aeaff8550c7f6a758e 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); |
|
Peter Kasting
2011/08/31 17:28:34
Seems like we can do away with one of the copies o
msw
2011/09/01 03:30:49
Done.
|
| +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,138 +45,25 @@ 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) { |
| 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); |
| + UMA_HISTOGRAM_COUNTS("SadTab.Created", kind_); |
| - 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); |
| - feedback_link_->set_listener(this); |
| - AddChildView(feedback_link_); |
| - } |
| - } |
| + // Set the background gradient. |
| + SkColor color1 = (kind_ == CRASHED) ? kCrashColor1 : kKillColor1; |
| + SkColor color2 = (kind_ == CRASHED) ? kCrashColor2 : kKillColor2; |
| + set_background( |
| + views::Background::CreateVerticalGradientBackground(color1, color2)); |
| } |
| SadTabView::~SadTabView() {} |
| -void SadTabView::OnPaint(gfx::Canvas* canvas) { |
| - if (!painted_) { |
| - // User actually saw the error, keep track for user experience stats. |
| - 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()); |
| - } |
| -} |
| - |
| -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::LinkClicked(views::Link* source, int event_flags) { |
| - if (tab_contents_ != NULL && source == learn_more_link_) { |
| + if (tab_contents_ != NULL && source == help_link_) { |
| GURL help_url = |
| google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ? |
| chrome::kCrashReasonURL : |
| @@ -198,3 +76,108 @@ void SadTabView::LinkClicked(views::Link* source, int event_flags) { |
| userfeedback::ChromeOsData_ChromeOsCategory_CRASH); |
| } |
| } |
| + |
| +void SadTabView::Layout() { |
| + // Specify the maximum message width explicitly. |
| + message_->SizeToFit(static_cast<int>(width() * kMessageSize)); |
| + // Layout centers |contents_view_| and |message_view_| in the SadTabView. |
| + View::Layout(); |
| + // Run |message_view_| layout explicity, to center |message_|. |
| + message_view_->Layout(); |
|
Peter Kasting
2011/08/31 17:28:34
Why is this necessary? Shouldn't the Layout() cal
msw
2011/09/01 03:30:49
I'm glad sky joined the review... The new GridLayo
|
| +} |
| + |
| +void SadTabView::ViewHierarchyChanged(bool is_add, |
| + views::View* parent, |
| + views::View* child) { |
| + if (child != this || !is_add) |
| + return; |
| + |
| + // Center the actual contents in |contents_view_| within the SadTabView. |
| + SetLayoutManager(new views::CenterLayout()); |
| + contents_view_ = new views::View(); |
| + contents_view_->SetLayoutManager( |
| + new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, kSpacing)); |
| + AddChildView(contents_view_); |
| + |
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
|
Peter Kasting
2011/08/31 17:28:34
Nit: Push each of these down to just above their f
msw
2011/09/01 03:30:49
Done.
|
| + const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
| + |
| + int image = (kind_ == CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB; |
|
Peter Kasting
2011/08/31 17:28:34
Nit: Just roll this into the call below and avoid
msw
2011/09/01 03:30:49
Done.
|
| + image_ = new views::ImageView(); |
| + image_->SetImage(rb.GetBitmapNamed(image)); |
| + contents_view_->AddChildView(image_); |
| + |
| + int title = (kind_ == CRASHED) ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE; |
| + title_ = new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(title))); |
| + title_->SetFont(base_font.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD)); |
| + title_->SetColor(kTextColor); |
| + contents_view_->AddChildView(title_); |
| + |
| + int msg = (kind_ == CRASHED) ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE; |
| + message_ = new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(msg))); |
| + 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_ = new views::View(); |
| + message_view_->SetLayoutManager(new views::CenterLayout()); |
| + message_view_->AddChildView(message_); |
| + contents_view_->AddChildView(message_view_); |
| + |
| + if (tab_contents_) { |
| + size_t link = (kind_ == CRASHED) ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE; |
| + std::wstring help_link(UTF16ToWide(l10n_util::GetStringUTF16(link))); |
| + help_link_ = 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_ = new views::View(); |
| + help_view_->SetLayoutManager(new views::CenterLayout()); |
| + contents_view_->AddChildView(help_view_); |
| + |
| + // |help_contents_view_| lays out [HELP PREFIX][HELP LINK][HELP SUFFIX]. |
| + help_contents_view_ = new views::View(); |
| + help_contents_view_->SetLayoutManager( |
| + new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| + help_view_->AddChildView(help_contents_view_); |
| + |
| + size_t offset = 0; |
| + int help = IDS_SAD_TAB_HELP_MESSAGE; |
| + string16 help_text(l10n_util::GetStringFUTF16(help, string16(), &offset)); |
| + |
| + help_prefix_ = new views::Label(UTF16ToWide(help_text.substr(0, offset))); |
| + help_prefix_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); |
| + help_prefix_->SetColor(kTextColor); |
| + help_contents_view_->AddChildView(help_prefix_); |
| + |
| + help_contents_view_->AddChildView(help_link_); |
| + |
| + help_suffix_ = new views::Label(UTF16ToWide(help_text.substr(offset))); |
| + help_suffix_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); |
| + help_suffix_->SetColor(kTextColor); |
| + help_contents_view_->AddChildView(help_suffix_); |
| + } else { |
| + contents_view_->AddChildView(help_link_); |
| + |
| + feedback_link_ = 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); |
| + contents_view_->AddChildView(feedback_link_); |
| + } |
| + } |
| +} |
| + |
| +void SadTabView::OnPaint(gfx::Canvas* canvas) { |
| + if (!painted_) { |
| + // User actually saw the error, keep track for user experience stats. |
| + UMA_HISTOGRAM_COUNTS("SadTab.Displayed", kind_); |
| + painted_ = true; |
| + } |
| + View::OnPaint(canvas); |
| +} |