[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #include "chrome/browser/ui/host_desktop.h" | ||||
6 | |||||
[email protected] | 40fdd01 | 2012-10-26 20:41:04 | [diff] [blame] | 7 | #if defined(OS_WIN) |
8 | #include <windows.h> | ||||
9 | #endif | ||||
10 | |||||
[email protected] | 40fdd01 | 2012-10-26 20:41:04 | [diff] [blame] | 11 | #include "ash/shell.h" |
[email protected] | cbafd1c | 2012-11-15 23:33:44 | [diff] [blame] | 12 | #include "chrome/browser/ui/ash/ash_util.h" |
13 | #include "chrome/browser/ui/aura/active_desktop_monitor.h" | ||||
[email protected] | 43fe8f67 | 2013-02-22 20:38:14 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser.h" |
[email protected] | abcfa65 | 2013-02-21 20:13:58 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 16 | |
17 | namespace chrome { | ||||
18 | |||||
[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 19 | HostDesktopType GetHostDesktopTypeForNativeView(gfx::NativeView native_view) { |
[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 20 | #if defined(USE_ASH) |
[email protected] | 9028a0e4 | 2012-12-15 00:45:14 | [diff] [blame] | 21 | // TODO(ananta) |
22 | // Once we've threaded creation context to wherever needed, we should remove | ||||
23 | // this check here. | ||||
24 | #if defined(OS_WIN) | ||||
25 | if (!native_view) | ||||
26 | return GetActiveDesktop(); | ||||
27 | #endif | ||||
[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 28 | return IsNativeViewInAsh(native_view) ? |
29 | HOST_DESKTOP_TYPE_ASH : | ||||
30 | HOST_DESKTOP_TYPE_NATIVE; | ||||
31 | #else | ||||
[email protected] | 5a02476 | 2012-10-24 21:20:25 | [diff] [blame] | 32 | return HOST_DESKTOP_TYPE_NATIVE; |
[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 33 | #endif |
34 | } | ||||
35 | |||||
36 | HostDesktopType GetHostDesktopTypeForNativeWindow( | ||||
37 | gfx::NativeWindow native_window) { | ||||
[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 38 | #if defined(USE_ASH) |
[email protected] | 9028a0e4 | 2012-12-15 00:45:14 | [diff] [blame] | 39 | // TODO(ananta) |
40 | // Once we've threaded creation context to wherever needed, we should remove | ||||
41 | // this check here. | ||||
42 | #if defined(OS_WIN) | ||||
43 | if (!native_window) | ||||
44 | return GetActiveDesktop(); | ||||
45 | #endif | ||||
[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 46 | return IsNativeWindowInAsh(native_window) ? |
47 | HOST_DESKTOP_TYPE_ASH : | ||||
48 | HOST_DESKTOP_TYPE_NATIVE; | ||||
49 | #else | ||||
50 | return HOST_DESKTOP_TYPE_NATIVE; | ||||
51 | #endif | ||||
52 | } | ||||
53 | |||||
[email protected] | 40fdd01 | 2012-10-26 20:41:04 | [diff] [blame] | 54 | HostDesktopType GetActiveDesktop() { |
[email protected] | cbafd1c | 2012-11-15 23:33:44 | [diff] [blame] | 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; | ||||
[email protected] | 40fdd01 | 2012-10-26 20:41:04 | [diff] [blame] | 68 | } |
69 | #endif | ||||
70 | return HOST_DESKTOP_TYPE_NATIVE; | ||||
71 | } | ||||
72 | |||||
[email protected] | 5fdb45b | 2012-10-23 20:26:28 | [diff] [blame] | 73 | } // namespace chrome |