| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/aura/active_desktop_monitor.h" | 5 #include "chrome/browser/ui/aura/active_desktop_monitor.h" |
| 6 | 6 |
| 7 #include "ui/aura/env.h" | 7 #include "ui/aura/env.h" |
| 8 #include "ui/aura/window_tree_host.h" | 8 #include "ui/aura/window_tree_host.h" |
| 9 | 9 |
| 10 #if defined(USE_X11) | 10 #if defined(USE_X11) |
| 11 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 11 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 12 #elif defined(OS_WIN) | 12 #elif defined(OS_WIN) |
| 13 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" | 13 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 ActiveDesktopMonitor* ActiveDesktopMonitor::g_instance_ = NULL; | 17 ActiveDesktopMonitor* ActiveDesktopMonitor::g_instance_ = NULL; |
| 18 | 18 |
| 19 ActiveDesktopMonitor::ActiveDesktopMonitor( | 19 ActiveDesktopMonitor::ActiveDesktopMonitor(ui::HostDesktopType initial_desktop) |
| 20 chrome::HostDesktopType initial_desktop) | |
| 21 : last_activated_desktop_(initial_desktop) { | 20 : last_activated_desktop_(initial_desktop) { |
| 22 DCHECK(!g_instance_); | 21 DCHECK(!g_instance_); |
| 23 g_instance_ = this; | 22 g_instance_ = this; |
| 24 aura::Env::GetInstance()->AddObserver(this); | 23 aura::Env::GetInstance()->AddObserver(this); |
| 25 } | 24 } |
| 26 | 25 |
| 27 ActiveDesktopMonitor::~ActiveDesktopMonitor() { | 26 ActiveDesktopMonitor::~ActiveDesktopMonitor() { |
| 28 DCHECK_EQ(g_instance_, this); | 27 DCHECK_EQ(g_instance_, this); |
| 29 aura::Env::GetInstance()->RemoveObserver(this); | 28 aura::Env::GetInstance()->RemoveObserver(this); |
| 30 g_instance_ = NULL; | 29 g_instance_ = NULL; |
| 31 } | 30 } |
| 32 | 31 |
| 33 // static | 32 // static |
| 34 chrome::HostDesktopType ActiveDesktopMonitor::GetLastActivatedDesktopType() { | 33 ui::HostDesktopType ActiveDesktopMonitor::GetLastActivatedDesktopType() { |
| 35 // Tests may not have created the monitor. | 34 // Tests may not have created the monitor. |
| 36 return g_instance_ ? g_instance_->last_activated_desktop_ : | 35 return g_instance_ ? g_instance_->last_activated_desktop_ |
| 37 chrome::HOST_DESKTOP_TYPE_NATIVE; | 36 : ui::HOST_DESKTOP_TYPE_NATIVE; |
| 38 } | 37 } |
| 39 | 38 |
| 40 // static | 39 // static |
| 41 bool ActiveDesktopMonitor::IsDesktopWindow(aura::WindowTreeHost* host) { | 40 bool ActiveDesktopMonitor::IsDesktopWindow(aura::WindowTreeHost* host) { |
| 42 // Only windows hosted by a DesktopWindowTreeHost implementation can be mapped | 41 // Only windows hosted by a DesktopWindowTreeHost implementation can be mapped |
| 43 // back to a content Window. All others, therefore, must be the root window | 42 // back to a content Window. All others, therefore, must be the root window |
| 44 // for an Ash display. | 43 // for an Ash display. |
| 45 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
| 46 return views::DesktopWindowTreeHostWin::GetContentWindowForHWND( | 45 return views::DesktopWindowTreeHostWin::GetContentWindowForHWND( |
| 47 host->GetAcceleratedWidget()) != NULL; | 46 host->GetAcceleratedWidget()) != NULL; |
| 48 #elif defined(USE_X11) | 47 #elif defined(USE_X11) |
| 49 return views::DesktopWindowTreeHostX11::GetContentWindowForXID( | 48 return views::DesktopWindowTreeHostX11::GetContentWindowForXID( |
| 50 host->GetAcceleratedWidget()) != NULL; | 49 host->GetAcceleratedWidget()) != NULL; |
| 51 #else | 50 #else |
| 52 NOTREACHED(); | 51 NOTREACHED(); |
| 53 return true; | 52 return true; |
| 54 #endif | 53 #endif |
| 55 } | 54 } |
| 56 | 55 |
| 57 void ActiveDesktopMonitor::OnWindowInitialized(aura::Window* window) {} | 56 void ActiveDesktopMonitor::OnWindowInitialized(aura::Window* window) {} |
| 58 | 57 |
| 59 void ActiveDesktopMonitor::OnHostActivated(aura::WindowTreeHost* host) { | 58 void ActiveDesktopMonitor::OnHostActivated(aura::WindowTreeHost* host) { |
| 60 if (IsDesktopWindow(host)) | 59 if (IsDesktopWindow(host)) |
| 61 last_activated_desktop_ = chrome::HOST_DESKTOP_TYPE_NATIVE; | 60 last_activated_desktop_ = ui::HOST_DESKTOP_TYPE_NATIVE; |
| 62 else | 61 else |
| 63 last_activated_desktop_ = chrome::HOST_DESKTOP_TYPE_ASH; | 62 last_activated_desktop_ = ui::HOST_DESKTOP_TYPE_ASH; |
| 64 DVLOG(1) << __FUNCTION__ | 63 DVLOG(1) << __FUNCTION__ |
| 65 << (last_activated_desktop_ == chrome::HOST_DESKTOP_TYPE_NATIVE ? | 64 << (last_activated_desktop_ == ui::HOST_DESKTOP_TYPE_NATIVE |
| 66 " native" : " ash") << " desktop activated."; | 65 ? " native" |
| 66 : " ash") |
| 67 << " desktop activated."; |
| 67 } | 68 } |
| OLD | NEW |