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 #include "chrome/browser/ui/panels/panel_manager.h" | 5 #include "chrome/browser/ui/panels/panel_manager.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 PanelManager::PanelManager() | 64 PanelManager::PanelManager() |
65 : panel_mouse_watcher_(PanelMouseWatcher::Create()), | 65 : panel_mouse_watcher_(PanelMouseWatcher::Create()), |
66 auto_sizing_enabled_(true), | 66 auto_sizing_enabled_(true), |
67 is_full_screen_(false), | 67 is_full_screen_(false), |
68 is_processing_overflow_(false) { | 68 is_processing_overflow_(false) { |
69 detached_strip_.reset(new DetachedPanelStrip(this)); | 69 detached_strip_.reset(new DetachedPanelStrip(this)); |
70 docked_strip_.reset(new DockedPanelStrip(this)); | 70 docked_strip_.reset(new DockedPanelStrip(this)); |
71 overflow_strip_.reset(new OverflowPanelStrip(this)); | 71 overflow_strip_.reset(new OverflowPanelStrip(this)); |
72 drag_controller_.reset(new PanelDragController()); | 72 drag_controller_.reset(new PanelDragController(this)); |
73 display_settings_provider_.reset(DisplaySettingsProvider::Create(this)); | 73 display_settings_provider_.reset(DisplaySettingsProvider::Create(this)); |
74 | 74 |
75 OnDisplayChanged(); | 75 OnDisplayChanged(); |
76 } | 76 } |
77 | 77 |
78 PanelManager::~PanelManager() { | 78 PanelManager::~PanelManager() { |
79 } | 79 } |
80 | 80 |
81 void PanelManager::OnDisplayChanged() { | 81 void PanelManager::OnDisplayChanged() { |
82 gfx::Rect work_area = display_settings_provider_->GetWorkArea(); | 82 gfx::Rect work_area = display_settings_provider_->GetWorkArea(); |
(...skipping 23 matching lines...) Expand all Loading... |
106 | 106 |
107 Panel* PanelManager::CreatePanel(Browser* browser) { | 107 Panel* PanelManager::CreatePanel(Browser* browser) { |
108 // Need to sync the display area if no panel is present. This is because we | 108 // Need to sync the display area if no panel is present. This is because we |
109 // could only get display area notifications through a panel window. | 109 // could only get display area notifications through a panel window. |
110 if (num_panels() == 0) | 110 if (num_panels() == 0) |
111 OnDisplayChanged(); | 111 OnDisplayChanged(); |
112 | 112 |
113 int width = browser->override_bounds().width(); | 113 int width = browser->override_bounds().width(); |
114 int height = browser->override_bounds().height(); | 114 int height = browser->override_bounds().height(); |
115 Panel* panel = new Panel(browser, gfx::Size(width, height)); | 115 Panel* panel = new Panel(browser, gfx::Size(width, height)); |
116 docked_strip_->AddPanel(panel); | 116 docked_strip_->AddPanel(panel, PanelStrip::DEFAULT_POSITION); |
117 | 117 |
118 content::NotificationService::current()->Notify( | 118 content::NotificationService::current()->Notify( |
119 chrome::NOTIFICATION_PANEL_ADDED, | 119 chrome::NOTIFICATION_PANEL_ADDED, |
120 content::Source<Panel>(panel), | 120 content::Source<Panel>(panel), |
121 content::NotificationService::NoDetails()); | 121 content::NotificationService::NoDetails()); |
122 | 122 |
123 if (num_panels() == 1) { | 123 if (num_panels() == 1) { |
124 full_screen_mode_timer_.Start(FROM_HERE, | 124 full_screen_mode_timer_.Start(FROM_HERE, |
125 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs), | 125 base::TimeDelta::FromMilliseconds(kFullScreenModeCheckIntervalMs), |
126 this, &PanelManager::CheckFullScreenMode); | 126 this, &PanelManager::CheckFullScreenMode); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 const gfx::Size& preferred_window_size) { | 176 const gfx::Size& preferred_window_size) { |
177 DCHECK(auto_sizing_enabled_); | 177 DCHECK(auto_sizing_enabled_); |
178 docked_strip_->ResizePanelWindow(panel, preferred_window_size); | 178 docked_strip_->ResizePanelWindow(panel, preferred_window_size); |
179 } | 179 } |
180 | 180 |
181 void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { | 181 void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { |
182 docked_strip_->ResizePanelWindow(panel, new_size); | 182 docked_strip_->ResizePanelWindow(panel, new_size); |
183 panel->SetAutoResizable(false); | 183 panel->SetAutoResizable(false); |
184 } | 184 } |
185 | 185 |
186 void PanelManager::MovePanelToStrip(Panel* panel, | 186 void PanelManager::MovePanelToStrip( |
187 PanelStrip::Type new_layout) { | 187 Panel* panel, |
| 188 PanelStrip::Type new_layout, |
| 189 PanelStrip::PositioningMask positioning_mask) { |
188 DCHECK(panel); | 190 DCHECK(panel); |
189 PanelStrip* current_strip = panel->panel_strip(); | 191 PanelStrip* current_strip = panel->panel_strip(); |
190 DCHECK(current_strip); | 192 DCHECK(current_strip); |
191 DCHECK_NE(current_strip->type(), new_layout); | 193 DCHECK_NE(current_strip->type(), new_layout); |
192 current_strip->RemovePanel(panel); | 194 current_strip->RemovePanel(panel); |
193 | 195 |
194 PanelStrip* target_strip = NULL; | 196 PanelStrip* target_strip = NULL; |
195 switch (new_layout) { | 197 switch (new_layout) { |
196 case PanelStrip::DETACHED: | 198 case PanelStrip::DETACHED: |
197 target_strip = detached_strip_.get(); | 199 target_strip = detached_strip_.get(); |
198 break; | 200 break; |
199 case PanelStrip::DOCKED: | 201 case PanelStrip::DOCKED: |
200 target_strip = docked_strip_.get(); | 202 target_strip = docked_strip_.get(); |
201 break; | 203 break; |
202 case PanelStrip::IN_OVERFLOW: | 204 case PanelStrip::IN_OVERFLOW: |
203 target_strip = overflow_strip_.get(); | 205 target_strip = overflow_strip_.get(); |
204 break; | 206 break; |
205 default: | 207 default: |
206 NOTREACHED(); | 208 NOTREACHED(); |
207 } | 209 } |
208 | 210 |
209 target_strip->AddPanel(panel); | 211 target_strip->AddPanel(panel, positioning_mask); |
210 | 212 |
211 content::NotificationService::current()->Notify( | 213 content::NotificationService::current()->Notify( |
212 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE, | 214 chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE, |
213 content::Source<Panel>(panel), | 215 content::Source<Panel>(panel), |
214 content::NotificationService::NoDetails()); | 216 content::NotificationService::NoDetails()); |
215 } | 217 } |
216 | 218 |
217 void PanelManager::MovePanelsToOverflow(Panel* last_panel_to_move) { | 219 void PanelManager::MovePanelsToOverflow(Panel* last_panel_to_move) { |
218 AutoReset<bool> processing_overflow(&is_processing_overflow_, true); | 220 AutoReset<bool> processing_overflow(&is_processing_overflow_, true); |
219 // Move panels to overflow in reverse to maintain their order. | 221 // Move panels to overflow in reverse to maintain their order. |
220 Panel* bumped_panel; | 222 Panel* bumped_panel; |
221 while ((bumped_panel = docked_strip_->last_panel())) { | 223 while ((bumped_panel = docked_strip_->last_panel())) { |
222 MovePanelToStrip(bumped_panel, PanelStrip::IN_OVERFLOW); | 224 MovePanelToStrip(bumped_panel, |
| 225 PanelStrip::IN_OVERFLOW, |
| 226 PanelStrip::DEFAULT_POSITION); |
223 if (bumped_panel == last_panel_to_move) | 227 if (bumped_panel == last_panel_to_move) |
224 break; | 228 break; |
225 } | 229 } |
226 DCHECK(!docked_strip_->panels().empty()); | 230 DCHECK(!docked_strip_->panels().empty()); |
227 } | 231 } |
228 | 232 |
229 void PanelManager::MovePanelsOutOfOverflowIfCanFit() { | 233 void PanelManager::MovePanelsOutOfOverflowIfCanFit() { |
230 if (is_processing_overflow_) | 234 if (is_processing_overflow_) |
231 return; | 235 return; |
232 | 236 |
233 Panel* overflow_panel; | 237 Panel* overflow_panel; |
234 while ((overflow_panel = overflow_strip_->first_panel()) && | 238 while ((overflow_panel = overflow_strip_->first_panel()) && |
235 docked_strip_->CanFitPanel(overflow_panel)) | 239 docked_strip_->CanFitPanel(overflow_panel)) { |
236 MovePanelToStrip(overflow_panel, PanelStrip::DOCKED); | 240 MovePanelToStrip(overflow_panel, |
| 241 PanelStrip::DOCKED, |
| 242 PanelStrip::DEFAULT_POSITION); |
| 243 } |
237 } | 244 } |
238 | 245 |
239 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 246 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
240 return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y); | 247 return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y); |
241 } | 248 } |
242 | 249 |
243 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { | 250 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
244 docked_strip_->BringUpOrDownTitlebars(bring_up); | 251 docked_strip_->BringUpOrDownTitlebars(bring_up); |
245 } | 252 } |
246 | 253 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 return panels; | 326 return panels; |
320 } | 327 } |
321 | 328 |
322 int PanelManager::overflow_strip_width() const { | 329 int PanelManager::overflow_strip_width() const { |
323 return kOverflowStripThickness; | 330 return kOverflowStripThickness; |
324 } | 331 } |
325 | 332 |
326 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { | 333 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { |
327 panel_mouse_watcher_.reset(watcher); | 334 panel_mouse_watcher_.reset(watcher); |
328 } | 335 } |
OLD | NEW |