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 "ash/wm/window_state_observer.h" 13 #include "base/basictypes.h" 14 #include "base/compiler_specific.h" 15 #include "ui/aura/client/activation_change_observer.h" 16 #include "ui/aura/layout_manager.h" 17 #include "ui/aura/window_observer.h" 18 #include "ui/base/ui_base_types.h" 19 #include "ui/events/event_handler.h" 20 21 namespace aura { 22 class Window; 23 } 24 25 namespace ash { 26 namespace wm { 27 class WindowState; 28 } 29 30 namespace internal { 31 32 // BaseLayoutManager is the simplest possible implementation for a window 33 // layout manager. It listens for changes to kShowStateKey and resizes the 34 // window appropriately. Subclasses should be sure to invoke the base class 35 // for adding and removing windows, otherwise show state will not be tracked 36 // properly. 37 class ASH_EXPORT BaseLayoutManager 38 : public aura::LayoutManager, 39 public aura::WindowObserver, 40 public aura::client::ActivationChangeObserver, 41 public ShellObserver, 42 public wm::WindowStateObserver { 43 public: 44 typedef std::set<aura::Window*> WindowSet; 45 46 explicit BaseLayoutManager(aura::Window* root_window); 47 virtual ~BaseLayoutManager(); 48 windows()49 const WindowSet& windows() const { return windows_; } 50 51 // Given a |window| and tentative |restore_bounds|, returns new bounds that 52 // ensure that at least a few pixels of the screen background are visible 53 // outside the edges of the window. 54 static gfx::Rect BoundsWithScreenEdgeVisible(aura::Window* window, 55 const gfx::Rect& restore_bounds); 56 57 // aura::LayoutManager overrides: 58 virtual void OnWindowResized() OVERRIDE; 59 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; 60 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; 61 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; 62 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 63 bool visible) OVERRIDE; 64 virtual void SetChildBounds(aura::Window* child, 65 const gfx::Rect& requested_bounds) OVERRIDE; 66 67 // aura::WindowObserver overrides: 68 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; 69 virtual void OnWindowBoundsChanged(aura::Window* window, 70 const gfx::Rect& old_bounds, 71 const gfx::Rect& new_bounds) OVERRIDE; 72 73 // aura::client::ActivationChangeObserver overrides: 74 virtual void OnWindowActivated(aura::Window* gained_active, 75 aura::Window* lost_active) OVERRIDE; 76 77 // ash::ShellObserver overrides: 78 virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE; 79 80 // wm::WindowStateObserver overrides: 81 virtual void OnWindowShowTypeChanged(wm::WindowState* window_state, 82 wm::WindowShowType type) OVERRIDE; 83 84 protected: 85 enum AdjustWindowReason { 86 ADJUST_WINDOW_DISPLAY_SIZE_CHANGED, 87 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED, 88 }; 89 90 // Invoked from OnWindowPropertyChanged() if |kShowStateKey| changes. 91 virtual void ShowStateChanged(wm::WindowState* window_state, 92 ui::WindowShowState last_show_state); 93 94 // Adjusts the window's bounds when the display area changes for given 95 // window. This happens when the display size, work area insets or 96 // the display on which the window exists has changed. 97 // If this is called for a display size change (i.e. |reason| 98 // is ADJUST_WINDOW_DISPLAY_SIZE_CHANGED), the non-maximized/non-fullscreen 99 // windows are readjusted to make sure the window is completely within the 100 // display region. Otherwise, it makes sure at least some parts of the window 101 // is on display. 102 virtual void AdjustAllWindowsBoundsForWorkAreaChange( 103 AdjustWindowReason reason); 104 105 // Adjusts the sizes of the specific window in respond to a screen change or 106 // display-area size change. 107 virtual void AdjustWindowBoundsForWorkAreaChange( 108 wm::WindowState* window_state, 109 AdjustWindowReason reason); 110 root_window()111 aura::Window* root_window() { return root_window_; } 112 113 private: 114 // Update window bounds based on a change in show state. 115 void UpdateBoundsFromShowState(wm::WindowState* controller); 116 117 // Set of windows we're listening to. 118 WindowSet windows_; 119 120 aura::Window* root_window_; 121 122 DISALLOW_COPY_AND_ASSIGN(BaseLayoutManager); 123 }; 124 125 } // namespace internal 126 } // namespace ash 127 128 #endif // ASH_WM_BASE_LAYOUT_MANAGER_H_ 129