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

Unified Diff: components/mus/ws/modal_window_controller.h

Issue 1818333002: Reland: mus: Enable system modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup 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 side-by-side diff with in-line comments
Download patch
Index: components/mus/ws/modal_window_controller.h
diff --git a/components/mus/ws/modal_window_controller.h b/components/mus/ws/modal_window_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..de5accfe152c81858a79987d4b5622d685ed68e9
--- /dev/null
+++ b/components/mus/ws/modal_window_controller.h
@@ -0,0 +1,79 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_MUS_WS_MODAL_WINDOW_CONTROLLER_H_
+#define COMPONENTS_MUS_WS_MODAL_WINDOW_CONTROLLER_H_
+
+#include <list>
+
+#include "components/mus/ws/server_window_observer.h"
+
+namespace mus {
+namespace ws {
+
+class EventDispatcher;
+class ServerWindow;
+
+namespace test {
+class EventDispatcherTestApi;
sky 2016/04/26 23:40:08 Create a ModalWindowControllerTestApi class and fr
mohsen 2016/04/27 20:18:25 Done.
+}
+
+// Used to keeps track of system modal windows and check whether windows are
+// blocked by modal windows or not to do appropriate retargetting of events.
+class ModalWindowController : public ServerWindowObserver {
+ public:
+ explicit ModalWindowController(EventDispatcher* event_dispatcher);
+ ~ModalWindowController() override;
+
+ // Adds a system modal window. The window remains modal to system until it is
+ // destroyed. There can exist multiple system modal windows, in which case the
+ // one that is visible and added most recently or shown most recently would be
+ // the active one.
+ void AddSystemModalWindow(ServerWindow* window);
+
+ // Checks whether |modal_window| is a visible modal window that blocks
+ // |window|.
+ bool IsWindowBlockedBy(const ServerWindow* window,
+ const ServerWindow* modal_window) const;
+
+ // Checks whether |window| is blocked by any visible modal window.
+ bool IsWindowBlocked(const ServerWindow* window) const;
+
+ // Returns the window that events targeted to |window| should be retargeted
+ // to; according to modal windows. If any modal window is blocking |window|
+ // (either system modal or window modal), returns the topmost one; otherwise,
+ // returns |window| itself.
+ const ServerWindow* GetTargetForWindow(const ServerWindow* window) const;
+ ServerWindow* GetTargetForWindow(ServerWindow* window) const {
+ return const_cast<ServerWindow*>(
+ GetTargetForWindow(static_cast<const ServerWindow*>(window)));
+ }
+
+ private:
+ using ServerWindowList = std::list<ServerWindow*>;
+ friend class test::EventDispatcherTestApi;
+
+ // Returns the system modal window that is visible and added/shown most
+ // recently, if any.
+ ServerWindow* GetActiveSystemModalWindow() const;
+
+ // Removes system modal window at the given iterator and unobserves it.
+ void RemoveSystemModalWindow(ServerWindowList::iterator it);
+
+ // ServerWindowObserver:
+ void OnWindowVisibilityChanged(ServerWindow* window) override;
+ void OnWindowDestroyed(ServerWindow* window) override;
+
+ EventDispatcher* event_dispatcher_;
+
+ // 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
+ ServerWindowList system_modal_windows_;
+
+ DISALLOW_COPY_AND_ASSIGN(ModalWindowController);
+};
+
+} // namespace ws
+} // namespace mus
+
+#endif // COMPONENTS_MUS_WS_MODAL_WINDOW_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698