PageRenderTime 22ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/chrome/browser/fullscreen_win.cc

https://gitlab.com/jonnialva90/iridium-browser
C++ | 115 lines | 85 code | 18 blank | 12 comment | 20 complexity | a0499ff626a3d99b9c2e21fe10328e35 MD5 | raw file
  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.
  4. #include "chrome/browser/fullscreen.h"
  5. #include <windows.h>
  6. #include <shellapi.h>
  7. #include "base/logging.h"
  8. #include "base/win/win_util.h"
  9. #include "base/win/windows_version.h"
  10. #if defined(USE_ASH)
  11. #include "ash/root_window_controller.h"
  12. #include "chrome/browser/ui/host_desktop.h"
  13. #endif
  14. static bool IsPlatformFullScreenMode() {
  15. // SHQueryUserNotificationState is only available for Vista and above.
  16. #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_VISTA)
  17. if (base::win::GetVersion() < base::win::VERSION_VISTA)
  18. return false;
  19. typedef HRESULT(WINAPI *SHQueryUserNotificationStatePtr)(
  20. QUERY_USER_NOTIFICATION_STATE* state);
  21. HMODULE shell32_base = ::GetModuleHandle(L"shell32.dll");
  22. if (!shell32_base) {
  23. NOTREACHED();
  24. return false;
  25. }
  26. SHQueryUserNotificationStatePtr query_user_notification_state_ptr =
  27. reinterpret_cast<SHQueryUserNotificationStatePtr>
  28. (::GetProcAddress(shell32_base, "SHQueryUserNotificationState"));
  29. if (!query_user_notification_state_ptr) {
  30. NOTREACHED();
  31. return false;
  32. }
  33. QUERY_USER_NOTIFICATION_STATE state;
  34. if (FAILED((*query_user_notification_state_ptr)(&state)))
  35. return false;
  36. return state == QUNS_RUNNING_D3D_FULL_SCREEN ||
  37. state == QUNS_PRESENTATION_MODE;
  38. #else
  39. return false;
  40. #endif
  41. }
  42. static bool IsFullScreenWindowMode() {
  43. // Get the foreground window which the user is currently working on.
  44. HWND wnd = ::GetForegroundWindow();
  45. if (!wnd)
  46. return false;
  47. // Get the monitor where the window is located.
  48. RECT wnd_rect;
  49. if (!::GetWindowRect(wnd, &wnd_rect))
  50. return false;
  51. HMONITOR monitor = ::MonitorFromRect(&wnd_rect, MONITOR_DEFAULTTONULL);
  52. if (!monitor)
  53. return false;
  54. MONITORINFO monitor_info = { sizeof(monitor_info) };
  55. if (!::GetMonitorInfo(monitor, &monitor_info))
  56. return false;
  57. // It should be the main monitor.
  58. if (!(monitor_info.dwFlags & MONITORINFOF_PRIMARY))
  59. return false;
  60. // The window should be at least as large as the monitor.
  61. if (!::IntersectRect(&wnd_rect, &wnd_rect, &monitor_info.rcMonitor))
  62. return false;
  63. if (!::EqualRect(&wnd_rect, &monitor_info.rcMonitor))
  64. return false;
  65. // At last, the window style should not have WS_DLGFRAME and WS_THICKFRAME and
  66. // its extended style should not have WS_EX_WINDOWEDGE and WS_EX_TOOLWINDOW.
  67. LONG style = ::GetWindowLong(wnd, GWL_STYLE);
  68. LONG ext_style = ::GetWindowLong(wnd, GWL_EXSTYLE);
  69. return !((style & (WS_DLGFRAME | WS_THICKFRAME)) ||
  70. (ext_style & (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW)));
  71. }
  72. static bool IsFullScreenConsoleMode() {
  73. // We detect this by attaching the current process to the console of the
  74. // foreground window and then checking if it is in full screen mode.
  75. DWORD pid = 0;
  76. ::GetWindowThreadProcessId(::GetForegroundWindow(), &pid);
  77. if (!pid)
  78. return false;
  79. if (!::AttachConsole(pid))
  80. return false;
  81. DWORD modes = 0;
  82. ::GetConsoleDisplayMode(&modes);
  83. ::FreeConsole();
  84. return (modes & (CONSOLE_FULLSCREEN | CONSOLE_FULLSCREEN_HARDWARE)) != 0;
  85. }
  86. bool IsFullScreenMode() {
  87. #if defined(USE_ASH)
  88. if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) {
  89. ash::RootWindowController* controller =
  90. ash::RootWindowController::ForTargetRootWindow();
  91. return controller && controller->GetWindowForFullscreenMode();
  92. }
  93. #endif
  94. return IsPlatformFullScreenMode() ||
  95. IsFullScreenWindowMode() ||
  96. IsFullScreenConsoleMode();
  97. }