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

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

Issue 1818333002: Reland: mus: Enable system modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_EVENT_DISPATCHER_H_ 5 #ifndef COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_
6 #define COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ 6 #define COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list>
10 #include <map> 11 #include <map>
11 #include <memory> 12 #include <memory>
12 13
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "cc/surfaces/surface_id.h" 15 #include "cc/surfaces/surface_id.h"
15 #include "components/mus/public/interfaces/input_event_matcher.mojom.h" 16 #include "components/mus/public/interfaces/input_event_matcher.mojom.h"
16 #include "components/mus/ws/server_window_observer.h" 17 #include "components/mus/ws/server_window_observer.h"
17 #include "ui/gfx/geometry/rect_f.h" 18 #include "ui/gfx/geometry/rect_f.h"
18 19
19 namespace ui { 20 namespace ui {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 54 }
54 55
55 // |capture_window_| will receive all input. See window_tree.mojom for 56 // |capture_window_| will receive all input. See window_tree.mojom for
56 // details. 57 // details.
57 ServerWindow* capture_window() { return capture_window_; } 58 ServerWindow* capture_window() { return capture_window_; }
58 const ServerWindow* capture_window() const { return capture_window_; } 59 const ServerWindow* capture_window() const { return capture_window_; }
59 // Setting capture can fail if the window is blocked by a modal window 60 // Setting capture can fail if the window is blocked by a modal window
60 // (indicated by returning |false|). 61 // (indicated by returning |false|).
61 bool SetCaptureWindow(ServerWindow* capture_window, bool in_nonclient_area); 62 bool SetCaptureWindow(ServerWindow* capture_window, bool in_nonclient_area);
62 63
64 // Adds a system modal window. The window remains modal to system until it is
65 // destroyed. There can exist multiple system modal windows, in which case the
66 // one that is visible and added most recently or shown most recently would be
67 // the active one.
68 void AddSystemModalWindow(ServerWindow* window);
69
70 // Checks if |modal_window| is a visible modal window that blocks current
71 // capture window and if that's the case, releases the capture.
72 void ReleaseCaptureBlockedByModalWindow(const ServerWindow* modal_window);
73
74 // Checks if the current capture window is blocked by any visible modal window
75 // and if that's the case, releases the capture.
76 void ReleaseCaptureBlockedByAnyModalWindow();
77
63 // Retrieves the ServerWindow of the last mouse move. 78 // Retrieves the ServerWindow of the last mouse move.
64 ServerWindow* mouse_cursor_source_window() const { 79 ServerWindow* mouse_cursor_source_window() const {
65 return mouse_cursor_source_window_; 80 return mouse_cursor_source_window_;
66 } 81 }
67 82
68 // Possibly updates the cursor. If we aren't in an implicit capture, we take 83 // Possibly updates the cursor. If we aren't in an implicit capture, we take
69 // the last known location of the mouse pointer, and look for the 84 // the last known location of the mouse pointer, and look for the
70 // ServerWindow* under it. 85 // ServerWindow* under it.
71 void UpdateCursorProviderByLastKnownLocation(); 86 void UpdateCursorProviderByLastKnownLocation();
72 87
73 // Adds an accelerator with the given id and event-matcher. If an accelerator 88 // Adds an accelerator with the given id and event-matcher. If an accelerator
74 // already exists with the same id or the same matcher, then the accelerator 89 // already exists with the same id or the same matcher, then the accelerator
75 // is not added. Returns whether adding the accelerator was successful or not. 90 // is not added. Returns whether adding the accelerator was successful or not.
76 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); 91 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher);
77 void RemoveAccelerator(uint32_t id); 92 void RemoveAccelerator(uint32_t id);
78 93
79 // Processes the supplied event, informing the delegate as approriate. This 94 // Processes the supplied event, informing the delegate as approriate. This
80 // may result in generating any number of events. 95 // may result in generating any number of events.
81 void ProcessEvent(const ui::Event& event); 96 void ProcessEvent(const ui::Event& event);
82 97
83 private: 98 private:
99 using ServerWindowList = std::list<ServerWindow*>;
84 friend class test::EventDispatcherTestApi; 100 friend class test::EventDispatcherTestApi;
85 101
86 // Keeps track of state associated with an active pointer. 102 // Keeps track of state associated with an active pointer.
87 struct PointerTarget { 103 struct PointerTarget {
88 PointerTarget() 104 PointerTarget()
89 : window(nullptr), 105 : window(nullptr),
90 is_mouse_event(false), 106 is_mouse_event(false),
91 in_nonclient_area(false), 107 in_nonclient_area(false),
92 is_pointer_down(false) {} 108 is_pointer_down(false) {}
93 109
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 157
142 // If |target->window| is valid, then passes the event to the delegate. 158 // If |target->window| is valid, then passes the event to the delegate.
143 void DispatchToPointerTarget(const PointerTarget& target, 159 void DispatchToPointerTarget(const PointerTarget& target,
144 const ui::LocatedEvent& event); 160 const ui::LocatedEvent& event);
145 161
146 // Stops sending pointer events to |window|. This does not remove the entry 162 // Stops sending pointer events to |window|. This does not remove the entry
147 // for |window| from |pointer_targets_|, rather it nulls out the window. This 163 // for |window| from |pointer_targets_|, rather it nulls out the window. This
148 // way we continue to eat events until the up/cancel is received. 164 // way we continue to eat events until the up/cancel is received.
149 void CancelPointerEventsToTarget(ServerWindow* window); 165 void CancelPointerEventsToTarget(ServerWindow* window);
150 166
151 // Returns true if we're currently an observer for |window|. We are an 167 // Used to observe a window. Can be called multiple times on a window. To
152 // observer for a window if any pointer events are targeting it. 168 // unobserve a window, UnobserveWindow() should be called the same number of
153 bool IsObservingWindow(ServerWindow* window); 169 // times.
170 void ObserveWindow(ServerWindow* winodw);
171 void UnobserveWindow(ServerWindow* winodw);
154 172
155 // Returns an Accelerator bound to the specified code/flags, and of the 173 // Returns an Accelerator bound to the specified code/flags, and of the
156 // matching |phase|. Otherwise returns null. 174 // matching |phase|. Otherwise returns null.
157 Accelerator* FindAccelerator(const ui::KeyEvent& event, 175 Accelerator* FindAccelerator(const ui::KeyEvent& event,
158 const mojom::AcceleratorPhase phase); 176 const mojom::AcceleratorPhase phase);
159 177
178 // Returns the system modal window that is visible and added/shown most
179 // recently, if any.
180 ServerWindow* GetActiveSystemModalWindow() const;
181
182 // Removes system modal window at the given iterator and unobserves it.
183 void RemoveSystemModalWindow(ServerWindowList::iterator it);
184
160 // ServerWindowObserver: 185 // ServerWindowObserver:
161 void OnWillChangeWindowHierarchy(ServerWindow* window, 186 void OnWillChangeWindowHierarchy(ServerWindow* window,
162 ServerWindow* new_parent, 187 ServerWindow* new_parent,
163 ServerWindow* old_parent) override; 188 ServerWindow* old_parent) override;
164 void OnWindowVisibilityChanged(ServerWindow* window) override; 189 void OnWindowVisibilityChanged(ServerWindow* window) override;
165 void OnWindowDestroyed(ServerWindow* window) override; 190 void OnWindowDestroyed(ServerWindow* window) override;
166 191
167 EventDispatcherDelegate* delegate_; 192 EventDispatcherDelegate* delegate_;
168 ServerWindow* root_; 193 ServerWindow* root_;
194
169 ServerWindow* capture_window_; 195 ServerWindow* capture_window_;
196 bool capture_window_in_nonclient_area_;
170 197
171 bool capture_window_in_nonclient_area_; 198 // List of system modal windows in order they are added/shown.
199 ServerWindowList system_modal_windows_;
200
172 bool mouse_button_down_; 201 bool mouse_button_down_;
173 ServerWindow* mouse_cursor_source_window_; 202 ServerWindow* mouse_cursor_source_window_;
174 203
175 // The on screen location of the mouse pointer. This can be outside the 204 // The on screen location of the mouse pointer. This can be outside the
176 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. 205 // bounds of |mouse_cursor_source_window_|, which can capture the cursor.
177 gfx::Point mouse_pointer_last_location_; 206 gfx::Point mouse_pointer_last_location_;
178 207
179 cc::SurfaceId surface_id_; 208 cc::SurfaceId surface_id_;
180 209
181 using Entry = std::pair<uint32_t, std::unique_ptr<Accelerator>>; 210 using Entry = std::pair<uint32_t, std::unique_ptr<Accelerator>>;
182 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_; 211 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_;
183 212
184 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; 213 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>;
185 // |pointer_targets_| contains the active pointers. For a mouse based pointer 214 // |pointer_targets_| contains the active pointers. For a mouse based pointer
186 // a PointerTarget is always active (and present in |pointer_targets_|). For 215 // a PointerTarget is always active (and present in |pointer_targets_|). For
187 // touch based pointers the pointer is active while down and removed on 216 // touch based pointers the pointer is active while down and removed on
188 // cancel or up. 217 // cancel or up.
189 PointerIdToTargetMap pointer_targets_; 218 PointerIdToTargetMap pointer_targets_;
190 219
220 // Keeps track of number of observe requests for each observed window.
221 std::map<const ServerWindow*, uint8_t> observed_windows_;
222
191 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); 223 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
192 }; 224 };
193 225
194 } // namespace ws 226 } // namespace ws
195 } // namespace mus 227 } // namespace mus
196 228
197 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ 229 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698