2015-01-29 21:53:53 +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_std_gtk.h"
|
2015-01-29 21:53:53 +01:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include <X11/Xlib.h>
|
2015-01-29 21:53:53 +01:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gdk/gdkx.h>
|
2017-05-17 11:29:28 +02:00
|
|
|
#include <gtk/gtk.h>
|
2015-01-29 21:53:53 +01:00
|
|
|
#undef Success // Definition conflicts with cef_message_router.h
|
|
|
|
#undef RootWindow // Definition conflicts with root_window.h
|
|
|
|
|
|
|
|
#include "include/base/cef_logging.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/client_handler_std.h"
|
2018-09-20 15:00:14 +02:00
|
|
|
#include "tests/cefclient/browser/util_gtk.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/browser/main_message_loop.h"
|
2015-01-29 21:53:53 +01:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
::Window GetXWindowForWidget(GtkWidget* widget) {
|
2018-09-20 15:00:14 +02:00
|
|
|
ScopedGdkThreadsEnter scoped_gdk_threads;
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
// The GTK window must be visible before we can retrieve the XID.
|
|
|
|
::Window xwindow = GDK_WINDOW_XID(gtk_widget_get_window(widget));
|
|
|
|
DCHECK(xwindow);
|
|
|
|
return xwindow;
|
|
|
|
}
|
|
|
|
|
2018-09-20 15:00:14 +02:00
|
|
|
void SetXWindowVisible(XDisplay* xdisplay, ::Window xwindow, bool visible) {
|
|
|
|
CHECK(xdisplay != 0);
|
2015-01-29 21:53:53 +01:00
|
|
|
|
|
|
|
// Retrieve the atoms required by the below XChangeProperty call.
|
2017-05-17 11:29:28 +02:00
|
|
|
const char* kAtoms[] = {"_NET_WM_STATE", "ATOM", "_NET_WM_STATE_HIDDEN"};
|
2015-01-29 21:53:53 +01:00
|
|
|
Atom atoms[3];
|
2017-05-17 11:29:28 +02:00
|
|
|
int result =
|
|
|
|
XInternAtoms(xdisplay, const_cast<char**>(kAtoms), 3, false, atoms);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!result) {
|
2015-01-29 21:53:53 +01:00
|
|
|
NOTREACHED();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-29 21:53:53 +01:00
|
|
|
|
|
|
|
if (!visible) {
|
|
|
|
// Set the hidden property state value.
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<Atom[]> data(new Atom[1]);
|
2015-01-29 21:53:53 +01:00
|
|
|
data[0] = atoms[2];
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
XChangeProperty(xdisplay, xwindow,
|
2015-01-29 21:53:53 +01:00
|
|
|
atoms[0], // name
|
|
|
|
atoms[1], // type
|
2017-05-17 11:29:28 +02:00
|
|
|
32, // size in bits of items in 'value'
|
2015-01-29 21:53:53 +01:00
|
|
|
PropModeReplace,
|
|
|
|
reinterpret_cast<const unsigned char*>(data.get()),
|
|
|
|
1); // num items
|
|
|
|
} else {
|
|
|
|
// Set an empty array of property state values.
|
2017-05-17 11:29:28 +02:00
|
|
|
XChangeProperty(xdisplay, xwindow,
|
2015-01-29 21:53:53 +01:00
|
|
|
atoms[0], // name
|
|
|
|
atoms[1], // type
|
2017-05-17 11:29:28 +02:00
|
|
|
32, // size in bits of items in 'value'
|
2021-06-17 22:08:01 +02:00
|
|
|
PropModeReplace, nullptr,
|
2015-01-29 21:53:53 +01:00
|
|
|
0); // num items
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 15:00:14 +02:00
|
|
|
void SetXWindowBounds(XDisplay* xdisplay,
|
|
|
|
::Window xwindow,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
size_t width,
|
|
|
|
size_t height) {
|
2018-09-20 15:00:14 +02:00
|
|
|
CHECK(xdisplay != 0);
|
2015-01-29 21:53:53 +01:00
|
|
|
XWindowChanges changes = {0};
|
|
|
|
changes.x = x;
|
|
|
|
changes.y = y;
|
|
|
|
changes.width = static_cast<int>(width);
|
|
|
|
changes.height = static_cast<int>(height);
|
2017-05-17 11:29:28 +02:00
|
|
|
XConfigureWindow(xdisplay, xwindow, CWX | CWY | CWHeight | CWWidth, &changes);
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
BrowserWindowStdGtk::BrowserWindowStdGtk(Delegate* delegate,
|
2022-03-22 19:31:30 +01:00
|
|
|
bool with_controls,
|
2015-01-29 21:53:53 +01:00
|
|
|
const std::string& startup_url)
|
2018-09-20 15:00:14 +02:00
|
|
|
: BrowserWindow(delegate), xdisplay_(nullptr) {
|
2022-03-22 19:31:30 +01:00
|
|
|
client_handler_ = new ClientHandlerStd(this, with_controls, startup_url);
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
|
2018-09-20 15:00:14 +02:00
|
|
|
void BrowserWindowStdGtk::set_xdisplay(XDisplay* xdisplay) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
DCHECK(!xdisplay_);
|
|
|
|
xdisplay_ = xdisplay;
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
void BrowserWindowStdGtk::CreateBrowser(
|
|
|
|
ClientWindowHandle parent_handle,
|
|
|
|
const CefRect& rect,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2015-02-14 00:17:08 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
2015-01-29 21:53:53 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
CefWindowInfo window_info;
|
|
|
|
window_info.SetAsChild(GetXWindowForWidget(parent_handle), rect);
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (delegate_->UseAlloyStyle()) {
|
|
|
|
window_info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
|
|
|
|
}
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
CefBrowserHost::CreateBrowser(window_info, client_handler_,
|
2017-05-17 11:29:28 +02:00
|
|
|
client_handler_->startup_url(), settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
extra_info, request_context);
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowStdGtk::GetPopupConfig(CefWindowHandle temp_handle,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
// The window will be properly sized after the browser is created.
|
|
|
|
windowInfo.SetAsChild(temp_handle, CefRect());
|
2024-04-17 18:01:26 +02:00
|
|
|
|
|
|
|
if (delegate_->UseAlloyStyle()) {
|
|
|
|
windowInfo.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
|
|
|
|
}
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
client = client_handler_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowStdGtk::ShowPopup(ClientWindowHandle parent_handle,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
size_t width,
|
|
|
|
size_t height) {
|
2015-01-29 21:53:53 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
if (browser_) {
|
|
|
|
::Window parent_xwindow = GetXWindowForWidget(parent_handle);
|
2018-09-20 15:00:14 +02:00
|
|
|
CHECK(xdisplay_ != 0);
|
2015-01-29 21:53:53 +01:00
|
|
|
::Window xwindow = browser_->GetHost()->GetWindowHandle();
|
|
|
|
DCHECK(xwindow);
|
|
|
|
|
2018-09-20 15:00:14 +02:00
|
|
|
XReparentWindow(xdisplay_, xwindow, parent_xwindow, x, y);
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2018-09-20 15:00:14 +02:00
|
|
|
SetXWindowBounds(xdisplay_, xwindow, x, y, width, height);
|
|
|
|
SetXWindowVisible(xdisplay_, xwindow, true);
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowStdGtk::Show() {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
if (browser_) {
|
|
|
|
::Window xwindow = browser_->GetHost()->GetWindowHandle();
|
|
|
|
DCHECK(xwindow);
|
2018-09-20 15:00:14 +02:00
|
|
|
SetXWindowVisible(xdisplay_, xwindow, true);
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowStdGtk::Hide() {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
if (browser_) {
|
|
|
|
::Window xwindow = browser_->GetHost()->GetWindowHandle();
|
|
|
|
DCHECK(xwindow);
|
2018-09-20 15:00:14 +02:00
|
|
|
SetXWindowVisible(xdisplay_, xwindow, false);
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindowStdGtk::SetBounds(int x, int y, size_t width, size_t height) {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2018-10-10 12:41:34 +02:00
|
|
|
if (xdisplay_ && browser_) {
|
2015-01-29 21:53:53 +01:00
|
|
|
::Window xwindow = browser_->GetHost()->GetWindowHandle();
|
|
|
|
DCHECK(xwindow);
|
2018-09-20 15:00:14 +02:00
|
|
|
SetXWindowBounds(xdisplay_, xwindow, x, y, width, height);
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:07:13 +01:00
|
|
|
void BrowserWindowStdGtk::SetFocus(bool focus) {
|
2015-01-29 21:53:53 +01:00
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2015-01-30 19:07:13 +01:00
|
|
|
browser_->GetHost()->SetFocus(focus);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ClientWindowHandle BrowserWindowStdGtk::GetWindowHandle() const {
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
|
|
|
// There is no GtkWidget* representation of this object.
|
|
|
|
NOTREACHED();
|
2021-06-17 22:08:01 +02:00
|
|
|
return nullptr;
|
2015-01-29 21:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace client
|