Commit 4e4f3ec7 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone] Added propagation of drop event modifiers from the platform.

The drag and drop client is supposed to set event flags according to the
current state of modifier keys (i.e., Ctrl, Shift, and Alt).  It was
not implemented in Ozone, but migration of Linux/X11 to Ozone requires
that.  This CL adds the methods that allow the DDDClientOzone to get
these flags from the platform.

The issue has been found by a test that broke at the attempt to use
DesktopDragDropClientOzone in place of DesktopDragDropClientAuraX11.

Bug: 990756
Change-Id: I2657383011a1bf9d716bb5bfa90dbcf010bba48f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2279975
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Reviewed-by: default avatarNick Yamane <nickdiego@igalia.com>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Auto-Submit: Alexander Dunaev <adunaev@igalia.com>
Cr-Commit-Position: refs/heads/master@{#785872}
parent 0c10a671
...@@ -76,11 +76,13 @@ class MockDropHandler : public WmDropHandler { ...@@ -76,11 +76,13 @@ class MockDropHandler : public WmDropHandler {
MockDropHandler() = default; MockDropHandler() = default;
~MockDropHandler() override = default; ~MockDropHandler() override = default;
MOCK_METHOD3(OnDragEnter, MOCK_METHOD4(OnDragEnter,
void(const gfx::PointF& point, void(const gfx::PointF& point,
std::unique_ptr<OSExchangeData> data, std::unique_ptr<OSExchangeData> data,
int operation)); int operation,
MOCK_METHOD2(OnDragMotion, int(const gfx::PointF& point, int operation)); int modifiers));
MOCK_METHOD3(OnDragMotion,
int(const gfx::PointF& point, int operation, int modifiers));
MOCK_METHOD0(MockOnDragDrop, void()); MOCK_METHOD0(MockOnDragDrop, void());
MOCK_METHOD0(OnDragLeave, void()); MOCK_METHOD0(OnDragLeave, void());
...@@ -91,7 +93,8 @@ class MockDropHandler : public WmDropHandler { ...@@ -91,7 +93,8 @@ class MockDropHandler : public WmDropHandler {
OSExchangeData* dropped_data() { return dropped_data_.get(); } OSExchangeData* dropped_data() { return dropped_data_.get(); }
protected: protected:
void OnDragDrop(std::unique_ptr<OSExchangeData> data) override { void OnDragDrop(std::unique_ptr<OSExchangeData> data,
int modifiers) override {
dropped_data_ = std::move(data); dropped_data_ = std::move(data);
MockOnDragDrop(); MockOnDragDrop();
on_drop_closure_.Run(); on_drop_closure_.Run();
...@@ -279,7 +282,7 @@ TEST_P(WaylandDataDragControllerTest, DropSeveralMimeTypes) { ...@@ -279,7 +282,7 @@ TEST_P(WaylandDataDragControllerTest, DropSeveralMimeTypes) {
kMimeTypeURIList, kMimeTypeURIList,
ToClipboardData(std::string("file:///home/user/file\r\n"))); ToClipboardData(std::string("file:///home/user/file\r\n")));
EXPECT_CALL(*drop_handler_, OnDragEnter(_, _, _)).Times(1); EXPECT_CALL(*drop_handler_, OnDragEnter(_, _, _, _)).Times(1);
gfx::Point entered_point(10, 10); gfx::Point entered_point(10, 10);
data_device_manager_->data_device()->OnEnter( data_device_manager_->data_device()->OnEnter(
1002, surface_->resource(), wl_fixed_from_int(entered_point.x()), 1002, surface_->resource(), wl_fixed_from_int(entered_point.x()),
...@@ -326,7 +329,7 @@ TEST_P(WaylandDataDragControllerTest, ValidateDroppedUriList) { ...@@ -326,7 +329,7 @@ TEST_P(WaylandDataDragControllerTest, ValidateDroppedUriList) {
auto* data_offer = data_device_manager_->data_device()->OnDataOffer(); auto* data_offer = data_device_manager_->data_device()->OnDataOffer();
data_offer->OnOffer(kMimeTypeURIList, ToClipboardData(kCase.content)); data_offer->OnOffer(kMimeTypeURIList, ToClipboardData(kCase.content));
EXPECT_CALL(*drop_handler_, OnDragEnter(_, _, _)).Times(1); EXPECT_CALL(*drop_handler_, OnDragEnter(_, _, _, _)).Times(1);
gfx::Point entered_point(10, 10); gfx::Point entered_point(10, 10);
data_device_manager_->data_device()->OnEnter( data_device_manager_->data_device()->OnEnter(
1002, surface_->resource(), wl_fixed_from_int(entered_point.x()), 1002, surface_->resource(), wl_fixed_from_int(entered_point.x()),
...@@ -381,7 +384,7 @@ TEST_P(WaylandDataDragControllerTest, ValidateDroppedXMozUrl) { ...@@ -381,7 +384,7 @@ TEST_P(WaylandDataDragControllerTest, ValidateDroppedXMozUrl) {
data_offer->OnOffer(kMimeTypeMozillaURL, data_offer->OnOffer(kMimeTypeMozillaURL,
ToClipboardData(base::UTF8ToUTF16(kCase.content))); ToClipboardData(base::UTF8ToUTF16(kCase.content)));
EXPECT_CALL(*drop_handler_, OnDragEnter(_, _, _)).Times(1); EXPECT_CALL(*drop_handler_, OnDragEnter(_, _, _, _)).Times(1);
gfx::Point entered_point(10, 10); gfx::Point entered_point(10, 10);
data_device_manager_->data_device()->OnEnter( data_device_manager_->data_device()->OnEnter(
1002, surface_->resource(), wl_fixed_from_int(entered_point.x()), 1002, surface_->resource(), wl_fixed_from_int(entered_point.x()),
......
...@@ -254,9 +254,11 @@ void WaylandToplevelWindow::OnDragEnter(const gfx::PointF& point, ...@@ -254,9 +254,11 @@ void WaylandToplevelWindow::OnDragEnter(const gfx::PointF& point,
// Wayland sends locations in DIP so they need to be translated to // Wayland sends locations in DIP so they need to be translated to
// physical pixels. // physical pixels.
// TODO(crbug.com/1102857): get the real event modifier here.
drop_handler->OnDragEnter( drop_handler->OnDragEnter(
gfx::ScalePoint(point, buffer_scale(), buffer_scale()), std::move(data), gfx::ScalePoint(point, buffer_scale(), buffer_scale()), std::move(data),
operation); operation,
/*modifiers=*/0);
} }
int WaylandToplevelWindow::OnDragMotion(const gfx::PointF& point, int WaylandToplevelWindow::OnDragMotion(const gfx::PointF& point,
...@@ -267,15 +269,18 @@ int WaylandToplevelWindow::OnDragMotion(const gfx::PointF& point, ...@@ -267,15 +269,18 @@ int WaylandToplevelWindow::OnDragMotion(const gfx::PointF& point,
// Wayland sends locations in DIP so they need to be translated to // Wayland sends locations in DIP so they need to be translated to
// physical pixels. // physical pixels.
// TODO(crbug.com/1102857): get the real event modifier here.
return drop_handler->OnDragMotion( return drop_handler->OnDragMotion(
gfx::ScalePoint(point, buffer_scale(), buffer_scale()), operation); gfx::ScalePoint(point, buffer_scale(), buffer_scale()), operation,
/*modifiers=*/0);
} }
void WaylandToplevelWindow::OnDragDrop(std::unique_ptr<OSExchangeData> data) { void WaylandToplevelWindow::OnDragDrop(std::unique_ptr<OSExchangeData> data) {
WmDropHandler* drop_handler = GetWmDropHandler(*this); WmDropHandler* drop_handler = GetWmDropHandler(*this);
if (!drop_handler) if (!drop_handler)
return; return;
drop_handler->OnDragDrop(std::move(data)); // TODO(crbug.com/1102857): get the real event modifier here.
drop_handler->OnDragDrop(std::move(data), /*modifiers=*/0);
} }
void WaylandToplevelWindow::OnDragLeave() { void WaylandToplevelWindow::OnDragLeave() {
......
...@@ -20,23 +20,31 @@ class OSExchangeData; ...@@ -20,23 +20,31 @@ class OSExchangeData;
class WM_PLATFORM_EXPORT WmDropHandler { class WM_PLATFORM_EXPORT WmDropHandler {
public: public:
// Notifies that dragging is entered to the window. |point| is in the // Notifies that drag has entered the window.
// coordinate space of the PlatformWindow. // |point| is in the coordinate space of the PlatformWindow.
// |operation| contains bitmask of ui::DragDropTypes suggested by the source.
// |modifiers| contains bitmask of ui::EventFlags that accompany the event.
virtual void OnDragEnter(const gfx::PointF& point, virtual void OnDragEnter(const gfx::PointF& point,
std::unique_ptr<OSExchangeData> data, std::unique_ptr<OSExchangeData> data,
int operation) = 0; int operation,
int modifiers) = 0;
// Notifies that dragging is moved. |widget_out| will be set with the
// widget located at |point|. |point| is in the coordinate space of the // Notifies that drag location has changed.
// PlatformWindow. It returns the operation selected by client and the // |point| is in the coordinate space of the PlatformWindow.
// returned value should be from ui::DragDropTypes. // |operation| contains bitmask of ui::DragDropTypes suggested by the source.
virtual int OnDragMotion(const gfx::PointF& point, int operation) = 0; // |modifiers| contains bitmask of ui::EventFlags that accompany the event.
// Returns one of ui::DragDropTypes values selected by the client.
virtual int OnDragMotion(const gfx::PointF& point,
int operation,
int modifiers) = 0;
// Notifies that dragged data is dropped. When it doesn't deliver // Notifies that dragged data is dropped. When it doesn't deliver
// the dragged data on OnDragEnter, it should put it to |data|. The location // the dragged data on OnDragEnter, it should put it to |data|. The location
// of the drop is the location of the latest DragEnter/DragMotion. If // of the drop is the location of the latest DragEnter/DragMotion. If
// OSExchangeData is provided on OnDragEnter, the |data| should be same as it. // OSExchangeData is provided on OnDragEnter, the |data| should be same as it.
virtual void OnDragDrop(std::unique_ptr<ui::OSExchangeData> data) = 0; // |modifiers| contains bitmask of ui::EventFlags that accompany the event.
virtual void OnDragDrop(std::unique_ptr<ui::OSExchangeData> data,
int modifiers) = 0;
// Notifies that dragging is left. // Notifies that dragging is left.
virtual void OnDragLeave() = 0; virtual void OnDragLeave() = 0;
......
...@@ -117,6 +117,14 @@ bool CoalesceEventsIfNeeded(x11::Event* const x11_event, ...@@ -117,6 +117,14 @@ bool CoalesceEventsIfNeeded(x11::Event* const x11_event,
return false; return false;
} }
#if defined(USE_OZONE)
int GetKeyModifiers(const XDragDropClient* client) {
if (!client)
return ui::XGetMaskAsEventFlags();
return client->current_modifier_state();
}
#endif // defined(USE_OZONE)
} // namespace } // namespace
X11Window::X11Window(PlatformWindowDelegate* platform_window_delegate) X11Window::X11Window(PlatformWindowDelegate* platform_window_delegate)
...@@ -828,22 +836,24 @@ int X11Window::UpdateDrag(const gfx::Point& screen_point) { ...@@ -828,22 +836,24 @@ int X11Window::UpdateDrag(const gfx::Point& screen_point) {
WmDropHandler* drop_handler = GetWmDropHandler(*this); WmDropHandler* drop_handler = GetWmDropHandler(*this);
if (!drop_handler) if (!drop_handler)
return DragDropTypes::DRAG_NONE; return DragDropTypes::DRAG_NONE;
DCHECK(drag_drop_client_);
auto* target_current_context = drag_drop_client_->target_current_context();
DCHECK(target_current_context);
if (!notified_enter_) { if (!notified_enter_) {
DCHECK(drag_drop_client_);
auto* target_current_context = drag_drop_client_->target_current_context();
DCHECK(target_current_context);
drop_handler->OnDragEnter( drop_handler->OnDragEnter(
gfx::PointF(screen_point), gfx::PointF(screen_point),
std::make_unique<ui::OSExchangeData>( std::make_unique<ui::OSExchangeData>(
std::make_unique<ui::XOSExchangeDataProvider>( std::make_unique<ui::XOSExchangeDataProvider>(
drag_drop_client_->xwindow(), drag_drop_client_->xwindow(),
target_current_context->fetched_targets())), target_current_context->fetched_targets())),
ui::DragDropTypes::DRAG_COPY); ui::DragDropTypes::DRAG_COPY,
GetKeyModifiers(target_current_context->source_client()));
notified_enter_ = true; notified_enter_ = true;
} }
drag_operation_ = drop_handler->OnDragMotion(gfx::PointF(screen_point), drag_operation_ = drop_handler->OnDragMotion(
ui::DragDropTypes::DRAG_COPY); gfx::PointF(screen_point), ui::DragDropTypes::DRAG_COPY,
GetKeyModifiers(target_current_context->source_client()));
return drag_operation_; return drag_operation_;
} }
...@@ -878,7 +888,10 @@ int X11Window::PerformDrop() { ...@@ -878,7 +888,10 @@ int X11Window::PerformDrop() {
// The drop data has been supplied on entering the window. The drop handler // The drop data has been supplied on entering the window. The drop handler
// should have it since then. // should have it since then.
drop_handler->OnDragDrop({}); auto* target_current_context = drag_drop_client_->target_current_context();
DCHECK(target_current_context);
drop_handler->OnDragDrop(
{}, GetKeyModifiers(target_current_context->source_client()));
notified_enter_ = false; notified_enter_ = false;
return drag_operation_; return drag_operation_;
} }
......
...@@ -178,7 +178,7 @@ void DesktopDragDropClientOzone::DragCancel() { ...@@ -178,7 +178,7 @@ void DesktopDragDropClientOzone::DragCancel() {
} }
bool DesktopDragDropClientOzone::IsDragDropInProgress() { bool DesktopDragDropClientOzone::IsDragDropInProgress() {
return bool(drag_context_) && bool(drag_context_->quit_closure); return drag_context_ && !drag_context_->quit_closure.is_null();
} }
void DesktopDragDropClientOzone::AddObserver( void DesktopDragDropClientOzone::AddObserver(
...@@ -194,7 +194,8 @@ void DesktopDragDropClientOzone::RemoveObserver( ...@@ -194,7 +194,8 @@ void DesktopDragDropClientOzone::RemoveObserver(
void DesktopDragDropClientOzone::OnDragEnter( void DesktopDragDropClientOzone::OnDragEnter(
const gfx::PointF& point, const gfx::PointF& point,
std::unique_ptr<ui::OSExchangeData> data, std::unique_ptr<ui::OSExchangeData> data,
int operation) { int operation,
int modifiers) {
last_drag_point_ = point; last_drag_point_ = point;
drag_operation_ = operation; drag_operation_ = operation;
...@@ -204,11 +205,12 @@ void DesktopDragDropClientOzone::OnDragEnter( ...@@ -204,11 +205,12 @@ void DesktopDragDropClientOzone::OnDragEnter(
return; return;
data_to_drop_ = std::move(data); data_to_drop_ = std::move(data);
UpdateTargetAndCreateDropEvent(point); UpdateTargetAndCreateDropEvent(point, modifiers);
} }
int DesktopDragDropClientOzone::OnDragMotion(const gfx::PointF& point, int DesktopDragDropClientOzone::OnDragMotion(const gfx::PointF& point,
int operation) { int operation,
int modifiers) {
last_drag_point_ = point; last_drag_point_ = point;
drag_operation_ = operation; drag_operation_ = operation;
...@@ -219,14 +221,15 @@ int DesktopDragDropClientOzone::OnDragMotion(const gfx::PointF& point, ...@@ -219,14 +221,15 @@ int DesktopDragDropClientOzone::OnDragMotion(const gfx::PointF& point,
// Ask the delegate what operation it would accept for the current data. // Ask the delegate what operation it would accept for the current data.
int client_operation = ui::DragDropTypes::DRAG_NONE; int client_operation = ui::DragDropTypes::DRAG_NONE;
std::unique_ptr<ui::DropTargetEvent> event = std::unique_ptr<ui::DropTargetEvent> event =
UpdateTargetAndCreateDropEvent(point); UpdateTargetAndCreateDropEvent(point, modifiers);
if (drag_drop_delegate_ && event) if (drag_drop_delegate_ && event)
client_operation = drag_drop_delegate_->OnDragUpdated(*event); client_operation = drag_drop_delegate_->OnDragUpdated(*event);
return client_operation; return client_operation;
} }
void DesktopDragDropClientOzone::OnDragDrop( void DesktopDragDropClientOzone::OnDragDrop(
std::unique_ptr<ui::OSExchangeData> data) { std::unique_ptr<ui::OSExchangeData> data,
int modifiers) {
// If we didn't have |data_to_drop_|, then |drag_drop_delegate_| had never // If we didn't have |data_to_drop_|, then |drag_drop_delegate_| had never
// been updated, and now it needs to receive deferred enter and update events // been updated, and now it needs to receive deferred enter and update events
// before handling the actual drop. // before handling the actual drop.
...@@ -239,7 +242,7 @@ void DesktopDragDropClientOzone::OnDragDrop( ...@@ -239,7 +242,7 @@ void DesktopDragDropClientOzone::OnDragDrop(
data_to_drop_ = std::move(data); data_to_drop_ = std::move(data);
// This will call the delegate's OnDragEntered if needed. // This will call the delegate's OnDragEntered if needed.
auto event = UpdateTargetAndCreateDropEvent(last_drag_point_); auto event = UpdateTargetAndCreateDropEvent(last_drag_point_, modifiers);
if (drag_drop_delegate_ && event) { if (drag_drop_delegate_ && event) {
if (posponed_enter_and_update) { if (posponed_enter_and_update) {
// TODO(https://crbug.com/1014860): deal with drop refusals. // TODO(https://crbug.com/1014860): deal with drop refusals.
...@@ -328,7 +331,8 @@ void DesktopDragDropClientOzone::QuitRunLoop() { ...@@ -328,7 +331,8 @@ void DesktopDragDropClientOzone::QuitRunLoop() {
std::unique_ptr<ui::DropTargetEvent> std::unique_ptr<ui::DropTargetEvent>
DesktopDragDropClientOzone::UpdateTargetAndCreateDropEvent( DesktopDragDropClientOzone::UpdateTargetAndCreateDropEvent(
const gfx::PointF& location) { const gfx::PointF& location,
int modifiers) {
const gfx::Point point(location.x(), location.y()); const gfx::Point point(location.x(), location.y());
aura::Window* window = GetTargetWindow(root_window_, point); aura::Window* window = GetTargetWindow(root_window_, point);
if (!window) { if (!window) {
...@@ -356,6 +360,7 @@ DesktopDragDropClientOzone::UpdateTargetAndCreateDropEvent( ...@@ -356,6 +360,7 @@ DesktopDragDropClientOzone::UpdateTargetAndCreateDropEvent(
auto event = std::make_unique<ui::DropTargetEvent>( auto event = std::make_unique<ui::DropTargetEvent>(
*data_to_drop_, target_location, gfx::PointF(root_location), *data_to_drop_, target_location, gfx::PointF(root_location),
drag_operation_); drag_operation_);
event->set_flags(modifiers);
if (delegate_has_changed) if (delegate_has_changed)
drag_drop_delegate_->OnDragEntered(*event); drag_drop_delegate_->OnDragEntered(*event);
return event; return event;
......
...@@ -89,9 +89,13 @@ class VIEWS_EXPORT DesktopDragDropClientOzone ...@@ -89,9 +89,13 @@ class VIEWS_EXPORT DesktopDragDropClientOzone
// ui::WmDropHandler // ui::WmDropHandler
void OnDragEnter(const gfx::PointF& point, void OnDragEnter(const gfx::PointF& point,
std::unique_ptr<ui::OSExchangeData> data, std::unique_ptr<ui::OSExchangeData> data,
int operation) override; int operation,
int OnDragMotion(const gfx::PointF& point, int operation) override; int modifiers) override;
void OnDragDrop(std::unique_ptr<ui::OSExchangeData> data) override; int OnDragMotion(const gfx::PointF& point,
int operation,
int modifiers) override;
void OnDragDrop(std::unique_ptr<ui::OSExchangeData> data,
int modifiers) override;
void OnDragLeave() override; void OnDragLeave() override;
// aura::WindowObserver // aura::WindowObserver
...@@ -111,7 +115,8 @@ class VIEWS_EXPORT DesktopDragDropClientOzone ...@@ -111,7 +115,8 @@ class VIEWS_EXPORT DesktopDragDropClientOzone
// is ready to accept OnDragUpdated or OnPerformDrop. Returns nullptr if // is ready to accept OnDragUpdated or OnPerformDrop. Returns nullptr if
// drop is not possible. // drop is not possible.
std::unique_ptr<ui::DropTargetEvent> UpdateTargetAndCreateDropEvent( std::unique_ptr<ui::DropTargetEvent> UpdateTargetAndCreateDropEvent(
const gfx::PointF& point); const gfx::PointF& point,
int modifiers);
// Updates |drag_drop_delegate_| along with |window|. // Updates |drag_drop_delegate_| along with |window|.
void UpdateDragDropDelegate(aura::Window* window); void UpdateDragDropDelegate(aura::Window* window);
......
...@@ -81,7 +81,7 @@ class FakePlatformWindow : public ui::PlatformWindow, public ui::WmDragHandler { ...@@ -81,7 +81,7 @@ class FakePlatformWindow : public ui::PlatformWindow, public ui::WmDragHandler {
ui::WmDropHandler* drop_handler = ui::GetWmDropHandler(*this); ui::WmDropHandler* drop_handler = ui::GetWmDropHandler(*this);
if (!drop_handler) if (!drop_handler)
return; return;
drop_handler->OnDragEnter(point, std::move(data), operation); drop_handler->OnDragEnter(point, std::move(data), operation, 0);
} }
int OnDragMotion(const gfx::PointF& point, int operation) { int OnDragMotion(const gfx::PointF& point, int operation) {
...@@ -89,14 +89,14 @@ class FakePlatformWindow : public ui::PlatformWindow, public ui::WmDragHandler { ...@@ -89,14 +89,14 @@ class FakePlatformWindow : public ui::PlatformWindow, public ui::WmDragHandler {
if (!drop_handler) if (!drop_handler)
return 0; return 0;
return drop_handler->OnDragMotion(point, operation); return drop_handler->OnDragMotion(point, operation, 0);
} }
void OnDragDrop(std::unique_ptr<OSExchangeData> data) { void OnDragDrop(std::unique_ptr<OSExchangeData> data) {
ui::WmDropHandler* drop_handler = ui::GetWmDropHandler(*this); ui::WmDropHandler* drop_handler = ui::GetWmDropHandler(*this);
if (!drop_handler) if (!drop_handler)
return; return;
drop_handler->OnDragDrop(std::move(data)); drop_handler->OnDragDrop(std::move(data), 0);
} }
void OnDragLeave() { void OnDragLeave() {
......
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