Commit c59f6260 authored by Daichi Hirono's avatar Daichi Hirono Committed by Commit Bot

Delivers drag and drop methods from Surface to DataDevice.

The CL lets Surface observe drag and drop events and delegates the events to
DataDevice thorugh DataDeviceManager.

Bug: b:31988797
Test: None
Change-Id: I9574cd86137922d7527bd297d182a7b45e632c9e
Reviewed-on: https://chromium-review.googlesource.com/579250
Commit-Queue: Daichi Hirono <hirono@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491951}
parent 7aaef892
......@@ -6,13 +6,19 @@
#include "base/logging.h"
#include "components/exo/data_device_delegate.h"
#include "components/exo/surface.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/drop_target_event.h"
namespace exo {
DataDevice::DataDevice(DataDeviceDelegate* delegate) : delegate_(delegate) {}
DataDevice::DataDevice(DataDeviceDelegate* delegate) : delegate_(delegate) {
WMHelper::GetInstance()->AddDragDropObserver(this);
}
DataDevice::~DataDevice() {
delegate_->OnDataDeviceDestroying(this);
WMHelper::GetInstance()->RemoveDragDropObserver(this);
}
void DataDevice::StartDrag(const DataSource* source_resource,
......@@ -28,4 +34,32 @@ void DataDevice::SetSelection(const DataSource* source, uint32_t serial) {
NOTIMPLEMENTED();
}
void DataDevice::OnDragEntered(const ui::DropTargetEvent& event) {
NOTIMPLEMENTED();
}
int DataDevice::OnDragUpdated(const ui::DropTargetEvent& event) {
NOTIMPLEMENTED();
return ui::DragDropTypes::DRAG_NONE;
}
void DataDevice::OnDragExited() {
NOTIMPLEMENTED();
}
int DataDevice::OnPerformDrop(const ui::DropTargetEvent& event) {
NOTIMPLEMENTED();
return ui::DragDropTypes::DRAG_NONE;
}
Surface* DataDevice::GetEffectiveTargetForEvent(
const ui::DropTargetEvent& event) const {
Surface* target =
Surface::AsSurface(static_cast<aura::Window*>(event.target()));
if (!target)
return nullptr;
return delegate_->CanAcceptDataEventsForSurface(target) ? target : nullptr;
}
} // namespace exo
......@@ -8,6 +8,11 @@
#include <cstdint>
#include "base/macros.h"
#include "components/exo/wm_helper.h"
namespace ui {
class DropTargetEvent;
}
namespace exo {
......@@ -19,10 +24,10 @@ enum class DndAction { kNone, kCopy, kMove, kAsk };
// Data transfer device providing access to inter-client data transfer
// mechanisms such as copy-and-paste and drag-and-drop.
class DataDevice {
class DataDevice : public WMHelper::DragDropObserver {
public:
explicit DataDevice(DataDeviceDelegate* delegate);
~DataDevice();
~DataDevice() override;
// Starts drag-and-drop operation.
// |source| is data source for the eventual transfer or null if data passing
......@@ -39,7 +44,15 @@ class DataDevice {
// selection. |serial| is a unique number of event which tigers SetSelection.
void SetSelection(const DataSource* source, uint32_t serial);
// Overridden from WMHelper::DragDropObserver:
void OnDragEntered(const ui::DropTargetEvent& event) override;
int OnDragUpdated(const ui::DropTargetEvent& event) override;
void OnDragExited() override;
int OnPerformDrop(const ui::DropTargetEvent& event) override;
private:
Surface* GetEffectiveTargetForEvent(const ui::DropTargetEvent& event) const;
DataDeviceDelegate* const delegate_;
DISALLOW_COPY_AND_ASSIGN(DataDevice);
......
......@@ -57,6 +57,10 @@ class DataDeviceDelegate {
// Called when the data is pasted on the DataDevice.
virtual void OnSelection(const DataOffer& data_offer) = 0;
// This should return true if |surface| is a valid target for this data
// device. E.g. the surface is owned by the same client as the data device.
virtual bool CanAcceptDataEventsForSurface(Surface* surface);
protected:
virtual ~DataDeviceDelegate() {}
};
......
......@@ -2843,6 +2843,10 @@ class WaylandDataDeviceDelegate : public DataDeviceDelegate {
// Overridden from DataDeviceDelegate:
void OnDataDeviceDestroying(DataDevice* device) override { delete this; }
bool CanAcceptDataEventsForSurface(Surface* surface) override {
return surface &&
wl_resource_get_client(GetSurfaceResource(surface)) == client_;
}
class DataOffer* OnDataOffer(const std::vector<std::string>& mime_types,
const base::flat_set<DndAction>& source_actions,
DndAction dnd_action) override {
......
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