Commit 679a9604 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

ozone/x11: Refactor X11WindowOzone to reuse ui::XWindow

As part of large refactoring in X11 code, crrev.com/c/1695008 introduces
ui::XWindow, a reusable X11 Window class extracted from
views::DesktopWindowTreeHostX11, it also modified DWTHX11 to leverage
ui::XWindow, making it more like DesktopWindowTreeHostPlatform, which uses
Ozone/PlatformWindow to abstract platform-specific window implementation.

This CL does an initial refactoring in X11WindowOzone, so that it starts
using ui::XWindow to back its PlatformWindow implementation, which
already fixes previous broken functionality, such as window activation.
Other improvements/fixes will be addressed in followup patches.

Bug: 981606, 789065
Change-Id: I9f7f686bbcaa51d391e77ce77b5dcfd15c91dc0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1698263Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#677005}
parent 0c213799
......@@ -74,7 +74,7 @@ class OzonePlatformX11 : public OzonePlatform {
PlatformWindowDelegate* delegate,
PlatformWindowInitProperties properties) override {
std::unique_ptr<X11WindowOzone> window = std::make_unique<X11WindowOzone>(
window_manager_.get(), delegate, properties.bounds);
delegate, properties, window_manager_.get());
window->SetTitle(base::ASCIIToUTF16("Ozone X11"));
return std::move(window);
}
......
......@@ -14,6 +14,7 @@
#include "ui/ozone/platform/x11/x11_window_ozone.h"
#include "ui/ozone/test/mock_platform_window_delegate.h"
#include "ui/platform_window/platform_window_delegate.h"
#include "ui/platform_window/platform_window_init_properties.h"
using ::testing::_;
......@@ -74,8 +75,9 @@ class X11ScreenOzoneTest : public testing::Test {
gfx::AcceleratedWidget* widget = nullptr) {
EXPECT_CALL(*delegate, OnAcceleratedWidgetAvailable(_))
.WillOnce(StoreWidget(widget));
X11WindowManagerOzone* wm = window_manager_.get();
return std::make_unique<X11WindowOzone>(wm, delegate, bounds);
PlatformWindowInitProperties init_params(bounds);
return std::make_unique<X11WindowOzone>(delegate, init_params,
window_manager_.get());
}
private:
......
This diff is collapsed.
......@@ -10,6 +10,7 @@
#include "base/containers/flat_set.h"
#include "base/macros.h"
#include "ui/base/x/x11_window.h"
#include "ui/base/x/x11_window_event_manager.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/x11/x11_event_source_libevent.h"
......@@ -20,15 +21,17 @@
namespace ui {
class X11WindowManagerOzone;
struct PlatformWindowInitProperties;
// PlatformWindow implementation for X11 Ozone. PlatformEvents are ui::Events.
class X11WindowOzone : public PlatformWindow,
public PlatformEventDispatcher,
public XEventDispatcher {
public XEventDispatcher,
public XWindow::Delegate {
public:
X11WindowOzone(X11WindowManagerOzone* window_manager,
PlatformWindowDelegate* delegate,
const gfx::Rect& bounds);
X11WindowOzone(PlatformWindowDelegate* delegate,
const PlatformWindowInitProperties& properties,
X11WindowManagerOzone* window_manager);
~X11WindowOzone() override;
gfx::AcceleratedWidget widget() const { return widget_; }
......@@ -36,7 +39,7 @@ class X11WindowOzone : public PlatformWindow,
// Called by |window_manager_| once capture is set to another X11WindowOzone.
void OnLostCapture();
// PlatformWindow:
// Overridden from PlatformWindow:
void Show() override;
void Hide() override;
void Close() override;
......@@ -60,50 +63,46 @@ class X11WindowOzone : public PlatformWindow,
bool HasCapture() const override;
void SetCursor(PlatformCursor cursor) override;
// XEventDispatcher:
// Overridden from ui::XEventDispatcher:
void CheckCanDispatchNextPlatformEvent(XEvent* xev) override;
void PlatformEventDispatchFinished() override;
PlatformEventDispatcher* GetPlatformEventDispatcher() override;
bool DispatchXEvent(XEvent* event) override;
private:
void RemoveFromWindowManager();
// Overridden from ui::XWindow::Delegate
void OnXWindowCreated() override;
void OnXWindowStateChanged() override;
void OnXWindowDamageEvent(const gfx::Rect& damage_rect) override;
void OnXWindowSizeChanged(const gfx::Size& size) override;
void OnXWindowCloseRequested() override;
void OnXWindowLostCapture() override;
void OnXWindowIsActiveChanged(bool active) override;
::Time GetTimestampForXWindow() override;
// PlatformEventDispatcher:
bool CanDispatchEvent(const PlatformEvent& event) override;
uint32_t DispatchEvent(const PlatformEvent& event) override;
void Create();
void Destroy();
XID CreateXWindow();
void SetXWindow(XID xwindow);
void Init(const PlatformWindowInitProperties& params);
void SetWidget(XID xwindow);
bool IsEventForXWindow(const XEvent& xev) const;
void ProcessXWindowEvent(XEvent* xev);
void OnWMStateUpdated();
void UnconfineCursor();
void RemoveFromWindowManager();
X11WindowManagerOzone* window_manager_;
PlatformWindowDelegate* const delegate_;
XDisplay* xdisplay_;
XID xroot_window_;
XID xwindow_;
bool mapped_;
gfx::Rect bounds_;
base::string16 window_title_;
PlatformWindowState state_;
base::flat_set<XAtom> window_properties_;
X11WindowManagerOzone* const window_manager_;
PlatformWindowState state_ = PlatformWindowState::kUnknown;
gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
std::unique_ptr<ui::XWindow> x11_window_;
bool is_shutting_down_ = false;
// Tells if this dispatcher can process next translated event based on a
// previous check in ::CheckCanDispatchNextPlatformEvent based on a XID
// target.
bool handle_next_event_ = false;
std::unique_ptr<ui::XScopedEventSelector> xwindow_events_;
// Keep track of barriers to confine cursor.
bool has_pointer_barriers_ = false;
std::array<XID, 4> pointer_barriers_;
gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
DISALLOW_COPY_AND_ASSIGN(X11WindowOzone);
};
......
......@@ -17,6 +17,7 @@
#include "ui/ozone/platform/x11/x11_window_manager_ozone.h"
#include "ui/ozone/test/mock_platform_window_delegate.h"
#include "ui/platform_window/platform_window_delegate.h"
#include "ui/platform_window/platform_window_init_properties.h"
namespace ui {
......@@ -59,8 +60,9 @@ class X11WindowOzoneTest : public testing::Test {
gfx::AcceleratedWidget* widget) {
EXPECT_CALL(*delegate, OnAcceleratedWidgetAvailable(_))
.WillOnce(StoreWidget(widget));
auto window = std::make_unique<X11WindowOzone>(window_manager_.get(),
delegate, bounds);
PlatformWindowInitProperties init_params(bounds);
auto window = std::make_unique<X11WindowOzone>(delegate, init_params,
window_manager_.get());
return std::move(window);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment