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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 if (icon_width != 0 && (badge_width % 2 != GetIcon(tab_id).width() % 2)) | 138 if (icon_width != 0 && (badge_width % 2 != GetIcon(tab_id).width() % 2)) |
| 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 = SkScalarFloorToScalar(SkIntToScalar(bounds.x()) + |
|
Peter Kasting
2012/02/06 23:21:51
Looks right to me
| |
| 149 SkScalarFloor(SkIntToScalar(bounds.x()) + | 149 SkIntToScalar(bounds.width()) / 2 - |
| 150 SkIntToScalar(bounds.width()) / 2 - | 150 SkIntToScalar(badge_width) / 2); |
| 151 SkIntToScalar(badge_width) / 2)); | |
| 152 rect.fRight = rect.fLeft + SkIntToScalar(badge_width); | 151 rect.fRight = rect.fLeft + SkIntToScalar(badge_width); |
| 153 } else { | 152 } else { |
| 154 rect.fRight = SkIntToScalar(bounds.right()); | 153 rect.fRight = SkIntToScalar(bounds.right()); |
| 155 rect.fLeft = rect.fRight - badge_width; | 154 rect.fLeft = rect.fRight - badge_width; |
| 156 } | 155 } |
| 157 | 156 |
| 158 SkPaint rect_paint; | 157 SkPaint rect_paint; |
| 159 rect_paint.setStyle(SkPaint::kFill_Style); | 158 rect_paint.setStyle(SkPaint::kFill_Style); |
| 160 rect_paint.setAntiAlias(true); | 159 rect_paint.setAntiAlias(true); |
| 161 rect_paint.setColor(background_color); | 160 rect_paint.setColor(background_color); |
| 162 canvas->GetSkCanvas()->drawRoundRect(rect, SkIntToScalar(2), | 161 canvas->GetSkCanvas()->drawRoundRect(rect, SkIntToScalar(2), |
| 163 SkIntToScalar(2), rect_paint); | 162 SkIntToScalar(2), rect_paint); |
| 164 | 163 |
| 165 // Overlay the gradient. It is stretchy, so we do this in three parts. | 164 // Overlay the gradient. It is stretchy, so we do this in three parts. |
| 166 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); | 165 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); |
| 167 SkBitmap* gradient_left = resource_bundle.GetBitmapNamed( | 166 SkBitmap* gradient_left = resource_bundle.GetBitmapNamed( |
| 168 IDR_BROWSER_ACTION_BADGE_LEFT); | 167 IDR_BROWSER_ACTION_BADGE_LEFT); |
| 169 SkBitmap* gradient_right = resource_bundle.GetBitmapNamed( | 168 SkBitmap* gradient_right = resource_bundle.GetBitmapNamed( |
| 170 IDR_BROWSER_ACTION_BADGE_RIGHT); | 169 IDR_BROWSER_ACTION_BADGE_RIGHT); |
| 171 SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( | 170 SkBitmap* gradient_center = resource_bundle.GetBitmapNamed( |
| 172 IDR_BROWSER_ACTION_BADGE_CENTER); | 171 IDR_BROWSER_ACTION_BADGE_CENTER); |
| 173 | 172 |
| 174 canvas->GetSkCanvas()->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); | 173 canvas->GetSkCanvas()->drawBitmap(*gradient_left, rect.fLeft, rect.fTop); |
| 175 canvas->TileImageInt(*gradient_center, | 174 gfx::Rect tile_rect(gfx::SkRectToRect(rect)); |
| 176 SkScalarFloor(rect.fLeft) + gradient_left->width(), | 175 tile_rect.Inset(gradient_left->width(), 0, gradient_right->width(), 0); |
| 177 SkScalarFloor(rect.fTop), | 176 canvas->TileImage(*gradient_center, tile_rect); |
| 178 SkScalarFloor(rect.width()) - gradient_left->width() - | |
| 179 gradient_right->width(), | |
| 180 SkScalarFloor(rect.height())); | |
| 181 canvas->GetSkCanvas()->drawBitmap(*gradient_right, | 177 canvas->GetSkCanvas()->drawBitmap(*gradient_right, |
| 182 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); | 178 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); |
| 183 | 179 |
| 184 // Finally, draw the text centered within the badge. We set a clip in case the | 180 // Finally, draw the text centered within the badge. We set a clip in case the |
| 185 // text was too large. | 181 // text was too large. |
| 186 rect.fLeft += kPadding; | 182 rect.fLeft += kPadding; |
| 187 rect.fRight -= kPadding; | 183 rect.fRight -= kPadding; |
| 188 canvas->GetSkCanvas()->clipRect(rect); | 184 canvas->GetSkCanvas()->clipRect(rect); |
| 189 canvas->GetSkCanvas()->drawText(text.c_str(), text.size(), | 185 canvas->GetSkCanvas()->drawText(text.c_str(), text.size(), |
| 190 rect.fLeft + (rect.width() - text_width) / 2, | 186 rect.fLeft + (rect.width() - text_width) / 2, |
| 191 rect.fTop + kTextSize + kTopTextPadding, | 187 rect.fTop + kTextSize + kTopTextPadding, |
| 192 *text_paint); | 188 *text_paint); |
| 193 canvas->Restore(); | 189 canvas->Restore(); |
| 194 } | 190 } |
| OLD | NEW |