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 "chrome/common/extensions/extension_action.h" | 5 #include "chrome/common/extensions/extension_action.h" |
6 | 6 |
7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/gfx/rect.h" | 9 #include "base/gfx/rect.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
11 #include "grit/app_resources.h" | 11 #include "grit/app_resources.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "third_party/skia/include/core/SkTypeface.h" | 13 #include "third_party/skia/include/core/SkTypeface.h" |
14 #include "third_party/skia/include/effects/SkGradientShader.h" | 14 #include "third_party/skia/include/effects/SkGradientShader.h" |
15 | 15 |
16 const int ExtensionAction::kDefaultTabId = -1; | 16 const int ExtensionAction::kDefaultTabId = -1; |
17 | 17 |
18 void ExtensionAction::ClearAllValuesForTab(int tab_id) { | 18 void ExtensionAction::ClearAllValuesForTab(int tab_id) { |
19 title_.erase(tab_id); | 19 title_.erase(tab_id); |
20 icon_.erase(tab_id); | 20 icon_.erase(tab_id); |
21 icon_index_.erase(tab_id); | 21 icon_index_.erase(tab_id); |
22 badge_text_.erase(tab_id); | 22 badge_text_.erase(tab_id); |
23 badge_text_color_.erase(tab_id); | 23 badge_text_color_.erase(tab_id); |
24 badge_background_color_.erase(tab_id); | 24 badge_background_color_.erase(tab_id); |
25 visible_.erase(tab_id); | 25 visible_.erase(tab_id); |
26 } | 26 } |
27 | 27 |
28 void ExtensionAction::PaintBadge(gfx::Canvas* canvas, | 28 void ExtensionAction::PaintBadge(gfx::Canvas* canvas, |
29 const gfx::Rect& bounds, | 29 const gfx::Rect& bounds, |
30 int tab_id) { | 30 int tab_id) { |
31 std::string text = GetBadgeText(tab_id); | 31 std::string text = GetBadgeText(tab_id); |
32 if (text.empty()) | 32 if (text.empty()) |
33 return; | 33 return; |
34 | 34 |
35 SkColor text_color = GetBadgeTextColor(tab_id); | 35 SkColor text_color = GetBadgeTextColor(tab_id); |
36 SkColor background_color = GetBadgeBackgroundColor(tab_id); | 36 SkColor background_color = GetBadgeBackgroundColor(tab_id); |
37 | 37 |
38 if (SkColorGetA(text_color) == 0x00) | 38 if (SkColorGetA(text_color) == 0x00) |
39 text_color = SK_ColorWHITE; | 39 text_color = SK_ColorWHITE; |
40 | 40 |
41 if (SkColorGetA(background_color) == 0x00) | 41 if (SkColorGetA(background_color) == 0x00) |
42 background_color = SkColorSetARGB(255, 218, 0, 24); // default badge color | 42 background_color = SkColorSetARGB(255, 218, 0, 24); // default badge color |
43 | 43 |
44 // Different platforms need slightly different constants to look good. | 44 // Different platforms need slightly different constants to look good. |
45 #if defined(OS_LINUX) | 45 #if defined(OS_LINUX) |
46 const int kTextSize = 9; | 46 const int kTextSize = 9; |
47 const int kBottomMargin = 4; | 47 const int kBottomMargin = 0; |
48 const int kPadding = 2; | 48 const int kPadding = 2; |
49 const int kBadgeHeight = 12; | 49 const int kTopTextPadding = 0; |
Aaron Boodman
2009/10/28 03:18:12
Weird. I wonder why these are different.
| |
50 const int kBadgeHeight = 11; | |
50 const int kMaxTextWidth = 23; | 51 const int kMaxTextWidth = 23; |
51 // The minimum width for center-aligning the badge. | 52 // The minimum width for center-aligning the badge. |
52 const int kCenterAlignThreshold = 20; | 53 const int kCenterAlignThreshold = 20; |
53 #else | 54 #else |
54 const int kTextSize = 8; | 55 const int kTextSize = 8; |
55 const int kBottomMargin = 5; | 56 const int kBottomMargin = 5; |
56 const int kPadding = 2; | 57 const int kPadding = 2; |
58 // The padding between the top of the badge and the top of the text. | |
59 const int kTopTextPadding = 1; | |
57 const int kBadgeHeight = 11; | 60 const int kBadgeHeight = 11; |
58 const int kMaxTextWidth = 23; | 61 const int kMaxTextWidth = 23; |
59 // The minimum width for center-aligning the badge. | 62 // The minimum width for center-aligning the badge. |
60 const int kCenterAlignThreshold = 20; | 63 const int kCenterAlignThreshold = 20; |
61 #endif | 64 #endif |
62 | 65 |
63 canvas->save(); | 66 canvas->save(); |
64 | 67 |
65 #if defined(OS_MACOSX) | 68 #if defined(OS_MACOSX) |
66 SkTypeface* typeface = | 69 SkTypeface* typeface = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 canvas->drawBitmap(*gradient_right, | 127 canvas->drawBitmap(*gradient_right, |
125 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); | 128 rect.fRight - SkIntToScalar(gradient_right->width()), rect.fTop); |
126 | 129 |
127 // Finally, draw the text centered within the badge. We set a clip in case the | 130 // Finally, draw the text centered within the badge. We set a clip in case the |
128 // text was too large. | 131 // text was too large. |
129 rect.fLeft += kPadding; | 132 rect.fLeft += kPadding; |
130 rect.fRight -= kPadding; | 133 rect.fRight -= kPadding; |
131 canvas->clipRect(rect); | 134 canvas->clipRect(rect); |
132 canvas->drawText(text.c_str(), text.size(), | 135 canvas->drawText(text.c_str(), text.size(), |
133 rect.fLeft + (rect.width() - text_width) / 2, | 136 rect.fLeft + (rect.width() - text_width) / 2, |
134 rect.fTop + kTextSize + 1, | 137 rect.fTop + kTextSize + kTopTextPadding, |
135 text_paint); | 138 text_paint); |
136 canvas->restore(); | 139 canvas->restore(); |
137 } | 140 } |
OLD | NEW |