summaryrefslogtreecommitdiff
path: root/chromium/components/exo/wayland/zxdg_shell.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-20 13:40:20 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-22 12:41:23 +0000
commit7961cea6d1041e3e454dae6a1da660b453efd238 (patch)
treec0eeb4a9ff9ba32986289c1653d9608e53ccb444 /chromium/components/exo/wayland/zxdg_shell.cc
parentb7034d0803538058e5c9d904ef03cf5eab34f6ef (diff)
downloadqtwebengine-chromium-7961cea6d1041e3e454dae6a1da660b453efd238.tar.gz
BASELINE: Update Chromium to 78.0.3904.130
Change-Id: If185e0c0061b3437531c97c9c8c78f239352a68b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/exo/wayland/zxdg_shell.cc')
-rw-r--r--chromium/components/exo/wayland/zxdg_shell.cc188
1 files changed, 109 insertions, 79 deletions
diff --git a/chromium/components/exo/wayland/zxdg_shell.cc b/chromium/components/exo/wayland/zxdg_shell.cc
index d0e02ee1ab2..bf796d7168b 100644
--- a/chromium/components/exo/wayland/zxdg_shell.cc
+++ b/chromium/components/exo/wayland/zxdg_shell.cc
@@ -14,6 +14,7 @@
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "components/exo/display.h"
+#include "components/exo/wayland/serial_tracker.h"
#include "components/exo/wayland/server_util.h"
#include "components/exo/wayland/wayland_positioner.h"
#include "components/exo/xdg_shell_surface.h"
@@ -149,111 +150,129 @@ using XdgSurfaceConfigureCallback =
uint32_t HandleXdgSurfaceV6ConfigureCallback(
wl_resource* resource,
+ SerialTracker* serial_tracker,
const XdgSurfaceConfigureCallback& callback,
const gfx::Size& size,
ash::WindowStateType state_type,
bool resizing,
bool activated,
const gfx::Vector2d& origin_offset) {
- uint32_t serial = wl_display_next_serial(
- wl_client_get_display(wl_resource_get_client(resource)));
+ uint32_t serial =
+ serial_tracker->GetNextSerial(SerialTracker::EventType::OTHER_EVENT);
callback.Run(size, state_type, resizing, activated);
zxdg_surface_v6_send_configure(resource, serial);
wl_client_flush(wl_resource_get_client(resource));
return serial;
}
+struct WaylandXdgSurface {
+ WaylandXdgSurface(std::unique_ptr<XdgShellSurface> shell_surface,
+ SerialTracker* const serial_tracker)
+ : shell_surface(std::move(shell_surface)),
+ serial_tracker(serial_tracker) {}
+
+ std::unique_ptr<XdgShellSurface> shell_surface;
+
+ // Owned by Server, which always outlives this surface.
+ SerialTracker* const serial_tracker;
+
+ DISALLOW_COPY_AND_ASSIGN(WaylandXdgSurface);
+};
+
// Wrapper around shell surface that allows us to handle the case where the
// xdg surface resource is destroyed before the toplevel resource.
class WaylandToplevel : public aura::WindowObserver {
public:
WaylandToplevel(wl_resource* resource, wl_resource* surface_resource)
: resource_(resource),
- shell_surface_(GetUserDataAs<XdgShellSurface>(surface_resource)),
- weak_ptr_factory_(this) {
- shell_surface_->host_window()->AddObserver(this);
- shell_surface_->set_close_callback(
+ shell_surface_data_(
+ GetUserDataAs<WaylandXdgSurface>(surface_resource)) {
+ shell_surface_data_->shell_surface->host_window()->AddObserver(this);
+ shell_surface_data_->shell_surface->set_close_callback(
base::Bind(&WaylandToplevel::OnClose, weak_ptr_factory_.GetWeakPtr()));
- shell_surface_->set_configure_callback(
+ shell_surface_data_->shell_surface->set_configure_callback(
base::Bind(&HandleXdgSurfaceV6ConfigureCallback, surface_resource,
+ shell_surface_data_->serial_tracker,
base::Bind(&WaylandToplevel::OnConfigure,
weak_ptr_factory_.GetWeakPtr())));
}
~WaylandToplevel() override {
- if (shell_surface_)
- shell_surface_->host_window()->RemoveObserver(this);
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->host_window()->RemoveObserver(this);
}
// Overridden from aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override {
- shell_surface_ = nullptr;
+ shell_surface_data_ = nullptr;
}
void SetParent(WaylandToplevel* parent) {
- if (!shell_surface_)
+ if (!shell_surface_data_)
return;
if (!parent) {
- shell_surface_->SetParent(nullptr);
+ shell_surface_data_->shell_surface->SetParent(nullptr);
return;
}
// This is a no-op if parent is not mapped.
- if (parent->shell_surface_ && parent->shell_surface_->GetWidget())
- shell_surface_->SetParent(parent->shell_surface_);
+ if (parent->shell_surface_data_ &&
+ parent->shell_surface_data_->shell_surface->GetWidget())
+ shell_surface_data_->shell_surface->SetParent(
+ parent->shell_surface_data_->shell_surface.get());
}
void SetTitle(const base::string16& title) {
- if (shell_surface_)
- shell_surface_->SetTitle(title);
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->SetTitle(title);
}
void SetApplicationId(const char* application_id) {
- if (shell_surface_)
- shell_surface_->SetApplicationId(application_id);
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->SetApplicationId(application_id);
}
void Move() {
- if (shell_surface_)
- shell_surface_->StartMove();
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->StartMove();
}
void Resize(int component) {
- if (!shell_surface_)
+ if (!shell_surface_data_)
return;
if (component != HTNOWHERE)
- shell_surface_->StartResize(component);
+ shell_surface_data_->shell_surface->StartResize(component);
}
void SetMaximumSize(const gfx::Size& size) {
- if (shell_surface_)
- shell_surface_->SetMaximumSize(size);
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->SetMaximumSize(size);
}
void SetMinimumSize(const gfx::Size& size) {
- if (shell_surface_)
- shell_surface_->SetMinimumSize(size);
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->SetMinimumSize(size);
}
void Maximize() {
- if (shell_surface_)
- shell_surface_->Maximize();
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->Maximize();
}
void Restore() {
- if (shell_surface_)
- shell_surface_->Restore();
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->Restore();
}
void SetFullscreen(bool fullscreen) {
- if (shell_surface_)
- shell_surface_->SetFullscreen(fullscreen);
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->SetFullscreen(fullscreen);
}
void Minimize() {
- if (shell_surface_)
- shell_surface_->Minimize();
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->Minimize();
}
private:
@@ -289,8 +308,8 @@ class WaylandToplevel : public aura::WindowObserver {
}
wl_resource* const resource_;
- XdgShellSurface* shell_surface_;
- base::WeakPtrFactory<WaylandToplevel> weak_ptr_factory_;
+ WaylandXdgSurface* shell_surface_data_;
+ base::WeakPtrFactory<WaylandToplevel> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(WaylandToplevel);
};
@@ -404,38 +423,39 @@ class WaylandPopup : aura::WindowObserver {
public:
WaylandPopup(wl_resource* resource, wl_resource* surface_resource)
: resource_(resource),
- shell_surface_(GetUserDataAs<ShellSurface>(surface_resource)),
- weak_ptr_factory_(this) {
- shell_surface_->host_window()->AddObserver(this);
- shell_surface_->set_close_callback(
+ shell_surface_data_(
+ GetUserDataAs<WaylandXdgSurface>(surface_resource)) {
+ shell_surface_data_->shell_surface->host_window()->AddObserver(this);
+ shell_surface_data_->shell_surface->set_close_callback(
base::Bind(&WaylandPopup::OnClose, weak_ptr_factory_.GetWeakPtr()));
- shell_surface_->set_configure_callback(
+ shell_surface_data_->shell_surface->set_configure_callback(
base::Bind(&HandleXdgSurfaceV6ConfigureCallback, surface_resource,
+ shell_surface_data_->serial_tracker,
base::Bind(&WaylandPopup::OnConfigure,
weak_ptr_factory_.GetWeakPtr())));
}
~WaylandPopup() override {
- if (shell_surface_)
- shell_surface_->host_window()->RemoveObserver(this);
+ if (shell_surface_data_)
+ shell_surface_data_->shell_surface->host_window()->RemoveObserver(this);
}
void Grab() {
- if (!shell_surface_) {
+ if (!shell_surface_data_) {
wl_resource_post_error(resource_, ZXDG_POPUP_V6_ERROR_INVALID_GRAB,
"the surface has already been destroyed");
return;
}
- if (shell_surface_->GetWidget()) {
+ if (shell_surface_data_->shell_surface->GetWidget()) {
wl_resource_post_error(resource_, ZXDG_POPUP_V6_ERROR_INVALID_GRAB,
"grab must be called before construction");
return;
}
- shell_surface_->Grab();
+ shell_surface_data_->shell_surface->Grab();
}
// Overridden from aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override {
- shell_surface_ = nullptr;
+ shell_surface_data_ = nullptr;
}
private:
@@ -452,8 +472,8 @@ class WaylandPopup : aura::WindowObserver {
}
wl_resource* const resource_;
- ShellSurface* shell_surface_;
- base::WeakPtrFactory<WaylandPopup> weak_ptr_factory_;
+ WaylandXdgSurface* shell_surface_data_;
+ base::WeakPtrFactory<WaylandPopup> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(WaylandPopup);
};
@@ -482,15 +502,15 @@ void xdg_surface_v6_destroy(wl_client* client, wl_resource* resource) {
void xdg_surface_v6_get_toplevel(wl_client* client,
wl_resource* resource,
uint32_t id) {
- ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource);
- if (shell_surface->GetEnabled()) {
+ auto* shell_surface_data = GetUserDataAs<WaylandXdgSurface>(resource);
+ if (shell_surface_data->shell_surface->GetEnabled()) {
wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_ALREADY_CONSTRUCTED,
"surface has already been constructed");
return;
}
- shell_surface->SetCanMinimize(true);
- shell_surface->SetEnabled(true);
+ shell_surface_data->shell_surface->SetCanMinimize(true);
+ shell_surface_data->shell_surface->SetEnabled(true);
wl_resource* xdg_toplevel_resource =
wl_resource_create(client, &zxdg_toplevel_v6_interface, 1, id);
@@ -505,21 +525,21 @@ void xdg_surface_v6_get_popup(wl_client* client,
uint32_t id,
wl_resource* parent_resource,
wl_resource* positioner_resource) {
- XdgShellSurface* shell_surface = GetUserDataAs<XdgShellSurface>(resource);
- if (shell_surface->GetEnabled()) {
+ auto* shell_surface_data = GetUserDataAs<WaylandXdgSurface>(resource);
+ if (shell_surface_data->shell_surface->GetEnabled()) {
wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_ALREADY_CONSTRUCTED,
"surface has already been constructed");
return;
}
- XdgShellSurface* parent = GetUserDataAs<XdgShellSurface>(parent_resource);
- if (!parent->GetWidget()) {
+ auto* parent_data = GetUserDataAs<WaylandXdgSurface>(parent_resource);
+ if (!parent_data->shell_surface->GetWidget()) {
wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
"popup parent not constructed");
return;
}
- if (shell_surface->GetWidget()) {
+ if (shell_surface_data->shell_surface->GetWidget()) {
wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_ALREADY_CONSTRUCTED,
"get_popup is called after constructed");
return;
@@ -527,33 +547,38 @@ void xdg_surface_v6_get_popup(wl_client* client,
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(
- parent->GetWidget()->GetNativeWindow());
+ parent_data->shell_surface->GetWidget()->GetNativeWindow());
gfx::Rect work_area = display.work_area();
- wm::ConvertRectFromScreen(parent->GetWidget()->GetNativeWindow(), &work_area);
+ wm::ConvertRectFromScreen(
+ parent_data->shell_surface->GetWidget()->GetNativeWindow(), &work_area);
// Try layout using parent's flip state.
WaylandPositioner* positioner =
GetUserDataAs<WaylandPositioner>(positioner_resource);
WaylandPositioner::Result position = positioner->CalculatePosition(
- work_area, parent->x_flipped(), parent->y_flipped());
+ work_area, parent_data->shell_surface->x_flipped(),
+ parent_data->shell_surface->y_flipped());
// Remember the new flip state for its child popups.
- shell_surface->set_x_flipped(position.x_flipped);
- shell_surface->set_y_flipped(position.y_flipped);
+ shell_surface_data->shell_surface->set_x_flipped(position.x_flipped);
+ shell_surface_data->shell_surface->set_y_flipped(position.y_flipped);
// |position| is relative to the parent's contents view origin, and |origin|
// is in screen coordinates.
gfx::Point origin = position.origin;
- views::View::ConvertPointToScreen(
- parent->GetWidget()->widget_delegate()->GetContentsView(), &origin);
- shell_surface->SetOrigin(origin);
- shell_surface->SetSize(position.size);
- shell_surface->DisableMovement();
- shell_surface->SetActivatable(false);
- shell_surface->SetCanMinimize(false);
- shell_surface->SetParent(parent);
- shell_surface->SetPopup();
- shell_surface->SetEnabled(true);
+ views::View::ConvertPointToScreen(parent_data->shell_surface->GetWidget()
+ ->widget_delegate()
+ ->GetContentsView(),
+ &origin);
+ shell_surface_data->shell_surface->SetOrigin(origin);
+ shell_surface_data->shell_surface->SetSize(position.size);
+ shell_surface_data->shell_surface->DisableMovement();
+ shell_surface_data->shell_surface->SetActivatable(false);
+ shell_surface_data->shell_surface->SetCanMinimize(false);
+ shell_surface_data->shell_surface->SetParent(
+ parent_data->shell_surface.get());
+ shell_surface_data->shell_surface->SetPopup();
+ shell_surface_data->shell_surface->SetEnabled(true);
wl_resource* xdg_popup_resource =
wl_resource_create(client, &zxdg_popup_v6_interface, 1, id);
@@ -575,14 +600,15 @@ void xdg_surface_v6_set_window_geometry(wl_client* client,
int32_t y,
int32_t width,
int32_t height) {
- GetUserDataAs<ShellSurface>(resource)->SetGeometry(
+ GetUserDataAs<WaylandXdgSurface>(resource)->shell_surface->SetGeometry(
gfx::Rect(x, y, width, height));
}
void xdg_surface_v6_ack_configure(wl_client* client,
wl_resource* resource,
uint32_t serial) {
- GetUserDataAs<ShellSurface>(resource)->AcknowledgeConfigure(serial);
+ GetUserDataAs<WaylandXdgSurface>(resource)
+ ->shell_surface->AcknowledgeConfigure(serial);
}
const struct zxdg_surface_v6_interface xdg_surface_v6_implementation = {
@@ -611,9 +637,9 @@ void xdg_shell_v6_get_xdg_surface(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* surface) {
- std::unique_ptr<ShellSurface> shell_surface =
- GetUserDataAs<Display>(resource)->CreateXdgShellSurface(
- GetUserDataAs<Surface>(surface));
+ auto* data = GetUserDataAs<WaylandXdgShell>(resource);
+ std::unique_ptr<XdgShellSurface> shell_surface =
+ data->display->CreateXdgShellSurface(GetUserDataAs<Surface>(surface));
if (!shell_surface) {
wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_ROLE,
"surface has already been assigned a role");
@@ -624,11 +650,15 @@ void xdg_shell_v6_get_xdg_surface(wl_client* client,
// mapped before they are enabled and can become visible.
shell_surface->SetEnabled(false);
+ std::unique_ptr<WaylandXdgSurface> wayland_shell_surface =
+ std::make_unique<WaylandXdgSurface>(std::move(shell_surface),
+ data->serial_tracker);
+
wl_resource* xdg_surface_resource =
wl_resource_create(client, &zxdg_surface_v6_interface, 1, id);
SetImplementation(xdg_surface_resource, &xdg_surface_v6_implementation,
- std::move(shell_surface));
+ std::move(wayland_shell_surface));
}
void xdg_shell_v6_pong(wl_client* client,