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

Side by Side Diff: chrome/browser/ui/views/sad_tab_view.cc

Issue 6053012: This adds a "killed tab" page and pages reload when killed on ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed indent Created 9 years, 11 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "third_party/skia/include/effects/SkGradientShader.h" 21 #include "third_party/skia/include/effects/SkGradientShader.h"
22 22
23 static const int kSadTabOffset = -64; 23 static const int kSadTabOffset = -64;
24 static const int kIconTitleSpacing = 20; 24 static const int kIconTitleSpacing = 20;
25 static const int kTitleMessageSpacing = 15; 25 static const int kTitleMessageSpacing = 15;
26 static const int kMessageBottomMargin = 20; 26 static const int kMessageBottomMargin = 20;
27 static const float kMessageSize = 0.65f; 27 static const float kMessageSize = 0.65f;
28 static const SkColor kTitleColor = SK_ColorWHITE; 28 static const SkColor kTitleColor = SK_ColorWHITE;
29 static const SkColor kMessageColor = SK_ColorWHITE; 29 static const SkColor kMessageColor = SK_ColorWHITE;
30 static const SkColor kLinkColor = SK_ColorWHITE; 30 static const SkColor kLinkColor = SK_ColorWHITE;
31 static const SkColor kBackgroundColor = SkColorSetRGB(35, 48, 64); 31 static const SkColor kCrashBackgroundColor = SkColorSetRGB(35, 48, 64);
32 static const SkColor kBackgroundEndColor = SkColorSetRGB(35, 48, 64); 32 static const SkColor kCrashBackgroundEndColor = SkColorSetRGB(35, 48, 64);
33 // TODO(gspencer): update these colors when the UI team has picked
34 // official versions. See http://crosbug.com/10711.
35 static const SkColor kKillBackgroundColor = SkColorSetRGB(57, 48, 88);
36 static const SkColor kKillBackgroundEndColor = SkColorSetRGB(57, 48, 88);
33 37
34 // Font size correction. 38 // Font size correction.
35 #if defined(CROS_FONTS_USING_BCI) 39 #if defined(CROS_FONTS_USING_BCI)
36 static const int kTitleFontSizeDelta = 1; 40 static const int kTitleFontSizeDelta = 1;
37 static const int kMessageFontSizeDelta = 0; 41 static const int kMessageFontSizeDelta = 0;
38 #else 42 #else
39 static const int kTitleFontSizeDelta = 2; 43 static const int kTitleFontSizeDelta = 2;
40 static const int kMessageFontSizeDelta = 1; 44 static const int kMessageFontSizeDelta = 1;
41 #endif 45 #endif
42 46
43 // static 47 // static
44 SkBitmap* SadTabView::sad_tab_bitmap_ = NULL; 48 SkBitmap* SadTabView::sad_tab_bitmap_ = NULL;
45 gfx::Font* SadTabView::title_font_ = NULL; 49 gfx::Font* SadTabView::title_font_ = NULL;
46 gfx::Font* SadTabView::message_font_ = NULL; 50 gfx::Font* SadTabView::message_font_ = NULL;
47 std::wstring SadTabView::title_; 51 std::wstring SadTabView::title_;
48 std::wstring SadTabView::message_; 52 std::wstring SadTabView::message_;
49 int SadTabView::title_width_; 53 int SadTabView::title_width_;
50 54
51 SadTabView::SadTabView(TabContents* tab_contents) 55 SadTabView::SadTabView(TabContents* tab_contents, Kind kind)
52 : tab_contents_(tab_contents), 56 : tab_contents_(tab_contents),
53 learn_more_link_(NULL) { 57 learn_more_link_(NULL),
58 kind_(kind) {
54 DCHECK(tab_contents); 59 DCHECK(tab_contents);
55 60
56 InitClass(); 61 InitClass(kind);
57 62
58 if (tab_contents != NULL) { 63 if (tab_contents != NULL) {
59 learn_more_link_ = 64 learn_more_link_ =
60 new views::Link(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE))); 65 new views::Link(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE)));
61 learn_more_link_->SetFont(*message_font_); 66 learn_more_link_->SetFont(*message_font_);
62 learn_more_link_->SetNormalColor(kLinkColor); 67 learn_more_link_->SetNormalColor(kLinkColor);
63 learn_more_link_->SetController(this); 68 learn_more_link_->SetController(this);
64 AddChildView(learn_more_link_); 69 AddChildView(learn_more_link_);
65 } 70 }
66 } 71 }
67 72
68 void SadTabView::Paint(gfx::Canvas* canvas) { 73 void SadTabView::Paint(gfx::Canvas* canvas) {
69 SkPaint paint; 74 SkPaint paint;
70 SkSafeUnref(paint.setShader(gfx::CreateGradientShader(0, height(), 75 SkSafeUnref(paint.setShader(
71 kBackgroundColor, 76 gfx::CreateGradientShader(
72 kBackgroundEndColor))); 77 0,
78 height(),
79 kind_ == CRASHED ? kCrashBackgroundColor : kKillBackgroundColor,
80 kind_ == CRASHED ?
81 kCrashBackgroundEndColor : kKillBackgroundEndColor)));
73 paint.setStyle(SkPaint::kFill_Style); 82 paint.setStyle(SkPaint::kFill_Style);
74 canvas->AsCanvasSkia()->drawRectCoords( 83 canvas->AsCanvasSkia()->drawRectCoords(
75 0, 0, SkIntToScalar(width()), SkIntToScalar(height()), paint); 84 0, 0, SkIntToScalar(width()), SkIntToScalar(height()), paint);
76 85
77 canvas->DrawBitmapInt(*sad_tab_bitmap_, icon_bounds_.x(), icon_bounds_.y()); 86 canvas->DrawBitmapInt(*sad_tab_bitmap_, icon_bounds_.x(), icon_bounds_.y());
78 87
79 canvas->DrawStringInt(WideToUTF16Hack(title_), *title_font_, kTitleColor, 88 canvas->DrawStringInt(WideToUTF16Hack(title_), *title_font_, kTitleColor,
80 title_bounds_.x(), title_bounds_.y(), 89 title_bounds_.x(), title_bounds_.y(),
81 title_bounds_.width(), title_bounds_.height(), 90 title_bounds_.width(), title_bounds_.height(),
82 gfx::Canvas::TEXT_ALIGN_CENTER); 91 gfx::Canvas::TEXT_ALIGN_CENTER);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 gfx::Insets insets = learn_more_link_->GetInsets(); 126 gfx::Insets insets = learn_more_link_->GetInsets();
118 link_bounds_.SetRect((width() - sz.width()) / 2, 127 link_bounds_.SetRect((width() - sz.width()) / 2,
119 message_bounds_.bottom() + kTitleMessageSpacing - 128 message_bounds_.bottom() + kTitleMessageSpacing -
120 insets.top(), sz.width(), sz.height()); 129 insets.top(), sz.width(), sz.height());
121 } 130 }
122 } 131 }
123 132
124 void SadTabView::LinkActivated(views::Link* source, int event_flags) { 133 void SadTabView::LinkActivated(views::Link* source, int event_flags) {
125 if (tab_contents_ != NULL && source == learn_more_link_) { 134 if (tab_contents_ != NULL && source == learn_more_link_) {
126 GURL help_url = 135 GURL help_url =
127 google_util::AppendGoogleLocaleParam(GURL(chrome::kCrashReasonURL)); 136 google_util::AppendGoogleLocaleParam(GURL(kind_ == CRASHED ?
137 chrome::kCrashReasonURL :
138 chrome::kKillReasonURL));
128 WindowOpenDisposition disposition(CURRENT_TAB); 139 WindowOpenDisposition disposition(CURRENT_TAB);
129 #if defined(OS_CHROMEOS) 140 #if defined(OS_CHROMEOS)
130 if (tab_contents_->delegate() && 141 if (tab_contents_->delegate() &&
131 tab_contents_->delegate()->IsPopup(tab_contents_)) { 142 tab_contents_->delegate()->IsPopup(tab_contents_)) {
132 // Popup windows are generally too small to effectively show help, 143 // Popup windows are generally too small to effectively show help,
133 // so open the help content in a new foregreound tab. 144 // so open the help content in a new foregreound tab.
134 disposition = NEW_FOREGROUND_TAB; 145 disposition = NEW_FOREGROUND_TAB;
135 } 146 }
136 #endif 147 #endif
137 tab_contents_->OpenURL(help_url, GURL(), disposition, PageTransition::LINK); 148 tab_contents_->OpenURL(help_url, GURL(), disposition, PageTransition::LINK);
138 } 149 }
139 } 150 }
140 151
141 // static 152 // static
142 void SadTabView::InitClass() { 153 void SadTabView::InitClass(Kind kind) {
143 static bool initialized = false; 154 static bool initialized = false;
144 if (!initialized) { 155 if (!initialized) {
145 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 156 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
146 title_font_ = new gfx::Font( 157 title_font_ = new gfx::Font(
147 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kTitleFontSizeDelta, 158 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kTitleFontSizeDelta,
148 gfx::Font::BOLD)); 159 gfx::Font::BOLD));
149 message_font_ = new gfx::Font( 160 message_font_ = new gfx::Font(
150 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kMessageFontSizeDelta)); 161 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(kMessageFontSizeDelta));
151 sad_tab_bitmap_ = rb.GetBitmapNamed(IDR_SAD_TAB); 162 sad_tab_bitmap_ = rb.GetBitmapNamed(
163 kind == CRASHED ? IDR_SAD_TAB : IDR_KILLED_TAB);
152 164
153 title_ = UTF16ToWide(l10n_util::GetStringUTF16(IDS_SAD_TAB_TITLE)); 165 title_ = UTF16ToWide(l10n_util::GetStringUTF16(
166 kind == CRASHED ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE));
154 title_width_ = title_font_->GetStringWidth(WideToUTF16Hack(title_)); 167 title_width_ = title_font_->GetStringWidth(WideToUTF16Hack(title_));
155 message_ = UTF16ToWide(l10n_util::GetStringUTF16(IDS_SAD_TAB_MESSAGE)); 168 message_ = UTF16ToWide(l10n_util::GetStringUTF16(
169 kind == CRASHED ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE));
156 170
157 initialized = true; 171 initialized = true;
158 } 172 }
159 } 173 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/sad_tab_view.h ('k') | chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698