| OLD | NEW |
| 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 "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/common/badge_util.h" | 10 #include "chrome/common/badge_util.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 badge_width = std::max(kBadgeHeight, badge_width); | 140 badge_width = std::max(kBadgeHeight, badge_width); |
| 141 | 141 |
| 142 // Paint the badge background color in the right location. It is usually | 142 // Paint the badge background color in the right location. It is usually |
| 143 // right-aligned, but it can also be center-aligned if it is large. | 143 // right-aligned, but it can also be center-aligned if it is large. |
| 144 SkRect rect; | 144 SkRect rect; |
| 145 rect.fBottom = SkIntToScalar(bounds.bottom() - kBottomMargin); | 145 rect.fBottom = SkIntToScalar(bounds.bottom() - kBottomMargin); |
| 146 rect.fTop = rect.fBottom - SkIntToScalar(kBadgeHeight); | 146 rect.fTop = rect.fBottom - SkIntToScalar(kBadgeHeight); |
| 147 if (badge_width >= kCenterAlignThreshold) { | 147 if (badge_width >= kCenterAlignThreshold) { |
| 148 rect.fLeft = SkIntToScalar( | 148 rect.fLeft = SkIntToScalar( |
| 149 SkScalarFloor(SkIntToScalar(bounds.x()) + | 149 SkScalarFloor(SkIntToScalar(bounds.x()) + |
| 150 SkIntToScalar(bounds.width() / 2) - | 150 SkIntToScalar(bounds.width() / 2.0) - |
| 151 SkIntToScalar(badge_width / 2))); | 151 SkIntToScalar(badge_width / 2.0))); |
| 152 rect.fRight = rect.fLeft + SkIntToScalar(badge_width); | 152 rect.fRight = rect.fLeft + SkIntToScalar(badge_width); |
| 153 } else { | 153 } else { |
| 154 rect.fRight = SkIntToScalar(bounds.right()); | 154 rect.fRight = SkIntToScalar(bounds.right()); |
| 155 rect.fLeft = rect.fRight - badge_width; | 155 rect.fLeft = rect.fRight - badge_width; |
| 156 } | 156 } |
| 157 | 157 |
| 158 SkPaint rect_paint; | 158 SkPaint rect_paint; |
| 159 rect_paint.setStyle(SkPaint::kFill_Style); | 159 rect_paint.setStyle(SkPaint::kFill_Style); |
| 160 rect_paint.setAntiAlias(true); | 160 rect_paint.setAntiAlias(true); |
| 161 rect_paint.setColor(background_color); | 161 rect_paint.setColor(background_color); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 185 // text was too large. | 185 // text was too large. |
| 186 rect.fLeft += kPadding; | 186 rect.fLeft += kPadding; |
| 187 rect.fRight -= kPadding; | 187 rect.fRight -= kPadding; |
| 188 canvas->AsCanvasSkia()->clipRect(rect); | 188 canvas->AsCanvasSkia()->clipRect(rect); |
| 189 canvas->AsCanvasSkia()->drawText(text.c_str(), text.size(), | 189 canvas->AsCanvasSkia()->drawText(text.c_str(), text.size(), |
| 190 rect.fLeft + (rect.width() - text_width) / 2, | 190 rect.fLeft + (rect.width() - text_width) / 2, |
| 191 rect.fTop + kTextSize + kTopTextPadding, | 191 rect.fTop + kTextSize + kTopTextPadding, |
| 192 *text_paint); | 192 *text_paint); |
| 193 canvas->Restore(); | 193 canvas->Restore(); |
| 194 } | 194 } |
| OLD | NEW |