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

Side by Side Diff: chrome/common/badge_util.cc

Issue 11588004: Move ScriptBadge, ActionInfo out of Extension; preparation for BrowserAction (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for CQ Created 7 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
« no previous file with comments | « chrome/common/badge_util.h ('k') | chrome/common/extensions/api/extension_action/action_info.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/badge_util.h" 5 #include "chrome/common/badge_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "third_party/skia/include/core/SkPaint.h" 10 #include "third_party/skia/include/core/SkPaint.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // Return the generated image. 138 // Return the generated image.
139 return canvas->ExtractImageRep().sk_bitmap(); 139 return canvas->ExtractImageRep().sk_bitmap();
140 } 140 }
141 141
142 void PaintBadge(gfx::Canvas* canvas, 142 void PaintBadge(gfx::Canvas* canvas,
143 const gfx::Rect& bounds, 143 const gfx::Rect& bounds,
144 const std::string& text, 144 const std::string& text,
145 const SkColor& text_color_in, 145 const SkColor& text_color_in,
146 const SkColor& background_color_in, 146 const SkColor& background_color_in,
147 int icon_width, 147 int icon_width,
148 extensions::Extension::ActionInfo::Type action_type) { 148 extensions::ActionInfo::Type action_type) {
149 if (text.empty()) 149 if (text.empty())
150 return; 150 return;
151 151
152 SkColor text_color = text_color_in; 152 SkColor text_color = text_color_in;
153 if (SkColorGetA(text_color_in) == 0x00) 153 if (SkColorGetA(text_color_in) == 0x00)
154 text_color = SK_ColorWHITE; 154 text_color = SK_ColorWHITE;
155 155
156 SkColor background_color = background_color_in; 156 SkColor background_color = background_color_in;
157 if (SkColorGetA(background_color_in) == 0x00) 157 if (SkColorGetA(background_color_in) == 0x00)
158 background_color = SkColorSetARGB(255, 218, 0, 24); 158 background_color = SkColorSetARGB(255, 218, 0, 24);
(...skipping 14 matching lines...) Expand all
173 // Force the pixel width of badge to be either odd (if the icon width is odd) 173 // Force the pixel width of badge to be either odd (if the icon width is odd)
174 // or even otherwise. If there is a mismatch you get http://crbug.com/26400. 174 // or even otherwise. If there is a mismatch you get http://crbug.com/26400.
175 if (icon_width != 0 && (badge_width % 2 != icon_width % 2)) 175 if (icon_width != 0 && (badge_width % 2 != icon_width % 2))
176 badge_width += 1; 176 badge_width += 1;
177 badge_width = std::max(kBadgeHeight, badge_width); 177 badge_width = std::max(kBadgeHeight, badge_width);
178 178
179 // Paint the badge background color in the right location. It is usually 179 // Paint the badge background color in the right location. It is usually
180 // right-aligned, but it can also be center-aligned if it is large. 180 // right-aligned, but it can also be center-aligned if it is large.
181 int rect_height = kBadgeHeight; 181 int rect_height = kBadgeHeight;
182 int bottom_margin = 182 int bottom_margin =
183 action_type == extensions::Extension::ActionInfo::TYPE_BROWSER ? 183 action_type == extensions::ActionInfo::TYPE_BROWSER ?
184 kBottomMarginBrowserAction : kBottomMarginPageAction; 184 kBottomMarginBrowserAction : kBottomMarginPageAction;
185 int rect_y = bounds.bottom() - bottom_margin - kBadgeHeight; 185 int rect_y = bounds.bottom() - bottom_margin - kBadgeHeight;
186 int rect_width = badge_width; 186 int rect_width = badge_width;
187 int rect_x = (badge_width >= kCenterAlignThreshold) ? 187 int rect_x = (badge_width >= kCenterAlignThreshold) ?
188 bounds.x() + (bounds.width() - badge_width) / 2 : 188 bounds.x() + (bounds.width() - badge_width) / 2 :
189 bounds.right() - badge_width; 189 bounds.right() - badge_width;
190 gfx::Rect rect(rect_x, rect_y, rect_width, rect_height); 190 gfx::Rect rect(rect_x, rect_y, rect_width, rect_height);
191 191
192 SkPaint rect_paint; 192 SkPaint rect_paint;
193 rect_paint.setStyle(SkPaint::kFill_Style); 193 rect_paint.setStyle(SkPaint::kFill_Style);
(...skipping 26 matching lines...) Expand all
220 canvas->sk_canvas()->drawText( 220 canvas->sk_canvas()->drawText(
221 text.c_str(), text.size(), 221 text.c_str(), text.size(),
222 SkFloatToScalar(rect.x() + 222 SkFloatToScalar(rect.x() +
223 static_cast<float>(rect.width() - text_width) / 2), 223 static_cast<float>(rect.width() - text_width) / 2),
224 SkFloatToScalar(rect.y() + kTextSize + kTopTextPadding), 224 SkFloatToScalar(rect.y() + kTextSize + kTopTextPadding),
225 *text_paint); 225 *text_paint);
226 canvas->Restore(); 226 canvas->Restore();
227 } 227 }
228 228
229 } // namespace badge_util 229 } // namespace badge_util
OLDNEW
« no previous file with comments | « chrome/common/badge_util.h ('k') | chrome/common/extensions/api/extension_action/action_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698