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_SHELF_LAYOUT_MANAGER_H_ | 5 #ifndef ASH_WM_SHELF_LAYOUT_MANAGER_H_ |
6 #define ASH_WM_SHELF_LAYOUT_MANAGER_H_ | 6 #define ASH_WM_SHELF_LAYOUT_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "ash/ash_export.h" | 9 #include "ash/ash_export.h" |
10 #include "ash/launcher/launcher.h" | 10 #include "ash/launcher/launcher.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/timer.h" |
13 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
14 #include "ui/gfx/insets.h" | 15 #include "ui/gfx/insets.h" |
15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
16 | 17 |
17 namespace aura { | |
18 class RootWindow; | |
19 } | |
20 | |
21 namespace views { | 18 namespace views { |
22 class Widget; | 19 class Widget; |
23 } | 20 } |
24 | 21 |
25 namespace ash { | 22 namespace ash { |
26 namespace internal { | 23 namespace internal { |
27 | 24 |
28 // ShelfLayoutManager is the layout manager responsible for the launcher and | 25 // ShelfLayoutManager is the layout manager responsible for the launcher and |
29 // status widgets. The launcher is given the total available width and told the | 26 // 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 | 27 // width of the status area. This allows the launcher to draw the background and |
(...skipping 19 matching lines...) Expand all Loading... |
50 }; | 47 }; |
51 | 48 |
52 // We reserve a small area at the bottom of the workspace area to ensure that | 49 // 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. | 50 // the bottom-of-window resize handle can be hit. |
54 // TODO(jamescook): Some day we may want the workspace area to be an even | 51 // 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 | 52 // 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 | 53 // removing this and finding a way for hover and click events to pass through |
57 // the invisible parts of the launcher. | 54 // the invisible parts of the launcher. |
58 static const int kWorkspaceAreaBottomInset; | 55 static const int kWorkspaceAreaBottomInset; |
59 | 56 |
| 57 // Height of the shelf when auto-hidden. |
| 58 static const int kAutoHideHeight; |
| 59 |
60 explicit ShelfLayoutManager(views::Widget* status); | 60 explicit ShelfLayoutManager(views::Widget* status); |
61 virtual ~ShelfLayoutManager(); | 61 virtual ~ShelfLayoutManager(); |
62 | 62 |
63 views::Widget* launcher_widget() { | 63 views::Widget* launcher_widget() { |
64 return launcher_ ? launcher_->widget() : NULL; | 64 return launcher_ ? launcher_->widget() : NULL; |
65 } | 65 } |
66 const views::Widget* launcher_widget() const { | 66 const views::Widget* launcher_widget() const { |
67 return launcher_ ? launcher_->widget() : NULL; | 67 return launcher_ ? launcher_->widget() : NULL; |
68 } | 68 } |
69 views::Widget* status() { return status_; } | 69 views::Widget* status() { return status_; } |
70 | 70 |
71 bool in_layout() const { return in_layout_; } | 71 bool in_layout() const { return in_layout_; } |
72 | 72 |
73 // See description above field. | 73 // See description above field. |
74 int shelf_height() const { return shelf_height_; } | 74 int shelf_height() const { return shelf_height_; } |
75 | 75 |
76 // Returns the bounds the specified window should be when maximized. | 76 // Returns the bounds the specified window should be when maximized. |
77 gfx::Rect GetMaximizedWindowBounds(aura::Window* window) const; | 77 gfx::Rect GetMaximizedWindowBounds(aura::Window* window) const; |
78 gfx::Rect GetUnmaximizedWorkAreaBounds(aura::Window* window) const; | 78 gfx::Rect GetUnmaximizedWorkAreaBounds(aura::Window* window) const; |
79 | 79 |
80 // The launcher is typically created after the layout manager. | 80 // The launcher is typically created after the layout manager. |
81 void SetLauncher(Launcher* launcher); | 81 void SetLauncher(Launcher* launcher); |
82 | 82 |
83 // Stops any animations and sets the bounds of the launcher and status | 83 // Stops any animations and sets the bounds of the launcher and status |
84 // widgets. | 84 // widgets. |
85 void LayoutShelf(); | 85 void LayoutShelf(); |
86 | 86 |
87 // Sets the visibility of the shelf to |state|. | 87 // Sets the visibility of the shelf to |state|. |
88 void SetState(VisibilityState visibility_state, | 88 void SetState(VisibilityState visibility_state); |
89 AutoHideState auto_hide_state); | |
90 VisibilityState visibility_state() const { return state_.visibility_state; } | 89 VisibilityState visibility_state() const { return state_.visibility_state; } |
91 AutoHideState auto_hide_state() const { return state_.auto_hide_state; } | 90 AutoHideState auto_hide_state() const { return state_.auto_hide_state; } |
92 | 91 |
| 92 // Invoked by the shelf/launcher when the auto-hide state may have changed. |
| 93 void UpdateAutoHideState(); |
| 94 |
93 // Sets whether any windows overlap the shelf. If a window overlaps the shelf | 95 // Sets whether any windows overlap the shelf. If a window overlaps the shelf |
94 // the shelf renders slightly differently. | 96 // the shelf renders slightly differently. |
95 void SetWindowOverlapsShelf(bool value); | 97 void SetWindowOverlapsShelf(bool value); |
96 | 98 |
97 // Overridden from aura::LayoutManager: | 99 // Overridden from aura::LayoutManager: |
98 virtual void OnWindowResized() OVERRIDE; | 100 virtual void OnWindowResized() OVERRIDE; |
99 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; | 101 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; |
100 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; | 102 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; |
101 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 103 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
102 bool visible) OVERRIDE; | 104 bool visible) OVERRIDE; |
103 virtual void SetChildBounds(aura::Window* child, | 105 virtual void SetChildBounds(aura::Window* child, |
104 const gfx::Rect& requested_bounds) OVERRIDE; | 106 const gfx::Rect& requested_bounds) OVERRIDE; |
105 | 107 |
106 private: | 108 private: |
| 109 class AutoHideEventFilter; |
| 110 |
107 struct TargetBounds { | 111 struct TargetBounds { |
108 TargetBounds() : opacity(0.0f) {} | 112 TargetBounds() : opacity(0.0f) {} |
109 | 113 |
110 float opacity; | 114 float opacity; |
111 gfx::Rect launcher_bounds; | 115 gfx::Rect launcher_bounds; |
112 gfx::Rect status_bounds; | 116 gfx::Rect status_bounds; |
113 gfx::Insets work_area_insets; | 117 gfx::Insets work_area_insets; |
114 }; | 118 }; |
115 | 119 |
116 struct State { | 120 struct State { |
(...skipping 18 matching lines...) Expand all Loading... |
135 // Calculates the target bounds assuming visibility of |visible|. | 139 // Calculates the target bounds assuming visibility of |visible|. |
136 void CalculateTargetBounds(const State& state, | 140 void CalculateTargetBounds(const State& state, |
137 TargetBounds* target_bounds) const; | 141 TargetBounds* target_bounds) const; |
138 | 142 |
139 // Updates the background of the shelf. | 143 // Updates the background of the shelf. |
140 void UpdateShelfBackground(BackgroundAnimator::ChangeType type); | 144 void UpdateShelfBackground(BackgroundAnimator::ChangeType type); |
141 | 145 |
142 // Returns whether the launcher should draw a background. | 146 // Returns whether the launcher should draw a background. |
143 bool GetLauncherPaintsBackground() const; | 147 bool GetLauncherPaintsBackground() const; |
144 | 148 |
| 149 // Updates the auto hide state immediately. |
| 150 void UpdateAutoHideStateNow(); |
| 151 |
| 152 // Returns the AutoHideState. This value is determined from the launcher and |
| 153 // tray. |
| 154 AutoHideState CalculateAutoHideState(VisibilityState visibility_state) const; |
| 155 |
145 // True when inside LayoutShelf method. Used to prevent calling LayoutShelf | 156 // True when inside LayoutShelf method. Used to prevent calling LayoutShelf |
146 // again from SetChildBounds(). | 157 // again from SetChildBounds(). |
147 bool in_layout_; | 158 bool in_layout_; |
148 | 159 |
149 // Current state. | 160 // Current state. |
150 State state_; | 161 State state_; |
151 | 162 |
152 // Height of the shelf (max of launcher and status). | 163 // Height of the shelf (max of launcher and status). |
153 int shelf_height_; | 164 int shelf_height_; |
154 | 165 |
155 Launcher* launcher_; | 166 Launcher* launcher_; |
156 views::Widget* status_; | 167 views::Widget* status_; |
157 | 168 |
158 // Do any windows overlap the shelf? This is maintained by WorkspaceManager. | 169 // Do any windows overlap the shelf? This is maintained by WorkspaceManager. |
159 bool window_overlaps_shelf_; | 170 bool window_overlaps_shelf_; |
160 | 171 |
161 aura::RootWindow* root_window_; | 172 base::OneShotTimer<ShelfLayoutManager> auto_hide_timer_; |
| 173 |
| 174 // EventFilter used to detect when user moves the mouse over the launcher to |
| 175 // trigger showing the launcher. |
| 176 scoped_ptr<AutoHideEventFilter> event_filter_; |
162 | 177 |
163 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManager); | 178 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManager); |
164 }; | 179 }; |
165 | 180 |
166 } // namespace internal | 181 } // namespace internal |
167 } // namespace ash | 182 } // namespace ash |
168 | 183 |
169 #endif // ASH_WM_SHELF_LAYOUT_MANAGER_H_ | 184 #endif // ASH_WM_SHELF_LAYOUT_MANAGER_H_ |
OLD | NEW |