Chromium Code Reviews| Index: services/ui/ws/window_tree.cc |
| diff --git a/services/ui/ws/window_tree.cc b/services/ui/ws/window_tree.cc |
| index df00978bf891c44a37fc702eb7283ed09e4a30be..7ac04189dc15966ed68054cfc82ba002f51c2ae8 100644 |
| --- a/services/ui/ws/window_tree.cc |
| +++ b/services/ui/ws/window_tree.cc |
| @@ -78,7 +78,8 @@ WindowTree::WindowTree(WindowServer* window_server, |
| next_window_id_(1), |
| access_policy_(std::move(access_policy)), |
| event_ack_id_(0), |
| - window_manager_internal_(nullptr) { |
| + window_manager_internal_(nullptr), |
| + weak_factory_(this) { |
| if (root) |
| roots_.insert(root); |
| access_policy_->Init(id_, this); |
| @@ -233,6 +234,15 @@ void WindowTree::NotifyChangeCompleted( |
| change_id, error_code == mojom::WindowManagerErrorCode::SUCCESS); |
| } |
| +void WindowTree::OnWmMoveDragImageCompleted() { |
| + waiting_for_move_drag_ack_ = false; |
| + |
| + if (has_queued_drag_window_move_) { |
| + has_queued_drag_window_move_ = false; |
| + OnDragContinued(queued_cursor_location_); |
| + } |
| +} |
| + |
| bool WindowTree::SetCapture(const ClientWindowId& client_window_id) { |
| ServerWindow* window = GetWindowByClientId(client_window_id); |
| WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); |
| @@ -1790,8 +1800,15 @@ void WindowTree::GetCursorLocationMemory( |
| void WindowTree::PerformDragDrop( |
| uint32_t change_id, |
| Id source_window_id, |
| + const gfx::Point& screen_location, |
| const std::unordered_map<std::string, std::vector<uint8_t>>& drag_data, |
| - uint32_t drag_operation) { |
| + const SkBitmap& drag_image, |
| + const gfx::Vector2d& drag_image_offset, |
| + uint32_t drag_operation, |
| + ui::mojom::DragEventSource source) { |
| + // TODO(erg): SkBitmap is the wrong data type for the drag image; we should |
| + // be passing ImageSkias once http://crbug.com/655874 is implemented. |
| + |
| ServerWindow* window = GetWindowByClientId(ClientWindowId(source_window_id)); |
| bool success = window && access_policy_->CanInitiateDragLoop(window); |
| if (!success || !ShouldRouteToWindowManager(window)) { |
| @@ -1821,13 +1838,15 @@ void WindowTree::PerformDragDrop( |
| return; |
| } |
| - // TODO(erg): Dealing with |drag_representation| is hard, so we're going to |
| - // deal with that later. |
| + WindowManagerState* wms = display_root->window_manager_state(); |
| + |
| + // Send the drag representation to the window manager. |
| + wms->window_tree()->window_manager_internal_->WmBuildDragImage( |
| + screen_location, drag_image, drag_image_offset, source); |
| // Here, we need to dramatically change how the mouse pointer works. Once |
| // we've started a drag drop operation, cursor events don't go to windows as |
| // normal. |
| - WindowManagerState* wms = display_root->window_manager_state(); |
| window_server_->StartDragLoop(change_id, window, this); |
| wms->SetDragDropSourceWindow(this, window, this, drag_data, drag_operation); |
| } |
| @@ -2120,6 +2139,29 @@ bool WindowTree::IsWindowCreatedByWindowManager( |
| window->id().client_id; |
| } |
| +void WindowTree::OnDragContinued(const gfx::Point& location) { |
| + DCHECK(window_server_->in_drag_loop()); |
| + |
| + if (window_server_->GetCurrentDragLoopInitiator() != this) |
|
sky
2017/03/23 00:05:36
Remind me when this can ever be false? I'm wonderi
|
| + return; |
| + |
| + ServerWindow* window = window_server_->GetCurrentDragLoopWindow(); |
| + WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); |
| + if (!display_root) |
| + return; |
| + |
| + if (waiting_for_move_drag_ack_) { |
| + has_queued_drag_window_move_ = true; |
| + queued_cursor_location_ = location; |
| + } else { |
| + WindowManagerState* wms = display_root->window_manager_state(); |
| + waiting_for_move_drag_ack_ = true; |
| + wms->window_tree()->window_manager_internal_->WmMoveDragImage( |
| + location, base::Bind(&WindowTree::OnWmMoveDragImageCompleted, |
|
sky
2017/03/23 00:05:36
Using 'completed' in the name here makes me think
Elliot Glaysher
2017/03/23 19:58:44
Done.
|
| + weak_factory_.GetWeakPtr())); |
|
sky
2017/03/23 00:05:36
Can you reset weak_factory_ once the drag is compl
Elliot Glaysher
2017/03/23 19:58:44
Done.
|
| + } |
| +} |
| + |
| void WindowTree::OnDragCompleted(bool success, uint32_t action_taken) { |
| DCHECK(window_server_->in_drag_loop()); |
| @@ -2135,6 +2177,7 @@ void WindowTree::OnDragCompleted(bool success, uint32_t action_taken) { |
| window_server_->EndDragLoop(); |
| WindowManagerState* wms = display_root->window_manager_state(); |
| wms->EndDragDrop(); |
| + wms->window_tree()->window_manager_internal_->WmDestroyDragImage(); |
| client()->OnPerformDragDropCompleted(change_id, success, action_taken); |
| } |