1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/aura/active_desktop_monitor.h"
7 #include "ui/aura/env.h"
8 #include "ui/aura/root_window.h"
11 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h"
13 #include "ui/views/widget/desktop_aura/desktop_root_window_host_win.h"
17 ActiveDesktopMonitor
* ActiveDesktopMonitor::g_instance_
= NULL
;
19 ActiveDesktopMonitor::ActiveDesktopMonitor(
20 chrome::HostDesktopType initial_desktop
)
21 : last_activated_desktop_(initial_desktop
) {
24 aura::Env::GetInstance()->AddObserver(this);
27 ActiveDesktopMonitor::~ActiveDesktopMonitor() {
28 DCHECK_EQ(g_instance_
, this);
29 aura::Env::GetInstance()->RemoveObserver(this);
34 chrome::HostDesktopType
ActiveDesktopMonitor::GetLastActivatedDesktopType() {
35 // Tests may not have created the monitor.
36 return g_instance_
? g_instance_
->last_activated_desktop_
:
37 chrome::HOST_DESKTOP_TYPE_NATIVE
;
41 bool ActiveDesktopMonitor::IsDesktopWindow(aura::RootWindow
* root_window
) {
42 // Only windows hosted by a DesktopWindowTreeHost implementation can be mapped
43 // back to a content Window. All others, therefore, must be the root window
44 // for an Ash display.
46 return views::DesktopWindowTreeHostWin::GetContentWindowForHWND(
47 root_window
->host()->GetAcceleratedWidget()) != NULL
;
48 #elif defined(USE_X11)
49 return views::DesktopWindowTreeHostX11::GetContentWindowForXID(
50 root_window
->host()->GetAcceleratedWidget()) != NULL
;
57 void ActiveDesktopMonitor::OnWindowInitialized(aura::Window
* window
) {}
59 void ActiveDesktopMonitor::OnRootWindowActivated(
60 aura::RootWindow
* root_window
) {
61 if (IsDesktopWindow(root_window
))
62 last_activated_desktop_
= chrome::HOST_DESKTOP_TYPE_NATIVE
;
64 last_activated_desktop_
= chrome::HOST_DESKTOP_TYPE_ASH
;
65 DVLOG(1) << __FUNCTION__
66 << (last_activated_desktop_
== chrome::HOST_DESKTOP_TYPE_NATIVE
?
67 " native" : " ash") << " desktop activated.";