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

Side by Side Diff: services/ui/ws/drag_controller.cc

Issue 2349973010: mus drag and drop: return the completed effect to the caller. (Closed)
Patch Set: Rename some effect_taken to action_taken for consistency. 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 unified diff | Download patch
« no previous file with comments | « services/ui/ws/drag_controller.h ('k') | services/ui/ws/drag_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/ws/drag_controller.h" 5 #include "services/ui/ws/drag_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "services/ui/ws/drag_source.h" 8 #include "services/ui/ws/drag_source.h"
9 #include "services/ui/ws/drag_target_connection.h" 9 #include "services/ui/ws/drag_target_connection.h"
10 #include "services/ui/ws/event_dispatcher.h" 10 #include "services/ui/ws/event_dispatcher.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 DragController::~DragController() { 52 DragController::~DragController() {
53 for (auto& pair : window_state_) { 53 for (auto& pair : window_state_) {
54 if (pair.second.observed) 54 if (pair.second.observed)
55 pair.first->RemoveObserver(this); 55 pair.first->RemoveObserver(this);
56 } 56 }
57 } 57 }
58 58
59 void DragController::Cancel() { 59 void DragController::Cancel() {
60 MessageDragCompleted(false); 60 MessageDragCompleted(false, ui::mojom::kDropEffectNone);
61 // |this| may be deleted now. 61 // |this| may be deleted now.
62 } 62 }
63 63
64 bool DragController::DispatchPointerEvent(const ui::PointerEvent& event, 64 bool DragController::DispatchPointerEvent(const ui::PointerEvent& event,
65 ServerWindow* current_target) { 65 ServerWindow* current_target) {
66 uint32_t event_flags = 66 uint32_t event_flags =
67 event.flags() & 67 event.flags() &
68 (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN); 68 (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN);
69 gfx::Point screen_position = event.location(); 69 gfx::Point screen_position = event.location();
70 70
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 110 }
111 111
112 if (event.type() == ET_POINTER_UP) { 112 if (event.type() == ET_POINTER_UP) {
113 if (current_target) { 113 if (current_target) {
114 QueueOperation(current_target, OperationType::DROP, event_flags, 114 QueueOperation(current_target, OperationType::DROP, event_flags,
115 screen_position); 115 screen_position);
116 waiting_for_final_drop_response_ = true; 116 waiting_for_final_drop_response_ = true;
117 } else { 117 } else {
118 // The pointer was released over no window or a window that doesn't 118 // The pointer was released over no window or a window that doesn't
119 // accept drags. 119 // accept drags.
120 MessageDragCompleted(false); 120 MessageDragCompleted(false, ui::mojom::kDropEffectNone);
121 } 121 }
122 } 122 }
123 123
124 return true; 124 return true;
125 } 125 }
126 126
127 void DragController::OnWillDestroyDragTargetConnection( 127 void DragController::OnWillDestroyDragTargetConnection(
128 DragTargetConnection* connection) { 128 DragTargetConnection* connection) {
129 called_on_drag_mime_types_.erase(connection); 129 called_on_drag_mime_types_.erase(connection);
130 } 130 }
131 131
132 void DragController::MessageDragCompleted(bool success) { 132 void DragController::MessageDragCompleted(bool success, uint32_t action_taken) {
133 for (DragTargetConnection* connection : called_on_drag_mime_types_) 133 for (DragTargetConnection* connection : called_on_drag_mime_types_)
134 connection->PerformOnDragDropDone(); 134 connection->PerformOnDragDropDone();
135 called_on_drag_mime_types_.clear(); 135 called_on_drag_mime_types_.clear();
136 136
137 source_->OnDragCompleted(success); 137 source_->OnDragCompleted(success, action_taken);
138 // |this| may be deleted now. 138 // |this| may be deleted now.
139 } 139 }
140 140
141 size_t DragController::GetSizeOfQueueForWindow(ServerWindow* window) { 141 size_t DragController::GetSizeOfQueueForWindow(ServerWindow* window) {
142 auto it = window_state_.find(window); 142 auto it = window_state_.find(window);
143 if (it == window_state_.end()) 143 if (it == window_state_.end())
144 return 0u; 144 return 0u;
145 if (it->second.waiting_on_reply == OperationType::NONE) 145 if (it->second.waiting_on_reply == OperationType::NONE)
146 return 0u; 146 return 0u;
147 if (it->second.queued_operation.type == OperationType::NONE) 147 if (it->second.queued_operation.type == OperationType::NONE)
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return; 248 return;
249 } 249 }
250 250
251 // We must remove the completed item. 251 // We must remove the completed item.
252 OnRespondToOperation(window); 252 OnRespondToOperation(window);
253 253
254 // TODO(erg): |bitmask| is the allowed drag actions at the mouse location. We 254 // TODO(erg): |bitmask| is the allowed drag actions at the mouse location. We
255 // should use this data to change the cursor. 255 // should use this data to change the cursor.
256 } 256 }
257 257
258 void DragController::OnDragDropCompleted(const WindowId& id, uint32_t bitmask) { 258 void DragController::OnDragDropCompleted(const WindowId& id, uint32_t action) {
259 ServerWindow* window = source_->GetWindowById(id); 259 ServerWindow* window = source_->GetWindowById(id);
260 if (!window) { 260 if (!window) {
261 // The window has been deleted after we sent the drop message. It's really 261 // The window has been deleted after we sent the drop message. It's really
262 // hard to recover from this so just signal to the source that our drag 262 // hard to recover from this so just signal to the source that our drag
263 // failed. 263 // failed.
264 MessageDragCompleted(false); 264 MessageDragCompleted(false, ui::mojom::kDropEffectNone);
265 return; 265 return;
266 } 266 }
267 267
268 OnRespondToOperation(window); 268 OnRespondToOperation(window);
269 MessageDragCompleted(bitmask != 0u); 269 MessageDragCompleted(action != 0u, action);
270 } 270 }
271 271
272 void DragController::OnWindowDestroying(ServerWindow* window) { 272 void DragController::OnWindowDestroying(ServerWindow* window) {
273 auto it = window_state_.find(window); 273 auto it = window_state_.find(window);
274 if (it != window_state_.end()) { 274 if (it != window_state_.end()) {
275 window->RemoveObserver(this); 275 window->RemoveObserver(this);
276 window_state_.erase(it); 276 window_state_.erase(it);
277 } 277 }
278 278
279 if (current_target_window_ == window) 279 if (current_target_window_ == window)
280 current_target_window_ = nullptr; 280 current_target_window_ = nullptr;
281 281
282 if (source_window_ == window) { 282 if (source_window_ == window) {
283 source_window_ = nullptr; 283 source_window_ = nullptr;
284 // Our source window is being deleted, fail the drag. 284 // Our source window is being deleted, fail the drag.
285 MessageDragCompleted(false); 285 MessageDragCompleted(false, ui::mojom::kDropEffectNone);
286 } 286 }
287 } 287 }
288 288
289 } // namespace ws 289 } // namespace ws
290 } // namespace ui 290 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/drag_controller.h ('k') | services/ui/ws/drag_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698