Commit e3863570 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

x11: Remove x11-specific WindowEventFilter implementation

This cleanup CL removes views::X11WindowEventFilter class in favor of generic
views::WindowEventFilter by modifying DesktopWindowTreeHostX11 to implement
WmMoveResizeHandler interface. As part of Aura/X11 => Ozone/X11 migration, this
makes non-client event handling in DWTHX11 more like DWTHPlatform as well as
removes one more unneeded usage of Event::native_event() which contributes to
X11 PlatformEvent migration sub-task.

Bug: 965991
Test: Covered by tests (no behavioral change).
Change-Id: Ie4a6457a2c4b68a09cb3b5622c65b736d2d490eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1772537Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#691298}
parent d7962142
...@@ -719,7 +719,6 @@ jumbo_component("views") { ...@@ -719,7 +719,6 @@ jumbo_component("views") {
"widget/desktop_aura/x11_move_loop_delegate.h", "widget/desktop_aura/x11_move_loop_delegate.h",
"widget/desktop_aura/x11_topmost_window_finder.h", "widget/desktop_aura/x11_topmost_window_finder.h",
"widget/desktop_aura/x11_whole_screen_move_loop.h", "widget/desktop_aura/x11_whole_screen_move_loop.h",
"widget/desktop_aura/x11_window_event_filter.h",
] ]
sources += [ sources += [
"widget/desktop_aura/desktop_drag_drop_client_aurax11.cc", "widget/desktop_aura/desktop_drag_drop_client_aurax11.cc",
...@@ -729,7 +728,6 @@ jumbo_component("views") { ...@@ -729,7 +728,6 @@ jumbo_component("views") {
"widget/desktop_aura/x11_desktop_window_move_client.cc", "widget/desktop_aura/x11_desktop_window_move_client.cc",
"widget/desktop_aura/x11_topmost_window_finder.cc", "widget/desktop_aura/x11_topmost_window_finder.cc",
"widget/desktop_aura/x11_whole_screen_move_loop.cc", "widget/desktop_aura/x11_whole_screen_move_loop.cc",
"widget/desktop_aura/x11_window_event_filter.cc",
] ]
if (use_atk) { if (use_atk) {
sources += [ sources += [
......
...@@ -62,9 +62,9 @@ ...@@ -62,9 +62,9 @@
#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_observer_x11.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host_observer_x11.h"
#include "ui/views/widget/desktop_aura/window_event_filter.h"
#include "ui/views/widget/desktop_aura/x11_desktop_handler.h" #include "ui/views/widget/desktop_aura/x11_desktop_handler.h"
#include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h" #include "ui/views/widget/desktop_aura/x11_desktop_window_move_client.h"
#include "ui/views/widget/desktop_aura/x11_window_event_filter.h"
#include "ui/views/window/native_frame_view.h" #include "ui/views/window/native_frame_view.h"
#include "ui/wm/core/compound_event_filter.h" #include "ui/wm/core/compound_event_filter.h"
#include "ui/wm/core/window_util.h" #include "ui/wm/core/window_util.h"
...@@ -267,14 +267,19 @@ void DesktopWindowTreeHostX11::RemoveObserver( ...@@ -267,14 +267,19 @@ void DesktopWindowTreeHostX11::RemoveObserver(
observer_list_.RemoveObserver(observer); observer_list_.RemoveObserver(observer);
} }
void DesktopWindowTreeHostX11::SwapNonClientEventHandler( void DesktopWindowTreeHostX11::AddNonClientEventFilter() {
std::unique_ptr<ui::EventHandler> handler) { if (non_client_event_filter_)
wm::CompoundEventFilter* compound_event_filter = return;
desktop_native_widget_aura_->root_window_event_filter(); non_client_event_filter_ = std::make_unique<WindowEventFilter>(this);
if (x11_non_client_event_filter_) non_client_event_filter_->SetWmMoveResizeHandler(this);
compound_event_filter->RemoveHandler(x11_non_client_event_filter_.get()); window()->AddPreTargetHandler(non_client_event_filter_.get());
compound_event_filter->AddHandler(handler.get()); }
x11_non_client_event_filter_ = std::move(handler);
void DesktopWindowTreeHostX11::RemoveNonClientEventFilter() {
if (!non_client_event_filter_)
return;
window()->RemovePreTargetHandler(non_client_event_filter_.get());
non_client_event_filter_.reset();
} }
void DesktopWindowTreeHostX11::CleanUpWindowList( void DesktopWindowTreeHostX11::CleanUpWindowList(
...@@ -313,9 +318,7 @@ void DesktopWindowTreeHostX11::OnNativeWidgetCreated( ...@@ -313,9 +318,7 @@ void DesktopWindowTreeHostX11::OnNativeWidgetCreated(
// notify events. // notify events.
X11DesktopHandler::get(); X11DesktopHandler::get();
// TODO(erg): Unify this code once the other consumer goes away. AddNonClientEventFilter();
SwapNonClientEventHandler(
std::unique_ptr<ui::EventHandler>(new X11WindowEventFilter(this)));
SetUseNativeFrame(params.type == Widget::InitParams::TYPE_WINDOW && SetUseNativeFrame(params.type == Widget::InitParams::TYPE_WINDOW &&
!params.remove_standard_frame); !params.remove_standard_frame);
...@@ -366,6 +369,7 @@ void DesktopWindowTreeHostX11::CloseNow() { ...@@ -366,6 +369,7 @@ void DesktopWindowTreeHostX11::CloseNow() {
return; return;
ReleaseCapture(); ReleaseCapture();
RemoveNonClientEventFilter();
native_widget_delegate_->OnNativeWidgetDestroying(); native_widget_delegate_->OnNativeWidgetDestroying();
// If we have children, close them. Use a copy for iteration because they'll // If we have children, close them. Use a copy for iteration because they'll
...@@ -381,12 +385,6 @@ void DesktopWindowTreeHostX11::CloseNow() { ...@@ -381,12 +385,6 @@ void DesktopWindowTreeHostX11::CloseNow() {
window_parent_ = nullptr; window_parent_ = nullptr;
} }
// Remove the event listeners we've installed. We need to remove these
// because otherwise we get assert during ~WindowEventDispatcher().
desktop_native_widget_aura_->root_window_event_filter()->RemoveHandler(
x11_non_client_event_filter_.get());
x11_non_client_event_filter_.reset();
// Destroy the compositor before destroying the |xwindow_| since shutdown // Destroy the compositor before destroying the |xwindow_| since shutdown
// may try to swap, and the swap without a window causes an X error, which // may try to swap, and the swap without a window causes an X error, which
// causes a crash with in-process renderer. // causes a crash with in-process renderer.
...@@ -1298,6 +1296,12 @@ void DesktopWindowTreeHostX11::InitX11Window(const Widget::InitParams& params) { ...@@ -1298,6 +1296,12 @@ void DesktopWindowTreeHostX11::InitX11Window(const Widget::InitParams& params) {
OnAcceleratedWidgetAvailable(); OnAcceleratedWidgetAvailable();
} }
void DesktopWindowTreeHostX11::DispatchHostWindowDragMovement(
int hittest,
const gfx::Point& pointer_location) {
x11_window_->WmMoveResize(hittest, pointer_location);
}
gfx::Size DesktopWindowTreeHostX11::AdjustSize( gfx::Size DesktopWindowTreeHostX11::AdjustSize(
const gfx::Size& requested_size_in_pixels) { const gfx::Size& requested_size_in_pixels) {
std::vector<display::Display> displays = std::vector<display::Display> displays =
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#include "ui/platform_window/platform_window_handler/wm_move_resize_handler.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
...@@ -34,7 +35,6 @@ class ImageSkia; ...@@ -34,7 +35,6 @@ class ImageSkia;
namespace ui { namespace ui {
enum class DomCode; enum class DomCode;
class EventHandler;
class KeyboardHook; class KeyboardHook;
class KeyEvent; class KeyEvent;
class MouseEvent; class MouseEvent;
...@@ -47,11 +47,13 @@ class DesktopDragDropClientAuraX11; ...@@ -47,11 +47,13 @@ class DesktopDragDropClientAuraX11;
class DesktopWindowTreeHostObserverX11; class DesktopWindowTreeHostObserverX11;
class NonClientFrameView; class NonClientFrameView;
class X11DesktopWindowMoveClient; class X11DesktopWindowMoveClient;
class WindowEventFilter;
class VIEWS_EXPORT DesktopWindowTreeHostX11 class VIEWS_EXPORT DesktopWindowTreeHostX11
: public DesktopWindowTreeHost, : public DesktopWindowTreeHost,
public aura::WindowTreeHost, public aura::WindowTreeHost,
public ui::PlatformEventDispatcher, public ui::PlatformEventDispatcher,
public ui::WmMoveResizeHandler,
public ui::XWindow::Delegate { public ui::XWindow::Delegate {
public: public:
DesktopWindowTreeHostX11( DesktopWindowTreeHostX11(
...@@ -85,8 +87,8 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -85,8 +87,8 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
void AddObserver(DesktopWindowTreeHostObserverX11* observer); void AddObserver(DesktopWindowTreeHostObserverX11* observer);
void RemoveObserver(DesktopWindowTreeHostObserverX11* observer); void RemoveObserver(DesktopWindowTreeHostObserverX11* observer);
// Swaps the current handler for events in the non client view with |handler|. void AddNonClientEventFilter();
void SwapNonClientEventHandler(std::unique_ptr<ui::EventHandler> handler); void RemoveNonClientEventFilter();
// Runs the |func| callback for each content-window, and deallocates the // Runs the |func| callback for each content-window, and deallocates the
// internal list of open windows. // internal list of open windows.
...@@ -224,6 +226,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -224,6 +226,11 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
// initialization related to talking to the X11 server. // initialization related to talking to the X11 server.
void InitX11Window(const Widget::InitParams& params); void InitX11Window(const Widget::InitParams& params);
// Overridden from WmMoveResizeHandler
void DispatchHostWindowDragMovement(
int hittest,
const gfx::Point& pointer_location) override;
// Creates an aura::WindowEventDispatcher to contain the content_window() // Creates an aura::WindowEventDispatcher to contain the content_window()
// along with all aura client objects that direct behavior. // along with all aura client objects that direct behavior.
aura::WindowEventDispatcher* InitDispatcher(const Widget::InitParams& params); aura::WindowEventDispatcher* InitDispatcher(const Widget::InitParams& params);
...@@ -296,7 +303,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -296,7 +303,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
DesktopDragDropClientAuraX11* drag_drop_client_ = nullptr; DesktopDragDropClientAuraX11* drag_drop_client_ = nullptr;
std::unique_ptr<ui::EventHandler> x11_non_client_event_filter_; std::unique_ptr<WindowEventFilter> non_client_event_filter_;
std::unique_ptr<X11DesktopWindowMoveClient> x11_window_move_client_; std::unique_ptr<X11DesktopWindowMoveClient> x11_window_move_client_;
// TODO(beng): Consider providing an interface to DesktopNativeWidgetAura // TODO(beng): Consider providing an interface to DesktopNativeWidgetAura
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/widget/desktop_aura/x11_window_event_filter.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test_x11.h"
#include "ui/base/x/x11_util.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
#include "ui/views/widget/native_widget_aura.h"
#include "ui/views/widget/widget.h"
namespace views {
X11WindowEventFilter::X11WindowEventFilter(
DesktopWindowTreeHost* window_tree_host)
: WindowEventFilter(window_tree_host),
xdisplay_(gfx::GetXDisplay()),
xwindow_(window_tree_host->AsWindowTreeHost()->GetAcceleratedWidget()),
x_root_window_(DefaultRootWindow(xdisplay_)) {}
X11WindowEventFilter::~X11WindowEventFilter() = default;
void X11WindowEventFilter::MaybeDispatchHostWindowDragMovement(
int hittest,
ui::MouseEvent* event) {
if (event->IsLeftMouseButton() && event->native_event()) {
// Get the |x_root_window_| location out of the native event.
const gfx::Point x_root_location =
ui::EventSystemLocationFromNative(event->native_event());
if (DispatchHostWindowDragMovement(hittest, x_root_location))
event->StopPropagation();
}
}
void X11WindowEventFilter::LowerWindow() {
XLowerWindow(xdisplay_, xwindow_);
}
bool X11WindowEventFilter::DispatchHostWindowDragMovement(
int hittest,
const gfx::Point& screen_location) {
int direction = ui::HitTestToWmMoveResizeDirection(hittest);
if (direction == -1)
return false;
ui::DoWMMoveResize(xdisplay_, x_root_window_, xwindow_, screen_location,
direction);
return true;
}
} // namespace views
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WINDOW_EVENT_FILTER_H_
#define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WINDOW_EVENT_FILTER_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/desktop_aura/window_event_filter.h"
namespace gfx {
class Point;
}
namespace views {
class DesktopWindowTreeHost;
// An EventFilter that sets properties on X11 windows.
class VIEWS_EXPORT X11WindowEventFilter : public WindowEventFilter {
public:
explicit X11WindowEventFilter(DesktopWindowTreeHost* window_tree_host);
~X11WindowEventFilter() override;
private:
// WindowEventFilter override:
void MaybeDispatchHostWindowDragMovement(int hittest,
ui::MouseEvent* event) override;
void LowerWindow() override;
bool DispatchHostWindowDragMovement(int hittest,
const gfx::Point& screen_location);
// The display and the native X window hosting the root window.
XDisplay* xdisplay_;
::Window xwindow_;
// The native root window.
::Window x_root_window_;
DISALLOW_COPY_AND_ASSIGN(X11WindowEventFilter);
};
} // namespace views
#endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WINDOW_EVENT_FILTER_H_
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