OLD | NEW |
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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "services/ui/public/interfaces/cursor.mojom.h" | 10 #include "services/ui/public/interfaces/cursor.mojom.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 void DragController::Cancel() { | 71 void DragController::Cancel() { |
72 MessageDragCompleted(false, ui::mojom::kDropEffectNone); | 72 MessageDragCompleted(false, ui::mojom::kDropEffectNone); |
73 // |this| may be deleted now. | 73 // |this| may be deleted now. |
74 } | 74 } |
75 | 75 |
76 bool DragController::DispatchPointerEvent(const ui::PointerEvent& event, | 76 bool DragController::DispatchPointerEvent(const ui::PointerEvent& event, |
77 ServerWindow* current_target) { | 77 ServerWindow* current_target) { |
| 78 DVLOG(2) << "DragController dispatching pointer event at " |
| 79 << event.location().ToString(); |
78 uint32_t event_flags = | 80 uint32_t event_flags = |
79 event.flags() & | 81 event.flags() & |
80 (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN); | 82 (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN); |
81 gfx::Point screen_position = event.location(); | 83 gfx::Point screen_position = event.location(); |
82 | 84 |
83 if (waiting_for_final_drop_response_) { | 85 if (waiting_for_final_drop_response_) { |
84 // If we're waiting on a target window to respond to the final drag drop | 86 // If we're waiting on a target window to respond to the final drag drop |
85 // call, don't process any more pointer events. | 87 // call, don't process any more pointer events. |
| 88 DVLOG(1) << "Ignoring event because we're waiting for final drop response"; |
86 return false; | 89 return false; |
87 } | 90 } |
88 | 91 |
89 if (event.pointer_details().id != drag_pointer_id_) | 92 if (event.pointer_details().id != drag_pointer_id_) { |
| 93 DVLOG(1) << "Ignoring event from different pointer " |
| 94 << event.pointer_details().id; |
90 return false; | 95 return false; |
| 96 } |
91 | 97 |
92 // If |current_target| doesn't accept drags, walk its hierarchy up until we | 98 // If |current_target| doesn't accept drags, walk its hierarchy up until we |
93 // find one that does (or set to nullptr at the top of the tree). | 99 // find one that does (or set to nullptr at the top of the tree). |
94 while (current_target && !current_target->can_accept_drops()) | 100 while (current_target && !current_target->can_accept_drops()) |
95 current_target = current_target->parent(); | 101 current_target = current_target->parent(); |
96 | 102 |
97 if (current_target) { | 103 if (current_target) { |
98 // If we're non-null, we're about to use |current_target| in some | 104 // If we're non-null, we're about to use |current_target| in some |
99 // way. Ensure that we receive notifications that this window has gone | 105 // way. Ensure that we receive notifications that this window has gone |
100 // away. | 106 // away. |
(...skipping 11 matching lines...) Expand all Loading... |
112 } | 118 } |
113 | 119 |
114 if (current_target) { | 120 if (current_target) { |
115 // TODO(erg): If we have a queued LEAVE operation, does this turn into a | 121 // TODO(erg): If we have a queued LEAVE operation, does this turn into a |
116 // noop? | 122 // noop? |
117 QueueOperation(current_target, OperationType::ENTER, event_flags, | 123 QueueOperation(current_target, OperationType::ENTER, event_flags, |
118 screen_position); | 124 screen_position); |
119 } | 125 } |
120 | 126 |
121 SetCurrentTargetWindow(current_target); | 127 SetCurrentTargetWindow(current_target); |
| 128 } else if (event.type() != ET_POINTER_UP) { |
| 129 DVLOG(1) << "Performing no action for pointer event at " |
| 130 << screen_position.ToString() |
| 131 << "! current_target=" << current_target; |
122 } | 132 } |
123 | 133 |
124 if (event.type() == ET_POINTER_UP) { | 134 if (event.type() == ET_POINTER_UP) { |
125 if (current_target) { | 135 if (current_target) { |
126 QueueOperation(current_target, OperationType::DROP, event_flags, | 136 QueueOperation(current_target, OperationType::DROP, event_flags, |
127 screen_position); | 137 screen_position); |
128 waiting_for_final_drop_response_ = true; | 138 waiting_for_final_drop_response_ = true; |
129 } else { | 139 } else { |
130 // The pointer was released over no window or a window that doesn't | 140 // The pointer was released over no window or a window that doesn't |
131 // accept drags. | 141 // accept drags. |
132 MessageDragCompleted(false, ui::mojom::kDropEffectNone); | 142 MessageDragCompleted(false, ui::mojom::kDropEffectNone); |
133 } | 143 } |
134 } | 144 } |
135 | 145 |
136 return true; | 146 return true; |
137 } | 147 } |
138 | 148 |
139 void DragController::OnWillDestroyDragTargetConnection( | 149 void DragController::OnWillDestroyDragTargetConnection( |
140 DragTargetConnection* connection) { | 150 DragTargetConnection* connection) { |
141 called_on_drag_mime_types_.erase(connection); | 151 called_on_drag_mime_types_.erase(connection); |
142 } | 152 } |
143 | 153 |
144 void DragController::MessageDragCompleted(bool success, | 154 void DragController::MessageDragCompleted(bool success, |
145 DropEffect action_taken) { | 155 DropEffect action_taken) { |
| 156 DVLOG(1) << "Drag Completed: success=" << success |
| 157 << ", action_taken=" << action_taken; |
146 for (DragTargetConnection* connection : called_on_drag_mime_types_) | 158 for (DragTargetConnection* connection : called_on_drag_mime_types_) |
147 connection->PerformOnDragDropDone(); | 159 connection->PerformOnDragDropDone(); |
148 called_on_drag_mime_types_.clear(); | 160 called_on_drag_mime_types_.clear(); |
149 | 161 |
150 source_->OnDragCompleted(success, action_taken); | 162 source_->OnDragCompleted(success, action_taken); |
151 // |this| may be deleted now. | 163 // |this| may be deleted now. |
152 } | 164 } |
153 | 165 |
154 size_t DragController::GetSizeOfQueueForWindow(ServerWindow* window) { | 166 size_t DragController::GetSizeOfQueueForWindow(ServerWindow* window) { |
155 auto it = window_state_.find(window); | 167 auto it = window_state_.find(window); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (!state.observed) { | 217 if (!state.observed) { |
206 state.observed = true; | 218 state.observed = true; |
207 window->AddObserver(this); | 219 window->AddObserver(this); |
208 } | 220 } |
209 } | 221 } |
210 | 222 |
211 void DragController::QueueOperation(ServerWindow* window, | 223 void DragController::QueueOperation(ServerWindow* window, |
212 OperationType type, | 224 OperationType type, |
213 uint32_t event_flags, | 225 uint32_t event_flags, |
214 const gfx::Point& screen_position) { | 226 const gfx::Point& screen_position) { |
| 227 DVLOG(2) << "Queueing operation " << ToString(type) << " to " << window; |
| 228 |
215 // If this window doesn't have the mime data, send it. | 229 // If this window doesn't have the mime data, send it. |
216 DragTargetConnection* connection = source_->GetDragTargetForWindow(window); | 230 DragTargetConnection* connection = source_->GetDragTargetForWindow(window); |
217 if (connection != source_connection_ && | 231 if (connection != source_connection_ && |
218 !base::ContainsKey(called_on_drag_mime_types_, connection)) { | 232 !base::ContainsKey(called_on_drag_mime_types_, connection)) { |
219 connection->PerformOnDragDropStart(mime_data_); | 233 connection->PerformOnDragDropStart(mime_data_); |
220 called_on_drag_mime_types_.insert(connection); | 234 called_on_drag_mime_types_.insert(connection); |
221 } | 235 } |
222 | 236 |
223 WindowState& state = window_state_[window]; | 237 WindowState& state = window_state_[window]; |
224 // Set the queued operation to the incoming. | 238 // Set the queued operation to the incoming. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 if (current_target_window_ == window) | 336 if (current_target_window_ == window) |
323 SetCurrentTargetWindow(nullptr); | 337 SetCurrentTargetWindow(nullptr); |
324 | 338 |
325 if (source_window_ == window) { | 339 if (source_window_ == window) { |
326 source_window_ = nullptr; | 340 source_window_ = nullptr; |
327 // Our source window is being deleted, fail the drag. | 341 // Our source window is being deleted, fail the drag. |
328 MessageDragCompleted(false, ui::mojom::kDropEffectNone); | 342 MessageDragCompleted(false, ui::mojom::kDropEffectNone); |
329 } | 343 } |
330 } | 344 } |
331 | 345 |
| 346 // static |
| 347 std::string DragController::ToString(OperationType type) { |
| 348 switch (type) { |
| 349 case OperationType::NONE: |
| 350 return "NONE"; |
| 351 case OperationType::ENTER: |
| 352 return "ENTER"; |
| 353 case OperationType::OVER: |
| 354 return "OVER"; |
| 355 case OperationType::LEAVE: |
| 356 return "LEAVE"; |
| 357 case OperationType::DROP: |
| 358 return "DROP"; |
| 359 } |
| 360 NOTREACHED(); |
| 361 return std::string(); |
| 362 } |
| 363 |
332 } // namespace ws | 364 } // namespace ws |
333 } // namespace ui | 365 } // namespace ui |
OLD | NEW |