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

Unified Diff: chrome/common/extensions/extension_action.cc

Issue 362007: Centering the browser action badges better (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension_action.cc
===================================================================
--- chrome/common/extensions/extension_action.cc (revision 30835)
+++ chrome/common/extensions/extension_action.cc (working copy)
@@ -106,7 +106,7 @@
text_color = SK_ColorWHITE;
if (SkColorGetA(background_color) == 0x00)
- background_color = SkColorSetARGB(255, 218, 0, 24); // default badge color
+ background_color = SkColorSetARGB(255, 218, 0, 24); // Default badge color.
canvas->save();
@@ -118,9 +118,14 @@
text_width = SkIntToScalar(
std::min(kMaxTextWidth, SkScalarFloor(text_width)));
- // Cacluate badge size. It is clamped to a min width just because it looks
+ // Calculate badge size. It is clamped to a min width just because it looks
// silly if it is too skinny.
int badge_width = SkScalarFloor(text_width) + kPadding * 2;
+ int icon_width = GetIcon(tab_id).width();
+ // Force the pixel width of badge to be either odd (if the icon width is odd)
+ // or even otherwise. If there is a mismatch you get http://crbug.com/26400.
+ if (icon_width != 0 && (badge_width % 2 != GetIcon(tab_id).width() % 2))
+ badge_width += 1;
badge_width = std::max(kBadgeHeight, badge_width);
// Paint the badge background color in the right location. It is usually
@@ -129,7 +134,9 @@
rect.fBottom = SkIntToScalar(bounds.bottom() - kBottomMargin);
rect.fTop = rect.fBottom - SkIntToScalar(kBadgeHeight);
if (badge_width >= kCenterAlignThreshold) {
- rect.fLeft = SkIntToScalar(bounds.CenterPoint().x() - badge_width / 2);
+ rect.fLeft = SkIntToScalar(
+ SkScalarFloor(SkIntToScalar(bounds.width() / 2.0) -
+ SkIntToScalar(badge_width / 2.0)));
rect.fRight = rect.fLeft + SkIntToScalar(badge_width);
} else {
rect.fRight = SkIntToScalar(bounds.right());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698