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_std_win.h"
6
7 #include "tests/cefclient/browser/client_handler_std.h"
8 #include "tests/shared/browser/main_message_loop.h"
9
10 namespace client {
11
BrowserWindowStdWin(Delegate * delegate,const std::string & startup_url)12 BrowserWindowStdWin::BrowserWindowStdWin(Delegate* delegate,
13 const std::string& startup_url)
14 : BrowserWindow(delegate) {
15 client_handler_ = new ClientHandlerStd(this, startup_url);
16 }
17
CreateBrowser(ClientWindowHandle parent_handle,const CefRect & rect,const CefBrowserSettings & settings,CefRefPtr<CefDictionaryValue> extra_info,CefRefPtr<CefRequestContext> request_context)18 void BrowserWindowStdWin::CreateBrowser(
19 ClientWindowHandle parent_handle,
20 const CefRect& rect,
21 const CefBrowserSettings& settings,
22 CefRefPtr<CefDictionaryValue> extra_info,
23 CefRefPtr<CefRequestContext> request_context) {
24 REQUIRE_MAIN_THREAD();
25
26 CefWindowInfo window_info;
27 window_info.SetAsChild(parent_handle, rect);
28
29 if (GetWindowLongPtr(parent_handle, GWL_EXSTYLE) & WS_EX_NOACTIVATE) {
30 // Don't activate the browser window on creation.
31 window_info.ex_style |= WS_EX_NOACTIVATE;
32 }
33
34 CefBrowserHost::CreateBrowser(window_info, client_handler_,
35 client_handler_->startup_url(), settings,
36 extra_info, request_context);
37 }
38
GetPopupConfig(CefWindowHandle temp_handle,CefWindowInfo & windowInfo,CefRefPtr<CefClient> & client,CefBrowserSettings & settings)39 void BrowserWindowStdWin::GetPopupConfig(CefWindowHandle temp_handle,
40 CefWindowInfo& windowInfo,
41 CefRefPtr<CefClient>& client,
42 CefBrowserSettings& settings) {
43 CEF_REQUIRE_UI_THREAD();
44
45 // The window will be properly sized after the browser is created.
46 windowInfo.SetAsChild(temp_handle, CefRect());
47
48 // Don't activate the hidden browser window on creation.
49 windowInfo.ex_style |= WS_EX_NOACTIVATE;
50
51 client = client_handler_;
52 }
53
ShowPopup(ClientWindowHandle parent_handle,int x,int y,size_t width,size_t height)54 void BrowserWindowStdWin::ShowPopup(ClientWindowHandle parent_handle,
55 int x,
56 int y,
57 size_t width,
58 size_t height) {
59 REQUIRE_MAIN_THREAD();
60
61 HWND hwnd = GetWindowHandle();
62 if (hwnd) {
63 SetParent(hwnd, parent_handle);
64 SetWindowPos(hwnd, nullptr, x, y, static_cast<int>(width),
65 static_cast<int>(height), SWP_NOZORDER | SWP_NOACTIVATE);
66
67 const bool no_activate =
68 GetWindowLongPtr(parent_handle, GWL_EXSTYLE) & WS_EX_NOACTIVATE;
69 ShowWindow(hwnd, no_activate ? SW_SHOWNOACTIVATE : SW_SHOW);
70 }
71 }
72
Show()73 void BrowserWindowStdWin::Show() {
74 REQUIRE_MAIN_THREAD();
75
76 HWND hwnd = GetWindowHandle();
77 if (hwnd && !::IsWindowVisible(hwnd))
78 ShowWindow(hwnd, SW_SHOW);
79 }
80
Hide()81 void BrowserWindowStdWin::Hide() {
82 REQUIRE_MAIN_THREAD();
83
84 HWND hwnd = GetWindowHandle();
85 if (hwnd) {
86 // When the frame window is minimized set the browser window size to 0x0 to
87 // reduce resource usage.
88 SetWindowPos(hwnd, nullptr, 0, 0, 0, 0,
89 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
90 }
91 }
92
SetBounds(int x,int y,size_t width,size_t height)93 void BrowserWindowStdWin::SetBounds(int x, int y, size_t width, size_t height) {
94 REQUIRE_MAIN_THREAD();
95
96 HWND hwnd = GetWindowHandle();
97 if (hwnd) {
98 // Set the browser window bounds.
99 SetWindowPos(hwnd, nullptr, x, y, static_cast<int>(width),
100 static_cast<int>(height), SWP_NOZORDER);
101 }
102 }
103
SetFocus(bool focus)104 void BrowserWindowStdWin::SetFocus(bool focus) {
105 REQUIRE_MAIN_THREAD();
106
107 if (browser_)
108 browser_->GetHost()->SetFocus(focus);
109 }
110
GetWindowHandle() const111 ClientWindowHandle BrowserWindowStdWin::GetWindowHandle() const {
112 REQUIRE_MAIN_THREAD();
113
114 if (browser_)
115 return browser_->GetHost()->GetWindowHandle();
116 return nullptr;
117 }
118
119 } // namespace client
120