Commit 6cb8f1ee authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone/x11] Moved the DnD handling from X11WindowOzone to X11Window.

This CL is the first step that prepares us to get rid of DWTHX11.

As we proceed with that, at some point we will have to throw off the
DesktopDragDropClientAuraX11 because it is used by DWTHX11, and migrate
DnD to DDDCOzone.  As the latter will be used on both Ozone and
non-Ozone, it needs the X11window to handle DnD.

Hence this change.  I move the DnD-related code from X11WindowOzone into
X11Window.

Change-Id: I682c794d9cfab4b7ad6b6a9b89331526f31d227a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213578Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Cr-Commit-Position: refs/heads/master@{#774026}
parent 8443f2e7
......@@ -481,7 +481,7 @@ jumbo_component("base") {
deps += [ "//ui/events" ]
}
if (is_desktop_linux && (use_x11 || ozone_platform_x11)) {
if ((is_desktop_linux || is_chromeos) && (use_x11 || ozone_platform_x11)) {
public_deps += [ "//ui/base/x" ]
# X11 drag and drop wants to use common drag and drop types.
......
......@@ -46,7 +46,7 @@ jumbo_component("x") {
"x11_workspace_handler.h",
]
if (is_desktop_linux) {
if (is_desktop_linux || is_chromeos) {
sources += [
"selection_owner.cc",
"selection_owner.h",
......
......@@ -672,7 +672,7 @@ void XDragDropClient::SendXdndDrop(XID dest_window) {
void XDragDropClient::EndMoveLoop() {
StopEndMoveLoopTimer();
delegate_->EndMoveLoop();
delegate_->EndDragLoop();
}
} // namespace ui
......@@ -60,8 +60,8 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient {
// Drops data at the current location and returns the resulting operation.
virtual int PerformDrop() = 0;
// Called to end the move loop that is maintained by the subclass.
virtual void EndMoveLoop() = 0;
// Called to end the drag loop that is maintained by the subclass.
virtual void EndDragLoop() = 0;
protected:
virtual ~Delegate() = default;
......
......@@ -4,19 +4,8 @@
#include "ui/ozone/platform/x11/x11_window_ozone.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/x/x11_os_exchange_data_provider.h"
#include "ui/base/x/x11_pointer_grab.h"
#include "ui/base/x/x11_topmost_window_finder.h"
#include "ui/events/event.h"
#include "ui/events/platform/scoped_event_dispatcher.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/events/x/x11_window_event_manager.h"
#include "ui/ozone/platform/x11/x11_cursor_ozone.h"
#include "ui/platform_window/platform_window_delegate.h"
#include "ui/platform_window/platform_window_handler/wm_drop_handler.h"
#include "ui/platform_window/x11/x11_topmost_window_finder.h"
#include "ui/platform_window/x11/x11_window_manager.h"
namespace ui {
......@@ -30,129 +19,4 @@ void X11WindowOzone::SetCursor(PlatformCursor cursor) {
XWindow::SetCursor(cursor_ozone->xcursor());
}
void X11WindowOzone::Initialize(PlatformWindowInitProperties properties) {
X11Window::Initialize(std::move(properties));
// Set a class property key that allows |this| to be used for drag action.
SetWmDragHandler(this, this);
drag_drop_client_ =
std::make_unique<XDragDropClient>(this, display(), window());
}
void X11WindowOzone::StartDrag(const ui::OSExchangeData& data,
int operation,
gfx::NativeCursor cursor,
base::OnceCallback<void(int)> callback) {
DCHECK(drag_drop_client_);
end_drag_callback_ = std::move(callback);
drag_drop_client_->InitDrag(operation, &data);
SetCapture();
dragging_ = true;
}
std::unique_ptr<ui::XTopmostWindowFinder> X11WindowOzone::CreateWindowFinder() {
return std::make_unique<X11TopmostWindowFinder>();
}
int X11WindowOzone::UpdateDrag(const gfx::Point& screen_point) {
WmDropHandler* drop_handler = GetWmDropHandler(*this);
if (!drop_handler)
return ui::DragDropTypes::DRAG_NONE;
// TODO: calculate the appropriate drag operation here.
return drop_handler->OnDragMotion(gfx::PointF(screen_point),
ui::DragDropTypes::DRAG_COPY);
}
void X11WindowOzone::UpdateCursor(
ui::DragDropTypes::DragOperation negotiated_operation) {
NOTIMPLEMENTED_LOG_ONCE();
}
void X11WindowOzone::OnBeginForeignDrag(XID window) {
NOTIMPLEMENTED_LOG_ONCE();
}
void X11WindowOzone::OnEndForeignDrag() {
NOTIMPLEMENTED_LOG_ONCE();
}
void X11WindowOzone::OnBeforeDragLeave() {
NOTIMPLEMENTED_LOG_ONCE();
}
int X11WindowOzone::PerformDrop() {
WmDropHandler* drop_handler = GetWmDropHandler(*this);
if (!drop_handler)
return ui::DragDropTypes::DRAG_NONE;
DCHECK(drag_drop_client_);
auto* target_current_context = drag_drop_client_->target_current_context();
DCHECK(target_current_context);
int drag_operation = ui::DragDropTypes::DRAG_NONE;
drop_handler->OnDragDrop(std::make_unique<ui::OSExchangeData>(
std::make_unique<ui::XOSExchangeDataProvider>(
drag_drop_client_->xwindow(),
target_current_context->fetched_targets())));
return drag_operation;
}
void X11WindowOzone::EndMoveLoop() {
std::move(end_drag_callback_).Run(0);
}
bool X11WindowOzone::DispatchDraggingUiEvent(ui::Event* event) {
// Drag and drop have a priority over other processing.
if (dragging_) {
DCHECK(drag_drop_client_);
switch (event->type()) {
case ui::ET_MOUSE_MOVED:
case ui::ET_MOUSE_DRAGGED: {
drag_drop_client_->HandleMouseMovement(
event->AsLocatedEvent()->root_location(),
event->AsMouseEvent()->flags(),
event->AsMouseEvent()->time_stamp());
return true;
}
case ui::ET_MOUSE_RELEASED:
if (!event->AsMouseEvent()->IsLeftMouseButton())
break;
// Assume that drags are being done with the left mouse button. Only
// break the drag if the left mouse button was released.
drag_drop_client_->HandleMouseReleased();
dragging_ = false;
ReleaseCapture();
return true;
case ui::ET_KEY_PRESSED:
if (event->AsKeyEvent()->key_code() != ui::VKEY_ESCAPE)
break;
EndMoveLoop();
drag_drop_client_->HandleMoveLoopEnded();
dragging_ = false;
ReleaseCapture();
return true;
default:
break;
}
}
return false;
}
void X11WindowOzone::OnXWindowSelectionEvent(XEvent* xev) {
X11Window::OnXWindowSelectionEvent(xev);
DCHECK(drag_drop_client_);
drag_drop_client_->OnSelectionNotify(xev->xselection);
}
void X11WindowOzone::OnXWindowDragDropEvent(XEvent* xev) {
X11Window::OnXWindowDragDropEvent(xev);
DCHECK(drag_drop_client_);
drag_drop_client_->HandleXdndEvent(xev->xclient);
}
} // namespace ui
......@@ -5,8 +5,6 @@
#ifndef UI_OZONE_PLATFORM_X11_X11_WINDOW_OZONE_H_
#define UI_OZONE_PLATFORM_X11_X11_WINDOW_OZONE_H_
#include "ui/base/x/x11_drag_drop_client.h"
#include "ui/platform_window/platform_window_handler/wm_drag_handler.h"
#include "ui/platform_window/x11/x11_window.h"
namespace ui {
......@@ -15,9 +13,7 @@ class PlatformWindowDelegate;
// PlatformWindow implementation for non-ChromeOS X11 Ozone.
// PlatformEvents are ui::Events.
class X11WindowOzone : public X11Window,
public WmDragHandler,
public XDragDropClient::Delegate {
class X11WindowOzone : public X11Window {
public:
explicit X11WindowOzone(PlatformWindowDelegate* delegate);
~X11WindowOzone() override;
......@@ -27,38 +23,6 @@ class X11WindowOzone : public X11Window,
// Overridden from PlatformWindow:
void SetCursor(PlatformCursor cursor) override;
// Overridden from X11Window:
void Initialize(PlatformWindowInitProperties properties) override;
private:
// WmDragHandler
void StartDrag(const ui::OSExchangeData& data,
int operation,
gfx::NativeCursor cursor,
base::OnceCallback<void(int)> callback) override;
// ui::XDragDropClient::Delegate
std::unique_ptr<ui::XTopmostWindowFinder> CreateWindowFinder() override;
int UpdateDrag(const gfx::Point& screen_point) override;
void UpdateCursor(
ui::DragDropTypes::DragOperation negotiated_operation) override;
void OnBeginForeignDrag(XID window) override;
void OnEndForeignDrag() override;
void OnBeforeDragLeave() override;
int PerformDrop() override;
void EndMoveLoop() override;
// X11Window:
bool DispatchDraggingUiEvent(ui::Event* event) override;
void OnXWindowSelectionEvent(XEvent* xev) override;
void OnXWindowDragDropEvent(XEvent* xev) override;
// True while the drag initiated in this window is in progress.
bool dragging_ = false;
std::unique_ptr<XDragDropClient> drag_drop_client_;
base::OnceCallback<void(int)> end_drag_callback_;
};
} // namespace ui
......
......@@ -7,7 +7,10 @@
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_event.h"
#include "ui/base/buildflags.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/x/x11_desktop_window_move_client.h"
#include "ui/base/x/x11_pointer_grab.h"
#include "ui/base/x/x11_topmost_window_finder.h"
#include "ui/base/x/x11_util.h"
#include "ui/base/x/x11_util_internal.h"
#include "ui/display/screen.h"
......@@ -21,10 +24,15 @@
#include "ui/platform_window/common/platform_window_defaults.h"
#include "ui/platform_window/extensions/workspace_extension_delegate.h"
#include "ui/platform_window/extensions/x11_extension_delegate.h"
#include "ui/platform_window/platform_window_handler/wm_drop_handler.h"
#include "ui/platform_window/x11/x11_topmost_window_finder.h"
#include "ui/platform_window/x11/x11_window_manager.h"
#if defined(USE_OZONE)
#include "ui/base/x/x11_os_exchange_data_provider.h"
#include "ui/events/ozone/events_ozone.h"
#else
#include "ui/base/dragdrop/os_exchange_data_provider_x11.h"
#endif // defined(USE_OZONE)
#if BUILDFLAG(USE_ATK)
......@@ -135,6 +143,11 @@ void X11Window::Initialize(PlatformWindowInitProperties properties) {
x11_extension_delegate_ = properties.x11_extension_delegate;
Init(config);
SetWmDragHandler(this, this);
drag_drop_client_ =
std::make_unique<XDragDropClient>(this, display(), window());
}
void X11Window::SetXEventDelegate(XEventDelegate* delegate) {
......@@ -641,10 +654,6 @@ void X11Window::OnXWindowCreated() {
platform_window_delegate_->OnAcceleratedWidgetAvailable(GetWidget());
}
bool X11Window::DispatchDraggingUiEvent(ui::Event* event) {
return false;
}
void X11Window::OnXWindowStateChanged() {
// Determine the new window state information to be propagated to the client.
// Note that the order of checks is important here, because window can have
......@@ -732,11 +741,15 @@ void X11Window::OnXWindowLostPointerGrab() {
void X11Window::OnXWindowSelectionEvent(XEvent* xev) {
if (x_event_delegate_)
x_event_delegate_->OnXWindowSelectionEvent(xev);
DCHECK(drag_drop_client_);
drag_drop_client_->OnSelectionNotify(xev->xselection);
}
void X11Window::OnXWindowDragDropEvent(XEvent* xev) {
if (x_event_delegate_)
x_event_delegate_->OnXWindowDragDropEvent(xev);
DCHECK(drag_drop_client_);
drag_drop_client_->HandleXdndEvent(xev->xclient);
}
base::Optional<gfx::Size> X11Window::GetMinimumSizeForXWindow() {
......@@ -767,6 +780,117 @@ void X11Window::EndMoveLoop() {
x11_window_move_client_->EndMoveLoop();
}
void X11Window::StartDrag(const OSExchangeData& data,
int operation,
gfx::NativeCursor cursor,
base::OnceCallback<void(int)> callback) {
DCHECK(drag_drop_client_);
end_drag_callback_ = std::move(callback);
drag_drop_client_->InitDrag(operation, &data);
SetCapture();
dragging_ = true;
}
std::unique_ptr<XTopmostWindowFinder> X11Window::CreateWindowFinder() {
return std::make_unique<X11TopmostWindowFinder>();
}
int X11Window::UpdateDrag(const gfx::Point& screen_point) {
WmDropHandler* drop_handler = GetWmDropHandler(*this);
if (!drop_handler)
return DragDropTypes::DRAG_NONE;
// TODO: calculate the appropriate drag operation here.
return drop_handler->OnDragMotion(gfx::PointF(screen_point),
DragDropTypes::DRAG_COPY);
}
void X11Window::UpdateCursor(
DragDropTypes::DragOperation negotiated_operation) {
NOTIMPLEMENTED_LOG_ONCE();
}
void X11Window::OnBeginForeignDrag(XID window) {
NOTIMPLEMENTED_LOG_ONCE();
}
void X11Window::OnEndForeignDrag() {
NOTIMPLEMENTED_LOG_ONCE();
}
void X11Window::OnBeforeDragLeave() {
NOTIMPLEMENTED_LOG_ONCE();
}
int X11Window::PerformDrop() {
WmDropHandler* drop_handler = GetWmDropHandler(*this);
if (!drop_handler)
return DragDropTypes::DRAG_NONE;
DCHECK(drag_drop_client_);
auto* target_current_context = drag_drop_client_->target_current_context();
DCHECK(target_current_context);
int drag_operation = DragDropTypes::DRAG_NONE;
#if defined(USE_OZONE)
drop_handler->OnDragDrop(std::make_unique<OSExchangeData>(
std::make_unique<XOSExchangeDataProvider>(
drag_drop_client_->xwindow(),
target_current_context->fetched_targets())));
#else
drop_handler->OnDragDrop(std::make_unique<OSExchangeData>(
std::make_unique<OSExchangeDataProviderX11>(
drag_drop_client_->xwindow(),
target_current_context->fetched_targets())));
#endif
return drag_operation;
}
void X11Window::EndDragLoop() {
std::move(end_drag_callback_).Run(0);
}
bool X11Window::DispatchDraggingUiEvent(Event* event) {
// Drag and drop have a priority over other processing.
if (dragging_) {
DCHECK(drag_drop_client_);
switch (event->type()) {
case ET_MOUSE_MOVED:
case ET_MOUSE_DRAGGED: {
drag_drop_client_->HandleMouseMovement(
event->AsLocatedEvent()->root_location(),
event->AsMouseEvent()->flags(),
event->AsMouseEvent()->time_stamp());
return true;
}
case ET_MOUSE_RELEASED:
if (!event->AsMouseEvent()->IsLeftMouseButton())
break;
// Assume that drags are being done with the left mouse button. Only
// break the drag if the left mouse button was released.
drag_drop_client_->HandleMouseReleased();
dragging_ = false;
ReleaseCapture();
return true;
case ET_KEY_PRESSED:
if (event->AsKeyEvent()->key_code() != VKEY_ESCAPE)
break;
EndMoveLoop();
drag_drop_client_->HandleMoveLoopEnded();
dragging_ = false;
ReleaseCapture();
return true;
default:
break;
}
}
return false;
}
gfx::Size X11Window::AdjustSizeForDisplay(
const gfx::Size& requested_size_in_pixels) {
#if defined(OS_CHROMEOS)
......@@ -796,7 +920,7 @@ gfx::Size X11Window::AdjustSizeForDisplay(
void X11Window::ConvertEventLocationToTargetLocation(
const gfx::Rect& target_window_bounds,
const gfx::Rect& current_window_bounds,
ui::LocatedEvent* located_event) {
LocatedEvent* located_event) {
// TODO(msisov): for ozone, we need to access PlatformScreen instead and get
// the displays.
auto* display = display::Screen::GetScreen();
......
......@@ -6,12 +6,14 @@
#define UI_PLATFORM_WINDOW_X11_X11_WINDOW_H_
#include "base/macros.h"
#include "ui/base/x/x11_drag_drop_client.h"
#include "ui/base/x/x11_window.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/platform_window/extensions/workspace_extension.h"
#include "ui/platform_window/extensions/x11_extension.h"
#include "ui/platform_window/platform_window.h"
#include "ui/platform_window/platform_window_handler/wm_drag_handler.h"
#include "ui/platform_window/platform_window_handler/wm_move_loop_handler.h"
#include "ui/platform_window/platform_window_handler/wm_move_resize_handler.h"
#include "ui/platform_window/platform_window_init_properties.h"
......@@ -19,6 +21,7 @@
namespace ui {
class PlatformWindowDelegate;
class X11ExtensionDelegate;
class X11DesktopWindowMoveClient;
class LocatedEvent;
......@@ -44,7 +47,9 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
public XEventDispatcher,
public WorkspaceExtension,
public X11Extension,
public WmMoveLoopHandler {
public WmMoveLoopHandler,
public WmDragHandler,
public XDragDropClient::Delegate {
public:
explicit X11Window(PlatformWindowDelegate* platform_window_delegate);
~X11Window() override;
......@@ -168,6 +173,23 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
bool RunMoveLoop(const gfx::Vector2d& drag_offset) override;
void EndMoveLoop() override;
// WmDragHandler
void StartDrag(const ui::OSExchangeData& data,
int operation,
gfx::NativeCursor cursor,
base::OnceCallback<void(int)> callback) override;
// ui::XDragDropClient::Delegate
std::unique_ptr<ui::XTopmostWindowFinder> CreateWindowFinder() override;
int UpdateDrag(const gfx::Point& screen_point) override;
void UpdateCursor(
ui::DragDropTypes::DragOperation negotiated_operation) override;
void OnBeginForeignDrag(XID window) override;
void OnEndForeignDrag() override;
void OnBeforeDragLeave() override;
int PerformDrop() override;
void EndDragLoop() override;
// Handles |xevent| as a Atk Key Event
bool HandleAsAtkEvent(XEvent* xevent);
......@@ -211,6 +233,14 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
std::unique_ptr<X11DesktopWindowMoveClient> x11_window_move_client_;
// True while the drag initiated in this window is in progress.
bool dragging_ = false;
// Called after the drag operation started in this window has completed.
base::OnceCallback<void(int)> end_drag_callback_;
// Handles XDND events going through this window.
std::unique_ptr<XDragDropClient> drag_drop_client_;
DISALLOW_COPY_AND_ASSIGN(X11Window);
};
......
......@@ -426,7 +426,7 @@ int DesktopDragDropClientAuraX11::PerformDrop() {
return drag_operation;
}
void DesktopDragDropClientAuraX11::EndMoveLoop() {
void DesktopDragDropClientAuraX11::EndDragLoop() {
move_loop_->EndMoveLoop();
}
......
......@@ -122,7 +122,7 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
void OnEndForeignDrag() override;
void OnBeforeDragLeave() override;
int PerformDrop() override;
void EndMoveLoop() override;
void EndDragLoop() override;
// A nested run loop that notifies this object of events through the
// ui::X11MoveLoopDelegate interface.
......
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