blob: 0fc2b3691716e52835d9eb793fe34202d78af2f8 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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_BASE_LAYOUT_MANAGER_H_
6#define ASH_WM_BASE_LAYOUT_MANAGER_H_
7
8#include <set>
9
10#include "ash/ash_export.h"
11#include "ash/shell_observer.h"
12#include "base/basictypes.h"
13#include "base/compiler_specific.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014#include "ui/aura/client/activation_change_observer.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000015#include "ui/aura/layout_manager.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000016#include "ui/aura/window_observer.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000017#include "ui/base/events/event_handler.h"
18#include "ui/base/ui_base_types.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000019
20namespace aura {
21class RootWindow;
22class Window;
23}
24
25namespace ash {
26namespace internal {
27
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
32// properly.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000033class ASH_EXPORT BaseLayoutManager
34 : public aura::LayoutManager,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000035 public ash::ShellObserver,
36 public aura::WindowObserver,
37 public aura::client::ActivationChangeObserver {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000038 public:
39 typedef std::set<aura::Window*> WindowSet;
40
41 explicit BaseLayoutManager(aura::RootWindow* root_window);
42 virtual ~BaseLayoutManager();
43
44 const WindowSet& windows() const { return windows_; }
45
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);
51
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;
61
Torne (Richard Coles)58218062012-11-14 11:43:16 +000062 // ash::ShellObserver overrides:
63 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE;
64
65 // WindowObserver overrides:
66 virtual void OnWindowPropertyChanged(aura::Window* window,
67 const void* key,
68 intptr_t old) OVERRIDE;
69 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010070 virtual void OnWindowBoundsChanged(aura::Window* window,
71 const gfx::Rect& old_bounds,
72 const gfx::Rect& new_bounds) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000073
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000074 // aura::client::ActivationChangeObserver overrides:
75 virtual void OnWindowActivated(aura::Window* gained_active,
76 aura::Window* lost_active) OVERRIDE;
77
Torne (Richard Coles)58218062012-11-14 11:43:16 +000078 protected:
Ben Murdoch558790d2013-07-30 15:19:42 +010079 enum AdjustWindowReason {
Ben Murdochbb1529c2013-08-08 10:24:53 +010080 ADJUST_WINDOW_DISPLAY_SIZE_CHANGED,
81 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED,
Ben Murdoch558790d2013-07-30 15:19:42 +010082 };
83
Torne (Richard Coles)58218062012-11-14 11:43:16 +000084 // Invoked from OnWindowPropertyChanged() if |kShowStateKey| changes.
85 virtual void ShowStateChanged(aura::Window* window,
86 ui::WindowShowState last_show_state);
87
Ben Murdochbb1529c2013-08-08 10:24:53 +010088 // 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
Ben Murdoch558790d2013-07-30 15:19:42 +010093 // 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
95 // is on display.
Ben Murdochbb1529c2013-08-08 10:24:53 +010096 virtual void AdjustAllWindowsBoundsForWorkAreaChange(
97 AdjustWindowReason reason);
Ben Murdoch558790d2013-07-30 15:19:42 +010098
99 // Adjusts the sizes of the specific window in respond to a screen change or
100 // display-area size change.
Ben Murdochbb1529c2013-08-08 10:24:53 +0100101 virtual void AdjustWindowBoundsForWorkAreaChange(aura::Window* window,
102 AdjustWindowReason reason);
Ben Murdoch558790d2013-07-30 15:19:42 +0100103
104 aura::RootWindow* root_window() { return root_window_; }
105
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000106 private:
107 // Update window bounds based on a change in show state.
108 void UpdateBoundsFromShowState(aura::Window* window);
109
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000110 // Set of windows we're listening to.
111 WindowSet windows_;
112
113 aura::RootWindow* root_window_;
114
115 DISALLOW_COPY_AND_ASSIGN(BaseLayoutManager);
116};
117
118} // namespace internal
119} // namespace ash
120
121#endif // ASH_WM_BASE_LAYOUT_MANAGER_H_