Commit 7a552011 authored by Daichi Hirono's avatar Daichi Hirono Committed by Commit Bot

Add DragDropObserver to WMHelper

DragDropObserver will be used by DataDevice instances to
observe drag drop events.

Bug: b:31988797
Test: None
Change-Id: I67d15f81a59730f0d78da3d56f120a16d84a43b3
Reviewed-on: https://chromium-review.googlesource.com/578748
Commit-Queue: Daichi Hirono <hirono@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491947}
parent a3ce56c4
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "components/viz/service/surfaces/surface_manager.h" #include "components/viz/service/surfaces/surface_manager.h"
#include "third_party/khronos/GLES2/gl2.h" #include "third_party/khronos/GLES2/gl2.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/window_delegate.h" #include "ui/aura/window_delegate.h"
#include "ui/aura/window_targeter.h" #include "ui/aura/window_targeter.h"
#include "ui/base/class_property.h" #include "ui/base/class_property.h"
...@@ -192,8 +193,8 @@ Surface::Surface() : window_(new aura::Window(new CustomWindowDelegate(this))) { ...@@ -192,8 +193,8 @@ Surface::Surface() : window_(new aura::Window(new CustomWindowDelegate(this))) {
window_->Init(ui::LAYER_NOT_DRAWN); window_->Init(ui::LAYER_NOT_DRAWN);
window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); window_->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter));
window_->set_owned_by_parent(false); window_->set_owned_by_parent(false);
WMHelper::GetInstance()->SetDragDropDelegate(window_.get());
} }
Surface::~Surface() { Surface::~Surface() {
for (SurfaceObserver& observer : observers_) for (SurfaceObserver& observer : observers_)
observer.OnSurfaceDestroying(this); observer.OnSurfaceDestroying(this);
...@@ -207,6 +208,8 @@ Surface::~Surface() { ...@@ -207,6 +208,8 @@ Surface::~Surface() {
// that they have been cancelled. // that they have been cancelled.
for (const auto& presentation_callback : pending_presentation_callbacks_) for (const auto& presentation_callback : pending_presentation_callbacks_)
presentation_callback.Run(base::TimeTicks(), base::TimeDelta()); presentation_callback.Run(base::TimeTicks(), base::TimeDelta());
WMHelper::GetInstance()->ResetDragDropDelegate(window_.get());
} }
// static // static
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "ui/aura/client/drag_drop_delegate.h"
#include "ui/base/dragdrop/drag_drop_types.h"
namespace exo { namespace exo {
namespace { namespace {
...@@ -86,6 +88,22 @@ void WMHelper::RemoveDisplayConfigurationObserver( ...@@ -86,6 +88,22 @@ void WMHelper::RemoveDisplayConfigurationObserver(
display_config_observers_.RemoveObserver(observer); display_config_observers_.RemoveObserver(observer);
} }
void WMHelper::AddDragDropObserver(DragDropObserver* observer) {
drag_drop_observers_.AddObserver(observer);
}
void WMHelper::RemoveDragDropObserver(DragDropObserver* observer) {
drag_drop_observers_.RemoveObserver(observer);
}
void WMHelper::SetDragDropDelegate(aura::Window* window) {
aura::client::SetDragDropDelegate(window, this);
}
void WMHelper::ResetDragDropDelegate(aura::Window* window) {
aura::client::SetDragDropDelegate(window, nullptr);
}
void WMHelper::NotifyWindowActivated(aura::Window* gained_active, void WMHelper::NotifyWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) { aura::Window* lost_active) {
for (ActivationObserver& observer : activation_observers_) for (ActivationObserver& observer : activation_observers_)
...@@ -138,4 +156,28 @@ void WMHelper::NotifyDisplayConfigurationChanged() { ...@@ -138,4 +156,28 @@ void WMHelper::NotifyDisplayConfigurationChanged() {
observer.OnDisplayConfigurationChanged(); observer.OnDisplayConfigurationChanged();
} }
void WMHelper::OnDragEntered(const ui::DropTargetEvent& event) {
for (DragDropObserver& observer : drag_drop_observers_)
observer.OnDragEntered(event);
}
int WMHelper::OnDragUpdated(const ui::DropTargetEvent& event) {
int valid_operation = ui::DragDropTypes::DRAG_NONE;
for (DragDropObserver& observer : drag_drop_observers_)
valid_operation = valid_operation | observer.OnDragUpdated(event);
return valid_operation;
}
void WMHelper::OnDragExited() {
for (DragDropObserver& observer : drag_drop_observers_)
observer.OnDragExited();
}
int WMHelper::OnPerformDrop(const ui::DropTargetEvent& event) {
for (DragDropObserver& observer : drag_drop_observers_)
observer.OnPerformDrop(event);
// TODO(hirono): Return the correct result instead of always returning
// DRAG_MOVE.
return ui::DragDropTypes::DRAG_MOVE;
}
} // namespace exo } // namespace exo
...@@ -5,8 +5,11 @@ ...@@ -5,8 +5,11 @@
#ifndef COMPONENTS_EXO_WM_HELPER_H_ #ifndef COMPONENTS_EXO_WM_HELPER_H_
#define COMPONENTS_EXO_WM_HELPER_H_ #define COMPONENTS_EXO_WM_HELPER_H_
#include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "ui/aura/client/drag_drop_delegate.h"
#include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor.h"
namespace aura { namespace aura {
...@@ -20,12 +23,13 @@ class ManagedDisplayInfo; ...@@ -20,12 +23,13 @@ class ManagedDisplayInfo;
namespace ui { namespace ui {
class EventHandler; class EventHandler;
class DropTargetEvent;
} }
namespace exo { namespace exo {
// A helper class for accessing WindowManager related features. // A helper class for accessing WindowManager related features.
class WMHelper { class WMHelper : public aura::client::DragDropDelegate {
public: public:
class ActivationObserver { class ActivationObserver {
public: public:
...@@ -81,7 +85,18 @@ class WMHelper { ...@@ -81,7 +85,18 @@ class WMHelper {
virtual ~DisplayConfigurationObserver() {} virtual ~DisplayConfigurationObserver() {}
}; };
virtual ~WMHelper(); class DragDropObserver {
public:
virtual void OnDragEntered(const ui::DropTargetEvent& event) = 0;
virtual int OnDragUpdated(const ui::DropTargetEvent& event) = 0;
virtual void OnDragExited() = 0;
virtual int OnPerformDrop(const ui::DropTargetEvent& event) = 0;
protected:
virtual ~DragDropObserver() {}
};
~WMHelper() override;
static void SetInstance(WMHelper* helper); static void SetInstance(WMHelper* helper);
static WMHelper* GetInstance(); static WMHelper* GetInstance();
...@@ -100,6 +115,10 @@ class WMHelper { ...@@ -100,6 +115,10 @@ class WMHelper {
void AddDisplayConfigurationObserver(DisplayConfigurationObserver* observer); void AddDisplayConfigurationObserver(DisplayConfigurationObserver* observer);
void RemoveDisplayConfigurationObserver( void RemoveDisplayConfigurationObserver(
DisplayConfigurationObserver* observer); DisplayConfigurationObserver* observer);
void AddDragDropObserver(DragDropObserver* observer);
void RemoveDragDropObserver(DragDropObserver* observer);
void SetDragDropDelegate(aura::Window*);
void ResetDragDropDelegate(aura::Window*);
virtual const display::ManagedDisplayInfo& GetDisplayInfo( virtual const display::ManagedDisplayInfo& GetDisplayInfo(
int64_t display_id) const = 0; int64_t display_id) const = 0;
...@@ -115,6 +134,12 @@ class WMHelper { ...@@ -115,6 +134,12 @@ class WMHelper {
virtual void RemovePostTargetHandler(ui::EventHandler* handler) = 0; virtual void RemovePostTargetHandler(ui::EventHandler* handler) = 0;
virtual bool IsTabletModeWindowManagerEnabled() const = 0; virtual bool IsTabletModeWindowManagerEnabled() const = 0;
// Overridden from aura::client::DragDropDelegate:
void OnDragEntered(const ui::DropTargetEvent& event) override;
int OnDragUpdated(const ui::DropTargetEvent& event) override;
void OnDragExited() override;
int OnPerformDrop(const ui::DropTargetEvent& event) override;
protected: protected:
WMHelper(); WMHelper();
...@@ -138,6 +163,7 @@ class WMHelper { ...@@ -138,6 +163,7 @@ class WMHelper {
base::ObserverList<TabletModeObserver> tablet_mode_observers_; base::ObserverList<TabletModeObserver> tablet_mode_observers_;
base::ObserverList<InputDeviceEventObserver> input_device_event_observers_; base::ObserverList<InputDeviceEventObserver> input_device_event_observers_;
base::ObserverList<DisplayConfigurationObserver> display_config_observers_; base::ObserverList<DisplayConfigurationObserver> display_config_observers_;
base::ObserverList<DragDropObserver> drag_drop_observers_;
DISALLOW_COPY_AND_ASSIGN(WMHelper); DISALLOW_COPY_AND_ASSIGN(WMHelper);
}; };
......
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