Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 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 ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_ |
| 6 | #define ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "ash/ash_export.h" |
| 11 | #include "base/basictypes.h" |
| 12 | #include "base/compiler_specific.h" |
| 13 | #include "base/memory/scoped_ptr.h" |
| 14 | #include "ui/aura/layout_manager.h" |
| 15 | #include "ui/aura/window_observer.h" |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 16 | #include "ui/keyboard/keyboard_controller_observer.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 17 | |
| 18 | namespace aura { |
| 19 | class Window; |
| 20 | class EventFilter; |
| 21 | } |
| 22 | namespace gfx { |
| 23 | class Rect; |
| 24 | } |
| 25 | namespace views { |
| 26 | class Widget; |
| 27 | } |
| 28 | |
| 29 | namespace ash { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 30 | |
| 31 | // LayoutManager for the modal window container. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 32 | // System modal windows which are centered on the screen will be kept centered |
| 33 | // when the container size changes. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 34 | class ASH_EXPORT SystemModalContainerLayoutManager |
| 35 | : public aura::LayoutManager, |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 36 | public aura::WindowObserver, |
| 37 | public keyboard::KeyboardControllerObserver { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 38 | public: |
| 39 | explicit SystemModalContainerLayoutManager(aura::Window* container); |
| 40 | virtual ~SystemModalContainerLayoutManager(); |
| 41 | |
| 42 | bool has_modal_background() const { return modal_background_ != NULL; } |
| 43 | |
| 44 | // Overridden from aura::LayoutManager: |
| 45 | virtual void OnWindowResized() OVERRIDE; |
| 46 | virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; |
| 47 | virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; |
| 48 | virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; |
| 49 | virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 50 | bool visibile) OVERRIDE; |
| 51 | virtual void SetChildBounds(aura::Window* child, |
| 52 | const gfx::Rect& requested_bounds) OVERRIDE; |
| 53 | |
| 54 | // Overridden from aura::WindowObserver: |
| 55 | virtual void OnWindowPropertyChanged(aura::Window* window, |
| 56 | const void* key, |
| 57 | intptr_t old) OVERRIDE; |
| 58 | virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 59 | |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 60 | // Overridden from keyboard::KeyboardControllerObserver: |
| 61 | virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE; |
| 62 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 63 | // Can a given |window| receive and handle input events? |
| 64 | bool CanWindowReceiveEvents(aura::Window* window); |
| 65 | |
| 66 | // Activates next modal window if any. Returns false if there |
| 67 | // are no more modal windows in this layout manager. |
| 68 | bool ActivateNextModalWindow(); |
| 69 | |
| 70 | // Creates modal background window, which is a partially-opaque |
| 71 | // fullscreen window. If there is already a modal background window, |
| 72 | // it will bring it the top. |
| 73 | void CreateModalBackground(); |
| 74 | |
| 75 | void DestroyModalBackground(); |
| 76 | |
| 77 | // Is the |window| modal background? |
| 78 | static bool IsModalBackground(aura::Window* window); |
| 79 | |
| 80 | private: |
| 81 | void AddModalWindow(aura::Window* window); |
| 82 | void RemoveModalWindow(aura::Window* window); |
| 83 | |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 84 | // Reposition the dialogs to become visible after the work area changes. |
| 85 | void PositionDialogsAfterWorkAreaResize(); |
| 86 | |
| 87 | // Get the usable bounds rectangle for enclosed dialogs. |
| 88 | gfx::Rect GetUsableDialogArea(); |
| 89 | |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 90 | // Gets the new bounds for a |window| to use which are either centered (if the |
| 91 | // window was previously centered) or fitted to the screen. |
| 92 | gfx::Rect GetCenteredAndOrFittedBounds(const aura::Window* window); |
| 93 | |
| 94 | // Returns true if |window_bounds| is centered. |
| 95 | bool DialogIsCentered(const gfx::Rect& window_bounds); |
| 96 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 97 | aura::Window* modal_window() { |
| 98 | return !modal_windows_.empty() ? modal_windows_.back() : NULL; |
| 99 | } |
| 100 | |
| 101 | // The container that owns the layout manager. |
| 102 | aura::Window* container_; |
| 103 | |
| 104 | // A widget that dims the windows behind the modal window(s) being |
| 105 | // shown in |container_|. |
| 106 | views::Widget* modal_background_; |
| 107 | |
| 108 | // A stack of modal windows. Only the topmost can receive events. |
| 109 | std::vector<aura::Window*> modal_windows_; |
| 110 | |
| 111 | DISALLOW_COPY_AND_ASSIGN(SystemModalContainerLayoutManager); |
| 112 | }; |
| 113 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 114 | } // namespace ash |
| 115 | |
| 116 | #endif // ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_ |