| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 class GetAttentionImageSource : public gfx::ImageSkiaSource { | 36 class GetAttentionImageSource : public gfx::ImageSkiaSource { |
| 37 public: | 37 public: |
| 38 explicit GetAttentionImageSource(const gfx::ImageSkia& icon) | 38 explicit GetAttentionImageSource(const gfx::ImageSkia& icon) |
| 39 : icon_(icon) {} | 39 : icon_(icon) {} |
| 40 | 40 |
| 41 // gfx::ImageSkiaSource overrides: | 41 // gfx::ImageSkiaSource overrides: |
| 42 virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) | 42 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 43 OVERRIDE { | 43 gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale); |
| 44 gfx::ImageSkiaRep icon_rep = icon_.GetRepresentation(scale_factor); | |
| 45 color_utils::HSL shift = {-1, 0, 0.5}; | 44 color_utils::HSL shift = {-1, 0, 0.5}; |
| 46 return gfx::ImageSkiaRep( | 45 return gfx::ImageSkiaRep( |
| 47 SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift), | 46 SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift), |
| 48 icon_rep.scale_factor()); | 47 icon_rep.scale()); |
| 49 } | 48 } |
| 50 | 49 |
| 51 private: | 50 private: |
| 52 const gfx::ImageSkia icon_; | 51 const gfx::ImageSkia icon_; |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 } // namespace | 54 } // namespace |
| 56 | 55 |
| 57 // TODO(tbarzic): Merge AnimationIconImageSource and IconAnimation together. | 56 // TODO(tbarzic): Merge AnimationIconImageSource and IconAnimation together. |
| 58 // Source for painting animated skia image. | 57 // Source for painting animated skia image. |
| 59 class AnimatedIconImageSource : public gfx::ImageSkiaSource { | 58 class AnimatedIconImageSource : public gfx::ImageSkiaSource { |
| 60 public: | 59 public: |
| 61 AnimatedIconImageSource( | 60 AnimatedIconImageSource( |
| 62 const gfx::ImageSkia& image, | 61 const gfx::ImageSkia& image, |
| 63 base::WeakPtr<ExtensionAction::IconAnimation> animation) | 62 base::WeakPtr<ExtensionAction::IconAnimation> animation) |
| 64 : image_(image), | 63 : image_(image), |
| 65 animation_(animation) { | 64 animation_(animation) { |
| 66 } | 65 } |
| 67 | 66 |
| 68 private: | 67 private: |
| 69 virtual ~AnimatedIconImageSource() {} | 68 virtual ~AnimatedIconImageSource() {} |
| 70 | 69 |
| 71 virtual gfx::ImageSkiaRep GetImageForScale(ui::ScaleFactor scale) OVERRIDE { | 70 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
| 72 gfx::ImageSkiaRep original_rep = image_.GetRepresentation(scale); | 71 gfx::ImageSkiaRep original_rep = image_.GetRepresentation(scale); |
| 73 if (!animation_.get()) | 72 if (!animation_.get()) |
| 74 return original_rep; | 73 return original_rep; |
| 75 | 74 |
| 76 // Original representation's scale factor may be different from scale | 75 // Original representation's scale factor may be different from scale |
| 77 // factor passed to this method. We want to use the former (since we are | 76 // factor passed to this method. We want to use the former (since we are |
| 78 // using bitmap for that scale). | 77 // using bitmap for that scale). |
| 79 return gfx::ImageSkiaRep( | 78 return gfx::ImageSkiaRep( |
| 80 animation_->Apply(original_rep.sk_bitmap()), | 79 animation_->Apply(original_rep.sk_bitmap()), original_rep.scale()); |
| 81 original_rep.scale_factor()); | |
| 82 } | 80 } |
| 83 | 81 |
| 84 gfx::ImageSkia image_; | 82 gfx::ImageSkia image_; |
| 85 base::WeakPtr<ExtensionAction::IconAnimation> animation_; | 83 base::WeakPtr<ExtensionAction::IconAnimation> animation_; |
| 86 | 84 |
| 87 DISALLOW_COPY_AND_ASSIGN(AnimatedIconImageSource); | 85 DISALLOW_COPY_AND_ASSIGN(AnimatedIconImageSource); |
| 88 }; | 86 }; |
| 89 | 87 |
| 90 const int ExtensionAction::kDefaultTabId = -1; | 88 const int ExtensionAction::kDefaultTabId = -1; |
| 91 // 100ms animation at 50fps (so 5 animation frames in total). | 89 // 100ms animation at 50fps (so 5 animation frames in total). |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 icon_animation->Start(); | 390 icon_animation->Start(); |
| 393 // After the icon is finished fading in (plus some padding to handle random | 391 // 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 | 392 // 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 | 393 // deleted even if it hasn't finished by the time the MessageLoop is |
| 396 // destroyed. | 394 // destroyed. |
| 397 base::MessageLoop::current()->PostDelayedTask( | 395 base::MessageLoop::current()->PostDelayedTask( |
| 398 FROM_HERE, | 396 FROM_HERE, |
| 399 base::Bind(&DestroyIconAnimation, base::Passed(&icon_animation)), | 397 base::Bind(&DestroyIconAnimation, base::Passed(&icon_animation)), |
| 400 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); | 398 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); |
| 401 } | 399 } |
| OLD | NEW |