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_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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 14 | #include "ui/aura/client/activation_change_observer.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 15 | #include "ui/aura/layout_manager.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 16 | #include "ui/aura/window_observer.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 17 | #include "ui/base/events/event_handler.h" |
| 18 | #include "ui/base/ui_base_types.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 19 | |
| 20 | namespace aura { |
| 21 | class RootWindow; |
| 22 | class Window; |
| 23 | } |
| 24 | |
| 25 | namespace ash { |
| 26 | namespace 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 33 | class ASH_EXPORT BaseLayoutManager |
| 34 | : public aura::LayoutManager, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 35 | public ash::ShellObserver, |
| 36 | public aura::WindowObserver, |
| 37 | public aura::client::ActivationChangeObserver { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 38 | 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 62 | // 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) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 70 | virtual void OnWindowBoundsChanged(aura::Window* window, |
| 71 | const gfx::Rect& old_bounds, |
| 72 | const gfx::Rect& new_bounds) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 73 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 74 | // aura::client::ActivationChangeObserver overrides: |
| 75 | virtual void OnWindowActivated(aura::Window* gained_active, |
| 76 | aura::Window* lost_active) OVERRIDE; |
| 77 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 78 | protected: |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 79 | enum AdjustWindowReason { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 80 | ADJUST_WINDOW_DISPLAY_SIZE_CHANGED, |
| 81 | ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED, |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 84 | // Invoked from OnWindowPropertyChanged() if |kShowStateKey| changes. |
| 85 | virtual void ShowStateChanged(aura::Window* window, |
| 86 | ui::WindowShowState last_show_state); |
| 87 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 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 |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 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 |
| 95 | // is on display. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 96 | virtual void AdjustAllWindowsBoundsForWorkAreaChange( |
| 97 | AdjustWindowReason reason); |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 98 | |
| 99 | // Adjusts the sizes of the specific window in respond to a screen change or |
| 100 | // display-area size change. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 101 | virtual void AdjustWindowBoundsForWorkAreaChange(aura::Window* window, |
| 102 | AdjustWindowReason reason); |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 103 | |
| 104 | aura::RootWindow* root_window() { return root_window_; } |
| 105 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 106 | private: |
| 107 | // Update window bounds based on a change in show state. |
| 108 | void UpdateBoundsFromShowState(aura::Window* window); |
| 109 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 110 | // 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_ |