1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4
5 #include "tests/cefclient/browser/browser_window_osr_win.h"
6
7 #include "tests/shared/browser/main_message_loop.h"
8
9 namespace client {
10
BrowserWindowOsrWin(BrowserWindow::Delegate * delegate,const std::string & startup_url,const OsrRendererSettings & settings)11 BrowserWindowOsrWin::BrowserWindowOsrWin(BrowserWindow::Delegate* delegate,
12 const std::string& startup_url,
13 const OsrRendererSettings& settings)
14 : BrowserWindow(delegate), osr_hwnd_(NULL), device_scale_factor_(0) {
15 osr_window_ = new OsrWindowWin(this, settings);
16 client_handler_ = new ClientHandlerOsr(this, osr_window_.get(), startup_url);
17 }
18
CreateBrowser(ClientWindowHandle parent_handle,const CefRect & rect,const CefBrowserSettings & settings,CefRefPtr<CefDictionaryValue> extra_info,CefRefPtr<CefRequestContext> request_context)19 void BrowserWindowOsrWin::CreateBrowser(
20 ClientWindowHandle parent_handle,
21 const CefRect& rect,
22 const CefBrowserSettings& settings,
23 CefRefPtr<CefDictionaryValue> extra_info,
24 CefRefPtr<CefRequestContext> request_context) {
25 REQUIRE_MAIN_THREAD();
26
27 // Create the new browser and native window on the UI thread.
28 RECT wnd_rect = {rect.x, rect.y, rect.x + rect.width, rect.y + rect.height};
29 osr_window_->CreateBrowser(parent_handle, wnd_rect, client_handler_, settings,
30 extra_info, request_context,
31 client_handler_->startup_url());
32 }
33
GetPopupConfig(CefWindowHandle temp_handle,CefWindowInfo & windowInfo,CefRefPtr<CefClient> & client,CefBrowserSettings & settings)34 void BrowserWindowOsrWin::GetPopupConfig(CefWindowHandle temp_handle,
35 CefWindowInfo& windowInfo,
36 CefRefPtr<CefClient>& client,
37 CefBrowserSettings& settings) {
38 CEF_REQUIRE_UI_THREAD();
39
40 windowInfo.SetAsWindowless(temp_handle);
41 windowInfo.shared_texture_enabled =
42 osr_window_->settings().shared_texture_enabled;
43 windowInfo.external_begin_frame_enabled =
44 osr_window_->settings().external_begin_frame_enabled;
45
46 // Don't activate the hidden browser on creation.
47 windowInfo.ex_style |= WS_EX_NOACTIVATE;
48
49 client = client_handler_;
50 }
51
ShowPopup(ClientWindowHandle parent_handle,int x,int y,size_t width,size_t height)52 void BrowserWindowOsrWin::ShowPopup(ClientWindowHandle parent_handle,
53 int x,
54 int y,
55 size_t width,
56 size_t height) {
57 REQUIRE_MAIN_THREAD();
58 if (osr_window_)
59 osr_window_->ShowPopup(parent_handle, x, y, width, height);
60 }
61
Show()62 void BrowserWindowOsrWin::Show() {
63 REQUIRE_MAIN_THREAD();
64 if (osr_window_)
65 osr_window_->Show();
66 }
67
Hide()68 void BrowserWindowOsrWin::Hide() {
69 REQUIRE_MAIN_THREAD();
70 if (osr_window_)
71 osr_window_->Hide();
72 }
73
SetBounds(int x,int y,size_t width,size_t height)74 void BrowserWindowOsrWin::SetBounds(int x, int y, size_t width, size_t height) {
75 REQUIRE_MAIN_THREAD();
76 if (osr_window_)
77 osr_window_->SetBounds(x, y, width, height);
78 }
79
SetFocus(bool focus)80 void BrowserWindowOsrWin::SetFocus(bool focus) {
81 REQUIRE_MAIN_THREAD();
82 if (osr_window_ && focus)
83 osr_window_->SetFocus();
84 }
85
SetDeviceScaleFactor(float device_scale_factor)86 void BrowserWindowOsrWin::SetDeviceScaleFactor(float device_scale_factor) {
87 REQUIRE_MAIN_THREAD();
88 if (device_scale_factor == device_scale_factor_)
89 return;
90
91 // Apply some sanity checks.
92 if (device_scale_factor < 1.0f || device_scale_factor > 4.0f)
93 return;
94
95 device_scale_factor_ = device_scale_factor;
96 if (osr_window_)
97 osr_window_->SetDeviceScaleFactor(device_scale_factor);
98 }
99
GetDeviceScaleFactor() const100 float BrowserWindowOsrWin::GetDeviceScaleFactor() const {
101 REQUIRE_MAIN_THREAD();
102 DCHECK_GT(device_scale_factor_, 0);
103 return device_scale_factor_;
104 }
105
GetWindowHandle() const106 ClientWindowHandle BrowserWindowOsrWin::GetWindowHandle() const {
107 REQUIRE_MAIN_THREAD();
108 return osr_hwnd_;
109 }
110
OnBrowserClosed(CefRefPtr<CefBrowser> browser)111 void BrowserWindowOsrWin::OnBrowserClosed(CefRefPtr<CefBrowser> browser) {
112 REQUIRE_MAIN_THREAD();
113
114 // Release the OSR window reference. It will be deleted on the UI thread.
115 osr_window_ = nullptr;
116
117 BrowserWindow::OnBrowserClosed(browser);
118 }
119
OnOsrNativeWindowCreated(HWND hwnd)120 void BrowserWindowOsrWin::OnOsrNativeWindowCreated(HWND hwnd) {
121 REQUIRE_MAIN_THREAD();
122 DCHECK(!osr_hwnd_);
123 osr_hwnd_ = hwnd;
124 }
125
126 } // namespace client
127