Chromium Code Reviews| Index: services/ui/ws/drag_controller.cc |
| diff --git a/services/ui/ws/drag_controller.cc b/services/ui/ws/drag_controller.cc |
| index e6020d8e03be73d924e74484e8a69e3a0ccaca60..1914eee00def5f869468139aa5928c37c1c0ecdb 100644 |
| --- a/services/ui/ws/drag_controller.cc |
| +++ b/services/ui/ws/drag_controller.cc |
| @@ -5,6 +5,8 @@ |
| #include "services/ui/ws/drag_controller.h" |
| #include "base/logging.h" |
| +#include "services/ui/public/interfaces/cursor.mojom.h" |
| +#include "services/ui/ws/drag_cursor_updater.h" |
| #include "services/ui/ws/drag_source.h" |
| #include "services/ui/ws/drag_target_connection.h" |
| #include "services/ui/ws/event_dispatcher.h" |
| @@ -22,17 +24,22 @@ struct DragController::Operation { |
| struct DragController::WindowState { |
| // Set to true once we've observed the ServerWindow* that is the key to this |
| // instance in |window_state_|. |
| - bool observed; |
| + bool observed = false; |
| - // If we're waiting for a response, this is the type of message. TYPE_NONE |
| - // means there's no outstanding |
| - OperationType waiting_on_reply; |
| + // If we're waiting for a response, this is the type of message. NONE means |
| + // there's no outstanding |
| + OperationType waiting_on_reply = OperationType::NONE; |
| - // The operation that we'll send off if |waiting_on_reply| isn't TYPE_NONE. |
| - Operation queued_operation; |
| + // The operation that we'll send off if |waiting_on_reply| isn't NONE. |
| + Operation queued_operation = {OperationType::NONE, 0, gfx::Point()}; |
| + |
| + // The current set of operations that this window accepts. This gets updated |
| + // on each return message. |
| + uint32_t window_operations = 0u; |
|
sky
2016/09/28 15:38:13
Please be consistent in the naming. You have OnDra
Elliot Glaysher
2016/09/28 18:15:31
Created a DropEffect and DropEffectBitmask type in
|
| }; |
| DragController::DragController( |
| + DragCursorUpdater* cursor_updater, |
| DragSource* source, |
| ServerWindow* source_window, |
| DragTargetConnection* source_connection, |
| @@ -40,12 +47,15 @@ DragController::DragController( |
| mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data, |
| uint32_t drag_operations) |
| : source_(source), |
| + cursor_updater_(cursor_updater), |
| drag_operations_(drag_operations), |
| drag_pointer_id_(drag_pointer), |
| + current_cursor_(static_cast<int32_t>(ui::mojom::Cursor::NO_DROP)), |
| source_window_(source_window), |
| source_connection_(source_connection), |
| mime_data_(std::move(mime_data)), |
| weak_factory_(this) { |
| + SetCurrentTargetWindow(nullptr); |
| EnsureWindowObserved(source_window_); |
| } |
| @@ -149,8 +159,38 @@ size_t DragController::GetSizeOfQueueForWindow(ServerWindow* window) { |
| return 2u; |
| } |
| +void DragController::UpdateCursor(ServerWindow* window, |
| + uint32_t effect_bitmask) { |
| + WindowState& state = window_state_[window]; |
| + state.window_operations = effect_bitmask; |
| + |
| + if (current_target_window_ == window) { |
| + current_cursor_ = CursorForWindowOperations(effect_bitmask); |
| + cursor_updater_->OnDragCursorUpdated(); |
| + } |
| +} |
| + |
| +int32_t DragController::CursorForWindowOperations(uint32_t window_operations) { |
| + uint32_t combined = window_operations & drag_operations_; |
| + return combined == ui::mojom::kDropEffectNone |
| + ? static_cast<int32_t>(ui::mojom::Cursor::NO_DROP) |
| + : static_cast<int32_t>(ui::mojom::Cursor::COPY); |
|
sky
2016/09/28 15:38:13
No link?
Elliot Glaysher
2016/09/28 18:15:31
No link. I went through all the cursors and the on
|
| +} |
| + |
| void DragController::SetCurrentTargetWindow(ServerWindow* current_target) { |
| current_target_window_ = current_target; |
| + |
| + if (current_target_window_) { |
| + // Immediately set the cursor to the last known set of operations (which |
| + // could be none). |
| + WindowState& state = window_state_[current_target_window_]; |
| + current_cursor_ = CursorForWindowOperations(state.window_operations); |
| + } else { |
| + // Can't drop in empty areas. |
| + current_cursor_ = static_cast<int32_t>(ui::mojom::Cursor::NO_DROP); |
| + } |
| + |
| + cursor_updater_->OnDragCursorUpdated(); |
| } |
| void DragController::EnsureWindowObserved(ServerWindow* window) { |
| @@ -250,9 +290,7 @@ void DragController::OnDragStatusCompleted(const WindowId& id, |
| // We must remove the completed item. |
| OnRespondToOperation(window); |
| - |
| - // TODO(erg): |bitmask| is the allowed drag actions at the mouse location. We |
| - // should use this data to change the cursor. |
| + UpdateCursor(window, bitmask); |
| } |
| void DragController::OnDragDropCompleted(const WindowId& id, uint32_t action) { |
| @@ -277,7 +315,7 @@ void DragController::OnWindowDestroying(ServerWindow* window) { |
| } |
| if (current_target_window_ == window) |
| - current_target_window_ = nullptr; |
| + SetCurrentTargetWindow(nullptr); |
| if (source_window_ == window) { |
| source_window_ = nullptr; |