blob: 05e3e7a56f0c38c7e23b26c46d44570aef1144f3 [file] [log] [blame]
[email protected]1b62b892012-01-17 17:08:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]4bb16502011-12-06 14:44:582// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]7634f962011-12-23 21:35:525#ifndef ASH_WM_SHELF_LAYOUT_MANAGER_H_
6#define ASH_WM_SHELF_LAYOUT_MANAGER_H_
[email protected]4bb16502011-12-06 14:44:587#pragma once
8
[email protected]27f6af62012-03-21 05:34:409#include "ash/ash_export.h"
10#include "ash/launcher/launcher.h"
[email protected]4bb16502011-12-06 14:44:5811#include "base/basictypes.h"
12#include "base/compiler_specific.h"
[email protected]b1c37fc2012-03-22 03:36:1313#include "base/timer.h"
[email protected]4bb16502011-12-06 14:44:5814#include "ui/aura/layout_manager.h"
[email protected]4bb16502011-12-06 14:44:5815#include "ui/gfx/insets.h"
16#include "ui/gfx/rect.h"
17
[email protected]4bb16502011-12-06 14:44:5818namespace views {
19class Widget;
20}
21
[email protected]55f593352011-12-24 05:42:4622namespace ash {
[email protected]4bb16502011-12-06 14:44:5823namespace internal {
24
[email protected]c758fbf2012-03-25 22:53:5925class ShelfLayoutManagerTest;
26class WorkspaceManager;
27
[email protected]22f9d312011-12-15 17:38:5528// 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]27f6af62012-03-21 05:34:4034class ASH_EXPORT ShelfLayoutManager : public aura::LayoutManager {
[email protected]4bb16502011-12-06 14:44:5835 public:
[email protected]27f6af62012-03-21 05:34:4036 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]bbb59f82012-03-14 04:04:3552 // 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]b1c37fc2012-03-22 03:36:1360 // Height of the shelf when auto-hidden.
61 static const int kAutoHideHeight;
62
[email protected]27f6af62012-03-21 05:34:4063 explicit ShelfLayoutManager(views::Widget* status);
[email protected]4bb16502011-12-06 14:44:5864 virtual ~ShelfLayoutManager();
65
[email protected]c758fbf2012-03-25 22:53:5966 // 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]d9456cb2012-03-21 16:41:0474 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]27f6af62012-03-21 05:34:4087 // 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]d9456cb2012-03-21 16:41:0491 // The launcher is typically created after the layout manager.
92 void SetLauncher(Launcher* launcher);
[email protected]4bb16502011-12-06 14:44:5893
[email protected]4bb16502011-12-06 14:44:5894 // Stops any animations and sets the bounds of the launcher and status
95 // widgets.
96 void LayoutShelf();
97
[email protected]c758fbf2012-03-25 22:53:5998 // Updates the visibility state.
99 void UpdateVisibilityState();
[email protected]203fe8582012-03-24 06:17:14100
[email protected]b1c37fc2012-03-22 03:36:13101 // Invoked by the shelf/launcher when the auto-hide state may have changed.
102 void UpdateAutoHideState();
103
[email protected]c758fbf2012-03-25 22:53:59104 VisibilityState visibility_state() const { return state_.visibility_state; }
105 AutoHideState auto_hide_state() const { return state_.auto_hide_state; }
106
[email protected]27f6af62012-03-21 05:34:40107 // 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]4bb16502011-12-06 14:44:58111 // 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]b1c37fc2012-03-22 03:36:13121 class AutoHideEventFilter;
[email protected]c758fbf2012-03-25 22:53:59122 friend class ShelfLayoutManagerTest;
[email protected]b1c37fc2012-03-22 03:36:13123
[email protected]4bb16502011-12-06 14:44:58124 struct TargetBounds {
[email protected]27f6af62012-03-21 05:34:40125 TargetBounds() : opacity(0.0f) {}
126
127 float opacity;
[email protected]4bb16502011-12-06 14:44:58128 gfx::Rect launcher_bounds;
129 gfx::Rect status_bounds;
130 gfx::Insets work_area_insets;
131 };
132
[email protected]27f6af62012-03-21 05:34:40133 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]c758fbf2012-03-25 22:53:59149 // Sets the visibility of the shelf to |state|.
150 void SetState(VisibilityState visibility_state);
151
[email protected]4bb16502011-12-06 14:44:58152 // Stops any animations.
153 void StopAnimating();
154
[email protected]35304ce2011-12-14 23:21:01155 // Calculates the target bounds assuming visibility of |visible|.
[email protected]27f6af62012-03-21 05:34:40156 void CalculateTargetBounds(const State& state,
157 TargetBounds* target_bounds) const;
[email protected]4bb16502011-12-06 14:44:58158
[email protected]a160baec2012-03-21 20:52:15159 // 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]4bb16502011-12-06 14:44:58164
[email protected]b1c37fc2012-03-22 03:36:13165 // 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]4bb16502011-12-06 14:44:58172 // True when inside LayoutShelf method. Used to prevent calling LayoutShelf
173 // again from SetChildBounds().
174 bool in_layout_;
175
[email protected]c758fbf2012-03-25 22:53:59176 // See description above setter.
177 bool always_auto_hide_;
178
[email protected]27f6af62012-03-21 05:34:40179 // Current state.
180 State state_;
[email protected]4bb16502011-12-06 14:44:58181
[email protected]27f6af62012-03-21 05:34:40182 // Height of the shelf (max of launcher and status).
183 int shelf_height_;
[email protected]4bb16502011-12-06 14:44:58184
[email protected]27f6af62012-03-21 05:34:40185 Launcher* launcher_;
[email protected]4bb16502011-12-06 14:44:58186 views::Widget* status_;
187
[email protected]c758fbf2012-03-25 22:53:59188 WorkspaceManager* workspace_manager_;
189
[email protected]27f6af62012-03-21 05:34:40190 // Do any windows overlap the shelf? This is maintained by WorkspaceManager.
191 bool window_overlaps_shelf_;
192
[email protected]b1c37fc2012-03-22 03:36:13193 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]5b0ca082012-03-14 06:20:22198
[email protected]4bb16502011-12-06 14:44:58199 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManager);
200};
201
202} // namespace internal
[email protected]55f593352011-12-24 05:42:46203} // namespace ash
[email protected]4bb16502011-12-06 14:44:58204
[email protected]7634f962011-12-23 21:35:52205#endif // ASH_WM_SHELF_LAYOUT_MANAGER_H_