| OLD | NEW |
| 1 // Copyright (c) 2012 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/browser/ui/extensions/icon_with_badge_image_source.h" | 5 #include "chrome/browser/ui/extensions/icon_with_badge_image_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 background_color = badge_->background_color; | 173 background_color = badge_->background_color; |
| 174 | 174 |
| 175 canvas->Save(); | 175 canvas->Save(); |
| 176 | 176 |
| 177 SkPaint* text_paint = nullptr; | 177 SkPaint* text_paint = nullptr; |
| 178 int text_width = 0; | 178 int text_width = 0; |
| 179 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); | 179 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); |
| 180 gfx::FontList base_font = rb->GetFontList(ResourceBundle::BaseFont) | 180 gfx::FontList base_font = rb->GetFontList(ResourceBundle::BaseFont) |
| 181 .DeriveWithHeightUpperBound(kBadgeHeight); | 181 .DeriveWithHeightUpperBound(kBadgeHeight); |
| 182 base::string16 utf16_text = base::UTF8ToUTF16(badge_->text); | 182 base::string16 utf16_text = base::UTF8ToUTF16(badge_->text); |
| 183 |
| 184 // See if we can squeeze a slightly larger font into the badge given the |
| 185 // actual string that is to be displayed. |
| 186 const int kMaxIncrementAttempts = 5; |
| 187 for (size_t i = 0; i < kMaxIncrementAttempts; ++i) { |
| 188 int w = 0; |
| 189 int h = 0; |
| 190 gfx::FontList bigger_font = base_font.Derive(1, 0); |
| 191 gfx::Canvas::SizeStringInt(utf16_text, bigger_font, &w, &h, 0, |
| 192 gfx::Canvas::NO_ELLIPSIS); |
| 193 if (h > kBadgeHeight) |
| 194 break; |
| 195 base_font = bigger_font; |
| 196 } |
| 197 |
| 183 if (ui::MaterialDesignController::IsModeMaterial()) { | 198 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 184 text_width = | 199 text_width = |
| 185 std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font)); | 200 std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font)); |
| 186 } else { | 201 } else { |
| 187 text_paint = GetBadgeTextPaintSingleton(); | 202 text_paint = GetBadgeTextPaintSingleton(); |
| 188 text_paint->setColor(text_color); | 203 text_paint->setColor(text_color); |
| 189 float scale = canvas->image_scale(); | 204 float scale = canvas->image_scale(); |
| 190 | 205 |
| 191 // Calculate text width. Font width may not be linear with respect to the | 206 // Calculate text width. Font width may not be linear with respect to the |
| 192 // scale factor (e.g. when hinting is applied), so we need to use the font | 207 // scale factor (e.g. when hinting is applied), so we need to use the font |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 305 } |
| 291 | 306 |
| 292 void IconWithBadgeImageSource::PaintBlockedActionDecoration( | 307 void IconWithBadgeImageSource::PaintBlockedActionDecoration( |
| 293 gfx::Canvas* canvas) { | 308 gfx::Canvas* canvas) { |
| 294 canvas->Save(); | 309 canvas->Save(); |
| 295 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 310 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 296 IDR_BLOCKED_EXTENSION_SCRIPT); | 311 IDR_BLOCKED_EXTENSION_SCRIPT); |
| 297 canvas->DrawImageInt(img, size().width() - img.width(), 0); | 312 canvas->DrawImageInt(img, size().width() - img.width(), 0); |
| 298 canvas->Restore(); | 313 canvas->Restore(); |
| 299 } | 314 } |
| OLD | NEW |