cleanup_animation_observer.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/wm/overview/cleanup_animation_observer.h"
  5. #include <utility>
  6. #include "ash/wm/overview/overview_delegate.h"
  7. #include "ui/aura/window.h"
  8. #include "ui/views/widget/widget.h"
  9. namespace ash {
  10. // Widget must own NativeWidget.
  11. // |widget_| will delete the NativeWidget and NativeWindow.
  12. // Mark the window as not owned by the parent to ensure that
  13. // OnImplicitAnimationsCompleted() is not called from ~Window() and the window
  14. // is not deleted there.
  15. CleanupAnimationObserver::CleanupAnimationObserver(
  16. std::unique_ptr<views::Widget> widget)
  17. : widget_(std::move(widget)), owner_(nullptr) {
  18. DCHECK(widget_);
  19. widget_->GetNativeWindow()->set_owned_by_parent(false);
  20. }
  21. CleanupAnimationObserver::~CleanupAnimationObserver() = default;
  22. void CleanupAnimationObserver::OnImplicitAnimationsCompleted() {
  23. // |widget_| may get reset if Shutdown() is called prior to this method.
  24. if (!widget_)
  25. return;
  26. if (owner_) {
  27. owner_->RemoveAndDestroyExitAnimationObserver(this);
  28. return;
  29. }
  30. delete this;
  31. }
  32. void CleanupAnimationObserver::SetOwner(OverviewDelegate* owner) {
  33. owner_ = owner;
  34. }
  35. void CleanupAnimationObserver::Shutdown() {
  36. widget_.reset();
  37. owner_ = nullptr;
  38. }
  39. } // namespace ash