Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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/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" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 badge_width += 1; | 139 badge_width += 1; |
| 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()) + |
|
Peter Kasting
2012/02/06 22:32:39
Nit: While here, convert SkIntToScalar(SkScalarFlo
tfarina
2012/02/06 23:12:16
Could you take another look, to see if I get this
| |
| 150 SkIntToScalar(bounds.width()) / 2 - | 150 SkIntToScalar(bounds.width()) / 2 - |
| 151 SkIntToScalar(badge_width) / 2)); | 151 SkIntToScalar(badge_width) / 2)); |
| 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); |
| 162 canvas->GetSkCanvas()->drawRoundRect(rect, SkIntToScalar(2), | 162 canvas->GetSkCanvas()->drawRoundRect(rect, SkIntToScalar(2), |
| 163 SkIntToScalar(2), rect_paint); | 163 SkIntToScalar(2), rect_paint); |
| 164 | 164 |
| 165 // Overlay the gradient. It is stretchy, so we do this in three parts. | 165 // Overlay the gradient. It is stretchy, so we do this in three parts. |
| 166 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); | 166 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); |
| 167 SkBitmap* gradient_left = resource_bundle.GetBitmapNamed( | 167 SkBitmap* gradient_left = resource_bundle.GetBitmapNamed( |
| 168 IDR_BROWSER_ACTION_BADGE_LEFT); | 168 IDR_BROWSER_ACTION_BADGE_LEFT); |
| 169 SkBitmap* gradient_right = resource_bundle.GetBitmapNamed( | 169 SkBitmap* gradient_right = resource_bundle.GetBitmapNamed( |
| 170 IDR_BROWSER_ACTION_BADGE_RIGHT); | 170 IDR_BROWSER_ACTION_BADGE_RIGHT); |
| 171 SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( | 171 SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( |
| 172 IDR_BROWSER_ACTION_BADGE_CENTER); | 172 IDR_BROWSER_ACTION_BADGE_CENTER); |
| 173 | 173 |
| 174 canvas->GetSkCanvas()->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); | 174 canvas->GetSkCanvas()->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); |
| 175 canvas->TileImageInt(*gradient_center, | 175 canvas->TileImage(*gradient_center, |
|
Peter Kasting
2012/02/06 22:32:39
Nit: Simpler:
gfx::Rect tile_rect(gfx::SkRectTo
| |
| 176 SkScalarFloor(rect.fLeft) + gradient_left->width(), | 176 gfx::Rect(SkScalarFloor(rect.fLeft) + gradient_left->width(), |
| 177 SkScalarFloor(rect.fTop), | 177 SkScalarFloor(rect.fTop), |
| 178 SkScalarFloor(rect.width()) - gradient_left->width() - | 178 SkScalarFloor(rect.width()) - gradient_left->width() - |
| 179 gradient_right->width(), | 179 gradient_right->width(), |
| 180 SkScalarFloor(rect.height())); | 180 SkScalarFloor(rect.height()))); |
| 181 canvas->GetSkCanvas()->drawBitmap(*gradient_right, | 181 canvas->GetSkCanvas()->drawBitmap(*gradient_right, |
| 182 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); | 182 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); |
| 183 | 183 |
| 184 // Finally, draw the text centered within the badge. We set a clip in case the | 184 // Finally, draw the text centered within the badge. We set a clip in case the |
| 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->GetSkCanvas()->clipRect(rect); | 188 canvas->GetSkCanvas()->clipRect(rect); |
| 189 canvas->GetSkCanvas()->drawText(text.c_str(), text.size(), | 189 canvas->GetSkCanvas()->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 |