910e62b5创建于 1月15日历史提交
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/native_window_tracker/native_window_tracker_aura.h"

#include <memory>

#include "ui/aura/window.h"

namespace ui {

NativeWindowTrackerAura::NativeWindowTrackerAura(gfx::NativeWindow window)
    : window_(window) {
  window->AddObserver(this);
}

NativeWindowTrackerAura::~NativeWindowTrackerAura() {
  if (window_) {
    window_->RemoveObserver(this);
  }
}

bool NativeWindowTrackerAura::WasNativeWindowDestroyed() const {
  return window_ == nullptr;
}

void NativeWindowTrackerAura::OnWindowDestroying(aura::Window* window) {
  window_->RemoveObserver(this);
  window_ = nullptr;
}

// static
std::unique_ptr<NativeWindowTracker> NativeWindowTracker::Create(
    gfx::NativeWindow window) {
  return std::make_unique<NativeWindowTrackerAura>(window);
}

}  // namespace ui