Chromium Code Reviews| 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..470d31c48ada6e22e661efe2667a770cc900c81a 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,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) { |
|
sky
2016/09/08 23:37:20
combine with if on 1102?
|
| + 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) { |
|
sky
2016/09/08 23:37:20
Combine with if on 1123?
|
| + 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); |
| @@ -1066,6 +1202,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( |