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" |
| 6 |
5 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
6 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
7 #include "base/gfx/rect.h" | 9 #include "base/gfx/rect.h" |
8 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
9 #include "chrome/common/extensions/extension_action.h" | |
10 #include "grit/app_resources.h" | 11 #include "grit/app_resources.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/skia/include/core/SkTypeface.h" | 13 #include "third_party/skia/include/core/SkTypeface.h" |
13 #include "third_party/skia/include/effects/SkGradientShader.h" | 14 #include "third_party/skia/include/effects/SkGradientShader.h" |
14 | 15 |
15 ExtensionAction::ExtensionAction() | 16 const int ExtensionAction::kDefaultTabId = -1; |
16 : type_(PAGE_ACTION) { | 17 |
| 18 void ExtensionAction::ClearAllValuesForTab(int tab_id) { |
| 19 title_.erase(tab_id); |
| 20 icon_.erase(tab_id); |
| 21 icon_index_.erase(tab_id); |
| 22 badge_text_.erase(tab_id); |
| 23 badge_text_color_.erase(tab_id); |
| 24 badge_background_color_.erase(tab_id); |
| 25 visible_.erase(tab_id); |
17 } | 26 } |
18 | 27 |
19 ExtensionAction::~ExtensionAction() { | 28 void ExtensionAction::PaintBadge(gfx::Canvas* canvas, |
20 } | 29 const gfx::Rect& bounds, |
21 | 30 int tab_id) { |
22 void ExtensionActionState::PaintBadge(gfx::Canvas* canvas, | 31 std::string text = GetBadgeText(tab_id); |
23 const gfx::Rect& bounds, | |
24 const std::string& text, | |
25 SkColor text_color, | |
26 SkColor background_color) { | |
27 if (text.empty()) | 32 if (text.empty()) |
28 return; | 33 return; |
29 | 34 |
| 35 SkColor text_color = GetBadgeTextColor(tab_id); |
| 36 SkColor background_color = GetBadgeBackgroundColor(tab_id); |
| 37 |
30 if (SkColorGetA(text_color) == 0x00) | 38 if (SkColorGetA(text_color) == 0x00) |
31 text_color = SK_ColorWHITE; | 39 text_color = SK_ColorWHITE; |
32 | 40 |
33 if (SkColorGetA(background_color) == 0x00) | 41 if (SkColorGetA(background_color) == 0x00) |
34 background_color = SkColorSetARGB(255, 218, 0, 24); // default badge color | 42 background_color = SkColorSetARGB(255, 218, 0, 24); // default badge color |
35 | 43 |
36 // Different platforms need slightly different constants to look good. | 44 // Different platforms need slightly different constants to look good. |
37 #if defined(OS_LINUX) | 45 #if defined(OS_LINUX) |
38 const int kTextSize = 9; | 46 const int kTextSize = 9; |
39 const int kBottomMargin = 4; | 47 const int kBottomMargin = 4; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // text was too large. | 123 // text was too large. |
116 rect.fLeft += kPadding; | 124 rect.fLeft += kPadding; |
117 rect.fRight -= kPadding; | 125 rect.fRight -= kPadding; |
118 canvas->clipRect(rect); | 126 canvas->clipRect(rect); |
119 canvas->drawText(text.c_str(), text.size(), | 127 canvas->drawText(text.c_str(), text.size(), |
120 rect.fLeft + (rect.width() - text_width) / 2, | 128 rect.fLeft + (rect.width() - text_width) / 2, |
121 rect.fTop + kTextSize + 1, | 129 rect.fTop + kTextSize + 1, |
122 text_paint); | 130 text_paint); |
123 canvas->restore(); | 131 canvas->restore(); |
124 } | 132 } |
OLD | NEW |