Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3360)

Unified Diff: chrome/browser/extensions/location_bar_controller.cc

Issue 10559054: Animate the script badges. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: really sending for review... Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/location_bar_controller.cc
diff --git a/chrome/browser/extensions/location_bar_controller.cc b/chrome/browser/extensions/location_bar_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1d2f10632162bbf5e3054f6877d58830eb7d8781
--- /dev/null
+++ b/chrome/browser/extensions/location_bar_controller.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/location_bar_controller.h"
+
+#include "base/compiler_specific.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkDevice.h"
+#include "third_party/skia/include/core/SkPaint.h"
+#include "ui/base/animation/animation.h"
+#include "ui/base/animation/animation_delegate.h"
+
+namespace extensions {
+
+LocationBarController::IconAnimation::IconAnimation(
+ LocationBarController* owner,
+ ui::AnimationDelegate* delegate)
+ // 100ms animation at 50fps (so 5 animation frames in total).
+ : ui::LinearAnimation(100, 50, delegate),
+ owner_(owner) {}
+
+LocationBarController::IconAnimation::~IconAnimation() {}
+
+const SkBitmap& LocationBarController::IconAnimation::Apply(
+ const SkBitmap& icon) const {
+ DCHECK_GT(icon.width(), 0);
+ DCHECK_GT(icon.height(), 0);
+
+ if (!device_.get() ||
+ (device_->width() != icon.width()) ||
+ (device_->height() != icon.height())) {
+ device_.reset(new SkDevice(
+ SkBitmap::kARGB_8888_Config, icon.width(), icon.height(), true));
+ }
+
+ SkCanvas canvas(device_.get());
+ canvas.clear(SK_ColorWHITE);
+ SkPaint paint;
+ paint.setAlpha(CurrentValueBetween(0, 255));
+ canvas.drawBitmap(icon, 0, 0, &paint);
+ return device_->accessBitmap(false);
+}
+
+void LocationBarController::IconAnimation::AddObserver(
+ LocationBarController::IconAnimation::Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void LocationBarController::IconAnimation::RemoveObserver(
+ LocationBarController::IconAnimation::Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void LocationBarController::IconAnimation::AnimateToState(double state) {
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ OnIconChanged(*this, owner_));
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698