OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/gfx/canvas.h" | 5 #include "app/gfx/canvas.h" |
6 #include "app/resource_bundle.h" | 6 #include "app/resource_bundle.h" |
7 #include "base/gfx/rect.h" | 7 #include "base/gfx/rect.h" |
8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
9 #include "chrome/common/extensions/extension_action.h" | 9 #include "chrome/common/extensions/extension_action.h" |
10 #include "grit/app_resources.h" | 10 #include "grit/app_resources.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/core/SkTypeface.h" | 12 #include "third_party/skia/include/core/SkTypeface.h" |
13 #include "third_party/skia/include/effects/SkGradientShader.h" | 13 #include "third_party/skia/include/effects/SkGradientShader.h" |
14 | 14 |
15 ExtensionAction::ExtensionAction() | 15 ExtensionAction::ExtensionAction() |
16 : type_(PAGE_ACTION) { | 16 : type_(PAGE_ACTION) { |
17 } | 17 } |
18 | 18 |
19 ExtensionAction::~ExtensionAction() { | 19 ExtensionAction::~ExtensionAction() { |
20 } | 20 } |
21 | 21 |
22 void ExtensionActionState::PaintBadge(gfx::Canvas* canvas, | 22 void ExtensionActionState::PaintBadge(gfx::Canvas* canvas, |
23 const gfx::Rect& bounds) { | 23 const gfx::Rect& bounds) const { |
24 const std::string& text = badge_text(); | 24 const std::string& text = badge_text(); |
25 if (text.empty()) | 25 if (text.empty()) |
26 return; | 26 return; |
27 | 27 |
28 // Different platforms need slightly different constants to look good. | 28 // Different platforms need slightly different constants to look good. |
29 #if defined(OS_LINUX) | 29 #if defined(OS_LINUX) |
30 const int kTextSize = 9; | 30 const int kTextSize = 9; |
31 const int kBottomMargin = 4; | 31 const int kBottomMargin = 4; |
32 const int kPadding = 2; | 32 const int kPadding = 2; |
33 const int kBadgeHeight = 12; | 33 const int kBadgeHeight = 12; |
34 const int kMaxTextWidth = 23; | 34 const int kMaxTextWidth = 23; |
35 // The minimum width for center-aligning the badge. | 35 // The minimum width for center-aligning the badge. |
36 const int kCenterAlignThreshold = 20; | 36 const int kCenterAlignThreshold = 20; |
37 #else | 37 #else |
38 const int kTextSize = 8; | 38 const int kTextSize = 8; |
39 const int kBottomMargin = 5; | 39 const int kBottomMargin = 5; |
40 const int kPadding = 2; | 40 const int kPadding = 2; |
41 const int kBadgeHeight = 11; | 41 const int kBadgeHeight = 11; |
42 const int kMaxTextWidth = 23; | 42 const int kMaxTextWidth = 23; |
43 // The minimum width for center-aligning the badge. | 43 // The minimum width for center-aligning the badge. |
44 const int kCenterAlignThreshold = 20; | 44 const int kCenterAlignThreshold = 20; |
45 #endif | 45 #endif |
46 | 46 |
47 canvas->save(); | 47 canvas->save(); |
48 | 48 |
49 SkTypeface* typeface = SkTypeface::CreateFromName("Arial", SkTypeface::kBold); | 49 SkTypeface* typeface = SkTypeface::CreateFromName("Arial", SkTypeface::kBold); |
50 SkPaint text_paint; | 50 SkPaint text_paint; |
51 text_paint.setAntiAlias(true); | 51 text_paint.setAntiAlias(true); |
52 text_paint.setColor(SK_ColorWHITE); | 52 text_paint.setColor(badge_text_color()); |
53 text_paint.setFakeBoldText(true); | 53 text_paint.setFakeBoldText(true); |
54 text_paint.setTextAlign(SkPaint::kLeft_Align); | 54 text_paint.setTextAlign(SkPaint::kLeft_Align); |
55 text_paint.setTextSize(SkIntToScalar(kTextSize)); | 55 text_paint.setTextSize(SkIntToScalar(kTextSize)); |
56 text_paint.setTypeface(typeface); | 56 text_paint.setTypeface(typeface); |
57 | 57 |
58 // Calculate text width. We clamp it to a max size. | 58 // Calculate text width. We clamp it to a max size. |
59 SkScalar text_width = text_paint.measureText(text.c_str(), text.size()); | 59 SkScalar text_width = text_paint.measureText(text.c_str(), text.size()); |
60 text_width = SkIntToScalar( | 60 text_width = SkIntToScalar( |
61 std::min(kMaxTextWidth, SkScalarFloor(text_width))); | 61 std::min(kMaxTextWidth, SkScalarFloor(text_width))); |
62 | 62 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // text was too large. | 107 // text was too large. |
108 rect.fLeft += kPadding; | 108 rect.fLeft += kPadding; |
109 rect.fRight -= kPadding; | 109 rect.fRight -= kPadding; |
110 canvas->clipRect(rect); | 110 canvas->clipRect(rect); |
111 canvas->drawText(text.c_str(), text.size(), | 111 canvas->drawText(text.c_str(), text.size(), |
112 rect.fLeft + (rect.width() - text_width) / 2, | 112 rect.fLeft + (rect.width() - text_width) / 2, |
113 rect.fTop + kTextSize + 1, | 113 rect.fTop + kTextSize + 1, |
114 text_paint); | 114 text_paint); |
115 canvas->restore(); | 115 canvas->restore(); |
116 } | 116 } |
OLD | NEW |