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 @@
#include "components/exo/data_device_delegate.h"
#include "components/exo/data_offer.h"
#include "components/exo/data_source.h"
#include "components/exo/seat.h"
#include "components/exo/surface.h"
#include "ui/base/clipboard/clipboard.h"
......@@ -39,9 +40,8 @@ DataDevice::~DataDevice() {
void DataDevice::StartDrag(DataSource* source,
Surface* origin,
Surface* icon,
uint32_t serial) {
// TODO(hirono): Check if serial is valid. crbug.com/746111
seat_->StartDrag(source, origin, icon);
ui::DragDropTypes::DragEventSource event_source) {
seat_->StartDrag(source, origin, icon, event_source);
}
void DataDevice::SetSelection(DataSource* source, uint32_t serial) {
......
......@@ -13,6 +13,7 @@
#include "components/exo/surface.h"
#include "components/exo/surface_observer.h"
#include "ui/base/clipboard/clipboard_observer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
namespace ui {
class DropTargetEvent;
......@@ -52,7 +53,7 @@ class DataDevice : public WMHelper::DragDropObserver,
void StartDrag(DataSource* source,
Surface* origin,
Surface* icon,
uint32_t serial);
ui::DragDropTypes::DragEventSource event_source);
// Sets selection data to the clipboard.
// |source| represents data comes from the client. |serial| is the unique
......@@ -78,6 +79,8 @@ class DataDevice : public WMHelper::DragDropObserver,
// Overridden from SurfaceObserver:
void OnSurfaceDestroying(Surface* surface) override;
DataDeviceDelegate* get_delegate() { return delegate_; }
private:
Surface* GetEffectiveTargetForEvent(const ui::DropTargetEvent& event) const;
void SetSelectionToCurrentClipboardData();
......
......@@ -14,7 +14,6 @@
#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/common/frame_sinks/copy_output_result.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/display/display.h"
#include "ui/display/screen.h"
......@@ -60,21 +59,26 @@ DndAction DragOperationToDndAction(int op) {
} // namespace
base::WeakPtr<DragDropOperation> DragDropOperation::Create(DataSource* source,
Surface* origin,
Surface* icon) {
auto* dnd_op = new DragDropOperation(source, origin, icon);
base::WeakPtr<DragDropOperation> DragDropOperation::Create(
DataSource* source,
Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source) {
auto* dnd_op = new DragDropOperation(source, origin, icon, event_source);
return dnd_op->weak_ptr_factory_.GetWeakPtr();
}
DragDropOperation::DragDropOperation(DataSource* source,
Surface* origin,
Surface* icon)
DragDropOperation::DragDropOperation(
DataSource* source,
Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source)
: SurfaceTreeHost("ExoDragDropOperation"),
source_(std::make_unique<ScopedDataSource>(source, this)),
origin_(std::make_unique<ScopedSurface>(origin, this)),
drag_start_point_(display::Screen::GetScreen()->GetCursorScreenPoint()),
os_exchange_data_(std::make_unique<ui::OSExchangeData>()),
event_source_(event_source),
weak_ptr_factory_(this) {
aura::Window* root_window = origin_->get()->window()->GetRootWindow();
DCHECK(root_window);
......@@ -86,9 +90,8 @@ DragDropOperation::DragDropOperation(DataSource* source,
#endif
DCHECK(drag_drop_controller_);
if (drag_drop_controller_->IsDragDropInProgress()) {
if (drag_drop_controller_->IsDragDropInProgress())
drag_drop_controller_->DragCancel();
}
drag_drop_controller_->AddObserver(this);
......@@ -99,7 +102,9 @@ DragDropOperation::DragDropOperation(DataSource* source,
base::BindOnce(&DragDropOperation::ScheduleStartDragDropOperation,
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));
source->GetDataForPreferredMimeTypes(
......@@ -175,6 +180,11 @@ void DragDropOperation::OnDragIconCaptured(
-icon_->get()->GetBufferOffset());
#endif
}
if (!captured_icon_) {
captured_icon_ = true;
counter_.Run();
}
}
void DragDropOperation::ScheduleStartDragDropOperation() {
......@@ -198,9 +208,7 @@ void DragDropOperation::StartDragDropOperation() {
int op = drag_drop_controller_->StartDragAndDrop(
std::move(os_exchange_data_), origin_->get()->window()->GetRootWindow(),
origin_->get()->window(), drag_start_point_, dnd_operations,
// We currently only support dragging with the mouse
ui::DragDropTypes::DragEventSource::DRAG_EVENT_SOURCE_MOUSE);
event_source_);
if (op) {
// Success
......
......@@ -11,6 +11,7 @@
#include "components/exo/surface_tree_host.h"
#include "components/exo/wm_helper.h"
#include "ui/aura/client/drag_drop_client_observer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
namespace ash {
class DragDropController;
......@@ -45,9 +46,11 @@ class DragDropOperation : public DataSourceObserver,
public aura::client::DragDropClientObserver {
public:
// Create an operation for a drag-drop originating from a wayland app.
static base::WeakPtr<DragDropOperation> Create(DataSource* source,
Surface* origin,
Surface* icon);
static base::WeakPtr<DragDropOperation> Create(
DataSource* source,
Surface* origin,
Surface* icon,
ui::DragDropTypes::DragEventSource event_source);
// DataSourceObserver:
void OnDataSourceDestroying(DataSource* source) override;
......@@ -65,7 +68,10 @@ class DragDropOperation : public DataSourceObserver,
private:
// A private constructor and destructor are used to prevent anyone else from
// 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;
void CaptureDragIcon();
......@@ -96,8 +102,12 @@ class DragDropOperation : public DataSourceObserver,
// want to ignore the OnDragStarted event.
bool started_by_this_object_ = false;
bool captured_icon_ = false;
std::string mime_type_;
ui::DragDropTypes::DragEventSource event_source_;
base::WeakPtrFactory<DragDropOperation> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DragDropOperation);
......
......@@ -84,9 +84,12 @@ Surface* Seat::GetFocusedSurface() {
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::Create(source, origin, icon);
DragDropOperation::Create(source, origin, icon, event_source);
}
void Seat::SetSelection(DataSource* source) {
......
......@@ -13,6 +13,7 @@
#include "ui/aura/client/focus_change_observer.h"
#include "ui/base/clipboard/clipboard_observer.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/keycodes/dom/dom_codes.h"
#include "ui/events/platform/platform_event_observer.h"
......@@ -65,7 +66,10 @@ class Seat : public aura::client::FocusChangeObserver,
// Sets clipboard data from |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:
void OnWindowFocused(aura::Window* gained_focus,
......
......@@ -288,6 +288,26 @@ class WaylandDataDeviceDelegate : public DataDeviceDelegate {
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:
wl_client* const client_;
wl_resource* const data_device_resource_;
......@@ -304,10 +324,15 @@ void data_device_start_drag(wl_client* client,
wl_resource* origin_resource,
wl_resource* icon_resource,
uint32_t serial) {
GetUserDataAs<DataDevice>(resource)->StartDrag(
source_resource ? GetUserDataAs<DataSource>(source_resource) : nullptr,
GetUserDataAs<Surface>(origin_resource),
icon_resource ? GetUserDataAs<Surface>(icon_resource) : nullptr, serial);
DataDevice* data_device = GetUserDataAs<DataDevice>(resource);
static_cast<WaylandDataDeviceDelegate*>(data_device->get_delegate())
->StartDrag(
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,
......
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