Chromium Code Reviews| 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, h; | |
|
Devlin
2016/05/26 20:50:25
nit: I think style requires these to be initialize
Evan Stade
2016/05/26 21:49:38
Done.
| |
| 189 gfx::FontList bigger_font = base_font.Derive(1, 0); | |
| 190 gfx::Canvas::SizeStringInt(utf16_text, bigger_font, &w, &h, 0, | |
| 191 gfx::Canvas::NO_ELLIPSIS); | |
| 192 if (h > kBadgeHeight) | |
| 193 break; | |
| 194 base_font = bigger_font; | |
| 195 } | |
| 196 | |
| 183 if (ui::MaterialDesignController::IsModeMaterial()) { | 197 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 184 text_width = | 198 text_width = |
| 185 std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font)); | 199 std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font)); |
| 186 } else { | 200 } else { |
| 187 text_paint = GetBadgeTextPaintSingleton(); | 201 text_paint = GetBadgeTextPaintSingleton(); |
| 188 text_paint->setColor(text_color); | 202 text_paint->setColor(text_color); |
| 189 float scale = canvas->image_scale(); | 203 float scale = canvas->image_scale(); |
| 190 | 204 |
| 191 // Calculate text width. Font width may not be linear with respect to the | 205 // 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 | 206 // 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 } | 304 } |
| 291 | 305 |
| 292 void IconWithBadgeImageSource::PaintBlockedActionDecoration( | 306 void IconWithBadgeImageSource::PaintBlockedActionDecoration( |
| 293 gfx::Canvas* canvas) { | 307 gfx::Canvas* canvas) { |
| 294 canvas->Save(); | 308 canvas->Save(); |
| 295 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 309 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 296 IDR_BLOCKED_EXTENSION_SCRIPT); | 310 IDR_BLOCKED_EXTENSION_SCRIPT); |
| 297 canvas->DrawImageInt(img, size().width() - img.width(), 0); | 311 canvas->DrawImageInt(img, size().width() - img.width(), 0); |
| 298 canvas->Restore(); | 312 canvas->Restore(); |
| 299 } | 313 } |
| OLD | NEW |