[email protected] | 1b62b89 | 2012-01-17 17:08:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 7634f96 | 2011-12-23 21:35:52 | [diff] [blame] | 5 | #ifndef ASH_WM_SHELF_LAYOUT_MANAGER_H_ |
| 6 | #define ASH_WM_SHELF_LAYOUT_MANAGER_H_ |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 7 | #pragma once |
| 8 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 9 | #include "ash/ash_export.h" |
| 10 | #include "ash/launcher/launcher.h" |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 11 | #include "base/basictypes.h" |
| 12 | #include "base/compiler_specific.h" |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 13 | #include "base/timer.h" |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 14 | #include "ui/aura/layout_manager.h" |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 15 | #include "ui/gfx/insets.h" |
| 16 | #include "ui/gfx/rect.h" |
| 17 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 18 | namespace views { |
| 19 | class Widget; |
| 20 | } |
| 21 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 22 | namespace ash { |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 23 | namespace internal { |
| 24 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 25 | class ShelfLayoutManagerTest; |
| 26 | class WorkspaceManager; |
| 27 | |
[email protected] | 22f9d31 | 2011-12-15 17:38:55 | [diff] [blame] | 28 | // ShelfLayoutManager is the layout manager responsible for the launcher and |
| 29 | // status widgets. The launcher is given the total available width and told the |
| 30 | // width of the status area. This allows the launcher to draw the background and |
| 31 | // layout to the status area. |
| 32 | // To respond to bounds changes in the status area StatusAreaLayoutManager works |
| 33 | // closely with ShelfLayoutManager. |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 34 | class ASH_EXPORT ShelfLayoutManager : public aura::LayoutManager { |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 35 | public: |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 36 | enum VisibilityState { |
| 37 | // Completely visible. |
| 38 | VISIBLE, |
| 39 | |
| 40 | // A couple of pixels are reserved at the bottom for the shelf. |
| 41 | AUTO_HIDE, |
| 42 | |
| 43 | // Nothing is shown. Used for fullscreen windows. |
| 44 | HIDDEN, |
| 45 | }; |
| 46 | |
| 47 | enum AutoHideState { |
| 48 | AUTO_HIDE_SHOWN, |
| 49 | AUTO_HIDE_HIDDEN, |
| 50 | }; |
| 51 | |
[email protected] | bbb59f8 | 2012-03-14 04:04:35 | [diff] [blame] | 52 | // We reserve a small area at the bottom of the workspace area to ensure that |
| 53 | // the bottom-of-window resize handle can be hit. |
| 54 | // TODO(jamescook): Some day we may want the workspace area to be an even |
| 55 | // multiple of the size of the grid (currently 8 pixels), which will require |
| 56 | // removing this and finding a way for hover and click events to pass through |
| 57 | // the invisible parts of the launcher. |
| 58 | static const int kWorkspaceAreaBottomInset; |
| 59 | |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 60 | // Height of the shelf when auto-hidden. |
| 61 | static const int kAutoHideHeight; |
| 62 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 63 | explicit ShelfLayoutManager(views::Widget* status); |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 64 | virtual ~ShelfLayoutManager(); |
| 65 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 66 | // Sets whether the shelf always auto-hides. Default is false. |
| 67 | void SetAlwaysAutoHide(bool value); |
| 68 | bool always_auto_hide() const { return always_auto_hide_; } |
| 69 | |
| 70 | void set_workspace_manager(WorkspaceManager* manager) { |
| 71 | workspace_manager_ = manager; |
| 72 | } |
| 73 | |
[email protected] | d9456cb | 2012-03-21 16:41:04 | [diff] [blame] | 74 | views::Widget* launcher_widget() { |
| 75 | return launcher_ ? launcher_->widget() : NULL; |
| 76 | } |
| 77 | const views::Widget* launcher_widget() const { |
| 78 | return launcher_ ? launcher_->widget() : NULL; |
| 79 | } |
| 80 | views::Widget* status() { return status_; } |
| 81 | |
| 82 | bool in_layout() const { return in_layout_; } |
| 83 | |
| 84 | // See description above field. |
| 85 | int shelf_height() const { return shelf_height_; } |
| 86 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 87 | // Returns the bounds the specified window should be when maximized. |
| 88 | gfx::Rect GetMaximizedWindowBounds(aura::Window* window) const; |
| 89 | gfx::Rect GetUnmaximizedWorkAreaBounds(aura::Window* window) const; |
| 90 | |
[email protected] | d9456cb | 2012-03-21 16:41:04 | [diff] [blame] | 91 | // The launcher is typically created after the layout manager. |
| 92 | void SetLauncher(Launcher* launcher); |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 93 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 94 | // Stops any animations and sets the bounds of the launcher and status |
| 95 | // widgets. |
| 96 | void LayoutShelf(); |
| 97 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 98 | // Updates the visibility state. |
| 99 | void UpdateVisibilityState(); |
[email protected] | 203fe858 | 2012-03-24 06:17:14 | [diff] [blame] | 100 | |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 101 | // Invoked by the shelf/launcher when the auto-hide state may have changed. |
| 102 | void UpdateAutoHideState(); |
| 103 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 104 | VisibilityState visibility_state() const { return state_.visibility_state; } |
| 105 | AutoHideState auto_hide_state() const { return state_.auto_hide_state; } |
| 106 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 107 | // Sets whether any windows overlap the shelf. If a window overlaps the shelf |
| 108 | // the shelf renders slightly differently. |
| 109 | void SetWindowOverlapsShelf(bool value); |
| 110 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 111 | // Overridden from aura::LayoutManager: |
| 112 | virtual void OnWindowResized() OVERRIDE; |
| 113 | virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; |
| 114 | virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; |
| 115 | virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 116 | bool visible) OVERRIDE; |
| 117 | virtual void SetChildBounds(aura::Window* child, |
| 118 | const gfx::Rect& requested_bounds) OVERRIDE; |
| 119 | |
| 120 | private: |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 121 | class AutoHideEventFilter; |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 122 | friend class ShelfLayoutManagerTest; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 123 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 124 | struct TargetBounds { |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 125 | TargetBounds() : opacity(0.0f) {} |
| 126 | |
| 127 | float opacity; |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 128 | gfx::Rect launcher_bounds; |
| 129 | gfx::Rect status_bounds; |
| 130 | gfx::Insets work_area_insets; |
| 131 | }; |
| 132 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 133 | struct State { |
| 134 | State() : visibility_state(VISIBLE), auto_hide_state(AUTO_HIDE_HIDDEN) {} |
| 135 | |
| 136 | // Returns true if the two states are considered equal. As |
| 137 | // |auto_hide_state| only matters if |visibility_state| is |AUTO_HIDE|, |
| 138 | // Equals() ignores the |auto_hide_state| as appropriate. |
| 139 | bool Equals(const State& other) const { |
| 140 | return other.visibility_state == visibility_state && |
| 141 | (visibility_state != AUTO_HIDE || |
| 142 | other.auto_hide_state == auto_hide_state); |
| 143 | } |
| 144 | |
| 145 | VisibilityState visibility_state; |
| 146 | AutoHideState auto_hide_state; |
| 147 | }; |
| 148 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 149 | // Sets the visibility of the shelf to |state|. |
| 150 | void SetState(VisibilityState visibility_state); |
| 151 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 152 | // Stops any animations. |
| 153 | void StopAnimating(); |
| 154 | |
[email protected] | 35304ce | 2011-12-14 23:21:01 | [diff] [blame] | 155 | // Calculates the target bounds assuming visibility of |visible|. |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 156 | void CalculateTargetBounds(const State& state, |
| 157 | TargetBounds* target_bounds) const; |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 158 | |
[email protected] | a160baec | 2012-03-21 20:52:15 | [diff] [blame] | 159 | // Updates the background of the shelf. |
| 160 | void UpdateShelfBackground(BackgroundAnimator::ChangeType type); |
| 161 | |
| 162 | // Returns whether the launcher should draw a background. |
| 163 | bool GetLauncherPaintsBackground() const; |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 164 | |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 165 | // Updates the auto hide state immediately. |
| 166 | void UpdateAutoHideStateNow(); |
| 167 | |
| 168 | // Returns the AutoHideState. This value is determined from the launcher and |
| 169 | // tray. |
| 170 | AutoHideState CalculateAutoHideState(VisibilityState visibility_state) const; |
| 171 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 172 | // True when inside LayoutShelf method. Used to prevent calling LayoutShelf |
| 173 | // again from SetChildBounds(). |
| 174 | bool in_layout_; |
| 175 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 176 | // See description above setter. |
| 177 | bool always_auto_hide_; |
| 178 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 179 | // Current state. |
| 180 | State state_; |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 181 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 182 | // Height of the shelf (max of launcher and status). |
| 183 | int shelf_height_; |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 184 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 185 | Launcher* launcher_; |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 186 | views::Widget* status_; |
| 187 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 188 | WorkspaceManager* workspace_manager_; |
| 189 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 190 | // Do any windows overlap the shelf? This is maintained by WorkspaceManager. |
| 191 | bool window_overlaps_shelf_; |
| 192 | |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 193 | base::OneShotTimer<ShelfLayoutManager> auto_hide_timer_; |
| 194 | |
| 195 | // EventFilter used to detect when user moves the mouse over the launcher to |
| 196 | // trigger showing the launcher. |
| 197 | scoped_ptr<AutoHideEventFilter> event_filter_; |
[email protected] | 5b0ca08 | 2012-03-14 06:20:22 | [diff] [blame] | 198 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 199 | DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManager); |
| 200 | }; |
| 201 | |
| 202 | } // namespace internal |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 203 | } // namespace ash |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 204 | |
[email protected] | 7634f96 | 2011-12-23 21:35:52 | [diff] [blame] | 205 | #endif // ASH_WM_SHELF_LAYOUT_MANAGER_H_ |