2013-10-18 18:33:56 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/window_test_runner_win.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/browser/main_message_loop.h"
|
2013-10-18 18:33:56 +02:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
namespace client {
|
2013-10-18 18:33:56 +02:00
|
|
|
namespace window_test {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
HWND GetRootHwnd(CefRefPtr<CefBrowser> browser) {
|
|
|
|
return ::GetAncestor(browser->GetHost()->GetWindowHandle(), GA_ROOT);
|
|
|
|
}
|
2013-10-18 18:33:56 +02:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
// Toggles the current display state.
|
|
|
|
void Toggle(HWND root_hwnd, UINT nCmdShow) {
|
2013-10-18 18:33:56 +02:00
|
|
|
// Retrieve current window placement information.
|
|
|
|
WINDOWPLACEMENT placement;
|
2015-01-22 21:21:21 +01:00
|
|
|
::GetWindowPlacement(root_hwnd, &placement);
|
2013-10-18 18:33:56 +02:00
|
|
|
|
|
|
|
if (placement.showCmd == nCmdShow)
|
2015-01-22 21:21:21 +01:00
|
|
|
::ShowWindow(root_hwnd, SW_RESTORE);
|
2013-10-18 18:33:56 +02:00
|
|
|
else
|
2015-01-22 21:21:21 +01:00
|
|
|
::ShowWindow(root_hwnd, nCmdShow);
|
2013-10-18 18:33:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void SetPosImpl(CefRefPtr<CefBrowser> browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height) {
|
2015-01-22 21:21:21 +01:00
|
|
|
HWND root_hwnd = GetRootHwnd(browser);
|
2016-01-19 21:09:01 +01:00
|
|
|
if (!root_hwnd)
|
|
|
|
return;
|
2013-10-18 18:33:56 +02:00
|
|
|
|
|
|
|
// Retrieve current window placement information.
|
|
|
|
WINDOWPLACEMENT placement;
|
2015-01-22 21:21:21 +01:00
|
|
|
::GetWindowPlacement(root_hwnd, &placement);
|
2013-10-18 18:33:56 +02:00
|
|
|
|
|
|
|
// Retrieve information about the display that contains the window.
|
2017-05-17 11:29:28 +02:00
|
|
|
HMONITOR monitor =
|
|
|
|
MonitorFromRect(&placement.rcNormalPosition, MONITOR_DEFAULTTONEAREST);
|
2013-10-18 18:33:56 +02:00
|
|
|
MONITORINFO info;
|
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
GetMonitorInfo(monitor, &info);
|
|
|
|
|
|
|
|
// Make sure the window is inside the display.
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRect display_rect(info.rcWork.left, info.rcWork.top,
|
|
|
|
info.rcWork.right - info.rcWork.left,
|
|
|
|
info.rcWork.bottom - info.rcWork.top);
|
2013-10-18 18:33:56 +02:00
|
|
|
CefRect window_rect(x, y, width, height);
|
2016-01-19 21:09:01 +01:00
|
|
|
WindowTestRunner::ModifyBounds(display_rect, window_rect);
|
2013-10-18 18:33:56 +02:00
|
|
|
|
|
|
|
if (placement.showCmd == SW_MINIMIZE || placement.showCmd == SW_MAXIMIZE) {
|
|
|
|
// The window is currently minimized or maximized. Restore it to the desired
|
|
|
|
// position.
|
|
|
|
placement.rcNormalPosition.left = window_rect.x;
|
|
|
|
placement.rcNormalPosition.right = window_rect.x + window_rect.width;
|
|
|
|
placement.rcNormalPosition.top = window_rect.y;
|
|
|
|
placement.rcNormalPosition.bottom = window_rect.y + window_rect.height;
|
2015-01-22 21:21:21 +01:00
|
|
|
::SetWindowPlacement(root_hwnd, &placement);
|
|
|
|
::ShowWindow(root_hwnd, SW_RESTORE);
|
2013-10-18 18:33:56 +02:00
|
|
|
} else {
|
|
|
|
// Set the window position.
|
2021-06-17 22:08:01 +02:00
|
|
|
::SetWindowPos(root_hwnd, nullptr, window_rect.x, window_rect.y,
|
2013-10-18 18:33:56 +02:00
|
|
|
window_rect.width, window_rect.height, SWP_NOZORDER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void MinimizeImpl(CefRefPtr<CefBrowser> browser) {
|
|
|
|
HWND root_hwnd = GetRootHwnd(browser);
|
|
|
|
if (!root_hwnd)
|
|
|
|
return;
|
|
|
|
Toggle(root_hwnd, SW_MINIMIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaximizeImpl(CefRefPtr<CefBrowser> browser) {
|
|
|
|
HWND root_hwnd = GetRootHwnd(browser);
|
|
|
|
if (!root_hwnd)
|
|
|
|
return;
|
|
|
|
Toggle(root_hwnd, SW_MAXIMIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreImpl(CefRefPtr<CefBrowser> browser) {
|
|
|
|
HWND root_hwnd = GetRootHwnd(browser);
|
|
|
|
if (!root_hwnd)
|
|
|
|
return;
|
|
|
|
::ShowWindow(root_hwnd, SW_RESTORE);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
WindowTestRunnerWin::WindowTestRunnerWin() {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
void WindowTestRunnerWin::SetPos(CefRefPtr<CefBrowser> browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height) {
|
2016-01-19 21:09:01 +01:00
|
|
|
if (CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
SetPosImpl(browser, x, y, width, height);
|
|
|
|
} else {
|
|
|
|
// Execute on the main application thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(SetPosImpl, browser, x, y, width, height));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowTestRunnerWin::Minimize(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
MinimizeImpl(browser);
|
|
|
|
} else {
|
|
|
|
// Execute on the main application thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(MinimizeImpl, browser));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2013-10-18 18:33:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void WindowTestRunnerWin::Maximize(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
MaximizeImpl(browser);
|
|
|
|
} else {
|
|
|
|
// Execute on the main application thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(MaximizeImpl, browser));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2013-10-18 18:33:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void WindowTestRunnerWin::Restore(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
RestoreImpl(browser);
|
|
|
|
} else {
|
|
|
|
// Execute on the main application thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(RestoreImpl, browser));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2013-10-18 18:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace window_test
|
2015-01-22 21:21:21 +01:00
|
|
|
} // namespace client
|