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

Side by Side Diff: services/ui/ws/drag_controller.h

Issue 2376583003: mus: Keep track of the drag cursor during DnD operations. (Closed)
Patch Set: style Created 4 years, 2 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
« no previous file with comments | « services/ui/ws/BUILD.gn ('k') | services/ui/ws/drag_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SERVICES_UI_WS_DRAG_CONTROLLER_H_ 5 #ifndef SERVICES_UI_WS_DRAG_CONTROLLER_H_
6 #define SERVICES_UI_WS_DRAG_CONTROLLER_H_ 6 #define SERVICES_UI_WS_DRAG_CONTROLLER_H_
7 7
8 #include <map>
9 #include <set>
10
8 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
9 #include "services/ui/common/types.h" 12 #include "services/ui/common/types.h"
10 #include "services/ui/ws/ids.h" 13 #include "services/ui/ws/ids.h"
11 #include "services/ui/ws/server_window_observer.h" 14 #include "services/ui/ws/server_window_observer.h"
12 15
13 namespace ui { 16 namespace ui {
14 namespace ws { 17 namespace ws {
15 18
16 namespace test { 19 namespace test {
17 class DragControllerTestApi; 20 class DragControllerTestApi;
18 } 21 }
19 22
23 class DragCursorUpdater;
20 class DragSource; 24 class DragSource;
21 class DragTargetConnection; 25 class DragTargetConnection;
22 26
27 // A single ui::mojom::kDropEffect operation.
28 using DropEffect = uint32_t;
sky 2016/09/28 20:02:38 Nice! Thanks!
29
30 // A bitmask of ui::mojom::kDropEffect operations.
31 using DropEffectBitmask = uint32_t;
32
23 // Represents all the data around the current ongoing drag operation. 33 // Represents all the data around the current ongoing drag operation.
24 // 34 //
25 // There should only be one instance of this class per userid. The 35 // There should only be one instance of this class per userid. The
26 // WindowManagerState's EventDispatcher creates and owns this instance. 36 // WindowManagerState's EventDispatcher creates and owns this instance.
27 class DragController : public ServerWindowObserver { 37 class DragController : public ServerWindowObserver {
28 public: 38 public:
29 DragController(DragSource* source, 39 DragController(DragCursorUpdater* cursor_updater,
40 DragSource* source,
30 ServerWindow* source_window, 41 ServerWindow* source_window,
31 DragTargetConnection* source_connection, 42 DragTargetConnection* source_connection,
32 int32_t drag_pointer, 43 int32_t drag_pointer,
33 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data, 44 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data,
34 uint32_t drag_operations); 45 DropEffectBitmask drag_operations);
35 ~DragController() override; 46 ~DragController() override;
36 47
48 int32_t current_cursor() const { return current_cursor_; }
49
37 // Cancels the current drag, ie, due to the user pressing Escape. 50 // Cancels the current drag, ie, due to the user pressing Escape.
38 void Cancel(); 51 void Cancel();
39 52
40 // Responds to a pointer move/release event. Returns true if the event was 53 // Responds to a pointer move/release event. Returns true if the event was
41 // handled by the drag. 54 // handled by the drag.
42 bool DispatchPointerEvent(const ui::PointerEvent& event, 55 bool DispatchPointerEvent(const ui::PointerEvent& event,
43 ServerWindow* current_target); 56 ServerWindow* current_target);
44 57
45 void OnWillDestroyDragTargetConnection(DragTargetConnection* connection); 58 void OnWillDestroyDragTargetConnection(DragTargetConnection* connection);
46 59
47 private: 60 private:
48 friend class test::DragControllerTestApi; 61 friend class test::DragControllerTestApi;
49 enum class OperationType { NONE, ENTER, OVER, LEAVE, DROP }; 62 enum class OperationType { NONE, ENTER, OVER, LEAVE, DROP };
50 struct Operation; 63 struct Operation;
51 struct WindowState; 64 struct WindowState;
52 65
53 // Notifies all windows we messaged that the drag is finished, and then tell 66 // Notifies all windows we messaged that the drag is finished, and then tell
54 // |source| the result. 67 // |source| the result.
55 void MessageDragCompleted(bool success, uint32_t action_taken); 68 void MessageDragCompleted(bool success, DropEffect action_taken);
56 69
57 // Returns the number of events on |window|. A value of 1 means that there's 70 // 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 71 // 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 72 // client, all values over 1 are queued and will be dispatched when the event
60 // in the front of the queue gets a response. 73 // in the front of the queue gets a response.
61 size_t GetSizeOfQueueForWindow(ServerWindow* window); 74 size_t GetSizeOfQueueForWindow(ServerWindow* window);
62 75
63 // Sets |current_target_window_| to |current_target|, making sure that we add 76 // Sets |current_target_window_| to |current_target|, making sure that we add
64 // and release ServerWindow observers correctly. 77 // and release ServerWindow observers correctly.
65 void SetCurrentTargetWindow(ServerWindow* current_target); 78 void SetCurrentTargetWindow(ServerWindow* current_target);
66 79
80 // Updates the possible cursor effects for |window|. |bitmask| is a
81 // bitmask of the current valid drag operations.
82 void SetWindowDropOperations(ServerWindow* window, DropEffectBitmask bitmask);
83
84 // Returns the ui::mojom::Cursor for the window |bitmask|, adjusted for types
85 // that the drag source allows.
86 int32_t CursorForEffectBitmask(DropEffectBitmask bitmask);
87
67 // Ensure that |window| has an entry in |window_state_| and that we're an 88 // Ensure that |window| has an entry in |window_state_| and that we're an
68 // observer. 89 // observer.
69 void EnsureWindowObserved(ServerWindow* window); 90 void EnsureWindowObserved(ServerWindow* window);
70 91
71 void QueueOperation(ServerWindow* window, 92 void QueueOperation(ServerWindow* window,
72 OperationType type, 93 OperationType type,
73 uint32_t event_flags, 94 uint32_t event_flags,
74 gfx::Point screen_position); 95 gfx::Point screen_position);
75 void DispatchOperation(ServerWindow* window, WindowState* state); 96 void DispatchOperation(ServerWindow* window, WindowState* state);
76 void OnRespondToOperation(ServerWindow* window); 97 void OnRespondToOperation(ServerWindow* window);
77 98
78 // Callback methods. 99 // Callback methods.
79 void OnDragStatusCompleted(const WindowId& id, uint32_t bitmask); 100 void OnDragStatusCompleted(const WindowId& id, DropEffectBitmask bitmask);
80 void OnDragDropCompleted(const WindowId& id, uint32_t action); 101 void OnDragDropCompleted(const WindowId& id, DropEffect action);
81 102
82 // ServerWindowObserver: 103 // ServerWindowObserver:
83 void OnWindowDestroying(ServerWindow* window) override; 104 void OnWindowDestroying(ServerWindow* window) override;
84 105
85 // Our owner. 106 // Our owner.
86 DragSource* source_; 107 DragSource* source_;
87 108
109 // Object to notify about all cursor changes.
110 DragCursorUpdater* cursor_updater_;
111
88 // A bit-field of acceptable drag operations offered by the source. 112 // A bit-field of acceptable drag operations offered by the source.
89 const uint32_t drag_operations_; 113 const DropEffectBitmask drag_operations_;
90 114
91 // Only act on pointer events that meet this id. 115 // Only act on pointer events that meet this id.
92 const int32_t drag_pointer_id_; 116 const int32_t drag_pointer_id_;
93 117
118 // The current mouse cursor during the drag.
119 int32_t current_cursor_;
120
94 // Sending OnDragOver() to our |source_| destroys us; there is a period where 121 // 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. 122 // we have to continue to exist, but not process any more pointer events.
96 bool waiting_for_final_drop_response_ = false; 123 bool waiting_for_final_drop_response_ = false;
97 124
98 ServerWindow* source_window_; 125 ServerWindow* source_window_;
99 ServerWindow* current_target_window_ = nullptr; 126 ServerWindow* current_target_window_ = nullptr;
100 127
101 // The target connection that |source_window_| is part of. 128 // The target connection that |source_window_| is part of.
102 DragTargetConnection* source_connection_; 129 DragTargetConnection* source_connection_;
103 130
(...skipping 12 matching lines...) Expand all
116 143
117 base::WeakPtrFactory<DragController> weak_factory_; 144 base::WeakPtrFactory<DragController> weak_factory_;
118 145
119 DISALLOW_COPY_AND_ASSIGN(DragController); 146 DISALLOW_COPY_AND_ASSIGN(DragController);
120 }; 147 };
121 148
122 } // namespace ws 149 } // namespace ws
123 } // namespace ui 150 } // namespace ui
124 151
125 #endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_ 152 #endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_
OLDNEW
« no previous file with comments | « services/ui/ws/BUILD.gn ('k') | services/ui/ws/drag_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698