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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 const char kPreferredTypeface[] = "Arial"; | 62 const char kPreferredTypeface[] = "Arial"; |
63 #endif | 63 #endif |
64 | 64 |
65 static SkPaint* text_paint = NULL; | 65 static SkPaint* text_paint = NULL; |
66 if (!text_paint) { | 66 if (!text_paint) { |
67 text_paint = new SkPaint; | 67 text_paint = new SkPaint; |
68 text_paint->setAntiAlias(true); | 68 text_paint->setAntiAlias(true); |
69 text_paint->setTextAlign(SkPaint::kLeft_Align); | 69 text_paint->setTextAlign(SkPaint::kLeft_Align); |
70 | 70 |
71 sk_sp<SkTypeface> typeface( | 71 sk_sp<SkTypeface> typeface( |
72 SkTypeface::CreateFromName(kPreferredTypeface, SkTypeface::kBold)); | 72 SkTypeface::MakeFromName(kPreferredTypeface, |
| 73 SkFontStyle::FromOldStyle(SkTypeface::kBold))); |
73 // Skia doesn't do any font fallback---if the user is missing the font then | 74 // Skia doesn't do any font fallback---if the user is missing the font then |
74 // typeface will be NULL. If we don't do manual fallback then we'll crash. | 75 // typeface will be NULL. If we don't do manual fallback then we'll crash. |
75 if (typeface) { | 76 if (typeface) { |
76 text_paint->setFakeBoldText(true); | 77 text_paint->setFakeBoldText(true); |
77 } else { | 78 } else { |
78 // Fall back to the system font. We don't bold it because we aren't sure | 79 // Fall back to the system font. We don't bold it because we aren't sure |
79 // how it will look. | 80 // how it will look. |
80 // For the most part this code path will only be hit on Linux systems | 81 // For the most part this code path will only be hit on Linux systems |
81 // that don't have Arial. | 82 // that don't have Arial. |
82 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 83 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
83 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | 84 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
84 typeface = sk_sp<SkTypeface>(SkTypeface::CreateFromName( | 85 typeface = sk_sp<SkTypeface>(SkTypeface::MakeFromName( |
85 base_font.GetFontName().c_str(), SkTypeface::kNormal)); | 86 base_font.GetFontName().c_str(), SkFontStyle())); |
86 DCHECK(typeface); | 87 DCHECK(typeface); |
87 } | 88 } |
88 | 89 |
89 text_paint->setTypeface(typeface.get()); | 90 text_paint->setTypeface(typeface.get()); |
90 // |text_paint| adds its own ref. Release the ref from CreateFontName. | 91 // |text_paint| adds its own ref. Release the ref from CreateFontName. |
91 } | 92 } |
92 return text_paint; | 93 return text_paint; |
93 } | 94 } |
94 | 95 |
95 gfx::ImageSkiaRep ScaleImageSkiaRep(const gfx::ImageSkiaRep& rep, | 96 gfx::ImageSkiaRep ScaleImageSkiaRep(const gfx::ImageSkiaRep& rep, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 gfx::FontList base_font = rb->GetFontList(ResourceBundle::BaseFont) | 181 gfx::FontList base_font = rb->GetFontList(ResourceBundle::BaseFont) |
181 .DeriveWithHeightUpperBound(kBadgeHeight); | 182 .DeriveWithHeightUpperBound(kBadgeHeight); |
182 base::string16 utf16_text = base::UTF8ToUTF16(badge_->text); | 183 base::string16 utf16_text = base::UTF8ToUTF16(badge_->text); |
183 | 184 |
184 // See if we can squeeze a slightly larger font into the badge given the | 185 // See if we can squeeze a slightly larger font into the badge given the |
185 // actual string that is to be displayed. | 186 // actual string that is to be displayed. |
186 const int kMaxIncrementAttempts = 5; | 187 const int kMaxIncrementAttempts = 5; |
187 for (size_t i = 0; i < kMaxIncrementAttempts; ++i) { | 188 for (size_t i = 0; i < kMaxIncrementAttempts; ++i) { |
188 int w = 0; | 189 int w = 0; |
189 int h = 0; | 190 int h = 0; |
190 gfx::FontList bigger_font = base_font.Derive(1, 0); | 191 gfx::FontList bigger_font = |
| 192 base_font.Derive(1, 0, gfx::Font::Weight::NORMAL); |
191 gfx::Canvas::SizeStringInt(utf16_text, bigger_font, &w, &h, 0, | 193 gfx::Canvas::SizeStringInt(utf16_text, bigger_font, &w, &h, 0, |
192 gfx::Canvas::NO_ELLIPSIS); | 194 gfx::Canvas::NO_ELLIPSIS); |
193 if (h > kBadgeHeight) | 195 if (h > kBadgeHeight) |
194 break; | 196 break; |
195 base_font = bigger_font; | 197 base_font = bigger_font; |
196 } | 198 } |
197 | 199 |
198 if (ui::MaterialDesignController::IsModeMaterial()) { | 200 if (ui::MaterialDesignController::IsModeMaterial()) { |
199 text_width = | 201 text_width = |
200 std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font)); | 202 std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } | 307 } |
306 | 308 |
307 void IconWithBadgeImageSource::PaintBlockedActionDecoration( | 309 void IconWithBadgeImageSource::PaintBlockedActionDecoration( |
308 gfx::Canvas* canvas) { | 310 gfx::Canvas* canvas) { |
309 canvas->Save(); | 311 canvas->Save(); |
310 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 312 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
311 IDR_BLOCKED_EXTENSION_SCRIPT); | 313 IDR_BLOCKED_EXTENSION_SCRIPT); |
312 canvas->DrawImageInt(img, size().width() - img.width(), 0); | 314 canvas->DrawImageInt(img, size().width() - img.width(), 0); |
313 canvas->Restore(); | 315 canvas->Restore(); |
314 } | 316 } |
OLD | NEW |