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/extensions/extension_action.h" | 5 #include "chrome/browser/extensions/extension_action.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "chrome/common/badge_util.h" | 12 #include "chrome/common/badge_util.h" |
13 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
14 #include "chrome/common/icon_with_badge_image_source.h" | 14 #include "chrome/common/icon_with_badge_image_source.h" |
15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
16 #include "grit/ui_resources.h" | 16 #include "grit/ui_resources.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 #include "third_party/skia/include/core/SkBitmapDevice.h" |
18 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
19 #include "third_party/skia/include/core/SkDevice.h" | |
20 #include "third_party/skia/include/core/SkPaint.h" | 20 #include "third_party/skia/include/core/SkPaint.h" |
21 #include "third_party/skia/include/effects/SkGradientShader.h" | 21 #include "third_party/skia/include/effects/SkGradientShader.h" |
22 #include "ui/base/animation/animation_delegate.h" | 22 #include "ui/base/animation/animation_delegate.h" |
23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
25 #include "ui/gfx/color_utils.h" | 25 #include "ui/gfx/color_utils.h" |
26 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
27 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
28 #include "ui/gfx/image/image_skia_source.h" | 28 #include "ui/gfx/image/image_skia_source.h" |
29 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 const SkBitmap& ExtensionAction::IconAnimation::Apply( | 108 const SkBitmap& ExtensionAction::IconAnimation::Apply( |
109 const SkBitmap& icon) const { | 109 const SkBitmap& icon) const { |
110 DCHECK_GT(icon.width(), 0); | 110 DCHECK_GT(icon.width(), 0); |
111 DCHECK_GT(icon.height(), 0); | 111 DCHECK_GT(icon.height(), 0); |
112 | 112 |
113 if (!device_.get() || | 113 if (!device_.get() || |
114 (device_->width() != icon.width()) || | 114 (device_->width() != icon.width()) || |
115 (device_->height() != icon.height())) { | 115 (device_->height() != icon.height())) { |
116 device_.reset(new SkDevice( | 116 device_.reset(new SkBitmapDevice( |
117 SkBitmap::kARGB_8888_Config, icon.width(), icon.height(), true)); | 117 SkBitmap::kARGB_8888_Config, icon.width(), icon.height(), true)); |
118 } | 118 } |
119 | 119 |
120 SkCanvas canvas(device_.get()); | 120 SkCanvas canvas(device_.get()); |
121 canvas.clear(SK_ColorWHITE); | 121 canvas.clear(SK_ColorWHITE); |
122 SkPaint paint; | 122 SkPaint paint; |
123 paint.setAlpha(CurrentValueBetween(0, 255)); | 123 paint.setAlpha(CurrentValueBetween(0, 255)); |
124 canvas.drawBitmap(icon, 0, 0, &paint); | 124 canvas.drawBitmap(icon, 0, 0, &paint); |
125 return device_->accessBitmap(false); | 125 return device_->accessBitmap(false); |
126 } | 126 } |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 icon_animation->Start(); | 392 icon_animation->Start(); |
393 // After the icon is finished fading in (plus some padding to handle random | 393 // After the icon is finished fading in (plus some padding to handle random |
394 // timer delays), destroy it. We use a delayed task so that the Animation is | 394 // timer delays), destroy it. We use a delayed task so that the Animation is |
395 // deleted even if it hasn't finished by the time the MessageLoop is | 395 // deleted even if it hasn't finished by the time the MessageLoop is |
396 // destroyed. | 396 // destroyed. |
397 base::MessageLoop::current()->PostDelayedTask( | 397 base::MessageLoop::current()->PostDelayedTask( |
398 FROM_HERE, | 398 FROM_HERE, |
399 base::Bind(&DestroyIconAnimation, base::Passed(&icon_animation)), | 399 base::Bind(&DestroyIconAnimation, base::Passed(&icon_animation)), |
400 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); | 400 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); |
401 } | 401 } |
OLD | NEW |