Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: chrome/browser/ui/panels/panel_manager.h

Issue 8744005: Refactor PanelManager to create PanelStrip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove leftover override Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifdef UNIT_TEST
18 #include "chrome/browser/ui/panels/panel_strip.h"
19 #include "chrome/browser/ui/panels/panel_mouse_watcher.h"
jianli 2011/11/30 19:27:01 Why do we need these 2 includes for UNIT_TEST? It
jennb 2011/11/30 19:55:12 Aren't we using UNIT_TEST guard and inline in .h w
20 #endif
Dmitry Titov 2011/11/30 20:38:45 having UNIT_TEST around whole #include can signifi
21
19 class Browser; 22 class Browser;
20 class Panel;
21 class PanelMouseWatcher; 23 class PanelMouseWatcher;
24 class PanelStrip;
22 25
23 // This class manages a set of panels. 26 // This class manages a set of panels.
24 // Note that the ref count is needed by using PostTask in the implementation. 27 class PanelManager : public AutoHidingDesktopBar::Observer {
25 class PanelManager : public PanelMouseWatcherObserver,
26 public AutoHidingDesktopBar::Observer {
27 public: 28 public:
28 typedef std::vector<Panel*> Panels; 29 typedef std::vector<Panel*> Panels;
29 30
30 // Returns a single instance. 31 // Returns a single instance.
31 static PanelManager* GetInstance(); 32 static PanelManager* GetInstance();
32 33
33 // Called when the display is changed, i.e. work area is updated. 34 // Called when the display is changed, i.e. work area is updated.
34 void OnDisplayChanged(); 35 void OnDisplayChanged();
35 36
36 // Creates a panel and returns it. The panel might be queued for display 37 // Creates a panel and returns it. The panel might be queued for display
37 // later. 38 // later.
38 Panel* CreatePanel(Browser* browser); 39 Panel* CreatePanel(Browser* browser);
39 40
40 void Remove(Panel* panel); 41 void Remove(Panel* panel);
41 void RemoveAll(); 42 void RemoveAll();
42 43
44 // Asynchronous confirmation of panel having been removed.
45 void OnPanelRemoved(Panel* panel);
46
43 // Drags the given panel. 47 // Drags the given panel.
44 void StartDragging(Panel* panel); 48 void StartDragging(Panel* panel);
45 void Drag(int delta_x); 49 void Drag(int delta_x);
46 void EndDragging(bool cancelled); 50 void EndDragging(bool cancelled);
47 51
48 // Invoked when a panel's expansion state changes. 52 // Invoked when a panel's expansion state changes.
49 void OnPanelExpansionStateChanged(Panel::ExpansionState old_state, 53 void OnPanelExpansionStateChanged(Panel::ExpansionState old_state,
50 Panel::ExpansionState new_state); 54 Panel::ExpansionState new_state);
51 55
52 // Invoked when the preferred window size of the given panel might need to 56 // Invoked when the preferred window size of the given panel might need to
(...skipping 12 matching lines...) Expand all
65 // hide bottom bar is present, we want to move the minimized panel to the 69 // 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. 70 // bottom of the screen, not the bottom of the work area.
67 int GetBottomPositionForExpansionState( 71 int GetBottomPositionForExpansionState(
68 Panel::ExpansionState expansion_state) const; 72 Panel::ExpansionState expansion_state) const;
69 73
70 // Returns the next browser window which could be either panel window or 74 // 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. 75 // tabbed window, to switch to if the given panel is going to be deactivated.
72 // Returns NULL if such window cannot be found. 76 // Returns NULL if such window cannot be found.
73 BrowserWindow* GetNextBrowserWindowToActivate(Panel* panel) const; 77 BrowserWindow* GetNextBrowserWindowToActivate(Panel* panel) const;
74 78
75 int num_panels() const { return panels_.size(); } 79 int num_panels() const;
76 bool is_dragging_panel() const; 80 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; 81 int StartingRightPosition() const;
82 82 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 83
88 // Moves a panel to the overflow strip. The panel does not currently 84 // Moves a panel to the overflow strip. The panel does not currently
89 // belong in any other strip. 85 // belong in any other strip.
90 // |is_new| is true if the panel was just created. 86 // |is_new| is true if the panel was just created.
91 void MoveToOverflowStrip(Panel* panel, bool is_new); 87 void MoveToOverflowStrip(Panel* panel, bool is_new);
92 88
93 // Overridden from PanelMouseWatcherObserver: 89 AutoHidingDesktopBar* auto_hiding_desktop_bar() const {
94 virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE; 90 return auto_hiding_desktop_bar_;
91 }
92
93 PanelMouseWatcher* mouse_watcher() const {
94 return panel_mouse_watcher_.get();
95 }
96
97 PanelStrip* panel_strip() const {
98 return panel_strip_.get();
99 }
95 100
96 #ifdef UNIT_TEST 101 #ifdef UNIT_TEST
97 static int horizontal_spacing() { return kPanelsHorizontalSpacing; } 102 static int horizontal_spacing() { return PanelStrip::horizontal_spacing(); }
98 103
99 const gfx::Rect& work_area() const { 104 const gfx::Rect& work_area() const {
100 return work_area_; 105 return work_area_;
101 } 106 }
102 107
103 void set_auto_hiding_desktop_bar( 108 void set_auto_hiding_desktop_bar(
104 AutoHidingDesktopBar* auto_hiding_desktop_bar) { 109 AutoHidingDesktopBar* auto_hiding_desktop_bar) {
105 auto_hiding_desktop_bar_ = auto_hiding_desktop_bar; 110 auto_hiding_desktop_bar_ = auto_hiding_desktop_bar;
106 } 111 }
107 112
113 void set_mouse_watcher(PanelMouseWatcher* watcher) {
114 panel_mouse_watcher_.reset(watcher);
115 }
116
108 void enable_auto_sizing(bool enabled) { 117 void enable_auto_sizing(bool enabled) {
109 auto_sizing_enabled_ = enabled; 118 auto_sizing_enabled_ = enabled;
110 } 119 }
111 120
112 void SetWorkAreaForTesting(const gfx::Rect& work_area) { 121 void SetWorkAreaForTesting(const gfx::Rect& work_area) {
113 SetWorkArea(work_area); 122 SetWorkArea(work_area);
114 } 123 }
115 124
116 void remove_delays_for_testing() { 125 void remove_delays_for_testing() {
117 remove_delays_for_testing_ = true; 126 panel_strip_->remove_delays_for_testing();
118 } 127 }
119 128
120 int minimized_panel_count() { 129 int minimized_panel_count() {
121 return minimized_panel_count_; 130 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 } 131 }
128 #endif 132 #endif
129 133
130 private: 134 private:
131 friend struct base::DefaultLazyInstanceTraits<PanelManager>; 135 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 136
140 PanelManager(); 137 PanelManager();
141 virtual ~PanelManager(); 138 virtual ~PanelManager();
142 139
143 // Overridden from AutoHidingDesktopBar::Observer: 140 // Overridden from AutoHidingDesktopBar::Observer:
144 virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE; 141 virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE;
145 virtual void OnAutoHidingDesktopBarVisibilityChanged( 142 virtual void OnAutoHidingDesktopBarVisibilityChanged(
146 AutoHidingDesktopBar::Alignment alignment, 143 AutoHidingDesktopBar::Alignment alignment,
147 AutoHidingDesktopBar::Visibility visibility) OVERRIDE; 144 AutoHidingDesktopBar::Visibility visibility) OVERRIDE;
148 145
149 // Applies the new work area. This is called by OnDisplayChanged and the test 146 // Applies the new work area. This is called by OnDisplayChanged and the test
150 // code. 147 // code.
151 void SetWorkArea(const gfx::Rect& work_area); 148 void SetWorkArea(const gfx::Rect& work_area);
152 149
153 // Adjusts the work area to exclude the influence of auto-hiding desktop bars. 150 // Adjusts the work area to exclude the influence of auto-hiding desktop bars.
154 void AdjustWorkAreaForAutoHidingDesktopBars(); 151 void AdjustWorkAreaForAutoHidingDesktopBars();
155 152
156 // Keep track of the minimized panels to control mouse watching. 153 // Positions the various groupings of panels.
157 void IncrementMinimizedPanels(); 154 void Layout();
158 void DecrementMinimizedPanels();
159 155
160 // Handles all the panels that're delayed to be removed. 156 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 157
189 // Use a mouse watcher to know when to bring up titlebars to "peek" at 158 // 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 159 // minimized panels. Mouse movement is only tracked when there is a minimized
191 // panel. 160 // panel.
192 scoped_ptr<PanelMouseWatcher> panel_mouse_watcher_; 161 scoped_ptr<PanelMouseWatcher> panel_mouse_watcher_;
193 int minimized_panel_count_;
194 bool are_titlebars_up_;
195 162
196 // The maximum work area avaialble. This area does not include the area taken 163 // The maximum work area avaialble. This area does not include the area taken
197 // by the always-visible (non-auto-hiding) desktop bars. 164 // by the always-visible (non-auto-hiding) desktop bars.
198 gfx::Rect work_area_; 165 gfx::Rect work_area_;
199 166
200 // The useable work area for computing the panel bounds. This area excludes 167 // 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 168 // 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 169 // bars (we only consider those bars that are aligned to bottom, left, and
203 // right of the screen edges) when they become fully visible. 170 // right of the screen edges) when they become fully visible.
204 gfx::Rect adjusted_work_area_; 171 gfx::Rect adjusted_work_area_;
205 172
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_; 173 scoped_refptr<AutoHidingDesktopBar> auto_hiding_desktop_bar_;
219 174
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 175 // 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 176 // changed. The testing code could set this flag to false so that other tests
229 // will not be affected. 177 // will not be affected.
230 bool auto_sizing_enabled_; 178 bool auto_sizing_enabled_;
231 179
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); 180 DISALLOW_COPY_AND_ASSIGN(PanelManager);
243 }; 181 };
244 182
245 #endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_ 183 #endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698