2015-01-27 01:03:25 +01:00
|
|
|
// Copyright (c) 2015 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/browser_window_osr_win.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/browser/main_message_loop.h"
|
|
|
|
#include "tests/shared/browser/util_win.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
BrowserWindowOsrWin::BrowserWindowOsrWin(BrowserWindow::Delegate* delegate,
|
2015-01-27 01:03:25 +01:00
|
|
|
const std::string& startup_url,
|
2015-04-09 16:59:34 +02:00
|
|
|
const OsrRenderer::Settings& settings)
|
2015-01-29 21:53:53 +01:00
|
|
|
: BrowserWindow(delegate),
|
2015-08-10 22:49:45 +02:00
|
|
|
osr_hwnd_(NULL),
|
|
|
|
device_scale_factor_(client::GetDeviceScaleFactor()) {
|
2015-04-09 16:59:34 +02:00
|
|
|
osr_window_ = new OsrWindowWin(this, settings);
|
2015-01-27 01:03:25 +01:00
|
|
|
client_handler_ = new ClientHandlerOsr(this, osr_window_.get(), startup_url);
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
void BrowserWindowOsrWin::CreateBrowser(
|
|
|
|
ClientWindowHandle parent_handle,
|
|
|
|
const CefRect& rect,
|
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
2015-01-27 01:03:25 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
// Create the new browser and native window on the UI thread.
|
2015-01-29 21:53:53 +01:00
|
|
|
RECT wnd_rect = {rect.x, rect.y, rect.x + rect.width, rect.y + rect.height};
|
|
|
|
osr_window_->CreateBrowser(parent_handle, wnd_rect, client_handler_, settings,
|
2015-02-14 00:17:08 +01:00
|
|
|
request_context, client_handler_->startup_url());
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
void BrowserWindowOsrWin::GetPopupConfig(CefWindowHandle temp_handle,
|
2015-01-27 01:03:25 +01:00
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
windowInfo.SetAsWindowless(temp_handle);
|
2015-01-27 01:03:25 +01:00
|
|
|
client = client_handler_;
|
|
|
|
}
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
void BrowserWindowOsrWin::ShowPopup(ClientWindowHandle parent_handle,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
size_t width,
|
|
|
|
size_t height) {
|
2015-01-27 01:03:25 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
if (osr_window_)
|
2015-01-29 21:53:53 +01:00
|
|
|
osr_window_->ShowPopup(parent_handle, x, y, width, height);
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrWin::Show() {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
if (osr_window_)
|
|
|
|
osr_window_->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrWin::Hide() {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
if (osr_window_)
|
|
|
|
osr_window_->Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrWin::SetBounds(int x, int y, size_t width, size_t height) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
if (osr_window_)
|
|
|
|
osr_window_->SetBounds(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
void BrowserWindowOsrWin::SetFocus(bool focus) {
|
2015-01-27 01:03:25 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
2015-01-30 19:07:13 +01:00
|
|
|
if (osr_window_ && focus)
|
2015-01-27 01:03:25 +01:00
|
|
|
osr_window_->SetFocus();
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
void BrowserWindowOsrWin::SetDeviceScaleFactor(float device_scale_factor) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
if (device_scale_factor == device_scale_factor_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Apply some sanity checks.
|
|
|
|
if (device_scale_factor < 1.0f || device_scale_factor > 4.0f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
device_scale_factor_ = device_scale_factor;
|
|
|
|
if (osr_window_)
|
|
|
|
osr_window_->SetDeviceScaleFactor(device_scale_factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
float BrowserWindowOsrWin::GetDeviceScaleFactor() const {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
return device_scale_factor_;
|
|
|
|
}
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
ClientWindowHandle BrowserWindowOsrWin::GetWindowHandle() const {
|
2015-01-27 01:03:25 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
return osr_hwnd_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrWin::OnBrowserClosed(CefRefPtr<CefBrowser> browser) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
// Release the OSR window reference. It will be deleted on the UI thread.
|
|
|
|
osr_window_ = NULL;
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
BrowserWindow::OnBrowserClosed(browser);
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowOsrWin::OnOsrNativeWindowCreated(HWND hwnd) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
DCHECK(!osr_hwnd_);
|
|
|
|
osr_hwnd_ = hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace client
|