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_list_impl.h"
20 bool g_force_
= false;
21 HostDesktopType g_force_type_
= HOST_DESKTOP_TYPE_COUNT
;
25 ScopedForceDesktopType::ScopedForceDesktopType(HostDesktopType type
)
26 : previous_type_(g_force_type_
),
27 previous_force_(g_force_
) {
32 ScopedForceDesktopType::~ScopedForceDesktopType() {
33 g_force_type_
= previous_type_
;
34 g_force_
= previous_force_
;
37 HostDesktopType
GetHostDesktopTypeForNativeView(gfx::NativeView native_view
) {
41 return IsNativeViewInAsh(native_view
) ?
42 HOST_DESKTOP_TYPE_ASH
:
43 HOST_DESKTOP_TYPE_NATIVE
;
45 return HOST_DESKTOP_TYPE_NATIVE
;
49 HostDesktopType
GetHostDesktopTypeForNativeWindow(
50 gfx::NativeWindow native_window
) {
54 return IsNativeWindowInAsh(native_window
) ?
55 HOST_DESKTOP_TYPE_ASH
:
56 HOST_DESKTOP_TYPE_NATIVE
;
58 return HOST_DESKTOP_TYPE_NATIVE
;
62 HostDesktopType
GetHostDesktopTypeForBrowser(const Browser
* browser
) {
65 for (HostDesktopType type
= HOST_DESKTOP_TYPE_FIRST
;
66 type
< HOST_DESKTOP_TYPE_COUNT
;
67 type
= static_cast<HostDesktopType
>(type
+ 1)) {
68 BrowserListImpl::const_iterator begin
=
69 BrowserListImpl::GetInstance(type
)->begin();
70 BrowserListImpl::const_iterator end
=
71 BrowserListImpl::GetInstance(type
)->end();
72 if (std::find(begin
, end
, browser
) != end
)
75 return HOST_DESKTOP_TYPE_NATIVE
;
78 HostDesktopType
GetActiveDesktop() {
79 #if defined(USE_ASH) && !defined(OS_CHROMEOS)
80 // The Ash desktop is considered active if a non-desktop RootWindow was last
81 // activated and the Ash desktop is still open. As it is, the Ash desktop
82 // will be considered the last active if a user switches from metro Chrome to
83 // the Windows desktop but doesn't activate any Chrome windows there (e.g.,
84 // by clicking on one or otherwise giving one focus). Consider finding a way
85 // to detect that the Windows desktop has been activated so that the native
86 // desktop can be considered active once the user switches to it if its
87 // BrowserList isn't empty.
88 if ((ActiveDesktopMonitor::GetLastActivatedDesktopType() ==
89 chrome::HOST_DESKTOP_TYPE_ASH
) &&
90 ash::Shell::HasInstance()) {
91 return HOST_DESKTOP_TYPE_ASH
;
94 return HOST_DESKTOP_TYPE_NATIVE
;