Index: chrome/browser/views/browser_actions_container.cc |
=================================================================== |
--- chrome/browser/views/browser_actions_container.cc (revision 29822) |
+++ chrome/browser/views/browser_actions_container.cc (working copy) |
@@ -203,88 +203,8 @@ |
void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { |
View::PaintChildren(canvas); |
- |
- const std::string& text = button_->browser_action_state()->badge_text(); |
- if (text.empty()) |
- return; |
- |
- const int kTextSize = 8; |
- const int kBottomMargin = 5; |
- const int kPadding = 2; |
- const int kBadgeHeight = 11; |
- const int kMaxTextWidth = 23; |
- const int kCenterAlignThreshold = 20; // at than width, we center align |
- |
- canvas->save(); |
- |
- SkTypeface* typeface = SkTypeface::CreateFromName("Arial", SkTypeface::kBold); |
- SkPaint text_paint; |
- text_paint.setAntiAlias(true); |
- text_paint.setColor(SK_ColorWHITE); |
- text_paint.setFakeBoldText(true); |
- text_paint.setTextAlign(SkPaint::kLeft_Align); |
- text_paint.setTextSize(SkIntToScalar(kTextSize)); |
- text_paint.setTypeface(typeface); |
- |
- // Calculate text width. We clamp it to a max size. |
- SkScalar text_width = text_paint.measureText(text.c_str(), text.size()); |
- text_width = SkIntToScalar( |
- std::min(kMaxTextWidth, SkScalarFloor(text_width))); |
- |
- // Cacluate 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; |
- badge_width = std::max(kBadgeHeight, badge_width); |
- |
- // Paint the badge background color in the right location. It is usually |
- // right-aligned, but it can also be center-aligned if it is large. |
- SkRect rect; |
- rect.fBottom = SkIntToScalar(height() - kBottomMargin); |
- rect.fTop = rect.fBottom - SkIntToScalar(kBadgeHeight); |
- if (badge_width >= kCenterAlignThreshold) { |
- rect.fLeft = SkIntToScalar((width() - badge_width) / 2); |
- rect.fRight = rect.fLeft + SkIntToScalar(badge_width); |
- } else { |
- rect.fRight = SkIntToScalar(width()); |
- rect.fLeft = rect.fRight - badge_width; |
- } |
- |
- SkPaint rect_paint; |
- rect_paint.setStyle(SkPaint::kFill_Style); |
- rect_paint.setAntiAlias(true); |
- rect_paint.setColor( |
- button_->browser_action_state()->badge_background_color()); |
- canvas->drawRoundRect(rect, SkIntToScalar(2), SkIntToScalar(2), rect_paint); |
- |
- // Overlay the gradient. It is stretchy, so we do this in three parts. |
- ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); |
- SkBitmap* gradient_left = resource_bundle.GetBitmapNamed( |
- IDR_BROWSER_ACTION_BADGE_LEFT); |
- SkBitmap* gradient_right = resource_bundle.GetBitmapNamed( |
- IDR_BROWSER_ACTION_BADGE_RIGHT); |
- SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( |
- IDR_BROWSER_ACTION_BADGE_CENTER); |
- |
- canvas->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); |
- canvas->TileImageInt(*gradient_center, |
- SkScalarFloor(rect.fLeft) + gradient_left->width(), |
- SkScalarFloor(rect.fTop), |
- SkScalarFloor(rect.width()) - gradient_left->width() - |
- gradient_right->width(), |
- SkScalarFloor(rect.height())); |
- canvas->drawBitmap(*gradient_right, |
- rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); |
- |
- // Finally, draw the text centered within the badge. We set a clip in case the |
- // text was too large. |
- rect.fLeft += kPadding; |
- rect.fRight -= kPadding; |
- canvas->clipRect(rect); |
- canvas->drawText(text.c_str(), text.size(), |
- rect.fLeft + (rect.width() - text_width) / 2, |
- rect.fTop + kTextSize + 1, |
- text_paint); |
- canvas->restore(); |
+ button_->browser_action_state()->PaintBadge(canvas, |
+ gfx::Rect(width(), height())); |
} |
Property changes on: chrome\browser\views\browser_actions_container.cc |
___________________________________________________________________ |
Modified: svn:mergeinfo |
Merged /trunk/src/chrome/browser/views/browser_actions_container.cc:r29556 |