1 // Copyright (c) 2011 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/fullscreen.h"
10 #include "base/logging.h"
11 #include "base/win/windows_version.h"
14 #include "ash/wm/window_util.h"
15 #include "chrome/browser/ui/host_desktop.h"
18 static bool IsPlatformFullScreenMode() {
19 // SHQueryUserNotificationState is only available for Vista and above.
20 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_VISTA)
21 if (base::win::GetVersion() < base::win::VERSION_VISTA
)
24 typedef HRESULT(WINAPI
*SHQueryUserNotificationStatePtr
)(
25 QUERY_USER_NOTIFICATION_STATE
* state
);
27 HMODULE shell32_base
= ::GetModuleHandle(L
"shell32.dll");
32 SHQueryUserNotificationStatePtr query_user_notification_state_ptr
=
33 reinterpret_cast<SHQueryUserNotificationStatePtr
>
34 (::GetProcAddress(shell32_base
, "SHQueryUserNotificationState"));
35 if (!query_user_notification_state_ptr
) {
40 QUERY_USER_NOTIFICATION_STATE state
;
41 if (FAILED((*query_user_notification_state_ptr
)(&state
)))
43 return state
== QUNS_RUNNING_D3D_FULL_SCREEN
||
44 state
== QUNS_PRESENTATION_MODE
;
50 static bool IsFullScreenWindowMode() {
51 // Get the foreground window which the user is currently working on.
52 HWND wnd
= ::GetForegroundWindow();
56 // Get the monitor where the window is located.
58 if (!::GetWindowRect(wnd
, &wnd_rect
))
60 HMONITOR monitor
= ::MonitorFromRect(&wnd_rect
, MONITOR_DEFAULTTONULL
);
63 MONITORINFO monitor_info
= { sizeof(monitor_info
) };
64 if (!::GetMonitorInfo(monitor
, &monitor_info
))
67 // It should be the main monitor.
68 if (!(monitor_info
.dwFlags
& MONITORINFOF_PRIMARY
))
71 // The window should be at least as large as the monitor.
72 if (!::IntersectRect(&wnd_rect
, &wnd_rect
, &monitor_info
.rcMonitor
))
74 if (!::EqualRect(&wnd_rect
, &monitor_info
.rcMonitor
))
77 // At last, the window style should not have WS_DLGFRAME and WS_THICKFRAME and
78 // its extended style should not have WS_EX_WINDOWEDGE and WS_EX_TOOLWINDOW.
79 LONG style
= ::GetWindowLong(wnd
, GWL_STYLE
);
80 LONG ext_style
= ::GetWindowLong(wnd
, GWL_EXSTYLE
);
81 return !((style
& (WS_DLGFRAME
| WS_THICKFRAME
)) ||
82 (ext_style
& (WS_EX_WINDOWEDGE
| WS_EX_TOOLWINDOW
)));
85 static bool IsFullScreenConsoleMode() {
86 // We detect this by attaching the current process to the console of the
87 // foreground window and then checking if it is in full screen mode.
89 ::GetWindowThreadProcessId(::GetForegroundWindow(), &pid
);
93 if (!::AttachConsole(pid
))
97 ::GetConsoleDisplayMode(&modes
);
100 return (modes
& (CONSOLE_FULLSCREEN
| CONSOLE_FULLSCREEN_HARDWARE
)) != 0;
103 bool IsFullScreenMode() {
105 if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH
)
106 return ash::wm::IsActiveWindowFullscreen();
108 return IsPlatformFullScreenMode() ||
109 IsFullScreenWindowMode() ||
110 IsFullScreenConsoleMode();