OLD | NEW |
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 <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "cc/surfaces/surface_id.h" | 14 #include "cc/surfaces/surface_id.h" |
15 #include "components/mus/public/interfaces/event_matcher.mojom.h" | 15 #include "components/mus/public/interfaces/event_matcher.mojom.h" |
| 16 #include "components/mus/ws/modal_window_controller.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 { |
20 class Event; | 21 class Event; |
21 class KeyEvent; | 22 class KeyEvent; |
22 class LocatedEvent; | 23 class LocatedEvent; |
23 } | 24 } |
24 | 25 |
25 namespace mus { | 26 namespace mus { |
(...skipping 27 matching lines...) Expand all Loading... |
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 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 156 |
142 // If |target->window| is valid, then passes the event to the delegate. | 157 // If |target->window| is valid, then passes the event to the delegate. |
143 void DispatchToPointerTarget(const PointerTarget& target, | 158 void DispatchToPointerTarget(const PointerTarget& target, |
144 const ui::LocatedEvent& event); | 159 const ui::LocatedEvent& event); |
145 | 160 |
146 // Stops sending pointer events to |window|. This does not remove the entry | 161 // 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 | 162 // 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. | 163 // way we continue to eat events until the up/cancel is received. |
149 void CancelPointerEventsToTarget(ServerWindow* window); | 164 void CancelPointerEventsToTarget(ServerWindow* window); |
150 | 165 |
151 // Returns true if we're currently an observer for |window|. We are an | 166 // 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. | 167 // unobserve a window, UnobserveWindow() should be called the same number of |
153 bool IsObservingWindow(ServerWindow* window); | 168 // times. |
| 169 void ObserveWindow(ServerWindow* winodw); |
| 170 void UnobserveWindow(ServerWindow* winodw); |
154 | 171 |
155 // Returns an Accelerator bound to the specified code/flags, and of the | 172 // Returns an Accelerator bound to the specified code/flags, and of the |
156 // matching |phase|. Otherwise returns null. | 173 // matching |phase|. Otherwise returns null. |
157 Accelerator* FindAccelerator(const ui::KeyEvent& event, | 174 Accelerator* FindAccelerator(const ui::KeyEvent& event, |
158 const mojom::AcceleratorPhase phase); | 175 const mojom::AcceleratorPhase phase); |
159 | 176 |
160 // ServerWindowObserver: | 177 // ServerWindowObserver: |
161 void OnWillChangeWindowHierarchy(ServerWindow* window, | 178 void OnWillChangeWindowHierarchy(ServerWindow* window, |
162 ServerWindow* new_parent, | 179 ServerWindow* new_parent, |
163 ServerWindow* old_parent) override; | 180 ServerWindow* old_parent) override; |
164 void OnWindowVisibilityChanged(ServerWindow* window) override; | 181 void OnWindowVisibilityChanged(ServerWindow* window) override; |
165 void OnWindowDestroyed(ServerWindow* window) override; | 182 void OnWindowDestroyed(ServerWindow* window) override; |
166 | 183 |
167 EventDispatcherDelegate* delegate_; | 184 EventDispatcherDelegate* delegate_; |
168 ServerWindow* root_; | 185 ServerWindow* root_; |
| 186 |
169 ServerWindow* capture_window_; | 187 ServerWindow* capture_window_; |
| 188 bool capture_window_in_nonclient_area_; |
170 | 189 |
171 bool capture_window_in_nonclient_area_; | 190 ModalWindowController modal_window_controller_; |
| 191 |
172 bool mouse_button_down_; | 192 bool mouse_button_down_; |
173 ServerWindow* mouse_cursor_source_window_; | 193 ServerWindow* mouse_cursor_source_window_; |
174 | 194 |
175 // The on screen location of the mouse pointer. This can be outside the | 195 // 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. | 196 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. |
177 gfx::Point mouse_pointer_last_location_; | 197 gfx::Point mouse_pointer_last_location_; |
178 | 198 |
179 cc::SurfaceId surface_id_; | 199 cc::SurfaceId surface_id_; |
180 | 200 |
181 using Entry = std::pair<uint32_t, std::unique_ptr<Accelerator>>; | 201 using Entry = std::pair<uint32_t, std::unique_ptr<Accelerator>>; |
182 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_; | 202 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_; |
183 | 203 |
184 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; | 204 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; |
185 // |pointer_targets_| contains the active pointers. For a mouse based pointer | 205 // |pointer_targets_| contains the active pointers. For a mouse based pointer |
186 // a PointerTarget is always active (and present in |pointer_targets_|). For | 206 // a PointerTarget is always active (and present in |pointer_targets_|). For |
187 // touch based pointers the pointer is active while down and removed on | 207 // touch based pointers the pointer is active while down and removed on |
188 // cancel or up. | 208 // cancel or up. |
189 PointerIdToTargetMap pointer_targets_; | 209 PointerIdToTargetMap pointer_targets_; |
190 | 210 |
| 211 // Keeps track of number of observe requests for each observed window. |
| 212 std::map<const ServerWindow*, uint8_t> observed_windows_; |
| 213 |
191 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 214 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
192 }; | 215 }; |
193 | 216 |
194 } // namespace ws | 217 } // namespace ws |
195 } // namespace mus | 218 } // namespace mus |
196 | 219 |
197 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ | 220 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ |
OLD | NEW |