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_WORKSPACE_WORKSPACE_LAYOUT_MANAGER_H_
6#define ASH_WM_WORKSPACE_WORKSPACE_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 "ash/wm/wm_types.h"
14#include "base/basictypes.h"
15#include "base/compiler_specific.h"
16#include "base/memory/scoped_ptr.h"
17#include "ui/aura/layout_manager.h"
18#include "ui/aura/window_observer.h"
19#include "ui/gfx/rect.h"
20#include "ui/keyboard/keyboard_controller_observer.h"
21#include "ui/wm/public/activation_change_observer.h"
22
23namespace aura {
24class RootWindow;
25class Window;
26}
27
28namespace ui {
29class Layer;
30}
31
32namespace ash {
33class ShelfLayoutManager;
34class WorkspaceLayoutManagerDelegate;
35
36namespace wm {
37class WindowState;
38class WMEvent;
39}
40
41// LayoutManager used on the window created for a workspace.
42class ASH_EXPORT WorkspaceLayoutManager
43    : public aura::LayoutManager,
44      public aura::WindowObserver,
45      public aura::client::ActivationChangeObserver,
46      public keyboard::KeyboardControllerObserver,
47      public ShellObserver,
48      public wm::WindowStateObserver {
49 public:
50  explicit WorkspaceLayoutManager(aura::Window* window);
51  virtual ~WorkspaceLayoutManager();
52
53  void SetShelf(ShelfLayoutManager* shelf);
54
55  // A delegate which can be set to add a backdrop behind the top most visible
56  // window. With the call the ownership of the delegate will be transferred to
57  // the WorkspaceLayoutManager.
58  void SetMaximizeBackdropDelegate(
59      scoped_ptr<WorkspaceLayoutManagerDelegate> delegate);
60
61  // Overridden from aura::LayoutManager:
62  virtual void OnWindowResized() OVERRIDE {}
63  virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
64  virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
65  virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE;
66  virtual void OnChildWindowVisibilityChanged(aura::Window* child,
67                                              bool visibile) OVERRIDE;
68  virtual void SetChildBounds(aura::Window* child,
69                              const gfx::Rect& requested_bounds) OVERRIDE;
70
71  // ash::ShellObserver overrides:
72  virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE;
73
74  // Overriden from WindowObserver:
75  virtual void OnWindowHierarchyChanged(
76      const WindowObserver::HierarchyChangeParams& params) OVERRIDE;
77  virtual void OnWindowPropertyChanged(aura::Window* window,
78                                       const void* key,
79                                       intptr_t old) OVERRIDE;
80  virtual void OnWindowStackingChanged(aura::Window* window) OVERRIDE;
81  virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
82  virtual void OnWindowBoundsChanged(aura::Window* window,
83                                     const gfx::Rect& old_bounds,
84                                     const gfx::Rect& new_bounds) OVERRIDE;
85
86  // aura::client::ActivationChangeObserver overrides:
87  virtual void OnWindowActivated(aura::Window* gained_active,
88                                 aura::Window* lost_active) OVERRIDE;
89
90  // keyboard::KeyboardControllerObserver overrides:
91  virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE;
92
93  // WindowStateObserver overrides:
94  virtual void OnPostWindowStateTypeChange(
95      wm::WindowState* window_state,
96      wm::WindowStateType old_type) OVERRIDE;
97
98 private:
99  typedef std::set<aura::Window*> WindowSet;
100
101  // Adjusts the bounds of all managed windows when the display area changes.
102  // This happens when the display size, work area insets has changed.
103  // If this is called for a display size change (i.e. |event|
104  // is DISPLAY_RESIZED), the non-maximized/non-fullscreen
105  // windows are readjusted to make sure the window is completely within the
106  // display region. Otherwise, it makes sure at least some parts of the window
107  // is on display.
108  void AdjustAllWindowsBoundsForWorkAreaChange(const wm::WMEvent* event);
109
110  // Updates the visibility state of the shelf.
111  void UpdateShelfVisibility();
112
113  // Updates the fullscreen state of the workspace and notifies Shell if it
114  // has changed.
115  void UpdateFullscreenState();
116
117  // Updates the bounds of the window for a stte type change from
118  // |old_show_type|.
119  void UpdateBoundsFromStateType(wm::WindowState* window_state,
120                                 wm::WindowStateType old_state_type);
121
122  // If |window_state| is maximized or fullscreen the bounds of the
123  // window are set and true is returned. Does nothing otherwise.
124  bool SetMaximizedOrFullscreenBounds(wm::WindowState* window_state);
125
126  // Animates the window bounds to |bounds|.
127  void SetChildBoundsAnimated(aura::Window* child, const gfx::Rect& bounds);
128
129  ShelfLayoutManager* shelf_;
130  aura::Window* window_;
131  aura::Window* root_window_;
132
133  // Set of windows we're listening to.
134  WindowSet windows_;
135
136  // The work area in the coordinates of |window_|.
137  gfx::Rect work_area_in_parent_;
138
139  // True if this workspace is currently in fullscreen mode.
140  bool is_fullscreen_;
141
142  // A window which covers the full container and which gets inserted behind the
143  // topmost visible window.
144  scoped_ptr<WorkspaceLayoutManagerDelegate> backdrop_delegate_;
145
146  DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager);
147};
148
149}  // namespace ash
150
151#endif  // ASH_WM_WORKSPACE_WORKSPACE_LAYOUT_MANAGER_H_
152