Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Unified Diff: services/ui/ws/drag_controller.h

Issue 2266603002: mus: Implement interwindow drag and drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove 'window &&' Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1cd7d3ad4da13d7a207b61551b1db6521e1be74f
--- /dev/null
+++ b/services/ui/ws/drag_controller.h
@@ -0,0 +1,125 @@
+// 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 "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;
+class DragTargetConnection;
+
+// 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* source_window,
+ DragTargetConnection* source_connection,
+ int32_t drag_pointer,
+ 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);
+
+ void OnWillDestroyDragTargetConnection(DragTargetConnection* connection);
+
+ private:
+ friend class test::DragControllerTestApi;
+ enum class OperationType { NONE, ENTER, OVER, LEAVE, DROP };
+ struct Operation;
+ struct WindowState;
+
+ // 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);
+
+ // Sets |current_target_window_| to |current_target|, making sure that we add
+ // and release ServerWindow observers correctly.
+ void SetCurrentTargetWindow(ServerWindow* current_target);
+
+ // Ensure that |window| has an entry in |window_state_| and that we're an
+ // observer.
+ void EnsureWindowObserved(ServerWindow* window);
+
+ void QueueOperation(ServerWindow* window,
+ OperationType type,
+ uint32_t event_flags,
+ gfx::Point screen_position);
+ void DispatchOperation(ServerWindow* window, WindowState* state);
+ void OnRespondToOperation(ServerWindow* window);
+
+ // 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_;
+
+ // 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_;
+ ServerWindow* current_target_window_ = nullptr;
+
+ // The target connection that |source_window_| is part of.
+ DragTargetConnection* source_connection_;
+
+ // A list of the offered mime types.
+ mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data_;
+
+ // We need to keep track of state on a per window basis. A window being in
+ // this map means that we're observing it. WindowState also keeps track of
+ // what type of operation we're waiting for a response from the window's
+ // client, along with a queued operation to send when we get a reply.
+ std::map<ServerWindow*, WindowState> window_state_;
+
+ // A set of DragTargetConnections* which have received the
+ // PerformOnDragMimeTypes() call.
+ std::set<DragTargetConnection*> called_on_drag_mime_types_;
+
+ base::WeakPtrFactory<DragController> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DragController);
+};
+
+} // namespace ws
+} // namespace ui
+
+#endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698