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

Side by Side Diff: components/mus/ws/window_manager_state.h

Issue 1775133003: Moves EventDispatcher from Display to WindowManagerState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: todo Created 4 years, 9 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
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 COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ 5 #ifndef COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_
6 #define COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ 6 #define COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/timer/timer.h"
11 #include "components/mus/public/interfaces/display.mojom.h" 12 #include "components/mus/public/interfaces/display.mojom.h"
13 #include "components/mus/ws/connection_manager.h"
14 #include "components/mus/ws/event_dispatcher.h"
15 #include "components/mus/ws/event_dispatcher_delegate.h"
12 #include "components/mus/ws/user_id.h" 16 #include "components/mus/ws/user_id.h"
13 17
18 namespace cc {
19 struct SurfaceId;
20 }
21
14 namespace mus { 22 namespace mus {
15 namespace ws { 23 namespace ws {
16 24
17 class Display; 25 class Display;
26 class PlatformDisplay;
18 class ServerWindow; 27 class ServerWindow;
19 class WindowTree; 28 class WindowTree;
20 29
30 namespace test {
31 class WindowManagerStateTestApi;
32 }
33
21 // Manages the state associated with a connection to a WindowManager for 34 // Manages the state associated with a connection to a WindowManager for
22 // a specific user. 35 // a specific user.
23 class WindowManagerState { 36 class WindowManagerState : public EventDispatcherDelegate {
24 public: 37 public:
25 // Creates a WindowManagerState that can host content from any user. 38 // Creates a WindowManagerState that can host content from any user.
26 explicit WindowManagerState(Display* display); 39 WindowManagerState(Display* display,
27 WindowManagerState(Display* display, const UserId& user_id); 40 PlatformDisplay* platform_display,
28 ~WindowManagerState(); 41 cc::SurfaceId surface_id);
42 WindowManagerState(Display* display,
43 PlatformDisplay* platform_display,
44 cc::SurfaceId surface_id,
45 const UserId& user_id);
46 ~WindowManagerState() override;
29 47
30 bool is_user_id_valid() const { return is_user_id_valid_; } 48 bool is_user_id_valid() const { return is_user_id_valid_; }
31 49
50 const UserId& user_id() const { return user_id_; }
51
32 ServerWindow* root() { return root_.get(); } 52 ServerWindow* root() { return root_.get(); }
33 const ServerWindow* root() const { return root_.get(); } 53 const ServerWindow* root() const { return root_.get(); }
34 54
35 WindowTree* tree() { return tree_; } 55 WindowTree* tree() { return tree_; }
36 const WindowTree* tree() const { return tree_; } 56 const WindowTree* tree() const { return tree_; }
37 57
38 Display* display() { return display_; } 58 Display* display() { return display_; }
39 const Display* display() const { return display_; } 59 const Display* display() const { return display_; }
40 60
41 void SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values); 61 void SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values);
42 const mojom::FrameDecorationValues& frame_decoration_values() const { 62 const mojom::FrameDecorationValues& frame_decoration_values() const {
43 return *frame_decoration_values_; 63 return *frame_decoration_values_;
44 } 64 }
45 bool got_frame_decoration_values() const { 65 bool got_frame_decoration_values() const {
46 return got_frame_decoration_values_; 66 return got_frame_decoration_values_;
47 } 67 }
48 68
69 void SetCapture(ServerWindow* window, bool in_nonclient_area);
70 ServerWindow* capture_window() { return event_dispatcher_.capture_window(); }
71 const ServerWindow* capture_window() const {
72 return event_dispatcher_.capture_window();
73 }
74
75 // Returns true if this is the WindowManager of the active user.
76 bool IsActive() const;
77
78 // TODO(sky): EventDispatcher is really an implementation detail and should
79 // not be exposed.
80 EventDispatcher* event_dispatcher() { return &event_dispatcher_; }
81
82 // Processes an event from PlatformDisplay.
83 void ProcessEvent(const ui::Event& event);
84
85 // Called when the ack from an event dispatched to a WindowTree is received.
86 // TODO(sky): make this private and use a callback.
87 void OnEventAck(mojom::WindowTree* tree);
88
49 // Returns a mojom::Display for the specified display. WindowManager specific 89 // Returns a mojom::Display for the specified display. WindowManager specific
50 // values are not set. 90 // values are not set.
51 mojom::DisplayPtr ToMojomDisplay() const; 91 mojom::DisplayPtr ToMojomDisplay() const;
52 92
93 void OnWillDestroyTree(WindowTree* tree);
94
53 private: 95 private:
96 class ProcessedEventTarget;
54 friend class Display; 97 friend class Display;
98 friend class test::WindowManagerStateTestApi;
55 99
56 WindowManagerState(Display* display, bool is_user_id_valid, 100 // There are two types of events that may be queued, both occur only when
101 // waiting for an ack from a client.
102 // . We get an event from the PlatformDisplay. This results in |event| being
103 // set, but |processed_target| is null.
104 // . We get an event from the EventDispatcher. In this case both |event| and
105 // |processed_target| are valid.
106 // The second case happens if EventDispatcher generates more than one event
107 // at a time.
108 struct QueuedEvent {
109 QueuedEvent();
110 ~QueuedEvent();
111
112 scoped_ptr<ui::Event> event;
113 scoped_ptr<ProcessedEventTarget> processed_target;
114 };
115
116 WindowManagerState(Display* display,
117 PlatformDisplay* platform_display,
118 cc::SurfaceId surface_id,
119 bool is_user_id_valid,
57 const UserId& user_id); 120 const UserId& user_id);
58 121
122 ConnectionManager* connection_manager();
123
124 void OnEventAckTimeout();
125
126 // Schedules an event to be processed later.
127 void QueueEvent(const ui::Event& event,
128 scoped_ptr<ProcessedEventTarget> processed_event_target);
129
130 // Processes the next valid event in |event_queue_|. If the event has already
131 // been processed it is dispatched, otherwise the event is passed to the
132 // EventDispatcher for processing.
133 void ProcessNextEventFromQueue();
134
135 // Dispatches the event to the appropriate client and starts the ack timer.
136 void DispatchInputEventToWindowImpl(ServerWindow* target,
137 bool in_nonclient_area,
138 const ui::Event& event);
139
140 // EventDispatcherDelegate:
141 void OnAccelerator(uint32_t accelerator_id, const ui::Event& event) override;
142 void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override;
143 ServerWindow* GetFocusedWindowForEventDispatcher() override;
144 void SetNativeCapture() override;
145 void ReleaseNativeCapture() override;
146 void OnServerWindowCaptureLost(ServerWindow* window) override;
147 void DispatchInputEventToWindow(ServerWindow* target,
148 bool in_nonclient_area,
149 const ui::Event& event) override;
150
59 Display* display_; 151 Display* display_;
152 PlatformDisplay* platform_display_;
60 // If this was created implicitly by a call 153 // If this was created implicitly by a call
61 // WindowTreeHostFactory::CreateWindowTreeHost(), then |is_user_id_valid_| 154 // WindowTreeHostFactory::CreateWindowTreeHost(), then |is_user_id_valid_|
62 // is false. 155 // is false.
63 const bool is_user_id_valid_; 156 const bool is_user_id_valid_;
64 const UserId user_id_; 157 const UserId user_id_;
158 // Root ServerWindow of this WindowManagerState. |root_| has a parent, the
159 // root ServerWindow of the Display.
65 scoped_ptr<ServerWindow> root_; 160 scoped_ptr<ServerWindow> root_;
66 WindowTree* tree_ = nullptr; 161 WindowTree* tree_ = nullptr;
67 162
68 // Set to true the first time SetFrameDecorationValues() is received. 163 // Set to true the first time SetFrameDecorationValues() is received.
69 bool got_frame_decoration_values_ = false; 164 bool got_frame_decoration_values_ = false;
70 mojom::FrameDecorationValuesPtr frame_decoration_values_; 165 mojom::FrameDecorationValuesPtr frame_decoration_values_;
71 166
167 mojom::WindowTree* tree_awaiting_input_ack_ = nullptr;
168 std::queue<scoped_ptr<QueuedEvent>> event_queue_;
169 base::OneShotTimer event_ack_timer_;
170
171 EventDispatcher event_dispatcher_;
172
72 DISALLOW_COPY_AND_ASSIGN(WindowManagerState); 173 DISALLOW_COPY_AND_ASSIGN(WindowManagerState);
73 }; 174 };
74 175
75 } // namespace ws 176 } // namespace ws
76 } // namespace mus 177 } // namespace mus
77 178
78 #endif // COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ 179 #endif // COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_
OLDNEW
« no previous file with comments | « components/mus/ws/window_manager_factory_registry.cc ('k') | components/mus/ws/window_manager_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698