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.
5 #include "tests/cefclient/browser/browser_window_std_gtk.h"
12 #undef Success // Definition conflicts with cef_message_router.h
13 #undef RootWindow // Definition conflicts with root_window.h
15 #include "include/base/cef_logging.h"
16 #include "tests/cefclient/browser/client_handler_std.h"
17 #include "tests/shared/browser/main_message_loop.h"
23 ::Window GetXWindowForWidget(GtkWidget* widget) {
24 // The GTK window must be visible before we can retrieve the XID.
25 ::Window xwindow = GDK_WINDOW_XID(gtk_widget_get_window(widget));
30 void SetXWindowVisible(::Window xwindow, bool visible) {
31 ::Display* xdisplay = cef_get_xdisplay();
33 // Retrieve the atoms required by the below XChangeProperty call.
34 const char* kAtoms[] = {
37 "_NET_WM_STATE_HIDDEN"
40 int result = XInternAtoms(xdisplay, const_cast<char**>(kAtoms), 3, false,
46 // Set the hidden property state value.
47 scoped_ptr<Atom[]> data(new Atom[1]);
50 XChangeProperty(xdisplay,
54 32, // size in bits of items in 'value'
56 reinterpret_cast<const unsigned char*>(data.get()),
59 // Set an empty array of property state values.
60 XChangeProperty(xdisplay,
64 32, // size in bits of items in 'value'
71 void SetXWindowBounds(::Window xwindow,
72 int x, int y, size_t width, size_t height) {
73 ::Display* xdisplay = cef_get_xdisplay();
74 XWindowChanges changes = {0};
77 changes.width = static_cast<int>(width);
78 changes.height = static_cast<int>(height);
79 XConfigureWindow(xdisplay, xwindow,
80 CWX | CWY | CWHeight | CWWidth, &changes);
85 BrowserWindowStdGtk::BrowserWindowStdGtk(Delegate* delegate,
86 const std::string& startup_url)
87 : BrowserWindow(delegate) {
88 client_handler_ = new ClientHandlerStd(this, startup_url);
91 void BrowserWindowStdGtk::CreateBrowser(
92 ClientWindowHandle parent_handle,
94 const CefBrowserSettings& settings,
95 CefRefPtr<CefRequestContext> request_context) {
96 REQUIRE_MAIN_THREAD();
98 CefWindowInfo window_info;
99 window_info.SetAsChild(GetXWindowForWidget(parent_handle), rect);
101 CefBrowserHost::CreateBrowser(window_info, client_handler_,
102 client_handler_->startup_url(),
103 settings, request_context);
106 void BrowserWindowStdGtk::GetPopupConfig(CefWindowHandle temp_handle,
107 CefWindowInfo& windowInfo,
108 CefRefPtr<CefClient>& client,
109 CefBrowserSettings& settings) {
110 // Note: This method may be called on any thread.
111 // The window will be properly sized after the browser is created.
112 windowInfo.SetAsChild(temp_handle, CefRect());
113 client = client_handler_;
116 void BrowserWindowStdGtk::ShowPopup(ClientWindowHandle parent_handle,
117 int x, int y, size_t width, size_t height) {
118 REQUIRE_MAIN_THREAD();
121 ::Window parent_xwindow = GetXWindowForWidget(parent_handle);
122 ::Display* xdisplay = cef_get_xdisplay();
123 ::Window xwindow = browser_->GetHost()->GetWindowHandle();
126 XReparentWindow(xdisplay, xwindow, parent_xwindow, x, y);
128 SetXWindowBounds(xwindow, x, y, width, height);
129 SetXWindowVisible(xwindow, true);
133 void BrowserWindowStdGtk::Show() {
134 REQUIRE_MAIN_THREAD();
137 ::Window xwindow = browser_->GetHost()->GetWindowHandle();
139 SetXWindowVisible(xwindow, true);
143 void BrowserWindowStdGtk::Hide() {
144 REQUIRE_MAIN_THREAD();
147 ::Window xwindow = browser_->GetHost()->GetWindowHandle();
149 SetXWindowVisible(xwindow, false);
153 void BrowserWindowStdGtk::SetBounds(int x, int y, size_t width, size_t height) {
154 REQUIRE_MAIN_THREAD();
157 ::Window xwindow = browser_->GetHost()->GetWindowHandle();
159 SetXWindowBounds(xwindow, x, y, width, height);
163 void BrowserWindowStdGtk::SetFocus(bool focus) {
164 REQUIRE_MAIN_THREAD();
167 browser_->GetHost()->SetFocus(focus);
170 ClientWindowHandle BrowserWindowStdGtk::GetWindowHandle() const {
171 REQUIRE_MAIN_THREAD();
173 // There is no GtkWidget* representation of this object.
179 } // namespace client