| 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 #include <map> | |
| 10 | |
| 11 #include "components/mus/ws/server_window_drawn_tracker_observer.h" | |
| 12 #include "components/mus/ws/server_window_observer.h" | |
| 13 | |
| 14 namespace mus { | |
| 15 namespace ws { | |
| 16 | |
| 17 class EventDispatcher; | |
| 18 class ServerWindow; | |
| 19 class ServerWindowDrawnTracker; | |
| 20 | |
| 21 namespace test { | |
| 22 class ModalWindowControllerTestApi; | |
| 23 } | |
| 24 | |
| 25 // Used to keeps track of system modal windows and check whether windows are | |
| 26 // blocked by modal windows or not to do appropriate retargetting of events. | |
| 27 class ModalWindowController : public ServerWindowObserver, | |
| 28 public ServerWindowDrawnTrackerObserver { | |
| 29 public: | |
| 30 explicit ModalWindowController(EventDispatcher* event_dispatcher); | |
| 31 ~ModalWindowController() override; | |
| 32 | |
| 33 // Adds a system modal window. The window remains modal to system until it is | |
| 34 // destroyed. There can exist multiple system modal windows, in which case the | |
| 35 // one that is visible and added most recently or shown most recently would be | |
| 36 // the active one. | |
| 37 void AddSystemModalWindow(ServerWindow* window); | |
| 38 | |
| 39 // Checks whether |modal_window| is a visible modal window that blocks | |
| 40 // |window|. | |
| 41 bool IsWindowBlockedBy(const ServerWindow* window, | |
| 42 const ServerWindow* modal_window) const; | |
| 43 | |
| 44 // Checks whether |window| is blocked by any visible modal window. | |
| 45 bool IsWindowBlocked(const ServerWindow* window) const; | |
| 46 | |
| 47 // Returns the window that events targeted to |window| should be retargeted | |
| 48 // to; according to modal windows. If any modal window is blocking |window| | |
| 49 // (either system modal or window modal), returns the topmost one; otherwise, | |
| 50 // returns |window| itself. | |
| 51 const ServerWindow* GetTargetForWindow(const ServerWindow* window) const; | |
| 52 ServerWindow* GetTargetForWindow(ServerWindow* window) const { | |
| 53 return const_cast<ServerWindow*>( | |
| 54 GetTargetForWindow(static_cast<const ServerWindow*>(window))); | |
| 55 } | |
| 56 | |
| 57 private: | |
| 58 friend class test::ModalWindowControllerTestApi; | |
| 59 | |
| 60 // Returns the system modal window that is visible and added/shown most | |
| 61 // recently, if any. | |
| 62 ServerWindow* GetActiveSystemModalWindow() const; | |
| 63 | |
| 64 // ServerWindowObserver: | |
| 65 void OnWindowDestroyed(ServerWindow* window) override; | |
| 66 | |
| 67 // ServerWindowDrawnTrackerObserver: | |
| 68 void OnDrawnStateChanged(ServerWindow* ancestor, | |
| 69 ServerWindow* window, | |
| 70 bool is_drawn) override; | |
| 71 | |
| 72 EventDispatcher* event_dispatcher_; | |
| 73 | |
| 74 // List of system modal windows in order they are added/shown. | |
| 75 std::list<ServerWindow*> system_modal_windows_; | |
| 76 | |
| 77 // Drawn trackers for system modal windows. | |
| 78 std::map<ServerWindow*, std::unique_ptr<ServerWindowDrawnTracker>> | |
| 79 window_drawn_trackers_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(ModalWindowController); | |
| 82 }; | |
| 83 | |
| 84 } // namespace ws | |
| 85 } // namespace mus | |
| 86 | |
| 87 #endif // COMPONENTS_MUS_WS_MODAL_WINDOW_CONTROLLER_H_ | |
| OLD | NEW |