Index: services/ui/public/cpp/window_tree_client.cc |
diff --git a/services/ui/public/cpp/window_tree_client.cc b/services/ui/public/cpp/window_tree_client.cc |
index c9ef386d8a36d955dcf42e481e75c9695f41bb2c..7d9c37418bd0647a3795a3aa9d01ebb812fe0e37 100644 |
--- a/services/ui/public/cpp/window_tree_client.cc |
+++ b/services/ui/public/cpp/window_tree_client.cc |
@@ -16,6 +16,7 @@ |
#include "services/ui/common/util.h" |
#include "services/ui/public/cpp/in_flight_change.h" |
#include "services/ui/public/cpp/input_event_handler.h" |
+#include "services/ui/public/cpp/window_drop_target.h" |
#include "services/ui/public/cpp/window_manager_delegate.h" |
#include "services/ui/public/cpp/window_observer.h" |
#include "services/ui/public/cpp/window_private.h" |
@@ -644,6 +645,33 @@ void WindowTreeClient::StopPointerWatcher() { |
has_pointer_watcher_ = false; |
} |
+void WindowTreeClient::PerformDragDrop( |
+ Window* window, |
+ const std::map<std::string, std::vector<uint8_t>>& drag_data, |
+ int drag_operation, |
+ const gfx::Point& cursor_location, |
+ const SkBitmap& bitmap, |
+ const base::Callback<void(bool)>& callback) { |
+ DCHECK(on_current_drag_finished_.is_null()); |
+ on_current_drag_finished_ = callback; |
+ |
+ // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when |
+ // we start showing an image representation of the drag under he cursor. |
+ |
+ if (window->drop_target()) { |
+ // To minimize the number of round trips, copy the drag drop data to our |
+ // handler here, instead of forcing mus to send this same data back. |
+ window->drop_target()->OnDragStart(drag_data); |
+ } |
+ |
+ current_drag_change_ = |
+ ScheduleInFlightChange(base::MakeUnique<InFlightDragChange>(window)); |
+ tree_->PerformDragDrop( |
+ current_drag_change_, window->server_id(), |
+ mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), |
+ drag_operation); |
+} |
+ |
void WindowTreeClient::PerformWindowMove( |
Window* window, |
ui::mojom::MoveLoopSource source, |
@@ -652,8 +680,8 @@ void WindowTreeClient::PerformWindowMove( |
DCHECK(on_current_move_finished_.is_null()); |
on_current_move_finished_ = callback; |
- current_move_loop_change_ = ScheduleInFlightChange( |
- base::MakeUnique<InFlightMoveLoopChange>(window)); |
+ current_move_loop_change_ = |
+ ScheduleInFlightChange(base::MakeUnique<InFlightDragChange>(window)); |
// Tell the window manager to take over moving us. |
tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), |
source, cursor_location); |
@@ -711,6 +739,11 @@ void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { |
observers_.RemoveObserver(observer); |
} |
+void WindowTreeClient::SetCanAcceptDrags(Id window_id, bool can_accept_drags) { |
+ DCHECK(tree_); |
+ tree_->SetCanAcceptDrags(window_id, can_accept_drags); |
+} |
+ |
void WindowTreeClient::SetCanAcceptEvents(Id window_id, |
bool can_accept_events) { |
DCHECK(tree_); |
@@ -1057,6 +1090,108 @@ void WindowTreeClient::OnWindowPredefinedCursorChanged( |
WindowPrivate(window).LocalSetPredefinedCursor(cursor); |
} |
+void WindowTreeClient::OnDragStart( |
+ Id window_id, |
+ mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { |
+ Window* window = GetWindowByServerId(window_id); |
+ if (!window) |
+ return; |
+ |
+ WindowDropTarget* target = window->drop_target(); |
+ if (!target) |
+ return; |
+ |
+ target->OnDragStart( |
+ mime_data.To<std::map<std::string, std::vector<uint8_t>>>()); |
+} |
+ |
+void WindowTreeClient::OnDragEnter(Id window_id, |
+ uint32_t key_state, |
+ const gfx::Point& position, |
+ uint32_t effect_bitmask, |
+ const OnDragEnterCallback& callback) { |
+ Window* window = GetWindowByServerId(window_id); |
+ if (!window) { |
+ callback.Run(mojom::kDropEffectNone); |
+ return; |
+ } |
+ |
+ WindowDropTarget* target = window->drop_target(); |
+ if (!target) { |
+ callback.Run(mojom::kDropEffectNone); |
+ return; |
+ } |
+ |
+ uint32_t ret = target->OnDragEnter(key_state, position, effect_bitmask); |
+ callback.Run(ret); |
+} |
+ |
+void WindowTreeClient::OnDragOver(Id window_id, |
+ uint32_t key_state, |
+ const gfx::Point& position, |
+ uint32_t effect_bitmask, |
+ const OnDragOverCallback& callback) { |
+ Window* window = GetWindowByServerId(window_id); |
+ if (!window) { |
+ callback.Run(mojom::kDropEffectNone); |
+ return; |
+ } |
+ |
+ WindowDropTarget* target = window->drop_target(); |
+ if (!target) { |
+ callback.Run(mojom::kDropEffectNone); |
+ return; |
+ } |
+ |
+ uint32_t ret = target->OnDragOver(key_state, position, effect_bitmask); |
+ callback.Run(ret); |
+} |
+ |
+void WindowTreeClient::OnDragLeave(Id window_id) { |
+ Window* window = GetWindowByServerId(window_id); |
+ if (!window) |
+ return; |
+ |
+ WindowDropTarget* target = window->drop_target(); |
+ if (!target) |
+ return; |
+ |
+ target->OnDragLeave(); |
+} |
+ |
+void WindowTreeClient::OnDragFinish(Id window_id) { |
+ Window* window = GetWindowByServerId(window_id); |
+ if (!window) |
+ return; |
+ |
+ WindowDropTarget* target = window->drop_target(); |
+ if (!target) |
+ return; |
+ |
+ target->OnDragFinish(); |
+} |
+ |
+void WindowTreeClient::OnDragDrop(Id window_id, |
+ uint32_t key_state, |
+ const gfx::Point& position, |
+ uint32_t effect_bitmask, |
+ const OnDragDropCallback& callback) { |
+ Window* window = GetWindowByServerId(window_id); |
+ if (!window) { |
+ callback.Run(mojom::kDropEffectNone); |
+ return; |
+ } |
+ |
+ WindowDropTarget* target = window->drop_target(); |
+ if (!target) { |
+ callback.Run(mojom::kDropEffectNone); |
+ return; |
+ } |
+ |
+ uint32_t ret = target->OnDragDrop(key_state, position, effect_bitmask); |
+ callback.Run(ret); |
+} |
+ |
void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
in_flight_map_.erase(change_id); |
@@ -1079,6 +1214,15 @@ void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
on_current_move_finished_.Run(success); |
on_current_move_finished_.Reset(); |
} |
+ |
+ if (change_id == current_drag_change_) { |
+ if (change->window() && change->window()->drop_target()) |
+ change->window()->drop_target()->OnDragFinish(); |
+ |
+ current_drag_change_ = 0; |
+ on_current_drag_finished_.Run(success); |
+ on_current_drag_finished_.Reset(); |
+ } |
} |
void WindowTreeClient::GetWindowManager( |