Commit 4466e978 authored by Fergus Dall's avatar Fergus Dall Committed by Commit Bot

Support touch-originated drags

Bug: 927324
Change-Id: I710f718f18410cc69391f1456b0ba7f02ea9e66d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1710652
Commit-Queue: Fergus Dall <sidereal@google.com>
Reviewed-by: default avatarNic Hollingum <hollingum@google.com>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681215}
parent 6cf2c15f
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "components/exo/data_device_delegate.h" #include "components/exo/data_device_delegate.h"
#include "components/exo/data_offer.h" #include "components/exo/data_offer.h"
#include "components/exo/data_source.h"
#include "components/exo/seat.h" #include "components/exo/seat.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
...@@ -39,9 +40,8 @@ DataDevice::~DataDevice() { ...@@ -39,9 +40,8 @@ DataDevice::~DataDevice() {
void DataDevice::StartDrag(DataSource* source, void DataDevice::StartDrag(DataSource* source,
Surface* origin, Surface* origin,
Surface* icon, Surface* icon,
uint32_t serial) { ui::DragDropTypes::DragEventSource event_source) {
// TODO(hirono): Check if serial is valid. crbug.com/746111 seat_->StartDrag(source, origin, icon, event_source);
seat_->StartDrag(source, origin, icon);
} }
void DataDevice::SetSelection(DataSource* source, uint32_t serial) { void DataDevice::SetSelection(DataSource* source, uint32_t serial) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "components/exo/surface.h" #include "components/exo/surface.h"
#include "components/exo/surface_observer.h" #include "components/exo/surface_observer.h"
#include "ui/base/clipboard/clipboard_observer.h" #include "ui/base/clipboard/clipboard_observer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
namespace ui { namespace ui {
class DropTargetEvent; class DropTargetEvent;
...@@ -52,7 +53,7 @@ class DataDevice : public WMHelper::DragDropObserver, ...@@ -52,7 +53,7 @@ class DataDevice : public WMHelper::DragDropObserver,
void StartDrag(DataSource* source, void StartDrag(DataSource* source,
Surface* origin, Surface* origin,
Surface* icon, Surface* icon,
uint32_t serial); ui::DragDropTypes::DragEventSource event_source);
// Sets selection data to the clipboard. // Sets selection data to the clipboard.
// |source| represents data comes from the client. |serial| is the unique // |source| represents data comes from the client. |serial| is the unique
...@@ -78,6 +79,8 @@ class DataDevice : public WMHelper::DragDropObserver, ...@@ -78,6 +79,8 @@ class DataDevice : public WMHelper::DragDropObserver,
// Overridden from SurfaceObserver: // Overridden from SurfaceObserver:
void OnSurfaceDestroying(Surface* surface) override; void OnSurfaceDestroying(Surface* surface) override;
DataDeviceDelegate* get_delegate() { return delegate_; }
private: private:
Surface* GetEffectiveTargetForEvent(const ui::DropTargetEvent& event) const; Surface* GetEffectiveTargetForEvent(const ui::DropTargetEvent& event) const;
void SetSelectionToCurrentClipboardData(); void SetSelectionToCurrentClipboardData();
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "components/viz/common/frame_sinks/copy_output_request.h" #include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/common/frame_sinks/copy_output_result.h" #include "components/viz/common/frame_sinks/copy_output_result.h"
#include "ui/aura/client/drag_drop_client.h" #include "ui/aura/client/drag_drop_client.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
...@@ -60,21 +59,26 @@ DndAction DragOperationToDndAction(int op) { ...@@ -60,21 +59,26 @@ DndAction DragOperationToDndAction(int op) {
} // namespace } // namespace
base::WeakPtr<DragDropOperation> DragDropOperation::Create(DataSource* source, base::WeakPtr<DragDropOperation> DragDropOperation::Create(
Surface* origin, DataSource* source,
Surface* icon) { Surface* origin,
auto* dnd_op = new DragDropOperation(source, origin, icon); Surface* icon,
ui::DragDropTypes::DragEventSource event_source) {
auto* dnd_op = new DragDropOperation(source, origin, icon, event_source);
return dnd_op->weak_ptr_factory_.GetWeakPtr(); return dnd_op->weak_ptr_factory_.GetWeakPtr();
} }
DragDropOperation::DragDropOperation(DataSource* source, DragDropOperation::DragDropOperation(
Surface* origin, DataSource* source,
Surface* icon) Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source)
: SurfaceTreeHost("ExoDragDropOperation"), : SurfaceTreeHost("ExoDragDropOperation"),
source_(std::make_unique<ScopedDataSource>(source, this)), source_(std::make_unique<ScopedDataSource>(source, this)),
origin_(std::make_unique<ScopedSurface>(origin, this)), origin_(std::make_unique<ScopedSurface>(origin, this)),
drag_start_point_(display::Screen::GetScreen()->GetCursorScreenPoint()), drag_start_point_(display::Screen::GetScreen()->GetCursorScreenPoint()),
os_exchange_data_(std::make_unique<ui::OSExchangeData>()), os_exchange_data_(std::make_unique<ui::OSExchangeData>()),
event_source_(event_source),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
aura::Window* root_window = origin_->get()->window()->GetRootWindow(); aura::Window* root_window = origin_->get()->window()->GetRootWindow();
DCHECK(root_window); DCHECK(root_window);
...@@ -86,9 +90,8 @@ DragDropOperation::DragDropOperation(DataSource* source, ...@@ -86,9 +90,8 @@ DragDropOperation::DragDropOperation(DataSource* source,
#endif #endif
DCHECK(drag_drop_controller_); DCHECK(drag_drop_controller_);
if (drag_drop_controller_->IsDragDropInProgress()) { if (drag_drop_controller_->IsDragDropInProgress())
drag_drop_controller_->DragCancel(); drag_drop_controller_->DragCancel();
}
drag_drop_controller_->AddObserver(this); drag_drop_controller_->AddObserver(this);
...@@ -99,7 +102,9 @@ DragDropOperation::DragDropOperation(DataSource* source, ...@@ -99,7 +102,9 @@ DragDropOperation::DragDropOperation(DataSource* source,
base::BindOnce(&DragDropOperation::ScheduleStartDragDropOperation, base::BindOnce(&DragDropOperation::ScheduleStartDragDropOperation,
weak_ptr_factory_.GetWeakPtr()); weak_ptr_factory_.GetWeakPtr());
counter_ = base::BarrierClosure(kMaxClipboardDataTypes, // Make the count kMaxClipboardDataTypes + 1 so we can wait for the icon to be
// captured as well.
counter_ = base::BarrierClosure(kMaxClipboardDataTypes + 1,
std::move(start_op_callback)); std::move(start_op_callback));
source->GetDataForPreferredMimeTypes( source->GetDataForPreferredMimeTypes(
...@@ -175,6 +180,11 @@ void DragDropOperation::OnDragIconCaptured( ...@@ -175,6 +180,11 @@ void DragDropOperation::OnDragIconCaptured(
-icon_->get()->GetBufferOffset()); -icon_->get()->GetBufferOffset());
#endif #endif
} }
if (!captured_icon_) {
captured_icon_ = true;
counter_.Run();
}
} }
void DragDropOperation::ScheduleStartDragDropOperation() { void DragDropOperation::ScheduleStartDragDropOperation() {
...@@ -198,9 +208,7 @@ void DragDropOperation::StartDragDropOperation() { ...@@ -198,9 +208,7 @@ void DragDropOperation::StartDragDropOperation() {
int op = drag_drop_controller_->StartDragAndDrop( int op = drag_drop_controller_->StartDragAndDrop(
std::move(os_exchange_data_), origin_->get()->window()->GetRootWindow(), std::move(os_exchange_data_), origin_->get()->window()->GetRootWindow(),
origin_->get()->window(), drag_start_point_, dnd_operations, origin_->get()->window(), drag_start_point_, dnd_operations,
event_source_);
// We currently only support dragging with the mouse
ui::DragDropTypes::DragEventSource::DRAG_EVENT_SOURCE_MOUSE);
if (op) { if (op) {
// Success // Success
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/exo/surface_tree_host.h" #include "components/exo/surface_tree_host.h"
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "ui/aura/client/drag_drop_client_observer.h" #include "ui/aura/client/drag_drop_client_observer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
namespace ash { namespace ash {
class DragDropController; class DragDropController;
...@@ -45,9 +46,11 @@ class DragDropOperation : public DataSourceObserver, ...@@ -45,9 +46,11 @@ class DragDropOperation : public DataSourceObserver,
public aura::client::DragDropClientObserver { public aura::client::DragDropClientObserver {
public: public:
// Create an operation for a drag-drop originating from a wayland app. // Create an operation for a drag-drop originating from a wayland app.
static base::WeakPtr<DragDropOperation> Create(DataSource* source, static base::WeakPtr<DragDropOperation> Create(
Surface* origin, DataSource* source,
Surface* icon); Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source);
// DataSourceObserver: // DataSourceObserver:
void OnDataSourceDestroying(DataSource* source) override; void OnDataSourceDestroying(DataSource* source) override;
...@@ -65,7 +68,10 @@ class DragDropOperation : public DataSourceObserver, ...@@ -65,7 +68,10 @@ class DragDropOperation : public DataSourceObserver,
private: private:
// A private constructor and destructor are used to prevent anyone else from // A private constructor and destructor are used to prevent anyone else from
// attempting to manage the lifetime of a DragDropOperation. // attempting to manage the lifetime of a DragDropOperation.
DragDropOperation(DataSource* source, Surface* origin, Surface* icon); DragDropOperation(DataSource* source,
Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source);
~DragDropOperation() override; ~DragDropOperation() override;
void CaptureDragIcon(); void CaptureDragIcon();
...@@ -96,8 +102,12 @@ class DragDropOperation : public DataSourceObserver, ...@@ -96,8 +102,12 @@ class DragDropOperation : public DataSourceObserver,
// want to ignore the OnDragStarted event. // want to ignore the OnDragStarted event.
bool started_by_this_object_ = false; bool started_by_this_object_ = false;
bool captured_icon_ = false;
std::string mime_type_; std::string mime_type_;
ui::DragDropTypes::DragEventSource event_source_;
base::WeakPtrFactory<DragDropOperation> weak_ptr_factory_; base::WeakPtrFactory<DragDropOperation> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DragDropOperation); DISALLOW_COPY_AND_ASSIGN(DragDropOperation);
......
...@@ -84,9 +84,12 @@ Surface* Seat::GetFocusedSurface() { ...@@ -84,9 +84,12 @@ Surface* Seat::GetFocusedSurface() {
return GetEffectiveFocus(WMHelper::GetInstance()->GetFocusedWindow()); return GetEffectiveFocus(WMHelper::GetInstance()->GetFocusedWindow());
} }
void Seat::StartDrag(DataSource* source, Surface* origin, Surface* icon) { void Seat::StartDrag(DataSource* source,
Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source) {
// DragDropOperation manages its own lifetime. // DragDropOperation manages its own lifetime.
DragDropOperation::Create(source, origin, icon); DragDropOperation::Create(source, origin, icon, event_source);
} }
void Seat::SetSelection(DataSource* source) { void Seat::SetSelection(DataSource* source) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/aura/client/focus_change_observer.h" #include "ui/aura/client/focus_change_observer.h"
#include "ui/base/clipboard/clipboard_observer.h" #include "ui/base/clipboard/clipboard_observer.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
#include "ui/events/keycodes/dom/dom_codes.h" #include "ui/events/keycodes/dom/dom_codes.h"
#include "ui/events/platform/platform_event_observer.h" #include "ui/events/platform/platform_event_observer.h"
...@@ -65,7 +66,10 @@ class Seat : public aura::client::FocusChangeObserver, ...@@ -65,7 +66,10 @@ class Seat : public aura::client::FocusChangeObserver,
// Sets clipboard data from |source|. // Sets clipboard data from |source|.
void SetSelection(DataSource* source); void SetSelection(DataSource* source);
void StartDrag(DataSource* source, Surface* origin, Surface* icon); void StartDrag(DataSource* source,
Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source);
// Overridden from aura::client::FocusChangeObserver: // Overridden from aura::client::FocusChangeObserver:
void OnWindowFocused(aura::Window* gained_focus, void OnWindowFocused(aura::Window* gained_focus,
......
...@@ -288,6 +288,26 @@ class WaylandDataDeviceDelegate : public DataDeviceDelegate { ...@@ -288,6 +288,26 @@ class WaylandDataDeviceDelegate : public DataDeviceDelegate {
wl_client_flush(client_); wl_client_flush(client_);
} }
void StartDrag(DataDevice* data_device,
DataSource* source,
Surface* origin,
Surface* icon,
uint32_t serial) {
base::Optional<wayland::SerialTracker::EventType> event_type =
serial_tracker_->GetEventType(serial);
if (event_type == wayland::SerialTracker::EventType::POINTER_BUTTON) {
data_device->StartDrag(
source, origin, icon,
ui::DragDropTypes::DragEventSource::DRAG_EVENT_SOURCE_MOUSE);
} else if (event_type == wayland::SerialTracker::EventType::TOUCH_DOWN) {
data_device->StartDrag(
source, origin, icon,
ui::DragDropTypes::DragEventSource::DRAG_EVENT_SOURCE_TOUCH);
} else {
source->Cancelled();
}
}
private: private:
wl_client* const client_; wl_client* const client_;
wl_resource* const data_device_resource_; wl_resource* const data_device_resource_;
...@@ -304,10 +324,15 @@ void data_device_start_drag(wl_client* client, ...@@ -304,10 +324,15 @@ void data_device_start_drag(wl_client* client,
wl_resource* origin_resource, wl_resource* origin_resource,
wl_resource* icon_resource, wl_resource* icon_resource,
uint32_t serial) { uint32_t serial) {
GetUserDataAs<DataDevice>(resource)->StartDrag( DataDevice* data_device = GetUserDataAs<DataDevice>(resource);
source_resource ? GetUserDataAs<DataSource>(source_resource) : nullptr, static_cast<WaylandDataDeviceDelegate*>(data_device->get_delegate())
GetUserDataAs<Surface>(origin_resource), ->StartDrag(
icon_resource ? GetUserDataAs<Surface>(icon_resource) : nullptr, serial); data_device,
source_resource ? GetUserDataAs<DataSource>(source_resource)
: nullptr,
GetUserDataAs<Surface>(origin_resource),
icon_resource ? GetUserDataAs<Surface>(icon_resource) : nullptr,
serial);
} }
void data_device_set_selection(wl_client* client, void data_device_set_selection(wl_client* client,
......
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