Commit 984bf1be authored by Sangwoo Ko's avatar Sangwoo Ko Committed by Commit Bot

Align InfobarView animation to Compositor

components/infobars/core/infobar is a AnimationDelegate but this can't use
AnimationDelegateViews or get widget as it would be layering violation.

So it's subclass, InfoBarView sets AnimationDelegateNotifier with AnimationDelegateViews. AnimationDelegateViews will adapt CompositorAnimationRunner for InfoBar and then forward callbacks to InfoBar.

There's no intentional behavior changes.

Bug: 824026
Change-Id: Id824a6a402682e9ec5a0f36216d92d92cffa5669
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1933839Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721507}
parent 8e21df05
...@@ -90,6 +90,11 @@ gfx::Insets GetCloseButtonSpacing() { ...@@ -90,6 +90,11 @@ gfx::Insets GetCloseButtonSpacing() {
InfoBarView::InfoBarView(std::unique_ptr<infobars::InfoBarDelegate> delegate) InfoBarView::InfoBarView(std::unique_ptr<infobars::InfoBarDelegate> delegate)
: infobars::InfoBar(std::move(delegate)), : infobars::InfoBar(std::move(delegate)),
views::ExternalFocusTracker(this, nullptr) { views::ExternalFocusTracker(this, nullptr) {
// Make Infobar animation aligned to the Compositor.
SetNotifier(std::make_unique<
gfx::AnimationDelegateNotifier<views::AnimationDelegateViews>>(
this, this));
set_owned_by_client(); // InfoBar deletes itself at the appropriate time. set_owned_by_client(); // InfoBar deletes itself at the appropriate time.
// Clip child layers; without this, buttons won't look correct during // Clip child layers; without this, buttons won't look correct during
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include <cmath> #include <cmath>
#include <memory>
#include <utility> #include <utility>
#include "base/logging.h" #include "base/logging.h"
...@@ -19,7 +20,8 @@ InfoBar::InfoBar(std::unique_ptr<InfoBarDelegate> delegate) ...@@ -19,7 +20,8 @@ InfoBar::InfoBar(std::unique_ptr<InfoBarDelegate> delegate)
: owner_(nullptr), : owner_(nullptr),
delegate_(std::move(delegate)), delegate_(std::move(delegate)),
container_(nullptr), container_(nullptr),
animation_(this), notifier_(std::make_unique<gfx::AnimationDelegateNotifier<>>(this)),
animation_(notifier_.get()),
height_(0), height_(0),
target_height_(0) { target_height_(0) {
DCHECK(delegate_ != nullptr); DCHECK(delegate_ != nullptr);
...@@ -42,6 +44,11 @@ void InfoBar::SetOwner(InfoBarManager* owner) { ...@@ -42,6 +44,11 @@ void InfoBar::SetOwner(InfoBarManager* owner) {
PlatformSpecificSetOwner(); PlatformSpecificSetOwner();
} }
void InfoBar::SetNotifier(std::unique_ptr<gfx::AnimationDelegate> notifier) {
notifier_ = std::move(notifier);
animation_.set_delegate(notifier_.get());
}
void InfoBar::Show(bool animate) { void InfoBar::Show(bool animate) {
PlatformSpecificShow(animate); PlatformSpecificShow(animate);
if (animate) { if (animate) {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/infobars/core/infobar_delegate.h" #include "components/infobars/core/infobar_delegate.h"
#include "ui/gfx/animation/animation_delegate.h" #include "ui/gfx/animation/animation_delegate_notifier.h"
#include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -48,6 +48,8 @@ class InfoBar : public gfx::AnimationDelegate { ...@@ -48,6 +48,8 @@ class InfoBar : public gfx::AnimationDelegate {
// without deleting it, for reparenting in another tab. // without deleting it, for reparenting in another tab.
void SetOwner(InfoBarManager* owner); void SetOwner(InfoBarManager* owner);
void SetNotifier(std::unique_ptr<gfx::AnimationDelegate> notifier);
// Makes the infobar visible. If |animate| is true, the infobar is then // Makes the infobar visible. If |animate| is true, the infobar is then
// animated to full size. // animated to full size.
void Show(bool animate); void Show(bool animate);
...@@ -107,6 +109,8 @@ class InfoBar : public gfx::AnimationDelegate { ...@@ -107,6 +109,8 @@ class InfoBar : public gfx::AnimationDelegate {
InfoBarManager* owner_; InfoBarManager* owner_;
std::unique_ptr<InfoBarDelegate> delegate_; std::unique_ptr<InfoBarDelegate> delegate_;
InfoBarContainer* container_; InfoBarContainer* container_;
std::unique_ptr<gfx::AnimationDelegate> notifier_;
gfx::SlideAnimation animation_; gfx::SlideAnimation animation_;
// The current and target heights. // The current and target heights.
......
...@@ -25,6 +25,7 @@ jumbo_component("animation") { ...@@ -25,6 +25,7 @@ jumbo_component("animation") {
"animation_container_element.h", "animation_container_element.h",
"animation_container_observer.h", "animation_container_observer.h",
"animation_delegate.h", "animation_delegate.h",
"animation_delegate_notifier.h",
"animation_export.h", "animation_export.h",
"animation_runner.cc", "animation_runner.cc",
"animation_runner.h", "animation_runner.h",
......
// Copyright 2019 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.
#ifndef UI_GFX_ANIMATION_ANIMATION_DELEGATE_NOTIFIER_H_
#define UI_GFX_ANIMATION_ANIMATION_DELEGATE_NOTIFIER_H_
#include "base/logging.h"
#include "ui/gfx/animation/animation_delegate.h"
namespace gfx {
// AnimationDelegateNotifier adapts AnimationDelegate (which is used by
// inheritance) into an object that is used by composition. This can be useful
// to compose the functionality of an AnimationDelegate subclass into an object
// that inherits directly from AnimationDelegate.
template <class AnimationDelegateType = gfx::AnimationDelegate>
class AnimationDelegateNotifier : public AnimationDelegateType {
public:
template <typename... Args>
AnimationDelegateNotifier(gfx::AnimationDelegate* owner, Args&&... args)
: AnimationDelegateType(std::forward<Args>(args)...), owner_(owner) {
DCHECK(owner_);
}
~AnimationDelegateNotifier() override = default;
// AnimationDelegateType:
void AnimationEnded(const Animation* animation) override {
AnimationDelegateType::AnimationEnded(animation);
owner_->AnimationEnded(animation);
}
void AnimationProgressed(const Animation* animation) override {
AnimationDelegateType::AnimationProgressed(animation);
owner_->AnimationProgressed(animation);
}
void AnimationCanceled(const Animation* animation) override {
AnimationDelegateType::AnimationCanceled(animation);
owner_->AnimationCanceled(animation);
}
void AnimationContainerWasSet(AnimationContainer* container) override {
AnimationDelegateType::AnimationContainerWasSet(container);
owner_->AnimationContainerWasSet(container);
}
private:
gfx::AnimationDelegate* const owner_;
};
} // namespace gfx
#endif // UI_GFX_ANIMATION_ANIMATION_DELEGATE_NOTIFIER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment