Chromium Code Reviews| Index: chrome/browser/ui/panels/docked_panel_strip.cc |
| diff --git a/chrome/browser/ui/panels/docked_panel_strip.cc b/chrome/browser/ui/panels/docked_panel_strip.cc |
| index d4cd227cac19fd76788d5eb3f63be9239b8b3f14..4b5dcb946517725e91a8b77e1ad1c938ae796553 100644 |
| --- a/chrome/browser/ui/panels/docked_panel_strip.cc |
| +++ b/chrome/browser/ui/panels/docked_panel_strip.cc |
| @@ -86,7 +86,8 @@ void DockedPanelStrip::SetDisplayArea(const gfx::Rect& display_area) { |
| } |
| void DockedPanelStrip::AddPanel(Panel* panel) { |
| - DCHECK_EQ(this, panel->panel_strip()); |
| + DCHECK_NE(this, panel->panel_strip()); |
| + panel->SetPanelStrip(this); |
| // Always update limits, even for exiting panels, in case the maximums changed |
| // while panel was out of the strip. |
| @@ -103,11 +104,11 @@ void DockedPanelStrip::AddPanel(Panel* panel) { |
| // Bump panels in the strip to make room for this panel. |
| // Prevent layout refresh when panel is removed from this strip. |
| disable_layout_refresh_ = true; |
| - PanelStrip* overflow_strip = panel_manager_->overflow_strip(); |
| int x; |
| while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { |
| DCHECK(!panels_.empty()); |
| - panels_.back()->MoveToStrip(overflow_strip); |
| + panel_manager_->ChangePanelLayout(panels_.back(), |
| + PanelStrip::IN_OVERFLOW); |
|
Andrei
2012/03/01 00:08:50
I like this change, and I can see how you are tryi
jennb
2012/03/01 20:52:58
Ended up leaving this, though moved into a subrout
|
| } |
| disable_layout_refresh_ = false; |
| @@ -203,45 +204,32 @@ int DockedPanelStrip::GetRightMostAvailablePosition() const { |
| (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); |
| } |
| -bool DockedPanelStrip::RemovePanel(Panel* panel) { |
| +void DockedPanelStrip::RemovePanel(Panel* panel) { |
| + DCHECK_EQ(this, panel->panel_strip()); |
| if (panel->has_temporary_layout()) { |
| panels_in_temporary_layout_.erase(panel); |
| - return true; |
| + return; |
| } |
| Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); |
| - if (iter == panels_.end()) |
| - return false; |
| + DCHECK(iter != panels_.end()); |
| if (panel->expansion_state() != Panel::EXPANDED) |
| DecrementMinimizedPanels(); |
| // Removing an element from the list will invalidate the iterator that refers |
| - // to it. So we need to check if the dragging panel iterators are affected. |
| - bool update_original_dragging_iterator_after_erase = false; |
| - if (dragging_panel_original_iterator_ != panels_.end()) { |
| - if (dragging_panel_current_iterator_ == iter) { |
| - // If the dragging panel is being removed, set both dragging iterators to |
| - // the end of the list. |
| - dragging_panel_current_iterator_ = dragging_panel_original_iterator_ = |
| - panels_.end(); |
| - } else if (dragging_panel_original_iterator_ == iter) { |
| - // If |dragging_panel_original_iterator_| refers to the element being |
| - // removed, set the flag so that the iterator can be updated to next |
| - // element. |
| - update_original_dragging_iterator_after_erase = true; |
| - } |
| - } |
| + // to it. So we need to update the iterator in that case. |
| + DCHECK(dragging_panel_current_iterator_ != iter); |
| + bool update_iterator_after_erase = |
| + (dragging_panel_original_iterator_ == iter); |
| iter = panels_.erase(iter); |
| - if (update_original_dragging_iterator_after_erase) |
| + if (update_iterator_after_erase) |
| dragging_panel_original_iterator_ = iter; |
| if (!disable_layout_refresh_) |
| RefreshLayout(); |
|
Andrei
2012/03/01 00:08:50
If AddPanel() sets panel->SetPanelStrip() to this,
jennb
2012/03/01 00:30:58
Agree. I actually tried it and undid the change. S
|
| - |
| - return true; |
| } |
| bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { |
| @@ -705,7 +693,6 @@ void DockedPanelStrip::RefreshLayout() { |
| // Add/remove panels from/to overflow. A change in work area or the |
| // resize/removal of a panel may affect how many panels fit in the strip. |
|
Andrei
2012/03/01 00:08:50
This is higher-level logic affecting multiple stri
jennb
2012/03/01 20:52:58
I simplified the logic that bumps panels to overfl
|
| - OverflowPanelStrip* overflow_strip = panel_manager_->overflow_strip(); |
| if (panel_iter != panels_.end()) { |
| // Prevent layout refresh when panel is removed from this strip. |
| disable_layout_refresh_ = true; |
| @@ -720,17 +707,18 @@ void DockedPanelStrip::RefreshLayout() { |
| for (std::vector<Panel*>::reverse_iterator iter = |
| panels_to_move_to_overflow.rbegin(); |
| iter != panels_to_move_to_overflow.rend(); ++iter) { |
| - (*iter)->MoveToStrip(overflow_strip); |
| + panel_manager_->ChangePanelLayout(*iter, PanelStrip::IN_OVERFLOW); |
| } |
| disable_layout_refresh_ = false; |
| } else { |
| // Attempt to add more panels from overflow to the strip. |
| + OverflowPanelStrip* overflow_strip = panel_manager_->overflow_strip(); |
| Panel* overflow_panel; |
| while ((overflow_panel = overflow_strip->first_panel()) && |
| GetRightMostAvailablePosition() >= |
| display_area_.x() + overflow_panel->restored_size().width()) { |
| - overflow_panel->MoveToStrip(this); |
| + panel_manager_->ChangePanelLayout(overflow_panel, PanelStrip::DOCKED); |
| } |
| } |
| } |
| @@ -738,7 +726,7 @@ void DockedPanelStrip::RefreshLayout() { |
| void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) { |
|
Andrei
2012/03/01 00:08:50
This can be easily moved to the manager I think.
jennb
2012/03/01 20:52:58
Ended up keeping this here. This provides a guard
|
| if (panels_in_temporary_layout_.erase(panel)) { |
| DCHECK(panel->has_temporary_layout()); |
| - panel->MoveToStrip(panel_manager_->overflow_strip()); |
| + panel_manager_->ChangePanelLayout(panel, PanelStrip::IN_OVERFLOW); |
| } |
| } |