cef/tests/cefclient/browser/window_test_runner_win.cc
Marshall Greenblatt 06e73fff15 Implement Views framework on Windows and Linux (issue #1749).
- Add Views header files in a new include/views directory.
- Add initial top-level window (CefWindow), control (CefBrowserView,
  CefLabelButton, CefMenuButton, CefPanel, CefScrollView,
  CefTextfield) and layout (CefBoxLayout, CefFlowLayout) support.
  See libcef/browser/views/view_impl.h comments for implementation
  details.
- Add Views example usage in cefclient and cefsimple and Views unit
  tests in cef_unittests. Pass the `--use-views` command-line flag to
  cefclient, cefsimple and cef_unittests to run using the Views
  framework instead of platform APIs. For cefclient and cefsimple
  this will create the browser window and all related functionality
  using the Views framework. For cef_unittests this will run all
  tests (except OSR tests) in a Views-based browser window. Views-
  specific unit tests (`--gtest_filter=Views*`) will be run even if
  the the `--use-views` flag is not specified.
- Pass the `--hide-frame` command-line flag to cefclient to demo a
  frameless Views-based browser window.
- Pass the `--hide-controls` command-line flag to cefclient to demo a
  browser window without top controls. This also works in non-Views
  mode.
- Pass the `--enable-high-dpi-support` command-line flag to
  cef_unittests on Windows to test high-DPI support on a display
  that supports it.
- Add CefImage for reading/writing image file formats.
- Add CefBrowser::DownloadImage() for downloading image URLs as a
  CefImage representation. This is primarily for loading favicons.
- Add CefMenuModel::CreateMenuModel() and CefMenuModelDelegate for
  creating custom menus. This is primarily for use with
  CefMenuButton.
- Add CefBrowser::TryCloseBrowser() helper for closing a browser.
  Also improve related documentation in cef_life_span_handler.h.
- Rename cef_page_range_t to cef_range_t. It is now also used by
  CefTextfield.
- Remove CefLifeSpanHandler::RunModal() which is never called.
- Add draggable regions example to cefclient.
2016-04-26 11:58:13 -04:00

137 lines
4.0 KiB
C++

// 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.
#include "cefclient/browser/window_test_runner_win.h"
#include "cefclient/browser/main_message_loop.h"
namespace client {
namespace window_test {
namespace {
HWND GetRootHwnd(CefRefPtr<CefBrowser> browser) {
return ::GetAncestor(browser->GetHost()->GetWindowHandle(), GA_ROOT);
}
// Toggles the current display state.
void Toggle(HWND root_hwnd, UINT nCmdShow) {
// Retrieve current window placement information.
WINDOWPLACEMENT placement;
::GetWindowPlacement(root_hwnd, &placement);
if (placement.showCmd == nCmdShow)
::ShowWindow(root_hwnd, SW_RESTORE);
else
::ShowWindow(root_hwnd, nCmdShow);
}
void SetPosImpl(CefRefPtr<CefBrowser> browser,
int x, int y, int width, int height) {
HWND root_hwnd = GetRootHwnd(browser);
if (!root_hwnd)
return;
// Retrieve current window placement information.
WINDOWPLACEMENT placement;
::GetWindowPlacement(root_hwnd, &placement);
// Retrieve information about the display that contains the window.
HMONITOR monitor = MonitorFromRect(&placement.rcNormalPosition,
MONITOR_DEFAULTTONEAREST);
MONITORINFO info;
info.cbSize = sizeof(info);
GetMonitorInfo(monitor, &info);
// Make sure the window is inside the display.
CefRect display_rect(
info.rcWork.left,
info.rcWork.top,
info.rcWork.right - info.rcWork.left,
info.rcWork.bottom - info.rcWork.top);
CefRect window_rect(x, y, width, height);
WindowTestRunner::ModifyBounds(display_rect, window_rect);
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;
::SetWindowPlacement(root_hwnd, &placement);
::ShowWindow(root_hwnd, SW_RESTORE);
} else {
// Set the window position.
::SetWindowPos(root_hwnd, NULL, window_rect.x, window_rect.y,
window_rect.width, window_rect.height, SWP_NOZORDER);
}
}
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
WindowTestRunnerWin::WindowTestRunnerWin() {
}
void WindowTestRunnerWin::SetPos(CefRefPtr<CefBrowser> browser,
int x, int y, int width, int height) {
if (CURRENTLY_ON_MAIN_THREAD()) {
SetPosImpl(browser, x, y, width, height);
} else {
// Execute on the main application thread.
MAIN_POST_CLOSURE(base::Bind(SetPosImpl, browser, x, y, width, height));
}
}
void WindowTestRunnerWin::Minimize(CefRefPtr<CefBrowser> browser) {
if (CURRENTLY_ON_MAIN_THREAD()) {
MinimizeImpl(browser);
} else {
// Execute on the main application thread.
MAIN_POST_CLOSURE(base::Bind(MinimizeImpl, browser));
}
}
void WindowTestRunnerWin::Maximize(CefRefPtr<CefBrowser> browser) {
if (CURRENTLY_ON_MAIN_THREAD()) {
MaximizeImpl(browser);
} else {
// Execute on the main application thread.
MAIN_POST_CLOSURE(base::Bind(MaximizeImpl, browser));
}
}
void WindowTestRunnerWin::Restore(CefRefPtr<CefBrowser> browser) {
if (CURRENTLY_ON_MAIN_THREAD()) {
RestoreImpl(browser);
} else {
// Execute on the main application thread.
MAIN_POST_CLOSURE(base::Bind(RestoreImpl, browser));
}
}
} // namespace window_test
} // namespace client