| OLD | NEW |
| (Empty) |
| 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_PANELS_PANEL_LAYOUT_MANAGER_H_ | |
| 6 #define ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "ash/ash_export.h" | |
| 12 #include "ash/shelf/shelf_icon_observer.h" | |
| 13 #include "ash/shell_observer.h" | |
| 14 #include "ash/wm/common/shelf/wm_shelf_observer.h" | |
| 15 #include "ash/wm/common/window_state_observer.h" | |
| 16 #include "ash/wm/common/wm_activation_observer.h" | |
| 17 #include "ash/wm/common/wm_display_observer.h" | |
| 18 #include "ash/wm/common/wm_layout_manager.h" | |
| 19 #include "ash/wm/common/wm_overview_mode_observer.h" | |
| 20 #include "ash/wm/common/wm_root_window_controller_observer.h" | |
| 21 #include "ash/wm/common/wm_window_observer.h" | |
| 22 #include "ash/wm/common/wm_window_tracker.h" | |
| 23 #include "base/compiler_specific.h" | |
| 24 #include "base/macros.h" | |
| 25 #include "base/memory/weak_ptr.h" | |
| 26 #include "ui/keyboard/keyboard_controller.h" | |
| 27 #include "ui/keyboard/keyboard_controller_observer.h" | |
| 28 | |
| 29 namespace aura { | |
| 30 class Window; | |
| 31 } | |
| 32 | |
| 33 namespace gfx { | |
| 34 class Rect; | |
| 35 } | |
| 36 | |
| 37 namespace views { | |
| 38 class Widget; | |
| 39 } | |
| 40 | |
| 41 namespace ash { | |
| 42 class PanelCalloutWidget; | |
| 43 class Shelf; | |
| 44 class ShelfLayoutManager; | |
| 45 | |
| 46 namespace wm { | |
| 47 class WmRootWindowController; | |
| 48 class WmShelf; | |
| 49 } | |
| 50 | |
| 51 // PanelLayoutManager is responsible for organizing panels within the | |
| 52 // workspace. It is associated with a specific container window (i.e. | |
| 53 // kShellWindowId_PanelContainer) and controls the layout of any windows | |
| 54 // added to that container. | |
| 55 // | |
| 56 // The constructor takes a |panel_container| argument which is expected to set | |
| 57 // its layout manager to this instance, e.g.: | |
| 58 // panel_container->SetLayoutManager(new PanelLayoutManager(panel_container)); | |
| 59 | |
| 60 class ASH_EXPORT PanelLayoutManager | |
| 61 : public wm::WmLayoutManager, | |
| 62 public ShelfIconObserver, | |
| 63 public wm::WindowStateObserver, | |
| 64 public wm::WmActivationObserver, | |
| 65 public wm::WmDisplayObserver, | |
| 66 public wm::WmOverviewModeObserver, | |
| 67 public wm::WmRootWindowControllerObserver, | |
| 68 public wm::WmWindowObserver, | |
| 69 public keyboard::KeyboardControllerObserver, | |
| 70 public wm::WmShelfObserver { | |
| 71 public: | |
| 72 explicit PanelLayoutManager(wm::WmWindow* panel_container); | |
| 73 ~PanelLayoutManager() override; | |
| 74 | |
| 75 // Returns the PanelLayoutManager in the specified hierarchy. This searches | |
| 76 // from the root of |window|. | |
| 77 static PanelLayoutManager* Get(wm::WmWindow* window); | |
| 78 | |
| 79 // Call Shutdown() before deleting children of panel_container. | |
| 80 void Shutdown(); | |
| 81 | |
| 82 void StartDragging(wm::WmWindow* panel); | |
| 83 void FinishDragging(); | |
| 84 | |
| 85 void ToggleMinimize(wm::WmWindow* panel); | |
| 86 | |
| 87 // Hide / Show the panel callout widgets. | |
| 88 void SetShowCalloutWidgets(bool show); | |
| 89 | |
| 90 // Returns the callout widget (arrow) for |panel|. | |
| 91 views::Widget* GetCalloutWidgetForPanel(wm::WmWindow* panel); | |
| 92 | |
| 93 wm::WmShelf* shelf() { return shelf_; } | |
| 94 void SetShelf(wm::WmShelf* shelf); | |
| 95 | |
| 96 // Overridden from wm::WmLayoutManager | |
| 97 void OnWindowResized() override; | |
| 98 void OnWindowAddedToLayout(wm::WmWindow* child) override; | |
| 99 void OnWillRemoveWindowFromLayout(wm::WmWindow* child) override; | |
| 100 void OnWindowRemovedFromLayout(wm::WmWindow* child) override; | |
| 101 void OnChildWindowVisibilityChanged(wm::WmWindow* child, | |
| 102 bool visibile) override; | |
| 103 void SetChildBounds(wm::WmWindow* child, | |
| 104 const gfx::Rect& requested_bounds) override; | |
| 105 | |
| 106 // Overridden from wm::WmOverviewModeObserver | |
| 107 void OnOverviewModeEnded() override; | |
| 108 | |
| 109 // Overridden from wm::WmRootWindowControllerObserver | |
| 110 void OnShelfAlignmentChanged() override; | |
| 111 | |
| 112 // Overridden from wm::WmWindowObserver | |
| 113 void OnWindowPropertyChanged(wm::WmWindow* window, | |
| 114 wm::WmWindowProperty property, | |
| 115 intptr_t old) override; | |
| 116 | |
| 117 // Overridden from wm::WindowStateObserver | |
| 118 void OnPostWindowStateTypeChange(wm::WindowState* window_state, | |
| 119 wm::WindowStateType old_type) override; | |
| 120 | |
| 121 // Overridden from wm::WmActivationObserver | |
| 122 void OnWindowActivated(wm::WmWindow* gained_active, | |
| 123 wm::WmWindow* lost_active) override; | |
| 124 | |
| 125 // Overridden from WindowTreeHostManager::Observer | |
| 126 void OnDisplayConfigurationChanged() override; | |
| 127 | |
| 128 // Overridden from wm::WmShelfObserver | |
| 129 void WillChangeVisibilityState(ShelfVisibilityState new_state) override; | |
| 130 void OnShelfIconPositionsChanged() override; | |
| 131 | |
| 132 private: | |
| 133 friend class PanelLayoutManagerTest; | |
| 134 friend class PanelWindowResizerTest; | |
| 135 friend class DockedWindowResizerTest; | |
| 136 friend class DockedWindowLayoutManagerTest; | |
| 137 friend class WorkspaceControllerTest; | |
| 138 friend class AcceleratorControllerTest; | |
| 139 | |
| 140 views::Widget* CreateCalloutWidget(); | |
| 141 | |
| 142 struct ASH_EXPORT PanelInfo { | |
| 143 PanelInfo() : window(NULL), callout_widget(NULL), slide_in(false) {} | |
| 144 | |
| 145 bool operator==(const wm::WmWindow* other_window) const { | |
| 146 return window == other_window; | |
| 147 } | |
| 148 | |
| 149 // Returns |callout_widget| as a widget. Used by tests. | |
| 150 views::Widget* CalloutWidget(); | |
| 151 | |
| 152 // A weak pointer to the panel window. | |
| 153 wm::WmWindow* window; | |
| 154 | |
| 155 // The callout widget for this panel. This pointer must be managed | |
| 156 // manually as this structure is used in a std::list. See | |
| 157 // http://www.chromium.org/developers/smart-pointer-guidelines | |
| 158 PanelCalloutWidget* callout_widget; | |
| 159 | |
| 160 // True on new and restored panel windows until the panel has been | |
| 161 // positioned. The first time Relayout is called the panel will be shown, | |
| 162 // and slide into position and this will be set to false. | |
| 163 bool slide_in; | |
| 164 }; | |
| 165 | |
| 166 typedef std::list<PanelInfo> PanelList; | |
| 167 | |
| 168 void MinimizePanel(wm::WmWindow* panel); | |
| 169 void RestorePanel(wm::WmWindow* panel); | |
| 170 | |
| 171 // Called whenever the panel layout might change. | |
| 172 void Relayout(); | |
| 173 | |
| 174 // Called whenever the panel stacking order needs to be updated (e.g. focus | |
| 175 // changes or a panel is moved). | |
| 176 void UpdateStacking(wm::WmWindow* active_panel); | |
| 177 | |
| 178 // Update the callout arrows for all managed panels. | |
| 179 void UpdateCallouts(); | |
| 180 | |
| 181 // Overridden from keyboard::KeyboardControllerObserver: | |
| 182 void OnKeyboardBoundsChanging(const gfx::Rect& keyboard_bounds) override; | |
| 183 | |
| 184 // Parent window associated with this layout manager. | |
| 185 wm::WmWindow* panel_container_; | |
| 186 | |
| 187 wm::WmRootWindowController* root_window_controller_; | |
| 188 | |
| 189 // Protect against recursive calls to OnWindowAddedToLayout(). | |
| 190 bool in_add_window_; | |
| 191 // Protect against recursive calls to Relayout(). | |
| 192 bool in_layout_; | |
| 193 // Indicates if the panel callout widget should be created. | |
| 194 bool show_callout_widgets_; | |
| 195 // Ordered list of unowned pointers to panel windows. | |
| 196 PanelList panel_windows_; | |
| 197 // The panel being dragged. | |
| 198 wm::WmWindow* dragged_panel_; | |
| 199 // The shelf we are observing for shelf icon changes. | |
| 200 wm::WmShelf* shelf_; | |
| 201 | |
| 202 // When not NULL, the shelf is hidden (i.e. full screen) and this tracks the | |
| 203 // set of panel windows which have been temporarily hidden and need to be | |
| 204 // restored when the shelf becomes visible again. | |
| 205 std::unique_ptr<wm::WmWindowTracker> restore_windows_on_shelf_visible_; | |
| 206 | |
| 207 // The last active panel. Used to maintain stacking order even if no panels | |
| 208 // are currently focused. | |
| 209 wm::WmWindow* last_active_panel_; | |
| 210 base::WeakPtrFactory<PanelLayoutManager> weak_factory_; | |
| 211 | |
| 212 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManager); | |
| 213 }; | |
| 214 | |
| 215 } // namespace ash | |
| 216 | |
| 217 #endif // ASH_WM_PANELS_PANEL_LAYOUT_MANAGER_H_ | |
| OLD | NEW |