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 | |
| 24 // Represents all the data around the current ongoing drag operation. | |
| 25 // | |
| 26 // There should only be one instance of this class per userid. The | |
| 27 // WindowManagerState's EventDispatcher creates and owns this instance. | |
| 28 class DragController : public ServerWindowObserver { | |
| 29 public: | |
| 30 DragController(DragSource* source, | |
| 31 ServerWindow* window, | |
| 32 int32_t darg_pointer, | |
|
sky
2016/09/08 23:37:20
darg->drag
| |
| 33 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data, | |
| 34 uint32_t drag_operations); | |
| 35 ~DragController() override; | |
| 36 | |
| 37 // Cancels the current drag, ie, due to the user pressing Escape. | |
| 38 void Cancel(); | |
| 39 | |
| 40 // Responds to a pointer move/release event. Returns true if the event was | |
| 41 // handled by the drag. | |
| 42 bool DispatchPointerEvent(const ui::PointerEvent& event, | |
| 43 ServerWindow* current_target); | |
| 44 | |
| 45 private: | |
| 46 friend class test::DragControllerTestApi; | |
| 47 enum class EventType { ENTER, OVER, LEAVE, DROP }; | |
| 48 struct Operation; | |
| 49 | |
| 50 // Notifies all windows we messaged that the drag is finished, and then tell | |
| 51 // |source| the result. | |
| 52 void MessageDragCompleted(bool success); | |
| 53 | |
| 54 // Returns the number of events on |window|. A value of 1 means that there's | |
| 55 // a single event outstanding that we're waiting for a response from the | |
| 56 // client, all values over 1 are queued and will be dispatched when the event | |
| 57 // in the front of the queue gets a response. | |
| 58 size_t GetSizeOfQueueForWindow(ServerWindow* window); | |
| 59 | |
| 60 void QueueEvent(ServerWindow* window, | |
|
sky
2016/09/08 23:37:21
It seems like this duplicates event queuing logic
Elliot Glaysher
2016/09/13 00:14:19
This isn't clear to me.
The event queueing logic
sky
2016/09/13 18:15:31
I was hoping to share logic, in so far as waiting
| |
| 61 EventType type, | |
| 62 uint32_t key_state, | |
| 63 gfx::Point screen_position); | |
| 64 void RemoveQueueFront(ServerWindow* window); | |
| 65 void DispatchFrontOfWindowQueue(ServerWindow* window, | |
| 66 std::deque<Operation>* queue); | |
| 67 | |
| 68 // Callback methods. | |
| 69 void OnDragStatusCompleted(const WindowId& id, uint32_t bitmask); | |
| 70 void OnDragDropCompleted(const WindowId& id, uint32_t bitmask); | |
| 71 | |
| 72 // ServerWindowObserver: | |
| 73 void OnWindowDestroying(ServerWindow* window) override; | |
| 74 | |
| 75 // Our owner. | |
| 76 DragSource* source_ = nullptr; | |
| 77 | |
| 78 // A bit-field of acceptable drag operations offered by the source. | |
| 79 const uint32_t drag_operations_; | |
| 80 | |
| 81 // Only act on pointer events that meet this id. | |
| 82 const int32_t drag_pointer_id_; | |
| 83 | |
| 84 // Sending OnDragOver() to our |source_| destroys us; there is a period where | |
| 85 // we have to continue to exist, but not process any more pointer events. | |
| 86 bool waiting_for_final_drop_response_ = false; | |
| 87 | |
| 88 ServerWindow* source_window_ = nullptr; | |
|
sky
2016/09/08 23:37:21
You set this in the member initialize, so don't se
| |
| 89 ServerWindow* current_target_window_ = nullptr; | |
| 90 | |
| 91 // A list of the offered mime types. | |
| 92 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data_; | |
| 93 | |
| 94 // Event queues for each window. If a vector is empty, there are no | |
| 95 // operations going on. If a vector has one operation, we're waiting on a | |
| 96 // response for that operation from the client. Every operation past the | |
| 97 // first is queued. | |
| 98 std::map<ServerWindow*, std::deque<Operation>> window_operations_; | |
| 99 | |
| 100 // A set of ServerWindows* which have received the PerformOnDragStart() call. | |
| 101 std::set<ServerWindow*> called_on_drag_start_; | |
| 102 | |
| 103 base::WeakPtrFactory<DragController> weak_factory_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(DragController); | |
| 106 }; | |
| 107 | |
| 108 } // namespace ws | |
| 109 } // namespace ui | |
| 110 | |
| 111 #endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_ | |
| OLD | NEW |