OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/sad_tab_view.h" | 5 #include "chrome/browser/views/sad_tab_view.h" |
6 | 6 |
7 #include "base/gfx/size.h" | 7 #include "base/gfx/size.h" |
8 #include "chrome/common/gfx/chrome_canvas.h" | 8 #include "chrome/common/gfx/chrome_canvas.h" |
9 #include "chrome/common/l10n_util.h" | 9 #include "chrome/common/l10n_util.h" |
10 #include "chrome/common/resource_bundle.h" | 10 #include "chrome/common/resource_bundle.h" |
11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
13 #include "skia/ext/skia_utils.h" | 13 #include "skia/ext/skia_utils.h" |
14 #include "skia/include/SkGradientShader.h" | 14 #include "skia/include/SkGradientShader.h" |
15 | 15 |
16 static const int kSadTabOffset = -64; | 16 static const int kSadTabOffset = -64; |
17 static const int kIconTitleSpacing = 20; | 17 static const int kIconTitleSpacing = 20; |
18 static const int kTitleMessageSpacing = 15; | 18 static const int kTitleMessageSpacing = 15; |
19 static const int kMessageBottomMargin = 20; | 19 static const int kMessageBottomMargin = 20; |
20 static const float kMessageSize = 0.65f; | 20 static const float kMessageSize = 0.65f; |
21 static const SkColor kTitleColor = SK_ColorWHITE; | 21 static const SkColor kTitleColor = SK_ColorWHITE; |
22 static const SkColor kMessageColor = SK_ColorWHITE; | 22 static const SkColor kMessageColor = SK_ColorWHITE; |
23 static const SkColor kBackgroundColor = SkColorSetRGB(35, 48, 64); | 23 static const SkColor kBackgroundColor = SkColorSetRGB(35, 48, 64); |
24 static const SkColor kBackgroundEndColor = SkColorSetRGB(35, 48, 64); | 24 static const SkColor kBackgroundEndColor = SkColorSetRGB(35, 48, 64); |
25 | 25 |
26 // static | 26 // static |
27 SkBitmap* SadTabView::sad_tab_bitmap_ = NULL; | 27 SkBitmap* SadTabView::sad_tab_bitmap_ = NULL; |
28 ChromeFont SadTabView::title_font_; | 28 ChromeFont* SadTabView::title_font_ = NULL; |
29 ChromeFont SadTabView::message_font_; | 29 ChromeFont* SadTabView::message_font_ = NULL; |
30 std::wstring SadTabView::title_; | 30 std::wstring SadTabView::title_; |
31 std::wstring SadTabView::message_; | 31 std::wstring SadTabView::message_; |
32 int SadTabView::title_width_; | 32 int SadTabView::title_width_; |
33 | 33 |
34 SadTabView::SadTabView() { | 34 SadTabView::SadTabView() { |
35 InitClass(); | 35 InitClass(); |
36 } | 36 } |
37 | 37 |
38 void SadTabView::Paint(ChromeCanvas* canvas) { | 38 void SadTabView::Paint(ChromeCanvas* canvas) { |
39 SkPaint paint; | 39 SkPaint paint; |
40 paint.setShader(skia::CreateGradientShader(0, height(), | 40 paint.setShader(skia::CreateGradientShader(0, height(), |
41 kBackgroundColor, | 41 kBackgroundColor, |
42 kBackgroundEndColor))->safeUnref(); | 42 kBackgroundEndColor))->safeUnref(); |
43 paint.setStyle(SkPaint::kFill_Style); | 43 paint.setStyle(SkPaint::kFill_Style); |
44 canvas->drawRectCoords(0, 0, | 44 canvas->drawRectCoords(0, 0, |
45 SkIntToScalar(width()), SkIntToScalar(height()), | 45 SkIntToScalar(width()), SkIntToScalar(height()), |
46 paint); | 46 paint); |
47 | 47 |
48 canvas->DrawBitmapInt(*sad_tab_bitmap_, icon_bounds_.x(), icon_bounds_.y()); | 48 canvas->DrawBitmapInt(*sad_tab_bitmap_, icon_bounds_.x(), icon_bounds_.y()); |
49 | 49 |
50 canvas->DrawStringInt(title_, title_font_, kTitleColor, title_bounds_.x(), | 50 canvas->DrawStringInt(title_, *title_font_, kTitleColor, title_bounds_.x(), |
51 title_bounds_.y(), title_bounds_.width(), | 51 title_bounds_.y(), title_bounds_.width(), |
52 title_bounds_.height(), | 52 title_bounds_.height(), |
53 ChromeCanvas::TEXT_ALIGN_CENTER); | 53 ChromeCanvas::TEXT_ALIGN_CENTER); |
54 | 54 |
55 canvas->DrawStringInt(message_, message_font_, kMessageColor, | 55 canvas->DrawStringInt(message_, *message_font_, kMessageColor, |
56 message_bounds_.x(), message_bounds_.y(), | 56 message_bounds_.x(), message_bounds_.y(), |
57 message_bounds_.width(), message_bounds_.height(), | 57 message_bounds_.width(), message_bounds_.height(), |
58 ChromeCanvas::MULTI_LINE); | 58 ChromeCanvas::MULTI_LINE); |
59 } | 59 } |
60 | 60 |
61 void SadTabView::Layout() { | 61 void SadTabView::Layout() { |
62 int icon_width = sad_tab_bitmap_->width(); | 62 int icon_width = sad_tab_bitmap_->width(); |
63 int icon_height = sad_tab_bitmap_->height(); | 63 int icon_height = sad_tab_bitmap_->height(); |
64 int icon_x = (width() - icon_width) / 2; | 64 int icon_x = (width() - icon_width) / 2; |
65 int icon_y = ((height() - icon_height) / 2) + kSadTabOffset; | 65 int icon_y = ((height() - icon_height) / 2) + kSadTabOffset; |
66 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); | 66 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); |
67 | 67 |
68 int title_x = (width() - title_width_) / 2; | 68 int title_x = (width() - title_width_) / 2; |
69 int title_y = icon_bounds_.bottom() + kIconTitleSpacing; | 69 int title_y = icon_bounds_.bottom() + kIconTitleSpacing; |
70 int title_height = title_font_.height(); | 70 int title_height = title_font_->height(); |
71 title_bounds_.SetRect(title_x, title_y, title_width_, title_height); | 71 title_bounds_.SetRect(title_x, title_y, title_width_, title_height); |
72 | 72 |
73 ChromeCanvas cc(0, 0, true); | 73 ChromeCanvas cc(0, 0, true); |
74 int message_width = static_cast<int>(width() * kMessageSize); | 74 int message_width = static_cast<int>(width() * kMessageSize); |
75 int message_height = 0; | 75 int message_height = 0; |
76 cc.SizeStringInt(message_, message_font_, &message_width, &message_height, | 76 cc.SizeStringInt(message_, *message_font_, &message_width, &message_height, |
77 ChromeCanvas::MULTI_LINE); | 77 ChromeCanvas::MULTI_LINE); |
78 int message_x = (width() - message_width) / 2; | 78 int message_x = (width() - message_width) / 2; |
79 int message_y = title_bounds_.bottom() + kTitleMessageSpacing; | 79 int message_y = title_bounds_.bottom() + kTitleMessageSpacing; |
80 message_bounds_.SetRect(message_x, message_y, message_width, message_height); | 80 message_bounds_.SetRect(message_x, message_y, message_width, message_height); |
81 } | 81 } |
82 | 82 |
83 // static | 83 // static |
84 void SadTabView::InitClass() { | 84 void SadTabView::InitClass() { |
85 static bool initialized = false; | 85 static bool initialized = false; |
86 if (!initialized) { | 86 if (!initialized) { |
87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
88 title_font_ = rb.GetFont(ResourceBundle::BaseFont). | 88 title_font_ = new ChromeFont( |
89 DeriveFont(2, ChromeFont::BOLD); | 89 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(2, ChromeFont::BOLD)); |
90 message_font_ = rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1); | 90 message_font_ = new ChromeFont( |
| 91 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(1)); |
91 sad_tab_bitmap_ = rb.GetBitmapNamed(IDR_SAD_TAB); | 92 sad_tab_bitmap_ = rb.GetBitmapNamed(IDR_SAD_TAB); |
92 | 93 |
93 title_ = l10n_util::GetString(IDS_SAD_TAB_TITLE); | 94 title_ = l10n_util::GetString(IDS_SAD_TAB_TITLE); |
94 title_width_ = title_font_.GetStringWidth(title_); | 95 title_width_ = title_font_->GetStringWidth(title_); |
95 message_ = l10n_util::GetString(IDS_SAD_TAB_MESSAGE); | 96 message_ = l10n_util::GetString(IDS_SAD_TAB_MESSAGE); |
96 | 97 |
97 initialized = true; | 98 initialized = true; |
98 } | 99 } |
99 } | 100 } |
OLD | NEW |