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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 "base/memory/weak_ptr.h"
9 #include "services/ui/common/types.h"
10 #include "services/ui/ws/ids.h"
11 #include "services/ui/ws/server_window_observer.h"
12
13 namespace ui {
14 namespace ws {
15
16 namespace test {
17 class DragControllerTestApi;
18 }
19
20 class DragSource;
21 class DragTargetConnection;
22
23 // Represents all the data around the current ongoing drag operation.
24 //
25 // There should only be one instance of this class per userid. The
26 // WindowManagerState's EventDispatcher creates and owns this instance.
27 class DragController : public ServerWindowObserver {
28 public:
29 DragController(DragSource* source,
30 ServerWindow* source_window,
31 DragTargetConnection* source_connection,
32 int32_t drag_pointer,
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 void OnWillDestroyDragTargetConnection(DragTargetConnection* connection);
46
47 private:
48 friend class test::DragControllerTestApi;
49 enum class OperationType { NONE, ENTER, OVER, LEAVE, DROP };
50 struct Operation;
51 struct WindowState;
52
53 // Notifies all windows we messaged that the drag is finished, and then tell
54 // |source| the result.
55 void MessageDragCompleted(bool success);
56
57 // 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
59 // client, all values over 1 are queued and will be dispatched when the event
60 // in the front of the queue gets a response.
61 size_t GetSizeOfQueueForWindow(ServerWindow* window);
62
63 // Sets |current_target_window_| to |current_target|, making sure that we add
64 // and release ServerWindow observers correctly.
65 void SetCurrentTargetWindow(ServerWindow* current_target);
66
67 // Ensure that |window| has an entry in |window_state_| and that we're an
68 // observer.
69 void EnsureWindowObserved(ServerWindow* window);
70
71 void QueueOperation(ServerWindow* window,
72 OperationType type,
73 uint32_t event_flags,
74 gfx::Point screen_position);
75 void DispatchOperation(ServerWindow* window, WindowState* state);
76 void OnRespondToOperation(ServerWindow* window);
77
78 // Callback methods.
79 void OnDragStatusCompleted(const WindowId& id, uint32_t bitmask);
80 void OnDragDropCompleted(const WindowId& id, uint32_t bitmask);
81
82 // ServerWindowObserver:
83 void OnWindowDestroying(ServerWindow* window) override;
84
85 // Our owner.
86 DragSource* source_;
87
88 // A bit-field of acceptable drag operations offered by the source.
89 const uint32_t drag_operations_;
90
91 // Only act on pointer events that meet this id.
92 const int32_t drag_pointer_id_;
93
94 // 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.
96 bool waiting_for_final_drop_response_ = false;
97
98 ServerWindow* source_window_;
99 ServerWindow* current_target_window_ = nullptr;
100
101 // The target connection that |source_window_| is part of.
102 DragTargetConnection* source_connection_;
103
104 // A list of the offered mime types.
105 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data_;
106
107 // We need to keep track of state on a per window basis. A window being in
108 // this map means that we're observing it. WindowState also keeps track of
109 // what type of operation we're waiting for a response from the window's
110 // client, along with a queued operation to send when we get a reply.
111 std::map<ServerWindow*, WindowState> window_state_;
112
113 // A set of DragTargetConnections* which have received the
114 // PerformOnDragMimeTypes() call.
115 std::set<DragTargetConnection*> called_on_drag_mime_types_;
116
117 base::WeakPtrFactory<DragController> weak_factory_;
118
119 DISALLOW_COPY_AND_ASSIGN(DragController);
120 };
121
122 } // namespace ws
123 } // namespace ui
124
125 #endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698