1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_WINDOW_MANAGER_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_WINDOW_MANAGER_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <map>
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <set>
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/ash_export.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/shell_observer.h"
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/window_state.h"
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/basictypes.h"
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/compiler_specific.h"
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_observer.h"
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/events/event_handler.h"
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/gfx/display_observer.h"
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace ui {
21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class TouchEvent;
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace ash {
25f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class MaximizeModeController;
2623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)class MaximizeModeWindowState;
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// A window manager which - when created - will force all windows into maximized
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// mode. Exception are panels and windows which cannot be maximized.
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Windows which cannot be maximized / resized are centered with a layer placed
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// behind the window so that no other windows are visible and/or obscured.
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// With the destruction of the manager all windows will be restored to their
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// original state.
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ASH_EXPORT MaximizeModeWindowManager : public aura::WindowObserver,
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                             public gfx::DisplayObserver,
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                             public ShellObserver,
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                             public ui::EventHandler {
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // This should only be deleted by the creator (ash::Shell).
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~MaximizeModeWindowManager();
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Returns the number of maximized & tracked windows by this manager.
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  int GetNumberOfManagedWindows();
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Adds a window which needs to be maximized. This is used by other window
465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // managers for windows which needs to get tracked due to (upcoming) state
475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // changes.
485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // The call gets ignored if the window was already or should not be handled.
495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  void AddWindow(aura::Window* window);
505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
5123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Called from a window state object when it gets destroyed.
5223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  void WindowStateDestroyed(aura::Window* window);
5323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // ShellObserver overrides:
55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnOverviewModeStarting() OVERRIDE;
56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnOverviewModeEnding() OVERRIDE;
57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Overridden from WindowObserver:
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void OnWindowAdded(aura::Window* window) OVERRIDE;
61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void OnWindowBoundsChanged(aura::Window* window,
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                     const gfx::Rect& old_bounds,
63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                     const gfx::Rect& new_bounds) OVERRIDE;
64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
65cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // gfx::DisplayObserver overrides:
66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void OnDisplayAdded(const gfx::Display& display) OVERRIDE;
67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void OnDisplayRemoved(const gfx::Display& display) OVERRIDE;
68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnDisplayMetricsChanged(const gfx::Display& display,
69cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                       uint32_t metrics) OVERRIDE;
70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // ui::EventHandler override:
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) protected:
75f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  friend class MaximizeModeController;
76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // The object should only be created by the ash::Shell.
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  MaximizeModeWindowManager();
79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
8123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  typedef std::map<aura::Window*, MaximizeModeWindowState*> WindowToState;
82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Maximize all windows and restore their current state.
84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void MaximizeAllWindows();
85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Restore all windows to their previous state.
87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void RestoreAllWindows();
88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // If the given window should be handled by us, this function will maximize it
90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // and add it to the list of known windows (remembering the initial show
91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // state).
92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Note: If the given window cannot be handled by us the function will return
93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // immediately.
94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void MaximizeAndTrackWindow(aura::Window* window);
95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Remove a window from our tracking list.
9723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  void ForgetWindow(aura::Window* window);
98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Returns true when the given window should be modified in any way by us.
100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool ShouldHandleWindow(aura::Window* window);
101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Add window creation observers to track creation of new windows.
103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void AddWindowCreationObservers();
104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Remove Window creation observers.
106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void RemoveWindowCreationObservers();
107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Change the internal state (e.g. observers) when the display configuration
109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // changes.
110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void DisplayConfigurationChanged();
111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Returns true when the |window| is a container window.
113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool IsContainerWindow(aura::Window* window);
114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Add a backdrop behind the currently active window on each desktop.
116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void EnableBackdropBehindTopWindowOnEachDisplay(bool enable);
117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Every window which got touched by our window manager gets added here.
11923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  WindowToState window_state_map_;
120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // All container windows which have to be tracked.
122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  std::set<aura::Window*> observed_container_windows_;
123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // True if all backdrops are hidden.
125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool backdrops_hidden_;
126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(MaximizeModeWindowManager);
128a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace ash
131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_WINDOW_MANAGER_H_
133