Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_UI_WS_DRAG_CONTROLLER_H_ | |
| 6 #define SERVICES_UI_WS_DRAG_CONTROLLER_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "services/ui/common/types.h" | |
| 12 #include "services/ui/ws/ids.h" | |
| 13 #include "services/ui/ws/server_window_observer.h" | |
| 14 | |
| 15 namespace ui { | |
| 16 namespace ws { | |
| 17 | |
| 18 namespace test { | |
| 19 class DragControllerTestApi; | |
| 20 } | |
| 21 | |
| 22 class DragSource; | |
| 23 class DragTargetConnection; | |
| 24 | |
| 25 // Represents all the data around the current ongoing drag operation. | |
| 26 // | |
| 27 // There should only be one instance of this class per userid. The | |
| 28 // WindowManagerState's EventDispatcher creates and owns this instance. | |
| 29 class DragController : public ServerWindowObserver { | |
| 30 public: | |
| 31 DragController(DragSource* source, | |
| 32 ServerWindow* source_window, | |
| 33 DragTargetConnection* source_connection, | |
| 34 int32_t drag_pointer, | |
| 35 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data, | |
| 36 uint32_t drag_operations); | |
| 37 ~DragController() override; | |
| 38 | |
| 39 // Cancels the current drag, ie, due to the user pressing Escape. | |
| 40 void Cancel(); | |
| 41 | |
| 42 // Responds to a pointer move/release event. Returns true if the event was | |
| 43 // handled by the drag. | |
| 44 bool DispatchPointerEvent(const ui::PointerEvent& event, | |
| 45 ServerWindow* current_target); | |
| 46 | |
| 47 void OnWillDestroyDragTargetConnection(DragTargetConnection* connection); | |
| 48 | |
| 49 private: | |
| 50 friend class test::DragControllerTestApi; | |
| 51 enum class OperationType { ENTER, OVER, LEAVE, DROP }; | |
| 52 struct Operation; | |
| 53 | |
| 54 // Notifies all windows we messaged that the drag is finished, and then tell | |
| 55 // |source| the result. | |
| 56 void MessageDragCompleted(bool success); | |
| 57 | |
| 58 // Returns the number of events on |window|. A value of 1 means that there's | |
| 59 // a single event outstanding that we're waiting for a response from the | |
| 60 // client, all values over 1 are queued and will be dispatched when the event | |
| 61 // in the front of the queue gets a response. | |
| 62 size_t GetSizeOfQueueForWindow(ServerWindow* window); | |
| 63 | |
| 64 // Sets |current_target_window_| to |current_target|, making sure that we add | |
| 65 // and release ServerWindow observers correctly. | |
| 66 void SetCurrentTargetWindow(ServerWindow* current_target); | |
| 67 | |
| 68 void QueueOperation(ServerWindow* window, | |
| 69 OperationType type, | |
| 70 uint32_t key_state, | |
| 71 gfx::Point screen_position); | |
| 72 void RemoveQueueFront(ServerWindow* window); | |
| 73 void DispatchFrontOfWindowQueue(ServerWindow* window, | |
| 74 std::deque<Operation>* queue); | |
| 75 | |
| 76 // Callback methods. | |
| 77 void OnDragStatusCompleted(const WindowId& id, uint32_t bitmask); | |
| 78 void OnDragDropCompleted(const WindowId& id, uint32_t bitmask); | |
| 79 | |
| 80 // ServerWindowObserver: | |
| 81 void OnWindowDestroying(ServerWindow* window) override; | |
| 82 | |
| 83 // Our owner. | |
| 84 DragSource* source_; | |
| 85 | |
| 86 // A bit-field of acceptable drag operations offered by the source. | |
| 87 const uint32_t drag_operations_; | |
| 88 | |
| 89 // Only act on pointer events that meet this id. | |
| 90 const int32_t drag_pointer_id_; | |
| 91 | |
| 92 // Sending OnDragOver() to our |source_| destroys us; there is a period where | |
| 93 // we have to continue to exist, but not process any more pointer events. | |
| 94 bool waiting_for_final_drop_response_ = false; | |
| 95 | |
| 96 ServerWindow* source_window_; | |
| 97 ServerWindow* current_target_window_ = nullptr; | |
| 98 | |
| 99 // The target connection that |source_window_| is part of. | |
| 100 DragTargetConnection* source_connection_; | |
| 101 | |
| 102 // A list of the offered mime types. | |
| 103 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data_; | |
| 104 | |
| 105 // Event queues for each window. If a vector is empty, there are no | |
| 106 // operations going on. If a vector has one operation, we're waiting on a | |
| 107 // response for that operation from the client. Every operation past the | |
| 108 // first is queued. | |
| 109 std::map<ServerWindow*, std::deque<Operation>> window_operations_; | |
|
sky
2016/09/13 18:15:31
Did you consider going with a structure other than
| |
| 110 | |
| 111 // A set of DragTargetConnections* which have received the | |
| 112 // PerformOnDragMimeTypes() call. | |
| 113 std::set<DragTargetConnection*> called_on_drag_mime_types_; | |
| 114 | |
| 115 base::WeakPtrFactory<DragController> weak_factory_; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(DragController); | |
| 118 }; | |
| 119 | |
| 120 } // namespace ws | |
| 121 } // namespace ui | |
| 122 | |
| 123 #endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_ | |
| OLD | NEW |