Commit 6ebf2aa4 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overview: Remove animation observe override from ScopedTransformWindow.

Replace GetTransformForRect with gfx::TransformBetweenRects.

Test: manual
Bug: none
Change-Id: I0e699c1caa28a8c8decca18b579070cc90aa5d0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1834643
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Auto-Submit: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702060}
parent 74640a89
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/geometry/safe_integer_conversions.h" #include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/geometry/vector2d_f.h" #include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/transform_util.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/wm/core/coordinate_conversion.h" #include "ui/wm/core/coordinate_conversion.h"
...@@ -1686,9 +1687,8 @@ void OverviewGrid::AddDraggedWindowIntoOverviewOnDragEnd( ...@@ -1686,9 +1687,8 @@ void OverviewGrid::AddDraggedWindowIntoOverviewOnDragEnd(
const gfx::Rect new_bounds = dragged_window->bounds(); const gfx::Rect new_bounds = dragged_window->bounds();
if (old_bounds != new_bounds) { if (old_bounds != new_bounds) {
// It's for smoother animation. // It's for smoother animation.
gfx::Transform transform = const gfx::Transform transform = gfx::TransformBetweenRects(
ScopedOverviewTransformWindow::GetTransformForRect( gfx::RectF(new_bounds), gfx::RectF(old_bounds));
gfx::RectF(new_bounds), gfx::RectF(old_bounds));
dragged_window->SetTransform(transform); dragged_window->SetTransform(transform);
} }
dragged_window->ClearProperty(ash::kCanAttachToAnotherWindowKey); dragged_window->ClearProperty(ash::kCanAttachToAnotherWindowKey);
......
...@@ -94,23 +94,35 @@ constexpr SkColor kCloseButtonInkDropRippleHighlightColor = ...@@ -94,23 +94,35 @@ constexpr SkColor kCloseButtonInkDropRippleHighlightColor =
SkColorSetA(kCloseButtonColor, 0x14); SkColorSetA(kCloseButtonColor, 0x14);
// A self-deleting animation observer that runs the given callback when its // A self-deleting animation observer that runs the given callback when its
// associated animation completes. // associated animation completes. Optionally takes a callback that is run when
// the animation starts.
class AnimationObserver : public ui::ImplicitAnimationObserver { class AnimationObserver : public ui::ImplicitAnimationObserver {
public: public:
explicit AnimationObserver(base::OnceClosure on_animation_finished) explicit AnimationObserver(base::OnceClosure on_animation_finished)
: on_animation_finished_(std::move(on_animation_finished)) { : AnimationObserver(base::NullCallback(),
std::move(on_animation_finished)) {}
AnimationObserver(base::OnceClosure on_animation_started,
base::OnceClosure on_animation_finished)
: on_animation_started_(std::move(on_animation_started)),
on_animation_finished_(std::move(on_animation_finished)) {
DCHECK(!on_animation_finished_.is_null()); DCHECK(!on_animation_finished_.is_null());
} }
~AnimationObserver() override = default; ~AnimationObserver() override = default;
// ui::ImplicitAnimationObserver: // ui::ImplicitAnimationObserver:
void OnLayerAnimationStarted(ui::LayerAnimationSequence* sequence) override {
if (!on_animation_started_.is_null())
std::move(on_animation_started_).Run();
}
void OnImplicitAnimationsCompleted() override { void OnImplicitAnimationsCompleted() override {
std::move(on_animation_finished_).Run(); std::move(on_animation_finished_).Run();
delete this; delete this;
} }
private: private:
base::OnceClosure on_animation_started_;
base::OnceClosure on_animation_finished_; base::OnceClosure on_animation_finished_;
DISALLOW_COPY_AND_ASSIGN(AnimationObserver); DISALLOW_COPY_AND_ASSIGN(AnimationObserver);
...@@ -408,7 +420,14 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds, ...@@ -408,7 +420,14 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds,
item_widget_.get(), minimized_bounds, minimized_animation_type, item_widget_.get(), minimized_bounds, minimized_animation_type,
minimized_animation_type == minimized_animation_type ==
OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW
? &transform_window_ ? new AnimationObserver{base::BindOnce(
&OverviewItem::
OnItemBoundsAnimationStarted,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(
&OverviewItem::
OnItemBoundsAnimationEnded,
weak_ptr_factory_.GetWeakPtr())}
: nullptr); : nullptr);
// On the first update show |item_widget_|. It's created on creation of // On the first update show |item_widget_|. It's created on creation of
...@@ -1057,6 +1076,19 @@ void OverviewItem::OnItemAddedAnimationCompleted() { ...@@ -1057,6 +1076,19 @@ void OverviewItem::OnItemAddedAnimationCompleted() {
OnStartingAnimationComplete(); OnStartingAnimationComplete();
} }
void OverviewItem::OnItemBoundsAnimationStarted() {
// Remove the shadow before animating because it may affect animation
// performance. The shadow will be added back once the animation is completed.
// Note that we can't use UpdateRoundedCornersAndShadow() since we don't want
// to update the rounded corners.
SetShadowBounds(base::nullopt);
}
void OverviewItem::OnItemBoundsAnimationEnded() {
UpdateRoundedCornersAndShadow();
OnDragAnimationCompleted();
}
void OverviewItem::PerformItemAddedAnimation( void OverviewItem::PerformItemAddedAnimation(
aura::Window* window, aura::Window* window,
const gfx::Transform& target_transform) { const gfx::Transform& target_transform) {
...@@ -1120,8 +1152,8 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds, ...@@ -1120,8 +1152,8 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds,
return; return;
} }
gfx::Transform transform = ScopedOverviewTransformWindow::GetTransformForRect( const gfx::Transform transform =
screen_rect, overview_item_bounds); gfx::TransformBetweenRects(screen_rect, overview_item_bounds);
if (is_first_update && if (is_first_update &&
animation_type == OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW) { animation_type == OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW) {
...@@ -1131,6 +1163,14 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds, ...@@ -1131,6 +1163,14 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds,
ScopedOverviewTransformWindow::ScopedAnimationSettings animation_settings; ScopedOverviewTransformWindow::ScopedAnimationSettings animation_settings;
transform_window_.BeginScopedAnimation(animation_type, &animation_settings); transform_window_.BeginScopedAnimation(animation_type, &animation_settings);
if (animation_type == OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW &&
!animation_settings.empty()) {
animation_settings.front()->AddObserver(new AnimationObserver{
base::BindOnce(&OverviewItem::OnItemBoundsAnimationStarted,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&OverviewItem::OnItemBoundsAnimationEnded,
weak_ptr_factory_.GetWeakPtr())});
}
SetTransform(window, transform); SetTransform(window, transform);
} }
...@@ -1276,12 +1316,6 @@ void OverviewItem::HandleGestureEndEvent() { ...@@ -1276,12 +1316,6 @@ void OverviewItem::HandleGestureEndEvent() {
} }
void OverviewItem::StartDrag() { void OverviewItem::StartDrag() {
// |transform_window_| handles hiding shadow and rounded edges mask while
// animating, and applies them after animation is complete. Prevent the
// shadow and rounded edges mask from showing up after dragging in the case
// the window is pressed while still animating.
transform_window_.CancelAnimationsListener();
aura::Window* widget_window = item_widget_->GetNativeWindow(); aura::Window* widget_window = item_widget_->GetNativeWindow();
aura::Window* window = GetWindow(); aura::Window* window = GetWindow();
if (widget_window && widget_window->parent() == window->parent()) { if (widget_window && widget_window->parent() == window->parent()) {
......
...@@ -265,6 +265,8 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate, ...@@ -265,6 +265,8 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate,
// Functions to be called back when their associated animations complete. // Functions to be called back when their associated animations complete.
void OnWindowCloseAnimationCompleted(); void OnWindowCloseAnimationCompleted();
void OnItemAddedAnimationCompleted(); void OnItemAddedAnimationCompleted();
void OnItemBoundsAnimationStarted();
void OnItemBoundsAnimationEnded();
// Performs the add-item-to-overview animation (which is a fade-in plus // Performs the add-item-to-overview animation (which is a fade-in plus
// scale-up animation), on the given |window|. |target_transform| is the final // scale-up animation), on the given |window|. |target_transform| is the final
......
...@@ -169,7 +169,6 @@ ScopedOverviewTransformWindow::~ScopedOverviewTransformWindow() { ...@@ -169,7 +169,6 @@ ScopedOverviewTransformWindow::~ScopedOverviewTransformWindow() {
// No need to update the clip since we're about to restore it to // No need to update the clip since we're about to restore it to
// `original_clip_rect_`. // `original_clip_rect_`.
UpdateRoundedCorners(/*show=*/false, /*update_clip=*/false); UpdateRoundedCorners(/*show=*/false, /*update_clip=*/false);
StopObservingImplicitAnimations();
aura::client::GetTransientWindowClient()->RemoveObserver(this); aura::client::GetTransientWindowClient()->RemoveObserver(this);
window_->layer()->SetClipRect(original_clip_rect_); window_->layer()->SetClipRect(original_clip_rect_);
} }
...@@ -183,18 +182,6 @@ float ScopedOverviewTransformWindow::GetItemScale(const gfx::SizeF& source, ...@@ -183,18 +182,6 @@ float ScopedOverviewTransformWindow::GetItemScale(const gfx::SizeF& source,
(source.height() - top_view_inset)); (source.height() - top_view_inset));
} }
// static
gfx::Transform ScopedOverviewTransformWindow::GetTransformForRect(
const gfx::RectF& src_rect,
const gfx::RectF& dst_rect) {
DCHECK(!src_rect.IsEmpty());
gfx::Transform transform;
transform.Translate(dst_rect.x() - src_rect.x(), dst_rect.y() - src_rect.y());
transform.Scale(dst_rect.width() / src_rect.width(),
dst_rect.height() / src_rect.height());
return transform;
}
void ScopedOverviewTransformWindow::RestoreWindow(bool reset_transform) { void ScopedOverviewTransformWindow::RestoreWindow(bool reset_transform) {
// Shadow controller may be null on shutdown. // Shadow controller may be null on shutdown.
if (Shell::Get()->shadow_controller()) if (Shell::Get()->shadow_controller())
...@@ -260,11 +247,6 @@ void ScopedOverviewTransformWindow::BeginScopedAnimation( ...@@ -260,11 +247,6 @@ void ScopedOverviewTransformWindow::BeginScopedAnimation(
animation_settings->push_back(std::move(settings)); animation_settings->push_back(std::move(settings));
} }
if (animation_type == OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW &&
animation_settings->size() > 0u) {
animation_settings->front()->AddObserver(this);
}
} }
bool ScopedOverviewTransformWindow::Contains(const aura::Window* target) const { bool ScopedOverviewTransformWindow::Contains(const aura::Window* target) const {
...@@ -437,24 +419,6 @@ void ScopedOverviewTransformWindow::UpdateRoundedCorners(bool show, ...@@ -437,24 +419,6 @@ void ScopedOverviewTransformWindow::UpdateRoundedCorners(bool show,
} }
} }
void ScopedOverviewTransformWindow::CancelAnimationsListener() {
StopObservingImplicitAnimations();
}
void ScopedOverviewTransformWindow::OnLayerAnimationStarted(
ui::LayerAnimationSequence* sequence) {
// Remove the shadow before animating because it may affect animation
// performance. The shadow will be added back once the animation is completed.
// Note that we can't use UpdateRoundedCornersAndShadow() since we don't want
// to update the rounded corners.
overview_item_->SetShadowBounds(base::nullopt);
}
void ScopedOverviewTransformWindow::OnImplicitAnimationsCompleted() {
overview_item_->UpdateRoundedCornersAndShadow();
overview_item_->OnDragAnimationCompleted();
}
void ScopedOverviewTransformWindow::OnTransientChildWindowAdded( void ScopedOverviewTransformWindow::OnTransientChildWindowAdded(
aura::Window* parent, aura::Window* parent,
aura::Window* transient_child) { aura::Window* transient_child) {
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
#include "ui/aura/client/transient_window_client_observer.h" #include "ui/aura/client/transient_window_client_observer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -40,10 +39,9 @@ class ScopedOverviewHideWindows; ...@@ -40,10 +39,9 @@ class ScopedOverviewHideWindows;
// fit in certain bounds. The window's state is restored when this object is // fit in certain bounds. The window's state is restored when this object is
// destroyed. // destroyed.
class ASH_EXPORT ScopedOverviewTransformWindow class ASH_EXPORT ScopedOverviewTransformWindow
: public ui::ImplicitAnimationObserver, : public aura::client::TransientWindowClientObserver {
public aura::client::TransientWindowClientObserver {
public: public:
// Overview windows have certain properties if their aspect ratio exceedes a // Overview windows have certain properties if their aspect ratio exceeds a
// threshold. This enum keeps track of which category the window falls into, // threshold. This enum keeps track of which category the window falls into,
// based on its aspect ratio. // based on its aspect ratio.
enum class GridWindowFillMode { enum class GridWindowFillMode {
...@@ -67,10 +65,6 @@ class ASH_EXPORT ScopedOverviewTransformWindow ...@@ -67,10 +65,6 @@ class ASH_EXPORT ScopedOverviewTransformWindow
int top_view_inset, int top_view_inset,
int title_height); int title_height);
// Returns the transform turning |src_rect| into |dst_rect|.
static gfx::Transform GetTransformForRect(const gfx::RectF& src_rect,
const gfx::RectF& dst_rect);
ScopedOverviewTransformWindow(OverviewItem* overview_item, ScopedOverviewTransformWindow(OverviewItem* overview_item,
aura::Window* window); aura::Window* window);
~ScopedOverviewTransformWindow() override; ~ScopedOverviewTransformWindow() override;
...@@ -148,13 +142,6 @@ class ASH_EXPORT ScopedOverviewTransformWindow ...@@ -148,13 +142,6 @@ class ASH_EXPORT ScopedOverviewTransformWindow
// any), otherwise it will skip updating that clip. // any), otherwise it will skip updating that clip.
void UpdateRoundedCorners(bool show, bool update_clip); void UpdateRoundedCorners(bool show, bool update_clip);
// Stop listening to any animations to finish.
void CancelAnimationsListener();
// ui::ImplicitAnimationObserver:
void OnLayerAnimationStarted(ui::LayerAnimationSequence* sequence) override;
void OnImplicitAnimationsCompleted() override;
// aura::client::TransientWindowClientObserver: // aura::client::TransientWindowClientObserver:
void OnTransientChildWindowAdded(aura::Window* parent, void OnTransientChildWindowAdded(aura::Window* parent,
aura::Window* transient_child) override; aura::Window* transient_child) override;
......
...@@ -394,9 +394,9 @@ void SplitViewController::SnapWindow(aura::Window* window, ...@@ -394,9 +394,9 @@ void SplitViewController::SnapWindow(aura::Window* window,
->OnSelectorItemDragEnded(/*snap=*/true); ->OnSelectorItemDragEnded(/*snap=*/true);
} }
// Update the divider position and window bounds before snapping a new // Update the divider position and window bounds before snapping a new
// window. Since the minimum size of |window| maybe larger than currently // window. Since the minimum size of |window| maybe larger than currently
// bounds in |snap_position|. // bounds in |snap_position|.
if (state_ != State::kNoSnap && if (state_ != State::kNoSnap &&
split_view_type_ == SplitViewType::kTabletType) { split_view_type_ == SplitViewType::kTabletType) {
divider_position_ = GetClosestFixedDividerPosition(); divider_position_ = GetClosestFixedDividerPosition();
...@@ -1679,9 +1679,8 @@ void SplitViewController::RestoreTransformIfApplicable(aura::Window* window) { ...@@ -1679,9 +1679,8 @@ void SplitViewController::RestoreTransformIfApplicable(aura::Window* window) {
// bounds and its transformed bounds before to be snapped. // bounds and its transformed bounds before to be snapped.
const gfx::Rect snapped_bounds = GetSnappedWindowBoundsInScreen( const gfx::Rect snapped_bounds = GetSnappedWindowBoundsInScreen(
window, (window == left_window_) ? LEFT : RIGHT); window, (window == left_window_) ? LEFT : RIGHT);
const gfx::Transform starting_transform = const gfx::Transform starting_transform = gfx::TransformBetweenRects(
ScopedOverviewTransformWindow::GetTransformForRect( gfx::RectF(snapped_bounds), gfx::RectF(item_bounds));
gfx::RectF(snapped_bounds), gfx::RectF(item_bounds));
SetTransformWithAnimation(window, starting_transform, gfx::Transform()); SetTransformWithAnimation(window, starting_transform, gfx::Transform());
} }
} }
......
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