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.
5 #ifndef ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
6 #define ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_
10 #include "ash/ash_export.h"
11 #include "ash/snap_to_pixel_layout_manager.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/aura/window_observer.h"
16 #include "ui/keyboard/keyboard_controller_observer.h"
31 // LayoutManager for the modal window container.
32 // System modal windows which are centered on the screen will be kept centered
33 // when the container size changes.
34 class ASH_EXPORT SystemModalContainerLayoutManager
35 : public SnapToPixelLayoutManager
,
36 public aura::WindowObserver
,
37 public keyboard::KeyboardControllerObserver
{
39 explicit SystemModalContainerLayoutManager(aura::Window
* container
);
40 virtual ~SystemModalContainerLayoutManager();
42 bool has_modal_background() const { return modal_background_
!= NULL
; }
44 // Overridden from SnapToPixelLayoutManager:
45 virtual void OnWindowResized() OVERRIDE
;
46 virtual void OnWindowAddedToLayout(aura::Window
* child
) OVERRIDE
;
47 virtual void OnWillRemoveWindowFromLayout(aura::Window
* child
) OVERRIDE
;
48 virtual void SetChildBounds(aura::Window
* child
,
49 const gfx::Rect
& requested_bounds
) OVERRIDE
;
51 // Overridden from aura::WindowObserver:
52 virtual void OnWindowPropertyChanged(aura::Window
* window
,
54 intptr_t old
) OVERRIDE
;
55 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
;
57 // Overridden from keyboard::KeyboardControllerObserver:
58 virtual void OnKeyboardBoundsChanging(const gfx::Rect
& new_bounds
) OVERRIDE
;
60 // Can a given |window| receive and handle input events?
61 bool CanWindowReceiveEvents(aura::Window
* window
);
63 // Activates next modal window if any. Returns false if there
64 // are no more modal windows in this layout manager.
65 bool ActivateNextModalWindow();
67 // Creates modal background window, which is a partially-opaque
68 // fullscreen window. If there is already a modal background window,
69 // it will bring it the top.
70 void CreateModalBackground();
72 void DestroyModalBackground();
74 // Is the |window| modal background?
75 static bool IsModalBackground(aura::Window
* window
);
78 void AddModalWindow(aura::Window
* window
);
79 void RemoveModalWindow(aura::Window
* window
);
81 // Reposition the dialogs to become visible after the work area changes.
82 void PositionDialogsAfterWorkAreaResize();
84 // Get the usable bounds rectangle for enclosed dialogs.
85 gfx::Rect
GetUsableDialogArea();
87 // Gets the new bounds for a |window| to use which are either centered (if the
88 // window was previously centered) or fitted to the screen.
89 gfx::Rect
GetCenteredAndOrFittedBounds(const aura::Window
* window
);
91 // Returns true if |window_bounds| is centered.
92 bool DialogIsCentered(const gfx::Rect
& window_bounds
);
94 aura::Window
* modal_window() {
95 return !modal_windows_
.empty() ? modal_windows_
.back() : NULL
;
98 // The container that owns the layout manager.
99 aura::Window
* container_
;
101 // A widget that dims the windows behind the modal window(s) being
102 // shown in |container_|.
103 views::Widget
* modal_background_
;
105 // A stack of modal windows. Only the topmost can receive events.
106 std::vector
<aura::Window
*> modal_windows_
;
108 DISALLOW_COPY_AND_ASSIGN(SystemModalContainerLayoutManager
);
113 #endif // ASH_WM_SYSTEM_MODAL_CONTAINER_LAYOUT_MANAGER_H_