summaryrefslogtreecommitdiffstats
path: root/chrome/browser/fullscreen_win.cc
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-25 20:54:06 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-25 20:54:06 +0000
commit3c64537927e5a31388c8fac8e04e575a12f6ff81 (patch)
treeadc23145813263daad9d696f2ffb3648dafa8bd5 /chrome/browser/fullscreen_win.cc
parent34ce848a57340642bb708d44bf1e6fa4ea3a07b5 (diff)
downloadchromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.zip
chromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.tar.gz
chromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.tar.bz2
Do not show notifications when in fullscreen or screensaver mode.
I add full-screen/presentation mode detection for all 3 platforms. I also add screensaver detection for MacOSX and Linux since it is missing in these 2 platforms. BUG=25061 TEST=Manual test Review URL: http://codereview.chromium.org/6359008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72539 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/fullscreen_win.cc')
-rw-r--r--chrome/browser/fullscreen_win.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/chrome/browser/fullscreen_win.cc b/chrome/browser/fullscreen_win.cc
new file mode 100644
index 0000000..68ddc18
--- /dev/null
+++ b/chrome/browser/fullscreen_win.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/fullscreen.h"
+
+#include <windows.h>
+#include <shellapi.h>
+
+static bool IsPlatformFullScreenMode() {
+ // SHQueryUserNotificationState is only available for Vista and above.
+#if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_VISTA)
+ QUERY_USER_NOTIFICATION_STATE state;
+ if (FAILED(::SHQueryUserNotificationState(&state)))
+ return false;
+ return state == QUNS_RUNNING_D3D_FULL_SCREEN ||
+ state == QUNS_PRESENTATION_MODE;
+#else
+ return false;
+#endif
+}
+
+static bool IsFullScreenWindowMode() {
+ // Get the foreground window which the user is currently working on.
+ HWND wnd = ::GetForegroundWindow();
+ if (!wnd)
+ return false;
+
+ // Get the monitor where the window is located.
+ RECT wnd_rect;
+ if (!::GetWindowRect(wnd, &wnd_rect))
+ return false;
+ HMONITOR monitor = ::MonitorFromRect(&wnd_rect, MONITOR_DEFAULTTONULL);
+ if (!monitor)
+ return false;
+ MONITORINFO monitor_info = { sizeof(monitor_info) };
+ if (!::GetMonitorInfo(monitor, &monitor_info))
+ return false;
+
+ // It should be the main monitor.
+ if (!(monitor_info.dwFlags & MONITORINFOF_PRIMARY))
+ return false;
+
+ // The window should be at least as large as the monitor.
+ if (!::IntersectRect(&wnd_rect, &wnd_rect, &monitor_info.rcMonitor))
+ return false;
+ if (!::EqualRect(&wnd_rect, &monitor_info.rcMonitor))
+ return false;
+
+ // At last, the window style should not have WS_DLGFRAME and WS_THICKFRAME and
+ // its extended style should not have WS_EX_WINDOWEDGE and WS_EX_TOOLWINDOW.
+ LONG style = ::GetWindowLong(wnd, GWL_STYLE);
+ LONG ext_style = ::GetWindowLong(wnd, GWL_EXSTYLE);
+ return !((style & (WS_DLGFRAME | WS_THICKFRAME)) ||
+ (ext_style & (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW)));
+}
+
+static bool IsFullScreenConsoleMode() {
+ // We detect this by attaching the current process to the console of the
+ // foreground window and then checking if it is in full screen mode.
+ DWORD pid = 0;
+ ::GetWindowThreadProcessId(::GetForegroundWindow(), &pid);
+ if (!pid)
+ return false;
+
+ if (!::AttachConsole(pid))
+ return false;
+
+ DWORD modes = 0;
+ ::GetConsoleDisplayMode(&modes);
+ ::FreeConsole();
+
+ return (modes & (CONSOLE_FULLSCREEN | CONSOLE_FULLSCREEN_HARDWARE)) != 0;
+}
+
+bool IsFullScreenMode() {
+ return IsPlatformFullScreenMode() ||
+ IsFullScreenWindowMode() ||
+ IsFullScreenConsoleMode();
+}