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

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

Issue 506003: Fix badge center-alignment logic.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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 | « no previous file | no next file » | 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) 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/common/extensions/extension_action.h" 5 #include "chrome/common/extensions/extension_action.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/gfx/font.h" 8 #include "app/gfx/font.h"
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/gfx/rect.h" 10 #include "base/gfx/rect.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 badge_width += 1; 130 badge_width += 1;
131 badge_width = std::max(kBadgeHeight, badge_width); 131 badge_width = std::max(kBadgeHeight, badge_width);
132 132
133 // Paint the badge background color in the right location. It is usually 133 // Paint the badge background color in the right location. It is usually
134 // right-aligned, but it can also be center-aligned if it is large. 134 // right-aligned, but it can also be center-aligned if it is large.
135 SkRect rect; 135 SkRect rect;
136 rect.fBottom = SkIntToScalar(bounds.bottom() - kBottomMargin); 136 rect.fBottom = SkIntToScalar(bounds.bottom() - kBottomMargin);
137 rect.fTop = rect.fBottom - SkIntToScalar(kBadgeHeight); 137 rect.fTop = rect.fBottom - SkIntToScalar(kBadgeHeight);
138 if (badge_width >= kCenterAlignThreshold) { 138 if (badge_width >= kCenterAlignThreshold) {
139 rect.fLeft = SkIntToScalar( 139 rect.fLeft = SkIntToScalar(
140 SkScalarFloor(SkIntToScalar(bounds.width() / 2.0) - 140 SkScalarFloor(SkIntToScalar(bounds.x()) +
141 SkIntToScalar(badge_width / 2.0))); 141 SkIntToScalar(bounds.width() / 2.0) -
142 SkIntToScalar(badge_width / 2.0);
142 rect.fRight = rect.fLeft + SkIntToScalar(badge_width); 143 rect.fRight = rect.fLeft + SkIntToScalar(badge_width);
143 } else { 144 } else {
144 rect.fRight = SkIntToScalar(bounds.right()); 145 rect.fRight = SkIntToScalar(bounds.right());
145 rect.fLeft = rect.fRight - badge_width; 146 rect.fLeft = rect.fRight - badge_width;
146 } 147 }
147 148
148 SkPaint rect_paint; 149 SkPaint rect_paint;
149 rect_paint.setStyle(SkPaint::kFill_Style); 150 rect_paint.setStyle(SkPaint::kFill_Style);
150 rect_paint.setAntiAlias(true); 151 rect_paint.setAntiAlias(true);
151 rect_paint.setColor(background_color); 152 rect_paint.setColor(background_color);
(...skipping 22 matching lines...) Expand all
174 // text was too large. 175 // text was too large.
175 rect.fLeft += kPadding; 176 rect.fLeft += kPadding;
176 rect.fRight -= kPadding; 177 rect.fRight -= kPadding;
177 canvas->clipRect(rect); 178 canvas->clipRect(rect);
178 canvas->drawText(text.c_str(), text.size(), 179 canvas->drawText(text.c_str(), text.size(),
179 rect.fLeft + (rect.width() - text_width) / 2, 180 rect.fLeft + (rect.width() - text_width) / 2,
180 rect.fTop + kTextSize + kTopTextPadding, 181 rect.fTop + kTextSize + kTopTextPadding,
181 *text_paint); 182 *text_paint);
182 canvas->restore(); 183 canvas->restore();
183 } 184 }
OLDNEW
« 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