1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
ash / wm / overview / cleanup_animation_observer.cc [blame]
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/overview/cleanup_animation_observer.h"
#include <utility>
#include "ash/wm/overview/overview_delegate.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
namespace ash {
CleanupAnimationObserver::CleanupAnimationObserver(
std::unique_ptr<views::Widget> widget)
: widget_(std::move(widget)), owner_(nullptr) {
DCHECK(widget_);
// Mark the window as not owned by the parent to ensure that
// `OnImplicitAnimationsCompleted()` is not called from `~Window()` and the
// window is not deleted there.
widget_->GetNativeWindow()->set_owned_by_parent(false);
shell_observation_.Observe(Shell::Get());
}
CleanupAnimationObserver::~CleanupAnimationObserver() = default;
void CleanupAnimationObserver::OnImplicitAnimationsCompleted() {
// `widget_` may get reset if `Shutdown()` is called prior to this method.
if (!widget_) {
return;
}
if (owner_) {
owner_->RemoveAndDestroyExitAnimationObserver(this);
return;
}
delete this;
}
void CleanupAnimationObserver::SetOwner(OverviewDelegate* owner) {
owner_ = owner;
}
void CleanupAnimationObserver::Shutdown() {
widget_.reset();
owner_ = nullptr;
}
void CleanupAnimationObserver::OnRootWindowWillShutdown(
aura::Window* root_window) {
if (!widget_ || widget_->GetNativeWindow()->GetRootWindow() != root_window) {
return;
}
if (owner_) {
owner_->RemoveAndDestroyExitAnimationObserver(this);
return;
}
delete this;
}
} // namespace ash