OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ |
6 #define CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ | 6 #define CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | |
14 #include "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" | 13 #include "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" |
15 #include "chrome/browser/ui/panels/panel.h" | 14 #include "chrome/browser/ui/panels/panel.h" |
16 #include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h" | |
17 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
18 | 16 |
| 17 // TODO(jennb): Clean up by removing functions below that cause this |
| 18 // to be required. |
| 19 #ifdef UNIT_TEST |
| 20 #include "chrome/browser/ui/panels/panel_strip.h" |
| 21 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
| 22 #endif |
| 23 |
19 class Browser; | 24 class Browser; |
20 class Panel; | |
21 class PanelMouseWatcher; | 25 class PanelMouseWatcher; |
| 26 class PanelStrip; |
22 | 27 |
23 // This class manages a set of panels. | 28 // This class manages a set of panels. |
24 // Note that the ref count is needed by using PostTask in the implementation. | 29 class PanelManager : public AutoHidingDesktopBar::Observer { |
25 class PanelManager : public PanelMouseWatcherObserver, | |
26 public AutoHidingDesktopBar::Observer { | |
27 public: | 30 public: |
28 typedef std::vector<Panel*> Panels; | 31 typedef std::vector<Panel*> Panels; |
29 | 32 |
30 // Returns a single instance. | 33 // Returns a single instance. |
31 static PanelManager* GetInstance(); | 34 static PanelManager* GetInstance(); |
32 | 35 |
33 // Called when the display is changed, i.e. work area is updated. | 36 // Called when the display is changed, i.e. work area is updated. |
34 void OnDisplayChanged(); | 37 void OnDisplayChanged(); |
35 | 38 |
36 // Creates a panel and returns it. The panel might be queued for display | 39 // Creates a panel and returns it. The panel might be queued for display |
37 // later. | 40 // later. |
38 Panel* CreatePanel(Browser* browser); | 41 Panel* CreatePanel(Browser* browser); |
39 | 42 |
40 void Remove(Panel* panel); | 43 void Remove(Panel* panel); |
41 void RemoveAll(); | 44 void RemoveAll(); |
42 | 45 |
| 46 // Asynchronous confirmation of panel having been removed. |
| 47 void OnPanelRemoved(Panel* panel); |
| 48 |
43 // Drags the given panel. | 49 // Drags the given panel. |
44 void StartDragging(Panel* panel); | 50 void StartDragging(Panel* panel); |
45 void Drag(int delta_x); | 51 void Drag(int delta_x); |
46 void EndDragging(bool cancelled); | 52 void EndDragging(bool cancelled); |
47 | 53 |
48 // Invoked when a panel's expansion state changes. | 54 // Invoked when a panel's expansion state changes. |
49 void OnPanelExpansionStateChanged(Panel::ExpansionState old_state, | 55 void OnPanelExpansionStateChanged(Panel::ExpansionState old_state, |
50 Panel::ExpansionState new_state); | 56 Panel::ExpansionState new_state); |
51 | 57 |
52 // Invoked when the preferred window size of the given panel might need to | 58 // Invoked when the preferred window size of the given panel might need to |
(...skipping 12 matching lines...) Expand all Loading... |
65 // hide bottom bar is present, we want to move the minimized panel to the | 71 // hide bottom bar is present, we want to move the minimized panel to the |
66 // bottom of the screen, not the bottom of the work area. | 72 // bottom of the screen, not the bottom of the work area. |
67 int GetBottomPositionForExpansionState( | 73 int GetBottomPositionForExpansionState( |
68 Panel::ExpansionState expansion_state) const; | 74 Panel::ExpansionState expansion_state) const; |
69 | 75 |
70 // Returns the next browser window which could be either panel window or | 76 // Returns the next browser window which could be either panel window or |
71 // tabbed window, to switch to if the given panel is going to be deactivated. | 77 // tabbed window, to switch to if the given panel is going to be deactivated. |
72 // Returns NULL if such window cannot be found. | 78 // Returns NULL if such window cannot be found. |
73 BrowserWindow* GetNextBrowserWindowToActivate(Panel* panel) const; | 79 BrowserWindow* GetNextBrowserWindowToActivate(Panel* panel) const; |
74 | 80 |
75 int num_panels() const { return panels_.size(); } | 81 int num_panels() const; |
76 bool is_dragging_panel() const; | 82 bool is_dragging_panel() const; |
77 const Panels& panels() const { return panels_; } | |
78 | |
79 int GetMaxPanelWidth() const; | |
80 int GetMaxPanelHeight() const; | |
81 int StartingRightPosition() const; | 83 int StartingRightPosition() const; |
82 | 84 const Panels& panels() const; |
83 // Moves a panel to the panel strip. The panel does not currently | |
84 // belong in any other strip. This may cause other panels to be | |
85 // bumped out of the panel strip. | |
86 void MoveToPanelStrip(Panel* panel); | |
87 | 85 |
88 // Moves a panel to the overflow strip. The panel does not currently | 86 // Moves a panel to the overflow strip. The panel does not currently |
89 // belong in any other strip. | 87 // belong in any other strip. |
90 // |is_new| is true if the panel was just created. | 88 // |is_new| is true if the panel was just created. |
91 void MoveToOverflowStrip(Panel* panel, bool is_new); | 89 void MoveToOverflowStrip(Panel* panel, bool is_new); |
92 | 90 |
93 // Overridden from PanelMouseWatcherObserver: | 91 AutoHidingDesktopBar* auto_hiding_desktop_bar() const { |
94 virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE; | 92 return auto_hiding_desktop_bar_; |
| 93 } |
| 94 |
| 95 PanelMouseWatcher* mouse_watcher() const { |
| 96 return panel_mouse_watcher_.get(); |
| 97 } |
| 98 |
| 99 PanelStrip* panel_strip() const { |
| 100 return panel_strip_.get(); |
| 101 } |
95 | 102 |
96 #ifdef UNIT_TEST | 103 #ifdef UNIT_TEST |
97 static int horizontal_spacing() { return kPanelsHorizontalSpacing; } | 104 static int horizontal_spacing() { return PanelStrip::horizontal_spacing(); } |
98 | 105 |
99 const gfx::Rect& work_area() const { | 106 const gfx::Rect& work_area() const { |
100 return work_area_; | 107 return work_area_; |
101 } | 108 } |
102 | 109 |
103 void set_auto_hiding_desktop_bar( | 110 void set_auto_hiding_desktop_bar( |
104 AutoHidingDesktopBar* auto_hiding_desktop_bar) { | 111 AutoHidingDesktopBar* auto_hiding_desktop_bar) { |
105 auto_hiding_desktop_bar_ = auto_hiding_desktop_bar; | 112 auto_hiding_desktop_bar_ = auto_hiding_desktop_bar; |
106 } | 113 } |
107 | 114 |
| 115 void set_mouse_watcher(PanelMouseWatcher* watcher) { |
| 116 panel_mouse_watcher_.reset(watcher); |
| 117 } |
| 118 |
108 void enable_auto_sizing(bool enabled) { | 119 void enable_auto_sizing(bool enabled) { |
109 auto_sizing_enabled_ = enabled; | 120 auto_sizing_enabled_ = enabled; |
110 } | 121 } |
111 | 122 |
112 void SetWorkAreaForTesting(const gfx::Rect& work_area) { | 123 void SetWorkAreaForTesting(const gfx::Rect& work_area) { |
113 SetWorkArea(work_area); | 124 SetWorkArea(work_area); |
114 } | 125 } |
115 | 126 |
116 void remove_delays_for_testing() { | 127 void remove_delays_for_testing() { |
117 remove_delays_for_testing_ = true; | 128 panel_strip_->remove_delays_for_testing(); |
118 } | 129 } |
119 | 130 |
120 int minimized_panel_count() { | 131 int minimized_panel_count() { |
121 return minimized_panel_count_; | 132 return panel_strip_->minimized_panel_count(); |
122 } | |
123 | |
124 // Tests should disable mouse watching if mouse movements will be simulated. | |
125 void disable_mouse_watching() { | |
126 mouse_watching_disabled_ = true; | |
127 } | 133 } |
128 #endif | 134 #endif |
129 | 135 |
130 private: | 136 private: |
131 friend struct base::DefaultLazyInstanceTraits<PanelManager>; | 137 friend struct base::DefaultLazyInstanceTraits<PanelManager>; |
132 FRIEND_TEST_ALL_PREFIXES(PanelBrowserTest, SizeClamping); | |
133 | |
134 enum TitlebarAction { | |
135 NO_ACTION, | |
136 BRING_UP, | |
137 BRING_DOWN | |
138 }; | |
139 | 138 |
140 PanelManager(); | 139 PanelManager(); |
141 virtual ~PanelManager(); | 140 virtual ~PanelManager(); |
142 | 141 |
143 // Overridden from AutoHidingDesktopBar::Observer: | 142 // Overridden from AutoHidingDesktopBar::Observer: |
144 virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE; | 143 virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE; |
145 virtual void OnAutoHidingDesktopBarVisibilityChanged( | 144 virtual void OnAutoHidingDesktopBarVisibilityChanged( |
146 AutoHidingDesktopBar::Alignment alignment, | 145 AutoHidingDesktopBar::Alignment alignment, |
147 AutoHidingDesktopBar::Visibility visibility) OVERRIDE; | 146 AutoHidingDesktopBar::Visibility visibility) OVERRIDE; |
148 | 147 |
149 // Applies the new work area. This is called by OnDisplayChanged and the test | 148 // Applies the new work area. This is called by OnDisplayChanged and the test |
150 // code. | 149 // code. |
151 void SetWorkArea(const gfx::Rect& work_area); | 150 void SetWorkArea(const gfx::Rect& work_area); |
152 | 151 |
153 // Adjusts the work area to exclude the influence of auto-hiding desktop bars. | 152 // Adjusts the work area to exclude the influence of auto-hiding desktop bars. |
154 void AdjustWorkAreaForAutoHidingDesktopBars(); | 153 void AdjustWorkAreaForAutoHidingDesktopBars(); |
155 | 154 |
156 // Keep track of the minimized panels to control mouse watching. | 155 // Positions the various groupings of panels. |
157 void IncrementMinimizedPanels(); | 156 void Layout(); |
158 void DecrementMinimizedPanels(); | |
159 | 157 |
160 // Handles all the panels that're delayed to be removed. | 158 scoped_ptr<PanelStrip> panel_strip_; |
161 void DelayedRemove(); | |
162 | |
163 // Does the remove. Called from Remove and DelayedRemove. | |
164 void DoRemove(Panel* panel); | |
165 | |
166 // Rearranges the positions of the panels starting from the given iterator. | |
167 // This is called when the display space has been changed, i.e. working | |
168 // area being changed or a panel being closed. | |
169 void Rearrange(Panels::iterator iter_to_start, int rightmost_position); | |
170 | |
171 // Help functions to drag the given panel. | |
172 void DragLeft(); | |
173 void DragRight(); | |
174 | |
175 // Does the real job of bringing up or down the titlebars. | |
176 void DoBringUpOrDownTitlebars(bool bring_up); | |
177 // The callback for a delyed task, checks if it still need to perform | |
178 // the delayed action. | |
179 void DelayedBringUpOrDownTitlebarsCheck(); | |
180 | |
181 int GetRightMostAvailablePosition() const; | |
182 | |
183 Panels panels_; | |
184 | |
185 // Stores the panels that are pending to remove. We want to delay the removal | |
186 // when we're in the process of the dragging. | |
187 Panels panels_pending_to_remove_; | |
188 | 159 |
189 // Use a mouse watcher to know when to bring up titlebars to "peek" at | 160 // Use a mouse watcher to know when to bring up titlebars to "peek" at |
190 // minimized panels. Mouse movement is only tracked when there is a minimized | 161 // minimized panels. Mouse movement is only tracked when there is a minimized |
191 // panel. | 162 // panel. |
192 scoped_ptr<PanelMouseWatcher> panel_mouse_watcher_; | 163 scoped_ptr<PanelMouseWatcher> panel_mouse_watcher_; |
193 int minimized_panel_count_; | |
194 bool are_titlebars_up_; | |
195 | 164 |
196 // The maximum work area avaialble. This area does not include the area taken | 165 // The maximum work area avaialble. This area does not include the area taken |
197 // by the always-visible (non-auto-hiding) desktop bars. | 166 // by the always-visible (non-auto-hiding) desktop bars. |
198 gfx::Rect work_area_; | 167 gfx::Rect work_area_; |
199 | 168 |
200 // The useable work area for computing the panel bounds. This area excludes | 169 // The useable work area for computing the panel bounds. This area excludes |
201 // the potential area that could be taken by the auto-hiding desktop | 170 // the potential area that could be taken by the auto-hiding desktop |
202 // bars (we only consider those bars that are aligned to bottom, left, and | 171 // bars (we only consider those bars that are aligned to bottom, left, and |
203 // right of the screen edges) when they become fully visible. | 172 // right of the screen edges) when they become fully visible. |
204 gfx::Rect adjusted_work_area_; | 173 gfx::Rect adjusted_work_area_; |
205 | 174 |
206 // Panel to drag. | |
207 size_t dragging_panel_index_; | |
208 | |
209 // Original x coordinate of the panel to drag. This is used to get back to | |
210 // the original position when we cancel the dragging. | |
211 int dragging_panel_original_x_; | |
212 | |
213 // Bounds of the panel to drag. It is first set to the original bounds when | |
214 // the dragging happens. Then it is updated to the position that will be set | |
215 // to when the dragging ends. | |
216 gfx::Rect dragging_panel_bounds_; | |
217 | |
218 scoped_refptr<AutoHidingDesktopBar> auto_hiding_desktop_bar_; | 175 scoped_refptr<AutoHidingDesktopBar> auto_hiding_desktop_bar_; |
219 | 176 |
220 // Delayed transitions support. Sometimes transitions between minimized and | |
221 // title-only states are delayed, for better usability with Taskbars/Docks. | |
222 TitlebarAction delayed_titlebar_action_; | |
223 bool remove_delays_for_testing_; | |
224 // Owned by MessageLoop after posting. | |
225 base::WeakPtrFactory<PanelManager> titlebar_action_factory_; | |
226 | |
227 // Whether or not bounds will be updated when the preferred content size is | 177 // Whether or not bounds will be updated when the preferred content size is |
228 // changed. The testing code could set this flag to false so that other tests | 178 // changed. The testing code could set this flag to false so that other tests |
229 // will not be affected. | 179 // will not be affected. |
230 bool auto_sizing_enabled_; | 180 bool auto_sizing_enabled_; |
231 | 181 |
232 bool mouse_watching_disabled_; // For tests to simulate mouse movements. | |
233 | |
234 static const int kPanelsHorizontalSpacing = 4; | |
235 | |
236 // Absolute minimum width and height for panels, including non-client area. | |
237 // Should only be big enough to accomodate a close button on the reasonably | |
238 // recognisable titlebar. | |
239 static const int kPanelMinWidth; | |
240 static const int kPanelMinHeight; | |
241 | |
242 DISALLOW_COPY_AND_ASSIGN(PanelManager); | 182 DISALLOW_COPY_AND_ASSIGN(PanelManager); |
243 }; | 183 }; |
244 | 184 |
245 #endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ | 185 #endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ |
OLD | NEW |