1 // Copyright 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/host_desktop.h"
11 #include "ash/shell.h"
12 #include "chrome/browser/ui/ash/ash_util.h"
13 #include "chrome/browser/ui/aura/active_desktop_monitor.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h"
19 HostDesktopType
GetHostDesktopTypeForNativeView(gfx::NativeView native_view
) {
22 // Once we've threaded creation context to wherever needed, we should remove
26 return GetActiveDesktop();
28 return IsNativeViewInAsh(native_view
) ?
29 HOST_DESKTOP_TYPE_ASH
:
30 HOST_DESKTOP_TYPE_NATIVE
;
32 return HOST_DESKTOP_TYPE_NATIVE
;
36 HostDesktopType
GetHostDesktopTypeForNativeWindow(
37 gfx::NativeWindow native_window
) {
40 // Once we've threaded creation context to wherever needed, we should remove
44 return GetActiveDesktop();
46 return IsNativeWindowInAsh(native_window
) ?
47 HOST_DESKTOP_TYPE_ASH
:
48 HOST_DESKTOP_TYPE_NATIVE
;
50 return HOST_DESKTOP_TYPE_NATIVE
;
54 HostDesktopType
GetActiveDesktop() {
55 #if defined(USE_ASH) && !defined(OS_CHROMEOS)
56 // The Ash desktop is considered active if a non-desktop RootWindow was last
57 // activated and the Ash desktop is still open. As it is, the Ash desktop
58 // will be considered the last active if a user switches from metro Chrome to
59 // the Windows desktop but doesn't activate any Chrome windows there (e.g.,
60 // by clicking on one or otherwise giving one focus). Consider finding a way
61 // to detect that the Windows desktop has been activated so that the native
62 // desktop can be considered active once the user switches to it if its
63 // BrowserList isn't empty.
64 if ((ActiveDesktopMonitor::GetLastActivatedDesktopType() ==
65 chrome::HOST_DESKTOP_TYPE_ASH
) &&
66 ash::Shell::HasInstance()) {
67 return HOST_DESKTOP_TYPE_ASH
;
70 return HOST_DESKTOP_TYPE_NATIVE
;