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

Side by Side Diff: chrome/common/extensions/extension_action.cc

Issue 2811032: Revert 50784 - Canvas refactoring part 3.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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
« no previous file with comments | « chrome/browser/views/theme_install_bubble_view.cc ('k') | gfx/canvas.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_skia.h" 12 #include "gfx/canvas.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
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->AsCanvasSkia()->save(); 121 canvas->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
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->AsCanvasSkia()->drawRoundRect(rect, SkIntToScalar(2), SkIntToScalar(2) , 161 canvas->drawRoundRect(rect, SkIntToScalar(2), SkIntToScalar(2), rect_paint);
162 rect_paint);
163 162
164 // Overlay the gradient. It is stretchy, so we do this in three parts. 163 // Overlay the gradient. It is stretchy, so we do this in three parts.
165 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); 164 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance();
166 SkBitmap* gradient_left = resource_bundle.GetBitmapNamed( 165 SkBitmap* gradient_left = resource_bundle.GetBitmapNamed(
167 IDR_BROWSER_ACTION_BADGE_LEFT); 166 IDR_BROWSER_ACTION_BADGE_LEFT);
168 SkBitmap* gradient_right = resource_bundle.GetBitmapNamed( 167 SkBitmap* gradient_right = resource_bundle.GetBitmapNamed(
169 IDR_BROWSER_ACTION_BADGE_RIGHT); 168 IDR_BROWSER_ACTION_BADGE_RIGHT);
170 SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( 169 SkBitmap* gradient_center = resource_bundle.GetBitmapNamed(
171 IDR_BROWSER_ACTION_BADGE_CENTER); 170 IDR_BROWSER_ACTION_BADGE_CENTER);
172 171
173 canvas->AsCanvasSkia()->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); 172 canvas->drawBitmap(*gradient_left, rect.fLeft, rect.fTop);
174 canvas->TileImageInt(*gradient_center, 173 canvas->TileImageInt(*gradient_center,
175 SkScalarFloor(rect.fLeft) + gradient_left->width(), 174 SkScalarFloor(rect.fLeft) + gradient_left->width(),
176 SkScalarFloor(rect.fTop), 175 SkScalarFloor(rect.fTop),
177 SkScalarFloor(rect.width()) - gradient_left->width() - 176 SkScalarFloor(rect.width()) - gradient_left->width() -
178 gradient_right->width(), 177 gradient_right->width(),
179 SkScalarFloor(rect.height())); 178 SkScalarFloor(rect.height()));
180 canvas->AsCanvasSkia()->drawBitmap(*gradient_right, 179 canvas->drawBitmap(*gradient_right,
181 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); 180 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop);
182 181
183 // Finally, draw the text centered within the badge. We set a clip in case the 182 // Finally, draw the text centered within the badge. We set a clip in case the
184 // text was too large. 183 // text was too large.
185 rect.fLeft += kPadding; 184 rect.fLeft += kPadding;
186 rect.fRight -= kPadding; 185 rect.fRight -= kPadding;
187 canvas->AsCanvasSkia()->clipRect(rect); 186 canvas->clipRect(rect);
188 canvas->AsCanvasSkia()->drawText(text.c_str(), text.size(), 187 canvas->drawText(text.c_str(), text.size(),
189 rect.fLeft + (rect.width() - text_width) / 2, 188 rect.fLeft + (rect.width() - text_width) / 2,
190 rect.fTop + kTextSize + kTopTextPadding, 189 rect.fTop + kTextSize + kTopTextPadding,
191 *text_paint); 190 *text_paint);
192 canvas->AsCanvasSkia()->restore(); 191 canvas->restore();
193 } 192 }
OLDNEW
« no previous file with comments | « chrome/browser/views/theme_install_bubble_view.cc ('k') | gfx/canvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698