OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/common/extensions/extension_action.h" | 5 #include "chrome/common/extensions/extension_action.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
12 #include "gfx/canvas.h" | 12 #include "gfx/canvas_skia.h" |
13 #include "gfx/font.h" | 13 #include "gfx/font.h" |
14 #include "gfx/rect.h" | 14 #include "gfx/rect.h" |
15 #include "grit/app_resources.h" | 15 #include "grit/app_resources.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
17 #include "third_party/skia/include/core/SkTypeface.h" | 17 #include "third_party/skia/include/core/SkTypeface.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 { |
21 | 21 |
22 // Different platforms need slightly different constants to look good. | 22 // Different platforms need slightly different constants to look good. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 SkColor text_color = GetBadgeTextColor(tab_id); | 112 SkColor text_color = GetBadgeTextColor(tab_id); |
113 SkColor background_color = GetBadgeBackgroundColor(tab_id); | 113 SkColor background_color = GetBadgeBackgroundColor(tab_id); |
114 | 114 |
115 if (SkColorGetA(text_color) == 0x00) | 115 if (SkColorGetA(text_color) == 0x00) |
116 text_color = SK_ColorWHITE; | 116 text_color = SK_ColorWHITE; |
117 | 117 |
118 if (SkColorGetA(background_color) == 0x00) | 118 if (SkColorGetA(background_color) == 0x00) |
119 background_color = SkColorSetARGB(255, 218, 0, 24); // Default badge color. | 119 background_color = SkColorSetARGB(255, 218, 0, 24); // Default badge color. |
120 | 120 |
121 canvas->save(); | 121 canvas->AsCanvasSkia()->save(); |
122 | 122 |
123 SkPaint* text_paint = GetTextPaint(); | 123 SkPaint* text_paint = GetTextPaint(); |
124 text_paint->setColor(text_color); | 124 text_paint->setColor(text_color); |
125 | 125 |
126 // Calculate text width. We clamp it to a max size. | 126 // Calculate text width. We clamp it to a max size. |
127 SkScalar text_width = text_paint->measureText(text.c_str(), text.size()); | 127 SkScalar text_width = text_paint->measureText(text.c_str(), text.size()); |
128 text_width = SkIntToScalar( | 128 text_width = SkIntToScalar( |
129 std::min(kMaxTextWidth, SkScalarFloor(text_width))); | 129 std::min(kMaxTextWidth, SkScalarFloor(text_width))); |
130 | 130 |
131 // Calculate badge size. It is clamped to a min width just because it looks | 131 // Calculate badge size. It is clamped to a min width just because it looks |
(...skipping 19 matching lines...) Expand all Loading... |
151 rect.fRight = rect.fLeft + SkIntToScalar(badge_width); | 151 rect.fRight = rect.fLeft + SkIntToScalar(badge_width); |
152 } else { | 152 } else { |
153 rect.fRight = SkIntToScalar(bounds.right()); | 153 rect.fRight = SkIntToScalar(bounds.right()); |
154 rect.fLeft = rect.fRight - badge_width; | 154 rect.fLeft = rect.fRight - badge_width; |
155 } | 155 } |
156 | 156 |
157 SkPaint rect_paint; | 157 SkPaint rect_paint; |
158 rect_paint.setStyle(SkPaint::kFill_Style); | 158 rect_paint.setStyle(SkPaint::kFill_Style); |
159 rect_paint.setAntiAlias(true); | 159 rect_paint.setAntiAlias(true); |
160 rect_paint.setColor(background_color); | 160 rect_paint.setColor(background_color); |
161 canvas->drawRoundRect(rect, SkIntToScalar(2), SkIntToScalar(2), rect_paint); | 161 canvas->AsCanvasSkia()->drawRoundRect(rect, SkIntToScalar(2), SkIntToScalar(2)
, |
| 162 rect_paint); |
162 | 163 |
163 // Overlay the gradient. It is stretchy, so we do this in three parts. | 164 // Overlay the gradient. It is stretchy, so we do this in three parts. |
164 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); | 165 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); |
165 SkBitmap* gradient_left = resource_bundle.GetBitmapNamed( | 166 SkBitmap* gradient_left = resource_bundle.GetBitmapNamed( |
166 IDR_BROWSER_ACTION_BADGE_LEFT); | 167 IDR_BROWSER_ACTION_BADGE_LEFT); |
167 SkBitmap* gradient_right = resource_bundle.GetBitmapNamed( | 168 SkBitmap* gradient_right = resource_bundle.GetBitmapNamed( |
168 IDR_BROWSER_ACTION_BADGE_RIGHT); | 169 IDR_BROWSER_ACTION_BADGE_RIGHT); |
169 SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( | 170 SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( |
170 IDR_BROWSER_ACTION_BADGE_CENTER); | 171 IDR_BROWSER_ACTION_BADGE_CENTER); |
171 | 172 |
172 canvas->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); | 173 canvas->AsCanvasSkia()->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); |
173 canvas->TileImageInt(*gradient_center, | 174 canvas->TileImageInt(*gradient_center, |
174 SkScalarFloor(rect.fLeft) + gradient_left->width(), | 175 SkScalarFloor(rect.fLeft) + gradient_left->width(), |
175 SkScalarFloor(rect.fTop), | 176 SkScalarFloor(rect.fTop), |
176 SkScalarFloor(rect.width()) - gradient_left->width() - | 177 SkScalarFloor(rect.width()) - gradient_left->width() - |
177 gradient_right->width(), | 178 gradient_right->width(), |
178 SkScalarFloor(rect.height())); | 179 SkScalarFloor(rect.height())); |
179 canvas->drawBitmap(*gradient_right, | 180 canvas->AsCanvasSkia()->drawBitmap(*gradient_right, |
180 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); | 181 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); |
181 | 182 |
182 // Finally, draw the text centered within the badge. We set a clip in case the | 183 // Finally, draw the text centered within the badge. We set a clip in case the |
183 // text was too large. | 184 // text was too large. |
184 rect.fLeft += kPadding; | 185 rect.fLeft += kPadding; |
185 rect.fRight -= kPadding; | 186 rect.fRight -= kPadding; |
186 canvas->clipRect(rect); | 187 canvas->AsCanvasSkia()->clipRect(rect); |
187 canvas->drawText(text.c_str(), text.size(), | 188 canvas->AsCanvasSkia()->drawText(text.c_str(), text.size(), |
188 rect.fLeft + (rect.width() - text_width) / 2, | 189 rect.fLeft + (rect.width() - text_width) / 2, |
189 rect.fTop + kTextSize + kTopTextPadding, | 190 rect.fTop + kTextSize + kTopTextPadding, |
190 *text_paint); | 191 *text_paint); |
191 canvas->restore(); | 192 canvas->AsCanvasSkia()->restore(); |
192 } | 193 } |
OLD | NEW |