Chromium Code Reviews| 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 #ifndef SERVICES_UI_WS_DRAG_CONTROLLER_H_ | 5 #ifndef SERVICES_UI_WS_DRAG_CONTROLLER_H_ |
| 6 #define SERVICES_UI_WS_DRAG_CONTROLLER_H_ | 6 #define SERVICES_UI_WS_DRAG_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "services/ui/common/types.h" | 9 #include "services/ui/common/types.h" |
| 10 #include "services/ui/ws/ids.h" | 10 #include "services/ui/ws/ids.h" |
| 11 #include "services/ui/ws/server_window_observer.h" | 11 #include "services/ui/ws/server_window_observer.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 namespace ws { | 14 namespace ws { |
| 15 | 15 |
| 16 namespace test { | 16 namespace test { |
| 17 class DragControllerTestApi; | 17 class DragControllerTestApi; |
| 18 } | 18 } |
| 19 | 19 |
| 20 class DragCursorUpdater; | |
| 20 class DragSource; | 21 class DragSource; |
| 21 class DragTargetConnection; | 22 class DragTargetConnection; |
| 22 | 23 |
| 23 // Represents all the data around the current ongoing drag operation. | 24 // Represents all the data around the current ongoing drag operation. |
| 24 // | 25 // |
| 25 // There should only be one instance of this class per userid. The | 26 // There should only be one instance of this class per userid. The |
| 26 // WindowManagerState's EventDispatcher creates and owns this instance. | 27 // WindowManagerState's EventDispatcher creates and owns this instance. |
| 27 class DragController : public ServerWindowObserver { | 28 class DragController : public ServerWindowObserver { |
| 28 public: | 29 public: |
| 29 DragController(DragSource* source, | 30 DragController(DragCursorUpdater* cursor_updater, |
| 31 DragSource* source, | |
| 30 ServerWindow* source_window, | 32 ServerWindow* source_window, |
| 31 DragTargetConnection* source_connection, | 33 DragTargetConnection* source_connection, |
| 32 int32_t drag_pointer, | 34 int32_t drag_pointer, |
| 33 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data, | 35 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data, |
| 34 uint32_t drag_operations); | 36 uint32_t drag_operations); |
| 35 ~DragController() override; | 37 ~DragController() override; |
| 36 | 38 |
| 39 int32_t current_cursor() { return current_cursor_; } | |
|
sky
2016/09/28 15:38:13
const
| |
| 40 | |
| 37 // Cancels the current drag, ie, due to the user pressing Escape. | 41 // Cancels the current drag, ie, due to the user pressing Escape. |
| 38 void Cancel(); | 42 void Cancel(); |
| 39 | 43 |
| 40 // Responds to a pointer move/release event. Returns true if the event was | 44 // Responds to a pointer move/release event. Returns true if the event was |
| 41 // handled by the drag. | 45 // handled by the drag. |
| 42 bool DispatchPointerEvent(const ui::PointerEvent& event, | 46 bool DispatchPointerEvent(const ui::PointerEvent& event, |
| 43 ServerWindow* current_target); | 47 ServerWindow* current_target); |
| 44 | 48 |
| 45 void OnWillDestroyDragTargetConnection(DragTargetConnection* connection); | 49 void OnWillDestroyDragTargetConnection(DragTargetConnection* connection); |
| 46 | 50 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 57 // Returns the number of events on |window|. A value of 1 means that there's | 61 // Returns the number of events on |window|. A value of 1 means that there's |
| 58 // a single event outstanding that we're waiting for a response from the | 62 // a single event outstanding that we're waiting for a response from the |
| 59 // client, all values over 1 are queued and will be dispatched when the event | 63 // client, all values over 1 are queued and will be dispatched when the event |
| 60 // in the front of the queue gets a response. | 64 // in the front of the queue gets a response. |
| 61 size_t GetSizeOfQueueForWindow(ServerWindow* window); | 65 size_t GetSizeOfQueueForWindow(ServerWindow* window); |
| 62 | 66 |
| 63 // Sets |current_target_window_| to |current_target|, making sure that we add | 67 // Sets |current_target_window_| to |current_target|, making sure that we add |
| 64 // and release ServerWindow observers correctly. | 68 // and release ServerWindow observers correctly. |
| 65 void SetCurrentTargetWindow(ServerWindow* current_target); | 69 void SetCurrentTargetWindow(ServerWindow* current_target); |
| 66 | 70 |
| 71 // Updates the possible cursor effects for |window|. |effect_bitmask| is a | |
| 72 // bitmask of the current valid drag operations. | |
| 73 void UpdateCursor(ServerWindow* window, uint32_t effect_bitmask); | |
|
sky
2016/09/28 15:38:13
This seems more like SetWindowDropOperations. It m
Elliot Glaysher
2016/09/28 18:15:31
Done.
| |
| 74 | |
| 75 // Returns the ui::mojom::Cursor for the window reporting it can handle | |
| 76 // |window_operations|. | |
| 77 int32_t CursorForWindowOperations(uint32_t window_operations); | |
|
sky
2016/09/28 15:38:13
Is there a reason you prefer using int32_t as the
Elliot Glaysher
2016/09/28 18:15:31
Because the consumer uses int32_t. I can, in a sep
| |
| 78 | |
| 67 // Ensure that |window| has an entry in |window_state_| and that we're an | 79 // Ensure that |window| has an entry in |window_state_| and that we're an |
| 68 // observer. | 80 // observer. |
| 69 void EnsureWindowObserved(ServerWindow* window); | 81 void EnsureWindowObserved(ServerWindow* window); |
| 70 | 82 |
| 71 void QueueOperation(ServerWindow* window, | 83 void QueueOperation(ServerWindow* window, |
| 72 OperationType type, | 84 OperationType type, |
| 73 uint32_t event_flags, | 85 uint32_t event_flags, |
| 74 gfx::Point screen_position); | 86 gfx::Point screen_position); |
| 75 void DispatchOperation(ServerWindow* window, WindowState* state); | 87 void DispatchOperation(ServerWindow* window, WindowState* state); |
| 76 void OnRespondToOperation(ServerWindow* window); | 88 void OnRespondToOperation(ServerWindow* window); |
| 77 | 89 |
| 78 // Callback methods. | 90 // Callback methods. |
| 79 void OnDragStatusCompleted(const WindowId& id, uint32_t bitmask); | 91 void OnDragStatusCompleted(const WindowId& id, uint32_t bitmask); |
| 80 void OnDragDropCompleted(const WindowId& id, uint32_t action); | 92 void OnDragDropCompleted(const WindowId& id, uint32_t action); |
| 81 | 93 |
| 82 // ServerWindowObserver: | 94 // ServerWindowObserver: |
| 83 void OnWindowDestroying(ServerWindow* window) override; | 95 void OnWindowDestroying(ServerWindow* window) override; |
| 84 | 96 |
| 85 // Our owner. | 97 // Our owner. |
| 86 DragSource* source_; | 98 DragSource* source_; |
| 87 | 99 |
| 100 // Object to notify about all cursor changes. | |
| 101 DragCursorUpdater* cursor_updater_; | |
| 102 | |
| 88 // A bit-field of acceptable drag operations offered by the source. | 103 // A bit-field of acceptable drag operations offered by the source. |
| 89 const uint32_t drag_operations_; | 104 const uint32_t drag_operations_; |
| 90 | 105 |
| 91 // Only act on pointer events that meet this id. | 106 // Only act on pointer events that meet this id. |
| 92 const int32_t drag_pointer_id_; | 107 const int32_t drag_pointer_id_; |
| 93 | 108 |
| 109 // The current mouse cursor during the drag. | |
| 110 int32_t current_cursor_; | |
| 111 | |
| 94 // Sending OnDragOver() to our |source_| destroys us; there is a period where | 112 // Sending OnDragOver() to our |source_| destroys us; there is a period where |
| 95 // we have to continue to exist, but not process any more pointer events. | 113 // we have to continue to exist, but not process any more pointer events. |
| 96 bool waiting_for_final_drop_response_ = false; | 114 bool waiting_for_final_drop_response_ = false; |
| 97 | 115 |
| 98 ServerWindow* source_window_; | 116 ServerWindow* source_window_; |
| 99 ServerWindow* current_target_window_ = nullptr; | 117 ServerWindow* current_target_window_ = nullptr; |
| 100 | 118 |
| 101 // The target connection that |source_window_| is part of. | 119 // The target connection that |source_window_| is part of. |
| 102 DragTargetConnection* source_connection_; | 120 DragTargetConnection* source_connection_; |
| 103 | 121 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 116 | 134 |
| 117 base::WeakPtrFactory<DragController> weak_factory_; | 135 base::WeakPtrFactory<DragController> weak_factory_; |
| 118 | 136 |
| 119 DISALLOW_COPY_AND_ASSIGN(DragController); | 137 DISALLOW_COPY_AND_ASSIGN(DragController); |
| 120 }; | 138 }; |
| 121 | 139 |
| 122 } // namespace ws | 140 } // namespace ws |
| 123 } // namespace ui | 141 } // namespace ui |
| 124 | 142 |
| 125 #endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_ | 143 #endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_ |
| OLD | NEW |