OLD | NEW |
---|---|
(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 COMPONENTS_MUS_WS_MODAL_WINDOW_CONTROLLER_H_ | |
6 #define COMPONENTS_MUS_WS_MODAL_WINDOW_CONTROLLER_H_ | |
7 | |
8 #include <list> | |
9 | |
10 #include "components/mus/ws/server_window_observer.h" | |
11 | |
12 namespace mus { | |
13 namespace ws { | |
14 | |
15 class EventDispatcher; | |
16 class ServerWindow; | |
17 | |
18 namespace test { | |
19 class EventDispatcherTestApi; | |
sky
2016/04/26 23:40:08
Create a ModalWindowControllerTestApi class and fr
mohsen
2016/04/27 20:18:25
Done.
| |
20 } | |
21 | |
22 // Used to keeps track of system modal windows and check whether windows are | |
23 // blocked by modal windows or not to do appropriate retargetting of events. | |
24 class ModalWindowController : public ServerWindowObserver { | |
25 public: | |
26 explicit ModalWindowController(EventDispatcher* event_dispatcher); | |
27 ~ModalWindowController() override; | |
28 | |
29 // Adds a system modal window. The window remains modal to system until it is | |
30 // destroyed. There can exist multiple system modal windows, in which case the | |
31 // one that is visible and added most recently or shown most recently would be | |
32 // the active one. | |
33 void AddSystemModalWindow(ServerWindow* window); | |
34 | |
35 // Checks whether |modal_window| is a visible modal window that blocks | |
36 // |window|. | |
37 bool IsWindowBlockedBy(const ServerWindow* window, | |
38 const ServerWindow* modal_window) const; | |
39 | |
40 // Checks whether |window| is blocked by any visible modal window. | |
41 bool IsWindowBlocked(const ServerWindow* window) const; | |
42 | |
43 // Returns the window that events targeted to |window| should be retargeted | |
44 // to; according to modal windows. If any modal window is blocking |window| | |
45 // (either system modal or window modal), returns the topmost one; otherwise, | |
46 // returns |window| itself. | |
47 const ServerWindow* GetTargetForWindow(const ServerWindow* window) const; | |
48 ServerWindow* GetTargetForWindow(ServerWindow* window) const { | |
49 return const_cast<ServerWindow*>( | |
50 GetTargetForWindow(static_cast<const ServerWindow*>(window))); | |
51 } | |
52 | |
53 private: | |
54 using ServerWindowList = std::list<ServerWindow*>; | |
55 friend class test::EventDispatcherTestApi; | |
56 | |
57 // Returns the system modal window that is visible and added/shown most | |
58 // recently, if any. | |
59 ServerWindow* GetActiveSystemModalWindow() const; | |
60 | |
61 // Removes system modal window at the given iterator and unobserves it. | |
62 void RemoveSystemModalWindow(ServerWindowList::iterator it); | |
63 | |
64 // ServerWindowObserver: | |
65 void OnWindowVisibilityChanged(ServerWindow* window) override; | |
66 void OnWindowDestroyed(ServerWindow* window) override; | |
67 | |
68 EventDispatcher* event_dispatcher_; | |
69 | |
70 // List of system modal windows in order they are added/shown. | |
sky
2016/04/26 23:40:08
Actually, this is reverse order, which I think it
mohsen
2016/04/27 20:18:25
They only reason I used reverse order is to be abl
| |
71 ServerWindowList system_modal_windows_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(ModalWindowController); | |
74 }; | |
75 | |
76 } // namespace ws | |
77 } // namespace mus | |
78 | |
79 #endif // COMPONENTS_MUS_WS_MODAL_WINDOW_CONTROLLER_H_ | |
OLD | NEW |