| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/sad_tab_gtk.h" | 5 #include "chrome/browser/gtk/sad_tab_gtk.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/gfx/chrome_canvas.h" | 9 #include "app/gfx/canvas.h" |
| 10 #include "app/gfx/chrome_font.h" | 10 #include "app/gfx/font.h" |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 13 #include "base/gfx/size.h" | 13 #include "base/gfx/size.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "skia/ext/skia_utils.h" | 17 #include "skia/ext/skia_utils.h" |
| 18 #include "third_party/skia/include/effects/SkGradientShader.h" | 18 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 gboolean SadTabGtk::OnExposeThunk(GtkWidget* widget, | 76 gboolean SadTabGtk::OnExposeThunk(GtkWidget* widget, |
| 77 GdkEventExpose* event, | 77 GdkEventExpose* event, |
| 78 const SadTabGtk* sad_tab) { | 78 const SadTabGtk* sad_tab) { |
| 79 return sad_tab->OnExpose(widget, event); | 79 return sad_tab->OnExpose(widget, event); |
| 80 } | 80 } |
| 81 | 81 |
| 82 gboolean SadTabGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) const { | 82 gboolean SadTabGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) const { |
| 83 ChromeCanvasPaint canvas(event); | 83 gfx::CanvasPaint canvas(event); |
| 84 SkPaint paint; | 84 SkPaint paint; |
| 85 paint.setShader(skia::CreateGradientShader(0, height_, | 85 paint.setShader(skia::CreateGradientShader(0, height_, |
| 86 kBackgroundColor, | 86 kBackgroundColor, |
| 87 kBackgroundEndColor))->safeUnref(); | 87 kBackgroundEndColor))->safeUnref(); |
| 88 paint.setStyle(SkPaint::kFill_Style); | 88 paint.setStyle(SkPaint::kFill_Style); |
| 89 canvas.drawRectCoords(0, 0, | 89 canvas.drawRectCoords(0, 0, |
| 90 SkIntToScalar(width_), | 90 SkIntToScalar(width_), |
| 91 SkIntToScalar(height_), | 91 SkIntToScalar(height_), |
| 92 paint); | 92 paint); |
| 93 | 93 |
| 94 const SadTabGtkConstants& sad_tab_constants = | 94 const SadTabGtkConstants& sad_tab_constants = |
| 95 g_sad_tab_constants.Get(); | 95 g_sad_tab_constants.Get(); |
| 96 | 96 |
| 97 // Paint the sad tab icon. | 97 // Paint the sad tab icon. |
| 98 canvas.DrawBitmapInt(*sad_tab_constants.sad_tab_bitmap, | 98 canvas.DrawBitmapInt(*sad_tab_constants.sad_tab_bitmap, |
| 99 icon_bounds_.x(), | 99 icon_bounds_.x(), |
| 100 icon_bounds_.y()); | 100 icon_bounds_.y()); |
| 101 | 101 |
| 102 // Paint the "Aw, snap!" | 102 // Paint the "Aw, snap!" |
| 103 canvas.DrawStringInt(sad_tab_constants.title, | 103 canvas.DrawStringInt(sad_tab_constants.title, |
| 104 sad_tab_constants.title_font, | 104 sad_tab_constants.title_font, |
| 105 kTitleTextColor, | 105 kTitleTextColor, |
| 106 0, | 106 0, |
| 107 title_y_, | 107 title_y_, |
| 108 width_, | 108 width_, |
| 109 sad_tab_constants.title_font.height(), | 109 sad_tab_constants.title_font.height(), |
| 110 ChromeCanvas::TEXT_ALIGN_CENTER); | 110 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 111 | 111 |
| 112 // Paint the explanatory message. | 112 // Paint the explanatory message. |
| 113 canvas.DrawStringInt( | 113 canvas.DrawStringInt( |
| 114 sad_tab_constants.message, | 114 sad_tab_constants.message, |
| 115 sad_tab_constants.message_font, | 115 sad_tab_constants.message_font, |
| 116 kMessageTextColor, | 116 kMessageTextColor, |
| 117 0, | 117 0, |
| 118 message_y_, | 118 message_y_, |
| 119 width_, | 119 width_, |
| 120 99999, // Let the height be large, and we'll clip if needed. | 120 99999, // Let the height be large, and we'll clip if needed. |
| 121 ChromeCanvas::TEXT_ALIGN_CENTER | | 121 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 122 ChromeCanvas::MULTI_LINE | | 122 gfx::Canvas::MULTI_LINE | |
| 123 ChromeCanvas::TEXT_VALIGN_TOP); | 123 gfx::Canvas::TEXT_VALIGN_TOP); |
| 124 | 124 |
| 125 return TRUE; | 125 return TRUE; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // static | 128 // static |
| 129 gboolean SadTabGtk::OnConfigureThunk(GtkWidget* widget, | 129 gboolean SadTabGtk::OnConfigureThunk(GtkWidget* widget, |
| 130 GdkEventConfigure* event, | 130 GdkEventConfigure* event, |
| 131 SadTabGtk* sad_tab) { | 131 SadTabGtk* sad_tab) { |
| 132 return sad_tab->OnConfigure(widget, event); | 132 return sad_tab->OnConfigure(widget, event); |
| 133 } | 133 } |
| 134 | 134 |
| 135 gboolean SadTabGtk::OnConfigure(GtkWidget* widget, GdkEventConfigure* event) { | 135 gboolean SadTabGtk::OnConfigure(GtkWidget* widget, GdkEventConfigure* event) { |
| 136 const SadTabGtkConstants& sad_tab_constants = | 136 const SadTabGtkConstants& sad_tab_constants = |
| 137 g_sad_tab_constants.Get(); | 137 g_sad_tab_constants.Get(); |
| 138 width_ = event->width; | 138 width_ = event->width; |
| 139 height_= event->height; | 139 height_= event->height; |
| 140 int icon_width = sad_tab_constants.sad_tab_bitmap->width(); | 140 int icon_width = sad_tab_constants.sad_tab_bitmap->width(); |
| 141 int icon_height = sad_tab_constants.sad_tab_bitmap->height(); | 141 int icon_height = sad_tab_constants.sad_tab_bitmap->height(); |
| 142 int icon_x = (event->width - icon_width) / 2; | 142 int icon_x = (event->width - icon_width) / 2; |
| 143 int icon_y = ((event->height - icon_height) / 2) + kSadTabOffset; | 143 int icon_y = ((event->height - icon_height) / 2) + kSadTabOffset; |
| 144 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); | 144 icon_bounds_.SetRect(icon_x, icon_y, icon_width, icon_height); |
| 145 | 145 |
| 146 title_y_ = | 146 title_y_ = |
| 147 icon_bounds_.bottom() + kIconTitleSpacing; | 147 icon_bounds_.bottom() + kIconTitleSpacing; |
| 148 int title_height = sad_tab_constants.title_font.height(); | 148 int title_height = sad_tab_constants.title_font.height(); |
| 149 message_y_ = | 149 message_y_ = |
| 150 title_y_ + title_height + kTitleMessageSpacing; | 150 title_y_ + title_height + kTitleMessageSpacing; |
| 151 return TRUE; | 151 return TRUE; |
| 152 } | 152 } |
| OLD | NEW |