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/cursor.mojom.h" | 10 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" |
11 #include "services/ui/ws/drag_cursor_updater.h" | 11 #include "services/ui/ws/drag_cursor_updater.h" |
12 #include "services/ui/ws/drag_source.h" | 12 #include "services/ui/ws/drag_source.h" |
13 #include "services/ui/ws/drag_target_connection.h" | 13 #include "services/ui/ws/drag_target_connection.h" |
14 #include "services/ui/ws/event_dispatcher.h" | 14 #include "services/ui/ws/event_dispatcher.h" |
15 #include "services/ui/ws/server_window.h" | 15 #include "services/ui/ws/server_window.h" |
| 16 #include "ui/base/cursor/cursor.h" |
16 | 17 |
17 namespace ui { | 18 namespace ui { |
18 namespace ws { | 19 namespace ws { |
19 | 20 |
20 struct DragController::Operation { | 21 struct DragController::Operation { |
21 OperationType type; | 22 OperationType type; |
22 uint32_t event_flags; | 23 uint32_t event_flags; |
23 gfx::Point screen_position; | 24 gfx::Point screen_position; |
24 }; | 25 }; |
25 | 26 |
(...skipping 19 matching lines...) Expand all Loading... |
45 DragSource* source, | 46 DragSource* source, |
46 ServerWindow* source_window, | 47 ServerWindow* source_window, |
47 DragTargetConnection* source_connection, | 48 DragTargetConnection* source_connection, |
48 int32_t drag_pointer, | 49 int32_t drag_pointer, |
49 const std::unordered_map<std::string, std::vector<uint8_t>>& mime_data, | 50 const std::unordered_map<std::string, std::vector<uint8_t>>& mime_data, |
50 DropEffectBitmask drag_operations) | 51 DropEffectBitmask drag_operations) |
51 : source_(source), | 52 : source_(source), |
52 cursor_updater_(cursor_updater), | 53 cursor_updater_(cursor_updater), |
53 drag_operations_(drag_operations), | 54 drag_operations_(drag_operations), |
54 drag_pointer_id_(drag_pointer), | 55 drag_pointer_id_(drag_pointer), |
55 current_cursor_(ui::mojom::CursorType::kNoDrop), | 56 current_cursor_(ui::CursorType::kNoDrop), |
56 source_window_(source_window), | 57 source_window_(source_window), |
57 source_connection_(source_connection), | 58 source_connection_(source_connection), |
58 mime_data_(mime_data), | 59 mime_data_(mime_data), |
59 weak_factory_(this) { | 60 weak_factory_(this) { |
60 SetCurrentTargetWindow(nullptr); | 61 SetCurrentTargetWindow(nullptr); |
61 EnsureWindowObserved(source_window_); | 62 EnsureWindowObserved(source_window_); |
62 } | 63 } |
63 | 64 |
64 DragController::~DragController() { | 65 DragController::~DragController() { |
65 for (auto& pair : window_state_) { | 66 for (auto& pair : window_state_) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 DropEffectBitmask bitmask) { | 181 DropEffectBitmask bitmask) { |
181 WindowState& state = window_state_[window]; | 182 WindowState& state = window_state_[window]; |
182 state.bitmask = bitmask; | 183 state.bitmask = bitmask; |
183 | 184 |
184 if (current_target_window_ == window) { | 185 if (current_target_window_ == window) { |
185 current_cursor_ = CursorForEffectBitmask(bitmask); | 186 current_cursor_ = CursorForEffectBitmask(bitmask); |
186 cursor_updater_->OnDragCursorUpdated(); | 187 cursor_updater_->OnDragCursorUpdated(); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 ui::mojom::CursorType DragController::CursorForEffectBitmask( | 191 ui::CursorData DragController::CursorForEffectBitmask( |
191 DropEffectBitmask bitmask) { | 192 DropEffectBitmask bitmask) { |
192 DropEffectBitmask combined = bitmask & drag_operations_; | 193 DropEffectBitmask combined = bitmask & drag_operations_; |
193 return combined == ui::mojom::kDropEffectNone ? ui::mojom::CursorType::kNoDrop | 194 return combined == ui::mojom::kDropEffectNone |
194 : ui::mojom::CursorType::kCopy; | 195 ? ui::CursorData(ui::CursorType::kNoDrop) |
| 196 : ui::CursorData(ui::CursorType::kCopy); |
195 } | 197 } |
196 | 198 |
197 void DragController::SetCurrentTargetWindow(ServerWindow* current_target) { | 199 void DragController::SetCurrentTargetWindow(ServerWindow* current_target) { |
198 current_target_window_ = current_target; | 200 current_target_window_ = current_target; |
199 | 201 |
200 if (current_target_window_) { | 202 if (current_target_window_) { |
201 // Immediately set the cursor to the last known set of operations (which | 203 // Immediately set the cursor to the last known set of operations (which |
202 // could be none). | 204 // could be none). |
203 WindowState& state = window_state_[current_target_window_]; | 205 WindowState& state = window_state_[current_target_window_]; |
204 current_cursor_ = CursorForEffectBitmask(state.bitmask); | 206 current_cursor_ = CursorForEffectBitmask(state.bitmask); |
205 } else { | 207 } else { |
206 // Can't drop in empty areas. | 208 // Can't drop in empty areas. |
207 current_cursor_ = ui::mojom::CursorType::kNoDrop; | 209 current_cursor_ = ui::CursorData(ui::CursorType::kNoDrop); |
208 } | 210 } |
209 | 211 |
210 cursor_updater_->OnDragCursorUpdated(); | 212 cursor_updater_->OnDragCursorUpdated(); |
211 } | 213 } |
212 | 214 |
213 void DragController::EnsureWindowObserved(ServerWindow* window) { | 215 void DragController::EnsureWindowObserved(ServerWindow* window) { |
214 if (!window) | 216 if (!window) |
215 return; | 217 return; |
216 | 218 |
217 WindowState& state = window_state_[window]; | 219 WindowState& state = window_state_[window]; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 return "LEAVE"; | 359 return "LEAVE"; |
358 case OperationType::DROP: | 360 case OperationType::DROP: |
359 return "DROP"; | 361 return "DROP"; |
360 } | 362 } |
361 NOTREACHED(); | 363 NOTREACHED(); |
362 return std::string(); | 364 return std::string(); |
363 } | 365 } |
364 | 366 |
365 } // namespace ws | 367 } // namespace ws |
366 } // namespace ui | 368 } // namespace ui |
OLD | NEW |