This source file includes following definitions.
- GetLastActivatedDesktopType
- IsDesktopWindow
- OnWindowInitialized
- OnHostActivated
#include "chrome/browser/ui/aura/active_desktop_monitor.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
#if defined(USE_X11)
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#elif defined(OS_WIN)
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
#endif
ActiveDesktopMonitor* ActiveDesktopMonitor::g_instance_ = NULL;
ActiveDesktopMonitor::ActiveDesktopMonitor(
chrome::HostDesktopType initial_desktop)
: last_activated_desktop_(initial_desktop) {
DCHECK(!g_instance_);
g_instance_ = this;
aura::Env::GetInstance()->AddObserver(this);
}
ActiveDesktopMonitor::~ActiveDesktopMonitor() {
DCHECK_EQ(g_instance_, this);
aura::Env::GetInstance()->RemoveObserver(this);
g_instance_ = NULL;
}
chrome::HostDesktopType ActiveDesktopMonitor::GetLastActivatedDesktopType() {
return g_instance_ ? g_instance_->last_activated_desktop_ :
chrome::HOST_DESKTOP_TYPE_NATIVE;
}
bool ActiveDesktopMonitor::IsDesktopWindow(aura::WindowTreeHost* host) {
#if defined(OS_WIN)
return views::DesktopWindowTreeHostWin::GetContentWindowForHWND(
host->GetAcceleratedWidget()) != NULL;
#elif defined(USE_X11)
return views::DesktopWindowTreeHostX11::GetContentWindowForXID(
host->GetAcceleratedWidget()) != NULL;
#else
NOTREACHED();
return true;
#endif
}
void ActiveDesktopMonitor::OnWindowInitialized(aura::Window* window) {}
void ActiveDesktopMonitor::OnHostActivated(aura::WindowTreeHost* host) {
if (IsDesktopWindow(host))
last_activated_desktop_ = chrome::HOST_DESKTOP_TYPE_NATIVE;
else
last_activated_desktop_ = chrome::HOST_DESKTOP_TYPE_ASH;
DVLOG(1) << __FUNCTION__
<< (last_activated_desktop_ == chrome::HOST_DESKTOP_TYPE_NATIVE ?
" native" : " ash") << " desktop activated.";
}