| Index: chrome/browser/ui/views/toolbar/app_menu_button.cc
|
| diff --git a/chrome/browser/ui/views/toolbar/app_menu_button.cc b/chrome/browser/ui/views/toolbar/app_menu_button.cc
|
| index 272cc0d040ab95740e921be83559b1e7ada2e5b5..4790981dbec7a1aabe1d62c98c84212cf233b767 100644
|
| --- a/chrome/browser/ui/views/toolbar/app_menu_button.cc
|
| +++ b/chrome/browser/ui/views/toolbar/app_menu_button.cc
|
| @@ -28,6 +28,7 @@
|
| #include "chrome/grit/theme_resources.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/base/theme_provider.h"
|
| +#include "ui/gfx/canvas.h"
|
| #include "ui/gfx/color_palette.h"
|
| #include "ui/gfx/paint_vector_icon.h"
|
| #include "ui/keyboard/keyboard_controller.h"
|
| @@ -37,6 +38,55 @@
|
|
|
| namespace {
|
| const float kIconSize = 16;
|
| +
|
| +class VectorIconAnimator {
|
| + public:
|
| + explicit VectorIconAnimator(const gfx::VectorIcon& icon)
|
| + : icon_(icon), duration_(gfx::GetDurationOfAnimation(icon)) {}
|
| + ~VectorIconAnimator() {}
|
| +
|
| + void Start(const base::Closure& animation_callback) {
|
| + start_time_ = base::TimeTicks::Now();
|
| + timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(17), this,
|
| + &VectorIconAnimator::TimerFired);
|
| + callback_ = animation_callback;
|
| + }
|
| +
|
| + base::TimeDelta GetElapsedTime() {
|
| + return base::TimeTicks::Now() - start_time_;
|
| + }
|
| +
|
| + void PaintIcon(gfx::Canvas* canvas,
|
| + SkColor color,
|
| + const gfx::Point& position) {
|
| + if (timer_.IsRunning()) {
|
| + gfx::ScopedCanvas scoped(canvas);
|
| + canvas->Translate(position.OffsetFromOrigin());
|
| + base::TimeDelta elapsed = base::TimeTicks::Now() - start_time_;
|
| + gfx::PaintVectorIcon(canvas, icon_, color, &elapsed);
|
| + } else {
|
| + canvas->DrawImageInt(gfx::CreateVectorIcon(icon_, color), position.x(),
|
| + position.y());
|
| + }
|
| + }
|
| +
|
| + private:
|
| + void TimerFired() {
|
| + if (duration_ > base::TimeTicks::Now() - start_time_)
|
| + timer_.Stop();
|
| +
|
| + callback_.Run();
|
| + }
|
| +
|
| + const gfx::VectorIcon& icon_;
|
| + base::Closure callback_;
|
| + base::TimeTicks start_time_;
|
| + base::RepeatingTimer timer_;
|
| + const base::TimeDelta duration_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(VectorIconAnimator);
|
| +};
|
| +
|
| } // namespace
|
|
|
| // static
|
| @@ -131,7 +181,7 @@ gfx::Size AppMenuButton::GetPreferredSize() const {
|
| }
|
|
|
| void AppMenuButton::Layout() {
|
| - if (animation_) {
|
| + if (animator_) {
|
| ink_drop_container()->SetBoundsRect(GetLocalBounds());
|
| image()->SetBoundsRect(GetLocalBounds());
|
| return;
|
| @@ -141,14 +191,14 @@ void AppMenuButton::Layout() {
|
| }
|
|
|
| void AppMenuButton::OnPaint(gfx::Canvas* canvas) {
|
| - if (!animation_) {
|
| + if (!animator_) {
|
| views::MenuButton::OnPaint(canvas);
|
| return;
|
| }
|
|
|
| - gfx::Rect bounds = GetLocalBounds();
|
| - bounds.Inset(gfx::Insets(ToolbarButton::kInteriorPadding));
|
| - animation_->PaintAppMenu(canvas, bounds);
|
| + animator_->PaintIcon(canvas, SK_ColorRED,
|
| + gfx::Vector2d(ToolbarButton::kInteriorPadding,
|
| + ToolbarButton::kInteriorPadding));
|
| }
|
|
|
| void AppMenuButton::TabInsertedAt(TabStripModel* tab_strip_model,
|
| @@ -182,13 +232,12 @@ void AppMenuButton::UpdateIcon(bool should_animate) {
|
| }
|
|
|
| if (should_use_new_icon_) {
|
| - if (!animation_)
|
| - animation_ = base::MakeUnique<AppMenuAnimation>(this, toolbar_icon_color);
|
| + if (!animator_)
|
| + animator_.reset(new VectorIconAnimator(kBrowserToolsAnimatedIcon));
|
|
|
| - animation_->set_target_color(severity_color);
|
| + // animation_->set_target_color(severity_color);
|
| if (should_animate)
|
| AnimateIconIfPossible();
|
| -
|
| return;
|
| }
|
|
|
| @@ -218,12 +267,16 @@ void AppMenuButton::SetTrailingMargin(int margin) {
|
| }
|
|
|
| void AppMenuButton::AnimateIconIfPossible() {
|
| - if (!animation_ || !should_use_new_icon_ ||
|
| + if (/*!animation_ ||*/ !should_use_new_icon_ ||
|
| severity_ == AppMenuIconController::Severity::NONE) {
|
| return;
|
| }
|
|
|
| - animation_->StartAnimation();
|
| + // animation_->StartAnimation();
|
| + animation_start_time_ = base::TimeTicks::Now();
|
| + animation_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(17),
|
| + static_cast<views::View*>(this),
|
| + &views::View::SchedulePaint);
|
| }
|
|
|
| void AppMenuButton::AppMenuAnimationStarted() {
|
|
|