Index: services/ui/ws/drag_controller.h |
diff --git a/services/ui/ws/drag_controller.h b/services/ui/ws/drag_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..801081f3c8b57a5c5c2ecdc8433751a5ae82194d |
--- /dev/null |
+++ b/services/ui/ws/drag_controller.h |
@@ -0,0 +1,111 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SERVICES_UI_WS_DRAG_CONTROLLER_H_ |
+#define SERVICES_UI_WS_DRAG_CONTROLLER_H_ |
+ |
+#include <deque> |
+ |
+#include "base/memory/weak_ptr.h" |
+#include "services/ui/common/types.h" |
+#include "services/ui/ws/ids.h" |
+#include "services/ui/ws/server_window_observer.h" |
+ |
+namespace ui { |
+namespace ws { |
+ |
+namespace test { |
+class DragControllerTestApi; |
+} |
+ |
+class DragSource; |
+ |
+// Represents all the data around the current ongoing drag operation. |
+// |
+// There should only be one instance of this class per userid. The |
+// WindowManagerState's EventDispatcher creates and owns this instance. |
+class DragController : public ServerWindowObserver { |
+ public: |
+ DragController(DragSource* source, |
+ ServerWindow* window, |
+ int32_t darg_pointer, |
sky
2016/09/08 23:37:20
darg->drag
|
+ mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data, |
+ uint32_t drag_operations); |
+ ~DragController() override; |
+ |
+ // Cancels the current drag, ie, due to the user pressing Escape. |
+ void Cancel(); |
+ |
+ // Responds to a pointer move/release event. Returns true if the event was |
+ // handled by the drag. |
+ bool DispatchPointerEvent(const ui::PointerEvent& event, |
+ ServerWindow* current_target); |
+ |
+ private: |
+ friend class test::DragControllerTestApi; |
+ enum class EventType { ENTER, OVER, LEAVE, DROP }; |
+ struct Operation; |
+ |
+ // Notifies all windows we messaged that the drag is finished, and then tell |
+ // |source| the result. |
+ void MessageDragCompleted(bool success); |
+ |
+ // Returns the number of events on |window|. A value of 1 means that there's |
+ // a single event outstanding that we're waiting for a response from the |
+ // client, all values over 1 are queued and will be dispatched when the event |
+ // in the front of the queue gets a response. |
+ size_t GetSizeOfQueueForWindow(ServerWindow* window); |
+ |
+ 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
|
+ EventType type, |
+ uint32_t key_state, |
+ gfx::Point screen_position); |
+ void RemoveQueueFront(ServerWindow* window); |
+ void DispatchFrontOfWindowQueue(ServerWindow* window, |
+ std::deque<Operation>* queue); |
+ |
+ // Callback methods. |
+ void OnDragStatusCompleted(const WindowId& id, uint32_t bitmask); |
+ void OnDragDropCompleted(const WindowId& id, uint32_t bitmask); |
+ |
+ // ServerWindowObserver: |
+ void OnWindowDestroying(ServerWindow* window) override; |
+ |
+ // Our owner. |
+ DragSource* source_ = nullptr; |
+ |
+ // A bit-field of acceptable drag operations offered by the source. |
+ const uint32_t drag_operations_; |
+ |
+ // Only act on pointer events that meet this id. |
+ const int32_t drag_pointer_id_; |
+ |
+ // Sending OnDragOver() to our |source_| destroys us; there is a period where |
+ // we have to continue to exist, but not process any more pointer events. |
+ bool waiting_for_final_drop_response_ = false; |
+ |
+ ServerWindow* source_window_ = nullptr; |
sky
2016/09/08 23:37:21
You set this in the member initialize, so don't se
|
+ ServerWindow* current_target_window_ = nullptr; |
+ |
+ // A list of the offered mime types. |
+ mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data_; |
+ |
+ // Event queues for each window. If a vector is empty, there are no |
+ // operations going on. If a vector has one operation, we're waiting on a |
+ // response for that operation from the client. Every operation past the |
+ // first is queued. |
+ std::map<ServerWindow*, std::deque<Operation>> window_operations_; |
+ |
+ // A set of ServerWindows* which have received the PerformOnDragStart() call. |
+ std::set<ServerWindow*> called_on_drag_start_; |
+ |
+ base::WeakPtrFactory<DragController> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DragController); |
+}; |
+ |
+} // namespace ws |
+} // namespace ui |
+ |
+#endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_ |