Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_ | 5 #ifndef ASH_WM_DOCK_DOCK_LAYOUT_MANAGER_H_ |
| 6 #define ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_ | 6 #define ASH_WM_DOCK_DOCK_LAYOUT_MANAGER_H_ |
| 7 | |
| 8 #include <list> | |
| 9 | 7 |
| 10 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 11 #include "ash/launcher/launcher_icon_observer.h" | |
| 12 #include "ash/shelf/shelf_layout_manager_observer.h" | 9 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 13 #include "ash/shell_observer.h" | 10 #include "ash/shell_observer.h" |
| 11 #include "ash/wm/property_util.h" | |
| 14 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 15 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/memory/weak_ptr.h" | |
| 18 #include "ui/aura/client/activation_change_observer.h" | 14 #include "ui/aura/client/activation_change_observer.h" |
| 19 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.h" |
| 20 #include "ui/aura/window_observer.h" | 16 #include "ui/aura/window_observer.h" |
| 21 #include "ui/keyboard/keyboard_controller.h" | |
| 22 #include "ui/keyboard/keyboard_controller_observer.h" | 17 #include "ui/keyboard/keyboard_controller_observer.h" |
| 23 | 18 |
| 24 namespace aura { | 19 namespace aura { |
| 25 class Window; | 20 class Window; |
| 26 } | 21 } |
| 27 | 22 |
| 28 namespace gfx { | 23 namespace gfx { |
| 29 class Rect; | 24 class Rect; |
| 30 } | 25 } |
| 31 | 26 |
| 32 namespace views { | |
| 33 class Widget; | |
| 34 } | |
| 35 | |
| 36 namespace ash { | 27 namespace ash { |
| 37 class Launcher; | 28 class Launcher; |
| 38 | 29 |
| 39 namespace internal { | 30 namespace internal { |
| 40 class PanelCalloutWidget; | |
| 41 class ShelfLayoutManager; | 31 class ShelfLayoutManager; |
| 42 | 32 |
| 43 // PanelLayoutManager is responsible for organizing panels within the | 33 // DockLayoutManager is responsible for organizing windows within the |
| 44 // workspace. It is associated with a specific container window (i.e. | 34 // dock (gutter). It is associated with a specific container window (i.e. |
| 45 // kShellWindowId_PanelContainer) and controls the layout of any windows | 35 // kShellWindowId_DockContainer) and controls the layout of any windows |
| 46 // added to that container. | 36 // added to that container. |
| 47 // | 37 // |
| 48 // The constructor takes a |panel_container| argument which is expected to set | 38 // The constructor takes a |dock_container| argument which is expected to set |
| 49 // its layout manager to this instance, e.g.: | 39 // its layout manager to this instance, e.g.: |
| 50 // panel_container->SetLayoutManager(new PanelLayoutManager(panel_container)); | 40 // dock_container->SetLayoutManager(new DockLayoutManager(dock_container)); |
| 51 | 41 |
| 52 class ASH_EXPORT PanelLayoutManager | 42 class ASH_EXPORT DockLayoutManager |
| 53 : public aura::LayoutManager, | 43 : public aura::LayoutManager, |
| 54 public ash::LauncherIconObserver, | |
| 55 public ash::ShellObserver, | 44 public ash::ShellObserver, |
| 56 public aura::WindowObserver, | 45 public aura::WindowObserver, |
| 57 public aura::client::ActivationChangeObserver, | 46 public aura::client::ActivationChangeObserver, |
| 58 public keyboard::KeyboardControllerObserver, | 47 public keyboard::KeyboardControllerObserver, |
| 59 public ShelfLayoutManagerObserver { | 48 public ash::ShelfLayoutManagerObserver { |
| 60 public: | 49 public: |
| 61 explicit PanelLayoutManager(aura::Window* panel_container); | 50 explicit DockLayoutManager(aura::Window* dock_container); |
| 62 virtual ~PanelLayoutManager(); | 51 virtual ~DockLayoutManager(); |
| 63 | 52 |
| 64 // Call Shutdown() before deleting children of panel_container. | 53 // Call Shutdown() before deleting children of dock_container. |
| 65 void Shutdown(); | 54 void Shutdown(); |
| 66 | 55 |
| 67 void StartDragging(aura::Window* panel); | 56 void StartDragging(aura::Window* window); |
| 68 void FinishDragging(); | 57 void FinishDragging(); |
| 69 | 58 |
| 70 void ToggleMinimize(aura::Window* panel); | 59 void ToggleMinimize(aura::Window* window); |
| 71 | 60 |
| 72 ash::Launcher* launcher() { return launcher_; } | 61 ash::Launcher* launcher() { return launcher_; } |
| 73 void SetLauncher(ash::Launcher* launcher); | 62 void SetLauncher(ash::Launcher* launcher); |
| 74 | 63 |
| 64 DockEdge FindDockEdge(const gfx::Rect& bounds) const; | |
| 65 | |
| 75 // Overridden from aura::LayoutManager: | 66 // Overridden from aura::LayoutManager: |
| 76 virtual void OnWindowResized() OVERRIDE; | 67 virtual void OnWindowResized() OVERRIDE; |
| 77 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; | 68 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; |
| 78 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; | 69 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; |
| 79 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; | 70 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; |
| 80 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 71 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 81 bool visibile) OVERRIDE; | 72 bool visibile) OVERRIDE; |
| 82 virtual void SetChildBounds(aura::Window* child, | 73 virtual void SetChildBounds(aura::Window* child, |
| 83 const gfx::Rect& requested_bounds) OVERRIDE; | 74 const gfx::Rect& requested_bounds) OVERRIDE; |
| 84 | 75 |
| 85 // Overridden from ash::LauncherIconObserver | |
| 86 virtual void OnLauncherIconPositionsChanged() OVERRIDE; | |
| 87 | |
| 88 // Overridden from ash::ShellObserver | 76 // Overridden from ash::ShellObserver |
| 89 virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE; | 77 virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE; |
| 90 | 78 |
| 91 // Overridden from aura::WindowObserver | 79 // Overridden from aura::WindowObserver |
| 92 virtual void OnWindowPropertyChanged(aura::Window* window, | 80 virtual void OnWindowPropertyChanged(aura::Window* window, |
| 93 const void* key, | 81 const void* key, |
| 94 intptr_t old) OVERRIDE; | 82 intptr_t old) OVERRIDE; |
| 95 virtual void OnWindowVisibilityChanged(aura::Window* window, | 83 virtual void OnWindowVisibilityChanged(aura::Window* window, |
| 96 bool visible) OVERRIDE; | 84 bool visible) OVERRIDE; |
| 97 | 85 |
| 98 // Overridden from aura::client::ActivationChangeObserver | 86 // Overridden from aura::client::ActivationChangeObserver |
| 99 virtual void OnWindowActivated(aura::Window* gained_active, | 87 virtual void OnWindowActivated(aura::Window* gained_active, |
| 100 aura::Window* lost_active) OVERRIDE; | 88 aura::Window* lost_active) OVERRIDE; |
| 101 | 89 |
| 102 // Overridden from ShelfLayoutManagerObserver | 90 // Overridden from ShelfLayoutManagerObserver |
| 103 virtual void WillChangeVisibilityState( | 91 virtual void WillChangeVisibilityState( |
| 104 ShelfVisibilityState new_state) OVERRIDE; | 92 ShelfVisibilityState new_state) OVERRIDE; |
| 105 | 93 |
| 106 private: | 94 private: |
| 107 friend class PanelLayoutManagerTest; | 95 void MinimizeWindow(aura::Window* window); |
| 108 friend class PanelWindowResizerTest; | 96 void RestoreWindow(aura::Window* window); |
| 109 | 97 |
| 110 views::Widget* CreateCalloutWidget(); | 98 enum ForceMove { |
| 99 DO_NOT_FORCE_MOVE, | |
| 100 FORCE_MOVE, | |
| 101 }; | |
|
stevenjb
2013/06/03 18:19:03
nit: blank line
varkha
2013/06/03 21:03:17
Done.
| |
| 102 // Called whenever the window layout might change. | |
| 103 void Relayout(ForceMove force_move); | |
| 111 | 104 |
| 112 struct PanelInfo{ | 105 // Called whenever the window stacking order needs to be updated (e.g. focus |
| 113 PanelInfo() : window(NULL), callout_widget(NULL), slide_in(false) {} | 106 // changes or a window is moved). |
| 114 | 107 void UpdateStacking(aura::Window* active_window); |
| 115 bool operator==(const aura::Window* other_window) const { | |
| 116 return window == other_window; | |
| 117 } | |
| 118 | |
| 119 // A weak pointer to the panel window. | |
| 120 aura::Window* window; | |
| 121 // The callout widget for this panel. This pointer must be managed | |
| 122 // manually as this structure is used in a std::list. See | |
| 123 // http://www.chromium.org/developers/smart-pointer-guidelines | |
| 124 PanelCalloutWidget* callout_widget; | |
| 125 | |
| 126 // True on new and restored panel windows until the panel has been | |
| 127 // positioned. The first time Relayout is called the panel will slide into | |
| 128 // position and this will be set to false. | |
| 129 bool slide_in; | |
| 130 }; | |
| 131 | |
| 132 typedef std::list<PanelInfo> PanelList; | |
| 133 | |
| 134 void MinimizePanel(aura::Window* panel); | |
| 135 void RestorePanel(aura::Window* panel); | |
| 136 | |
| 137 // Called whenever the panel layout might change. | |
| 138 void Relayout(); | |
| 139 | |
| 140 // Called whenever the panel stacking order needs to be updated (e.g. focus | |
| 141 // changes or a panel is moved). | |
| 142 void UpdateStacking(aura::Window* active_panel); | |
| 143 | |
| 144 // Update the callout arrows for all managed panels. | |
| 145 void UpdateCallouts(); | |
| 146 | 108 |
| 147 // Overridden from keyboard::KeyboardControllerObserver: | 109 // Overridden from keyboard::KeyboardControllerObserver: |
| 148 virtual void OnKeyboardBoundsChanging( | 110 virtual void OnKeyboardBoundsChanging( |
| 149 const gfx::Rect& keyboard_bounds) OVERRIDE; | 111 const gfx::Rect& keyboard_bounds) OVERRIDE; |
| 150 | 112 |
| 151 // Parent window associated with this layout manager. | 113 // Parent window associated with this layout manager. |
| 152 aura::Window* panel_container_; | 114 aura::Window* dock_container_; |
| 153 // Protect against recursive calls to Relayout(). | 115 // Protect against recursive calls to Relayout(). |
| 154 bool in_layout_; | 116 bool in_layout_; |
| 155 // Ordered list of unowned pointers to panel windows. | 117 // The docked window being dragged. |
| 156 PanelList panel_windows_; | 118 aura::Window* dragged_window_; |
| 157 // The panel being dragged. | |
| 158 aura::Window* dragged_panel_; | |
| 159 // The launcher we are observing for launcher icon changes. | 119 // The launcher we are observing for launcher icon changes. |
| 160 Launcher* launcher_; | 120 Launcher* launcher_; |
| 161 // The shelf layout manager being observed for visibility changes. | 121 // The shelf layout manager being observed for visibility changes. |
| 162 ShelfLayoutManager* shelf_layout_manager_; | 122 ShelfLayoutManager* shelf_layout_manager_; |
| 163 // Tracks the visibility of the shelf. Defaults to false when there is no | 123 // Tracks the visibility of the shelf. Defaults to false when there is no |
| 164 // shelf. | 124 // shelf. |
| 165 bool shelf_hidden_; | 125 bool shelf_hidden_; |
| 166 // The last active panel. Used to maintain stacking even if no panels are | |
| 167 // currently focused. | |
| 168 aura::Window* last_active_panel_; | |
| 169 base::WeakPtrFactory<PanelLayoutManager> weak_factory_; | |
| 170 | 126 |
| 171 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManager); | 127 // side of the screen the dock is positioned at |
| 128 enum DockAlignment { | |
| 129 DOCK_ALIGNMENT_NONE, | |
| 130 DOCK_ALIGNMENT_LEFT, | |
| 131 DOCK_ALIGNMENT_RIGHT, | |
| 132 }; | |
| 133 DockAlignment alignment_; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(DockLayoutManager); | |
| 172 }; | 136 }; |
| 173 | 137 |
| 174 } // namespace internal | 138 } // namespace internal |
| 175 } // namespace ash | 139 } // namespace ash |
| 176 | 140 |
| 177 #endif // ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_ | 141 #endif // ASH_WM_DOCK_DOCK_LAYOUT_MANAGER_H_ |
| OLD | NEW |