Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Unified Diff: services/ui/public/cpp/window_tree_client.cc

Issue 2266603002: mus: Implement interwindow drag and drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 07f856e1a8e081a9bd603d99a7242ba836a62bf5..f76d86ea7ca1fc04b467d7750b4d2645d9a14a4d 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"
@@ -631,6 +632,34 @@ void WindowTreeClient::StopPointerWatcher() {
has_pointer_watcher_ = false;
}
+void WindowTreeClient::PerformDragDrop(
+ Window* window,
+ int drag_pointer,
+ 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(), drag_pointer,
+ mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data),
+ drag_operation);
+}
+
void WindowTreeClient::PerformWindowMove(
Window* window,
ui::mojom::MoveLoopSource source,
@@ -639,8 +668,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);
@@ -698,6 +727,11 @@ void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) {
observers_.RemoveObserver(observer);
}
+void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) {
+ DCHECK(tree_);
+ tree_->SetCanAcceptDrops(window_id, can_accept_drops);
+}
+
void WindowTreeClient::SetCanAcceptEvents(Id window_id,
bool can_accept_events) {
DCHECK(tree_);
@@ -1044,6 +1078,82 @@ void WindowTreeClient::OnWindowPredefinedCursorChanged(
WindowPrivate(window).LocalSetPredefinedCursor(cursor);
}
+void WindowTreeClient::OnDragMimeTypes(
+ mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) {
+ mime_drag_data_ = std::move(mime_data);
+}
+
+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 || !window->drop_target()) {
+ callback.Run(mojom::kDropEffectNone);
+ return;
+ }
+
+ if (!base::ContainsKey(entered_windows_, window_id)) {
+ window->drop_target()->OnDragStart(
+ mime_drag_data_.To<std::map<std::string, std::vector<uint8_t>>>());
+ }
+
+ uint32_t ret =
+ window->drop_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 || !window->drop_target()) {
+ callback.Run(mojom::kDropEffectNone);
+ return;
+ }
+
+ uint32_t ret =
+ window->drop_target()->OnDragOver(key_state, position, effect_bitmask);
+ callback.Run(ret);
+}
+
+void WindowTreeClient::OnDragLeave(Id window_id) {
+ Window* window = GetWindowByServerId(window_id);
+ if (!window || !window->drop_target())
+ return;
+
+ window->drop_target()->OnDragLeave();
+}
+
+void WindowTreeClient::OnDragFinish() {
+ for (Id id : entered_windows_) {
+ Window* window = GetWindowByServerId(id);
+ if (!window || !window->drop_target())
+ continue;
+ window->drop_target()->OnDragFinish();
+ }
+ entered_windows_.clear();
+}
+
+void WindowTreeClient::OnCompleteDrop(Id window_id,
+ uint32_t key_state,
+ const gfx::Point& position,
+ uint32_t effect_bitmask,
+ const OnCompleteDropCallback& callback) {
+ Window* window = GetWindowByServerId(window_id);
+ if (!window || !window->drop_target()) {
+ callback.Run(mojom::kDropEffectNone);
+ return;
+ }
+
+ uint32_t ret = window->drop_target()->OnCompleteDrop(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);
@@ -1066,6 +1176,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(

Powered by Google App Engine
This is Rietveld 408576698