OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/location_bar_controller.h" |
| 6 |
| 7 #include "base/compiler_specific.h" |
| 8 #include "third_party/skia/include/core/SkCanvas.h" |
| 9 #include "third_party/skia/include/core/SkDevice.h" |
| 10 #include "third_party/skia/include/core/SkPaint.h" |
| 11 #include "ui/base/animation/animation.h" |
| 12 #include "ui/base/animation/animation_delegate.h" |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 LocationBarController::IconAnimation::IconAnimation( |
| 17 LocationBarController* owner, |
| 18 ui::AnimationDelegate* delegate) |
| 19 // 100ms animation at 50fps (so 5 animation frames in total). |
| 20 : ui::LinearAnimation(100, 50, delegate), |
| 21 owner_(owner) {} |
| 22 |
| 23 LocationBarController::IconAnimation::~IconAnimation() {} |
| 24 |
| 25 const SkBitmap& LocationBarController::IconAnimation::Apply( |
| 26 const SkBitmap& icon) const { |
| 27 DCHECK_GT(icon.width(), 0); |
| 28 DCHECK_GT(icon.height(), 0); |
| 29 |
| 30 if (!device_.get() || |
| 31 (device_->width() != icon.width()) || |
| 32 (device_->height() != icon.height())) { |
| 33 device_.reset(new SkDevice( |
| 34 SkBitmap::kARGB_8888_Config, icon.width(), icon.height(), true)); |
| 35 } |
| 36 |
| 37 SkCanvas canvas(device_.get()); |
| 38 canvas.clear(SK_ColorWHITE); |
| 39 SkPaint paint; |
| 40 paint.setAlpha(CurrentValueBetween(0, 255)); |
| 41 canvas.drawBitmap(icon, 0, 0, &paint); |
| 42 return device_->accessBitmap(false); |
| 43 } |
| 44 |
| 45 void LocationBarController::IconAnimation::AddObserver( |
| 46 LocationBarController::IconAnimation::Observer* observer) { |
| 47 observers_.AddObserver(observer); |
| 48 } |
| 49 |
| 50 void LocationBarController::IconAnimation::RemoveObserver( |
| 51 LocationBarController::IconAnimation::Observer* observer) { |
| 52 observers_.RemoveObserver(observer); |
| 53 } |
| 54 |
| 55 void LocationBarController::IconAnimation::AnimateToState(double state) { |
| 56 FOR_EACH_OBSERVER(Observer, |
| 57 observers_, |
| 58 OnIconChanged(*this, owner_)); |
| 59 } |
| 60 |
| 61 } // namespace extensions |
OLD | NEW |