Index: chrome/browser/ui/panels/panel_manager.cc |
diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc |
index c918b8a0d9c510fdc0e6ec7146f1df72df4e3fa5..0013a5337022788184f717582b3bea6427c7773d 100644 |
--- a/chrome/browser/ui/panels/panel_manager.cc |
+++ b/chrome/browser/ui/panels/panel_manager.cc |
@@ -117,7 +117,7 @@ Panel* PanelManager::CreatePanel(Browser* browser) { |
int width = browser->override_bounds().width(); |
int height = browser->override_bounds().height(); |
Panel* panel = new Panel(browser, gfx::Size(width, height)); |
- panel->MoveToStrip(docked_strip_.get()); |
+ docked_strip_->AddPanel(panel); |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_PANEL_ADDED, |
@@ -147,10 +147,11 @@ void PanelManager::CheckFullScreenMode() { |
} |
void PanelManager::OnPanelClosed(Panel* panel) { |
- if (num_panels() == 0) |
+ if (num_panels() == 1) |
full_screen_mode_timer_.Stop(); |
drag_controller_->OnPanelClosed(panel); |
+ panel->panel_strip()->RemovePanel(panel); |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_PANEL_CLOSED, |
@@ -192,6 +193,74 @@ void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { |
docked_strip_->ResizePanelWindow(panel, new_size); |
} |
+void PanelManager::MovePanelToStrip(Panel* panel, |
+ PanelStrip::Type new_layout) { |
+ DCHECK(panel); |
+ PanelStrip* current_strip = panel->panel_strip(); |
+ DCHECK(current_strip); |
+ DCHECK_NE(current_strip->type(), new_layout); |
+ current_strip->RemovePanel(panel); |
+ |
+ PanelStrip* target_strip = NULL; |
+ switch (new_layout) { |
+ case PanelStrip::DETACHED: |
+ target_strip = detached_strip_.get(); |
+ break; |
+ case PanelStrip::DOCKED: |
+ EnsurePanelFitsInDock(panel); |
+ target_strip = docked_strip_.get(); |
+ break; |
+ case PanelStrip::IN_OVERFLOW: |
+ target_strip = overflow_strip_.get(); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
+ |
+ target_strip->AddPanel(panel); |
+ |
+ content::NotificationService::current()->Notify( |
+ chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE, |
+ content::Source<Panel>(panel), |
+ content::NotificationService::NoDetails()); |
+} |
+ |
+void PanelManager::EnsurePanelFitsInDock(Panel* panel) { |
jianli
2012/03/02 02:26:09
nit: EnsurePanelFitsInDockedStrip?
|
+ // Prevent layout refreshes while adjusting panels. |
+ docked_strip_->enable_layout_refresh(false); |
+ while (!docked_strip_->CanFitPanel(panel)) |
+ MovePanelToStrip(docked_strip_->last_panel(), PanelStrip::IN_OVERFLOW); |
jianli
2012/03/02 02:26:09
We know that we start from last docked panel and m
|
+ docked_strip_->enable_layout_refresh(true); // Re-enable. |
+} |
+ |
+void PanelManager::MovePanelsToOverflow(Panel* last_panel_to_move) { |
+ // Prevent layout refreshes while adjusting panels. |
+ docked_strip_->enable_layout_refresh(false); |
+ |
+ // Move panels to overflow in reverse to maintain their order. |
+ Panel* bumped_panel; |
+ while ((bumped_panel = docked_strip_->last_panel())) { |
+ MovePanelToStrip(bumped_panel, PanelStrip::IN_OVERFLOW); |
jianli
2012/03/02 02:26:09
ditto.
|
+ if (bumped_panel == last_panel_to_move) |
+ break; |
+ } |
+ DCHECK(!docked_strip_->panels().empty()); |
+ |
+ docked_strip_->enable_layout_refresh(true); // Re-enable. |
+} |
+ |
+void PanelManager::MovePanelsOutOfOverflowIfCanFit() { |
+ // Prevent layout refreshes while adjusting panels. |
+ docked_strip_->enable_layout_refresh(false); |
+ |
+ Panel* overflow_panel; |
+ while ((overflow_panel = overflow_strip_->first_panel()) && |
+ docked_strip_->CanFitPanel(overflow_panel)) |
+ MovePanelToStrip(overflow_panel, PanelStrip::DOCKED); |
+ |
+ docked_strip_->enable_layout_refresh(true); // Re-enable. |
+} |
+ |
bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y); |
} |