Commit 6983e9fa authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

X11 and Ozone: Move static methods to DWTHLinux.

At first, I wanted to remove these static methods, but then decided
to keep them and remove later when we no longer need them.

Bug: 990756
Change-Id: If6132986e25bb1c8712acdbc90ce29093616bff7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1860341Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#705946}
parent 9a8c5c02
......@@ -7,12 +7,12 @@
#include <vector>
#include "ui/gfx/native_widget_types.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
#include "ui/views/widget/widget.h"
bool IsFullScreenMode() {
std::vector<aura::Window*> all_windows =
views::DesktopWindowTreeHostX11::GetAllOpenWindows();
views::DesktopWindowTreeHostLinux::GetAllOpenWindows();
// Only the topmost window is checked. This works fine in the most cases, but
// it may return false when there are multiple displays and one display has
// a fullscreen window but others don't. See: crbug.com/345484
......
......@@ -200,7 +200,7 @@ void SelectFileDialogImplGTK::SelectFileImpl(
host->ReleaseCapture();
std::unique_ptr<base::OnceClosure> callback =
std::make_unique<base::OnceClosure>(
views::DesktopWindowTreeHostX11::GetHostForXID(
views::DesktopWindowTreeHostLinux::GetHostForWidget(
host->GetAcceleratedWidget())
->DisableEventListening());
// OnFilePickerDestroy() is called when |dialog| destroyed, which allows
......
......@@ -251,10 +251,10 @@ class UIControlsDesktopX11 : public UIControlsAura {
// Most interactive_ui_tests run inside of the aura_test_helper
// environment. This means that we can't rely on display::Screen and several
// other things to work properly. Therefore we hack around this by
// iterating across the windows owned DesktopWindowTreeHostX11 since this
// iterating across the windows owned DesktopWindowTreeHostLinux since this
// doesn't rely on having a DesktopScreenX11.
std::vector<aura::Window*> windows =
DesktopWindowTreeHostX11::GetAllOpenWindows();
DesktopWindowTreeHostLinux::GetAllOpenWindows();
const auto i =
std::find_if(windows.cbegin(), windows.cend(), [point](auto* window) {
return window->GetBoundsInScreen().Contains(point) ||
......
......@@ -13,10 +13,13 @@
#include "ui/views/widget/widget.h"
#include "ui/wm/core/shadow_controller.h"
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
#endif
#if defined(USE_X11)
#include "ui/gfx/x/x11.h" // nogncheck
#include "ui/gfx/x/x11_types.h" // nogncheck
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#endif
namespace views {
......@@ -69,8 +72,8 @@ BOOL CALLBACK FindAllWindowsCallback(HWND hwnd, LPARAM param) {
std::vector<aura::Window*> GetAllTopLevelWindows() {
std::vector<aura::Window*> roots;
#if defined(USE_X11)
roots = DesktopWindowTreeHostX11::GetAllOpenWindows();
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
roots = DesktopWindowTreeHostLinux::GetAllOpenWindows();
#elif defined(OS_WIN)
{
FindAllWindowsData data = {&roots};
......
......@@ -118,8 +118,8 @@ display::Display DesktopScreenX11::GetDisplayNearestWindow(
// aura::Window's screen bounds.
aura::WindowTreeHost* host = window->GetHost();
if (host) {
DesktopWindowTreeHostX11* rwh =
DesktopWindowTreeHostX11::GetHostForXID(host->GetAcceleratedWidget());
auto* rwh = DesktopWindowTreeHostLinux::GetHostForWidget(
host->GetAcceleratedWidget());
if (rwh) {
const gfx::Rect pixel_rect = rwh->GetBoundsInPixels();
const gfx::Rect dip_rect =
......
......@@ -19,8 +19,17 @@
#include "ui/views/widget/desktop_aura/window_event_filter_linux.h"
#include "ui/views/widget/widget.h"
DEFINE_UI_CLASS_PROPERTY_TYPE(views::DesktopWindowTreeHostLinux*)
namespace views {
std::list<gfx::AcceleratedWidget>* DesktopWindowTreeHostLinux::open_windows_ =
nullptr;
DEFINE_UI_CLASS_PROPERTY_KEY(DesktopWindowTreeHostLinux*,
kHostForRootWindow,
nullptr)
namespace {
class SwapWithNewSizeObserverHelper : public ui::CompositorObserver {
......@@ -63,7 +72,48 @@ DesktopWindowTreeHostLinux::DesktopWindowTreeHostLinux(
: DesktopWindowTreeHostPlatform(native_widget_delegate,
desktop_native_widget_aura) {}
DesktopWindowTreeHostLinux::~DesktopWindowTreeHostLinux() = default;
DesktopWindowTreeHostLinux::~DesktopWindowTreeHostLinux() {
window()->ClearProperty(kHostForRootWindow);
}
// static
aura::Window* DesktopWindowTreeHostLinux::GetContentWindowForWidget(
gfx::AcceleratedWidget widget) {
auto* host = DesktopWindowTreeHostLinux::GetHostForWidget(widget);
return host ? host->GetContentWindow() : nullptr;
}
// static
DesktopWindowTreeHostLinux* DesktopWindowTreeHostLinux::GetHostForWidget(
gfx::AcceleratedWidget widget) {
aura::WindowTreeHost* host =
aura::WindowTreeHost::GetForAcceleratedWidget(widget);
return host ? host->window()->GetProperty(kHostForRootWindow) : nullptr;
}
// static
std::vector<aura::Window*> DesktopWindowTreeHostLinux::GetAllOpenWindows() {
std::vector<aura::Window*> windows(open_windows().size());
std::transform(open_windows().begin(), open_windows().end(), windows.begin(),
GetContentWindowForWidget);
return windows;
}
// static
void DesktopWindowTreeHostLinux::CleanUpWindowList(
void (*func)(aura::Window* window)) {
if (!open_windows_)
return;
while (!open_windows_->empty()) {
gfx::AcceleratedWidget widget = open_windows_->front();
func(GetContentWindowForWidget(widget));
if (!open_windows_->empty() && open_windows_->front() == widget)
open_windows_->erase(open_windows_->begin());
}
delete open_windows_;
open_windows_ = nullptr;
}
void DesktopWindowTreeHostLinux::SetPendingXVisualId(int x_visual_id) {
pending_x_visual_id_ = x_visual_id;
......@@ -106,6 +156,8 @@ void DesktopWindowTreeHostLinux::Init(const Widget::InitParams& params) {
void DesktopWindowTreeHostLinux::OnNativeWidgetCreated(
const Widget::InitParams& params) {
window()->SetProperty(kHostForRootWindow, this);
CreateNonClientEventFilter();
DesktopWindowTreeHostPlatform::OnNativeWidgetCreated(params);
}
......@@ -229,10 +281,26 @@ void DesktopWindowTreeHostLinux::DispatchEvent(ui::Event* event) {
}
void DesktopWindowTreeHostLinux::OnClosed() {
open_windows().remove(GetAcceleratedWidget());
DestroyNonClientEventFilter();
DesktopWindowTreeHostPlatform::OnClosed();
}
void DesktopWindowTreeHostLinux::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) {
open_windows().push_front(widget);
DesktopWindowTreeHostPlatform::OnAcceleratedWidgetAvailable(widget);
}
void DesktopWindowTreeHostLinux::OnActivationChanged(bool active) {
if (active) {
auto widget = GetAcceleratedWidget();
open_windows().remove(widget);
open_windows().insert(open_windows().begin(), widget);
}
DesktopWindowTreeHostPlatform::OnActivationChanged(active);
}
void DesktopWindowTreeHostLinux::AddAdditionalInitProperties(
const Widget::InitParams& params,
ui::PlatformWindowInitProperties* properties) {
......@@ -318,6 +386,12 @@ ui::PlatformWindowLinux* DesktopWindowTreeHostLinux::GetPlatformWindowLinux() {
return static_cast<ui::PlatformWindowLinux*>(platform_window());
}
std::list<gfx::AcceleratedWidget>& DesktopWindowTreeHostLinux::open_windows() {
if (!open_windows_)
open_windows_ = new std::list<gfx::AcceleratedWidget>();
return *open_windows_;
}
// As DWTHX11 subclasses DWTHPlatform through DWTHLinux now (during transition
// period. see https://crbug.com/990756), we need to guard this factory method.
// TODO(msisov): remove this guard once DWTHX11 is finally merged into
......
......@@ -35,6 +35,23 @@ class VIEWS_EXPORT DesktopWindowTreeHostLinux
DesktopNativeWidgetAura* desktop_native_widget_aura);
~DesktopWindowTreeHostLinux() override;
// A way of converting a |widget| into the content_window()
// of the associated DesktopNativeWidgetAura.
static aura::Window* GetContentWindowForWidget(gfx::AcceleratedWidget widget);
// A way of converting a |widget| into this object.
static DesktopWindowTreeHostLinux* GetHostForWidget(
gfx::AcceleratedWidget widget);
// Get all open top-level windows. This includes windows that may not be
// visible. This list is sorted in their stacking order, i.e. the first window
// is the topmost window.
static std::vector<aura::Window*> GetAllOpenWindows();
// Runs the |func| callback for each content-window, and deallocates the
// internal list of open windows.
static void CleanUpWindowList(void (*func)(aura::Window* window));
// This must be called before the window is created, because the visual cannot
// be changed after. Useful for X11. Not in use for Wayland.
void SetPendingXVisualId(int x_visual_id);
......@@ -64,6 +81,8 @@ class VIEWS_EXPORT DesktopWindowTreeHostLinux
// PlatformWindowDelegateBase:
void DispatchEvent(ui::Event* event) override;
void OnClosed() override;
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
void OnActivationChanged(bool active) override;
private:
FRIEND_TEST_ALL_PREFIXES(DesktopWindowTreeHostLinuxTest, HitTest);
......@@ -94,6 +113,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostLinux
const ui::PlatformWindowLinux* GetPlatformWindowLinux() const;
ui::PlatformWindowLinux* GetPlatformWindowLinux();
// See comment for variable open_windows_.
static std::list<gfx::AcceleratedWidget>& open_windows();
// A handler for events intended for non client area.
// A posthandler for events intended for non client area. Handles events if no
// other consumer handled them.
......@@ -110,6 +132,10 @@ class VIEWS_EXPORT DesktopWindowTreeHostLinux
uint32_t modal_dialog_counter_ = 0;
// A list of all (top-level) windows that have been created but not yet
// destroyed.
static std::list<gfx::AcceleratedWidget>* open_windows_;
// The display and the native X window hosting the root window.
base::WeakPtrFactory<DesktopWindowTreeHostLinux> weak_factory_{this};
......
......@@ -66,18 +66,8 @@
#include "ui/accessibility/platform/atk_util_auralinux.h"
#endif
DEFINE_UI_CLASS_PROPERTY_TYPE(views::DesktopWindowTreeHostX11*)
namespace views {
std::list<XID>* DesktopWindowTreeHostX11::open_windows_ = nullptr;
DEFINE_UI_CLASS_PROPERTY_KEY(aura::Window*, kViewsWindowForRootWindow, NULL)
DEFINE_UI_CLASS_PROPERTY_KEY(DesktopWindowTreeHostX11*,
kHostForRootWindow,
NULL)
namespace {
bool ShouldDiscardKeyEvent(XEvent* xev) {
......@@ -100,35 +90,12 @@ DesktopWindowTreeHostX11::DesktopWindowTreeHostX11(
desktop_native_widget_aura) {}
DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() {
window()->ClearProperty(kHostForRootWindow);
wm::SetWindowMoveClient(window(), nullptr);
// ~DWTHPlatform notifies the DestkopNativeWidgetAura about destruction and
// also destroyes the dispatcher.
}
// static
aura::Window* DesktopWindowTreeHostX11::GetContentWindowForXID(XID xid) {
aura::WindowTreeHost* host =
aura::WindowTreeHost::GetForAcceleratedWidget(xid);
return host ? host->window()->GetProperty(kViewsWindowForRootWindow) : NULL;
}
// static
DesktopWindowTreeHostX11* DesktopWindowTreeHostX11::GetHostForXID(XID xid) {
aura::WindowTreeHost* host =
aura::WindowTreeHost::GetForAcceleratedWidget(xid);
return host ? host->window()->GetProperty(kHostForRootWindow) : nullptr;
}
// static
std::vector<aura::Window*> DesktopWindowTreeHostX11::GetAllOpenWindows() {
std::vector<aura::Window*> windows(open_windows().size());
std::transform(open_windows().begin(), open_windows().end(), windows.begin(),
GetContentWindowForXID);
return windows;
}
void DesktopWindowTreeHostX11::AddObserver(
DesktopWindowTreeHostObserverX11* observer) {
observer_list_.AddObserver(observer);
......@@ -139,21 +106,6 @@ void DesktopWindowTreeHostX11::RemoveObserver(
observer_list_.RemoveObserver(observer);
}
void DesktopWindowTreeHostX11::CleanUpWindowList(
void (*func)(aura::Window* window)) {
if (!open_windows_)
return;
while (!open_windows_->empty()) {
gfx::AcceleratedWidget widget = open_windows_->front();
func(GetContentWindowForXID(widget));
if (!open_windows_->empty() && open_windows_->front() == widget)
open_windows_->erase(open_windows_->begin());
}
delete open_windows_;
open_windows_ = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation:
......@@ -171,9 +123,6 @@ void DesktopWindowTreeHostX11::Init(const Widget::InitParams& params) {
void DesktopWindowTreeHostX11::OnNativeWidgetCreated(
const Widget::InitParams& params) {
window()->SetProperty(kViewsWindowForRootWindow, GetContentWindow());
window()->SetProperty(kHostForRootWindow, this);
// Ensure that the X11DesktopHandler exists so that it tracks create/destroy
// notify events.
X11DesktopHandler::get();
......@@ -213,42 +162,9 @@ void DesktopWindowTreeHostX11::EndMoveLoop() {
x11_window_move_client_->EndMoveLoop();
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, private:
std::list<gfx::AcceleratedWidget>& DesktopWindowTreeHostX11::open_windows() {
if (!open_windows_)
open_windows_ = new std::list<gfx::AcceleratedWidget>();
return *open_windows_;
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11 implementation:
void DesktopWindowTreeHostX11::OnClosed() {
open_windows().remove(GetAcceleratedWidget());
DesktopWindowTreeHostLinux::OnClosed();
}
void DesktopWindowTreeHostX11::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) {
open_windows().push_front(widget);
WindowTreeHostPlatform::OnAcceleratedWidgetAvailable(widget);
}
void DesktopWindowTreeHostX11::OnAcceleratedWidgetDestroyed() {}
void DesktopWindowTreeHostX11::OnActivationChanged(bool active) {
if (active) {
// TODO(thomasanderson): Remove this window shuffling and use XWindowCache
// instead.
auto widget = GetAcceleratedWidget();
open_windows().remove(widget);
open_windows().insert(open_windows().begin(), widget);
}
DesktopWindowTreeHostPlatform::OnActivationChanged(active);
}
void DesktopWindowTreeHostX11::OnXWindowMapped() {
for (DesktopWindowTreeHostObserverX11& observer : observer_list_)
observer.OnWindowMapped(GetXWindow()->window());
......
......@@ -44,25 +44,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
DesktopNativeWidgetAura* desktop_native_widget_aura);
~DesktopWindowTreeHostX11() override;
// A way of converting an X11 |xid| host window into the content_window()
// of the associated DesktopNativeWidgetAura.
static aura::Window* GetContentWindowForXID(XID xid);
// A way of converting an X11 |xid| host window into this object.
static DesktopWindowTreeHostX11* GetHostForXID(XID xid);
// Get all open top-level windows. This includes windows that may not be
// visible. This list is sorted in their stacking order, i.e. the first window
// is the topmost window.
static std::vector<aura::Window*> GetAllOpenWindows();
void AddObserver(DesktopWindowTreeHostObserverX11* observer);
void RemoveObserver(DesktopWindowTreeHostObserverX11* observer);
// Runs the |func| callback for each content-window, and deallocates the
// internal list of open windows.
static void CleanUpWindowList(void (*func)(aura::Window* window));
protected:
// Overridden from DesktopWindowTreeHost:
void Init(const Widget::InitParams& params) override;
......@@ -78,18 +62,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
private:
friend class DesktopWindowTreeHostX11HighDPITest;
// See comment for variable open_windows_.
static std::list<XID>& open_windows();
// PlatformWindowDelegate overrides:
//
// DWTHX11 temporarily overrides the PlatformWindowDelegate methods instead of
// underlying DWTHPlatform and WTHPlatform. Eventually, these will be removed
// from here as we progress in https://crbug.com/990756.
void OnClosed() override;
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
void OnAcceleratedWidgetDestroyed() override;
void OnActivationChanged(bool active) override;
void OnXWindowMapped() override;
void OnXWindowUnmapped() override;
......@@ -111,10 +88,6 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
base::ObserverList<DesktopWindowTreeHostObserverX11>::Unchecked
observer_list_;
// A list of all (top-level) windows that have been created but not yet
// destroyed.
static std::list<gfx::AcceleratedWidget>* open_windows_;
// The display and the native X window hosting the root window.
base::WeakPtrFactory<DesktopWindowTreeHostX11> weak_factory_{this};
......
......@@ -454,7 +454,7 @@ TEST_F(DesktopWindowTreeHostX11Test, ChildWindowDestructionDuringTearDown) {
ASSERT_NE(parent_widget.GetNativeWindow()->GetHost()->GetAcceleratedWidget(),
child_widget.GetNativeWindow()->GetHost()->GetAcceleratedWidget());
Widget::CloseAllSecondaryWidgets();
EXPECT_TRUE(DesktopWindowTreeHostX11::GetAllOpenWindows().empty());
EXPECT_TRUE(DesktopWindowTreeHostLinux::GetAllOpenWindows().empty());
}
// A Widget that allows setting the min/max size for the widget.
......
......@@ -23,7 +23,7 @@ aura::Window* X11TopmostWindowFinder::FindLocalProcessWindowAt(
ignore_ = ignore;
std::vector<aura::Window*> local_process_windows =
DesktopWindowTreeHostX11::GetAllOpenWindows();
DesktopWindowTreeHostLinux::GetAllOpenWindows();
if (std::none_of(local_process_windows.cbegin(), local_process_windows.cend(),
[this](auto* window) {
return ShouldStopIteratingAtLocalProcessWindow(window);
......@@ -31,7 +31,8 @@ aura::Window* X11TopmostWindowFinder::FindLocalProcessWindowAt(
return nullptr;
ui::EnumerateTopLevelWindows(this);
return DesktopWindowTreeHostX11::GetContentWindowForXID(toplevel_);
return DesktopWindowTreeHostLinux::GetContentWindowForWidget(
static_cast<gfx::AcceleratedWidget>(toplevel_));
}
XID X11TopmostWindowFinder::FindWindowAt(
......@@ -45,8 +46,8 @@ bool X11TopmostWindowFinder::ShouldStopIterating(XID xid) {
if (!ui::IsWindowVisible(xid))
return false;
aura::Window* window =
views::DesktopWindowTreeHostX11::GetContentWindowForXID(xid);
auto* window = DesktopWindowTreeHostLinux::GetContentWindowForWidget(
static_cast<gfx::AcceleratedWidget>(xid));
if (window) {
if (ShouldStopIteratingAtLocalProcessWindow(window)) {
toplevel_ = xid;
......@@ -72,9 +73,11 @@ bool X11TopmostWindowFinder::ShouldStopIteratingAtLocalProcessWindow(
if (!window->IsVisible())
return false;
DesktopWindowTreeHostX11* host = DesktopWindowTreeHostX11::GetHostForXID(
auto* host = DesktopWindowTreeHostLinux::GetHostForWidget(
window->GetHost()->GetAcceleratedWidget());
if (!host->GetXRootWindowOuterBounds().Contains(screen_loc_in_pixels_))
if (!static_cast<DesktopWindowTreeHostX11*>(host)
->GetXRootWindowOuterBounds()
.Contains(screen_loc_in_pixels_))
return false;
aura::client::ScreenPositionClient* screen_position_client =
......
......@@ -59,7 +59,7 @@
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
#endif
#if defined(USE_X11)
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#endif
......@@ -1065,7 +1065,7 @@ void NativeWidgetAura::SetInitialFocus(ui::WindowShowState show_state) {
// Widget, public:
namespace {
#if defined(OS_WIN) || defined(USE_X11)
#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
void CloseWindow(aura::Window* window) {
if (window) {
Widget* widget = Widget::GetWidgetForNativeView(window);
......@@ -1095,13 +1095,13 @@ void Widget::CloseAllSecondaryWidgets() {
EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0);
#endif
#if defined(USE_X11)
DesktopWindowTreeHostX11::CleanUpWindowList(CloseWindow);
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
DesktopWindowTreeHostLinux::CleanUpWindowList(CloseWindow);
#endif
}
const ui::NativeTheme* Widget::GetNativeTheme() const {
#if defined(USE_X11)
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
const LinuxUI* linux_ui = LinuxUI::instance();
if (linux_ui) {
ui::NativeTheme* native_theme =
......
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