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_BASE_LAYOUT_MANAGER_H_
6 #define ASH_WM_BASE_LAYOUT_MANAGER_H_
10 #include "ash/ash_export.h"
11 #include "ash/shell_observer.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "ui/aura/client/activation_change_observer.h"
15 #include "ui/aura/layout_manager.h"
16 #include "ui/aura/window_observer.h"
17 #include "ui/base/events/event_handler.h"
18 #include "ui/base/ui_base_types.h"
28 // BaseLayoutManager is the simplest possible implementation for a window
29 // layout manager. It listens for changes to kShowStateKey and resizes the
30 // window appropriately. Subclasses should be sure to invoke the base class
31 // for adding and removing windows, otherwise show state will not be tracked
33 class ASH_EXPORT BaseLayoutManager
34 : public aura::LayoutManager
,
35 public ash::ShellObserver
,
36 public aura::WindowObserver
,
37 public aura::client::ActivationChangeObserver
{
39 typedef std::set
<aura::Window
*> WindowSet
;
41 explicit BaseLayoutManager(aura::RootWindow
* root_window
);
42 virtual ~BaseLayoutManager();
44 const WindowSet
& windows() const { return windows_
; }
46 // Given a |window| and tentative |restore_bounds|, returns new bounds that
47 // ensure that at least a few pixels of the screen background are visible
48 // outside the edges of the window.
49 static gfx::Rect
BoundsWithScreenEdgeVisible(aura::Window
* window
,
50 const gfx::Rect
& restore_bounds
);
52 // LayoutManager overrides:
53 virtual void OnWindowResized() OVERRIDE
;
54 virtual void OnWindowAddedToLayout(aura::Window
* child
) OVERRIDE
;
55 virtual void OnWillRemoveWindowFromLayout(aura::Window
* child
) OVERRIDE
;
56 virtual void OnWindowRemovedFromLayout(aura::Window
* child
) OVERRIDE
;
57 virtual void OnChildWindowVisibilityChanged(aura::Window
* child
,
58 bool visible
) OVERRIDE
;
59 virtual void SetChildBounds(aura::Window
* child
,
60 const gfx::Rect
& requested_bounds
) OVERRIDE
;
62 // ash::ShellObserver overrides:
63 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE
;
65 // WindowObserver overrides:
66 virtual void OnWindowPropertyChanged(aura::Window
* window
,
68 intptr_t old
) OVERRIDE
;
69 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
;
70 virtual void OnWindowBoundsChanged(aura::Window
* window
,
71 const gfx::Rect
& old_bounds
,
72 const gfx::Rect
& new_bounds
) OVERRIDE
;
74 // aura::client::ActivationChangeObserver overrides:
75 virtual void OnWindowActivated(aura::Window
* gained_active
,
76 aura::Window
* lost_active
) OVERRIDE
;
79 enum AdjustWindowReason
{
80 ADJUST_WINDOW_DISPLAY_SIZE_CHANGED
,
81 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED
,
84 // Invoked from OnWindowPropertyChanged() if |kShowStateKey| changes.
85 virtual void ShowStateChanged(aura::Window
* window
,
86 ui::WindowShowState last_show_state
);
88 // Adjusts the window's bounds when the display area changes for given
89 // window. This happens when the display size, work area insets or
90 // the display on which the window exists has changed.
91 // If this is called for a display size change (i.e. |reason|
92 // is ADJUST_WINDOW_DISPLAY_SIZE_CHANGED), the non-maximized/non-fullscreen
93 // windows are readjusted to make sure the window is completely within the
94 // display region. Otherwise, it makes sure at least some parts of the window
96 virtual void AdjustAllWindowsBoundsForWorkAreaChange(
97 AdjustWindowReason reason
);
99 // Adjusts the sizes of the specific window in respond to a screen change or
100 // display-area size change.
101 virtual void AdjustWindowBoundsForWorkAreaChange(aura::Window
* window
,
102 AdjustWindowReason reason
);
104 aura::RootWindow
* root_window() { return root_window_
; }
107 // Update window bounds based on a change in show state.
108 void UpdateBoundsFromShowState(aura::Window
* window
);
110 // Set of windows we're listening to.
113 aura::RootWindow
* root_window_
;
115 DISALLOW_COPY_AND_ASSIGN(BaseLayoutManager
);
118 } // namespace internal
121 #endif // ASH_WM_BASE_LAYOUT_MANAGER_H_