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/docked_panel_strip.h" | 5 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 gfx::Rect old_area = display_area_; | 79 gfx::Rect old_area = display_area_; |
80 display_area_ = display_area; | 80 display_area_ = display_area; |
81 | 81 |
82 if (panels_.empty()) | 82 if (panels_.empty()) |
83 return; | 83 return; |
84 | 84 |
85 RefreshLayout(); | 85 RefreshLayout(); |
86 } | 86 } |
87 | 87 |
88 void DockedPanelStrip::AddPanel(Panel* panel) { | 88 void DockedPanelStrip::AddPanel(Panel* panel) { |
89 DCHECK_EQ(this, panel->panel_strip()); | 89 DCHECK_NE(this, panel->panel_strip()); |
90 panel->SetPanelStrip(this); | |
90 | 91 |
91 // Always update limits, even for exiting panels, in case the maximums changed | 92 // Always update limits, even for exiting panels, in case the maximums changed |
92 // while panel was out of the strip. | 93 // while panel was out of the strip. |
93 int max_panel_width = GetMaxPanelWidth(); | 94 int max_panel_width = GetMaxPanelWidth(); |
94 int max_panel_height = GetMaxPanelHeight(); | 95 int max_panel_height = GetMaxPanelHeight(); |
95 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | 96 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
96 gfx::Size(max_panel_width, max_panel_height)); | 97 gfx::Size(max_panel_width, max_panel_height)); |
97 | 98 |
98 gfx::Size restored_size = panel->restored_size(); | 99 gfx::Size restored_size = panel->restored_size(); |
99 int height = restored_size.height(); | 100 int height = restored_size.height(); |
100 int width = restored_size.width(); | 101 int width = restored_size.width(); |
101 | 102 |
102 if (panel->initialized()) { | 103 if (panel->initialized()) { |
103 // Bump panels in the strip to make room for this panel. | 104 // Bump panels in the strip to make room for this panel. |
104 // Prevent layout refresh when panel is removed from this strip. | 105 // Prevent layout refresh when panel is removed from this strip. |
105 disable_layout_refresh_ = true; | 106 disable_layout_refresh_ = true; |
106 PanelStrip* overflow_strip = panel_manager_->overflow_strip(); | |
107 int x; | 107 int x; |
108 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { | 108 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { |
109 DCHECK(!panels_.empty()); | 109 DCHECK(!panels_.empty()); |
110 panels_.back()->MoveToStrip(overflow_strip); | 110 panel_manager_->ChangePanelLayout(panels_.back(), |
111 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
| |
111 } | 112 } |
112 disable_layout_refresh_ = false; | 113 disable_layout_refresh_ = false; |
113 | 114 |
114 Panel::ExpansionState expansion_state_to_restore; | 115 Panel::ExpansionState expansion_state_to_restore; |
115 if (panel->expansion_state() == Panel::EXPANDED) { | 116 if (panel->expansion_state() == Panel::EXPANDED) { |
116 expansion_state_to_restore = Panel::EXPANDED; | 117 expansion_state_to_restore = Panel::EXPANDED; |
117 } else { | 118 } else { |
118 if (are_titlebars_up_ || panel->IsDrawingAttention()) { | 119 if (are_titlebars_up_ || panel->IsDrawingAttention()) { |
119 expansion_state_to_restore = Panel::TITLE_ONLY; | 120 expansion_state_to_restore = Panel::TITLE_ONLY; |
120 height = panel->TitleOnlyHeight(); | 121 height = panel->TitleOnlyHeight(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 197 |
197 int DockedPanelStrip::StartingRightPosition() const { | 198 int DockedPanelStrip::StartingRightPosition() const { |
198 return display_area_.right(); | 199 return display_area_.right(); |
199 } | 200 } |
200 | 201 |
201 int DockedPanelStrip::GetRightMostAvailablePosition() const { | 202 int DockedPanelStrip::GetRightMostAvailablePosition() const { |
202 return panels_.empty() ? StartingRightPosition() : | 203 return panels_.empty() ? StartingRightPosition() : |
203 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); | 204 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); |
204 } | 205 } |
205 | 206 |
206 bool DockedPanelStrip::RemovePanel(Panel* panel) { | 207 void DockedPanelStrip::RemovePanel(Panel* panel) { |
208 DCHECK_EQ(this, panel->panel_strip()); | |
207 if (panel->has_temporary_layout()) { | 209 if (panel->has_temporary_layout()) { |
208 panels_in_temporary_layout_.erase(panel); | 210 panels_in_temporary_layout_.erase(panel); |
209 return true; | 211 return; |
210 } | 212 } |
211 | 213 |
212 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); | 214 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); |
213 if (iter == panels_.end()) | 215 DCHECK(iter != panels_.end()); |
214 return false; | |
215 | 216 |
216 if (panel->expansion_state() != Panel::EXPANDED) | 217 if (panel->expansion_state() != Panel::EXPANDED) |
217 DecrementMinimizedPanels(); | 218 DecrementMinimizedPanels(); |
218 | 219 |
219 // Removing an element from the list will invalidate the iterator that refers | 220 // Removing an element from the list will invalidate the iterator that refers |
220 // to it. So we need to check if the dragging panel iterators are affected. | 221 // to it. So we need to update the iterator in that case. |
221 bool update_original_dragging_iterator_after_erase = false; | 222 DCHECK(dragging_panel_current_iterator_ != iter); |
222 if (dragging_panel_original_iterator_ != panels_.end()) { | 223 bool update_iterator_after_erase = |
223 if (dragging_panel_current_iterator_ == iter) { | 224 (dragging_panel_original_iterator_ == iter); |
224 // If the dragging panel is being removed, set both dragging iterators to | |
225 // the end of the list. | |
226 dragging_panel_current_iterator_ = dragging_panel_original_iterator_ = | |
227 panels_.end(); | |
228 } else if (dragging_panel_original_iterator_ == iter) { | |
229 // If |dragging_panel_original_iterator_| refers to the element being | |
230 // removed, set the flag so that the iterator can be updated to next | |
231 // element. | |
232 update_original_dragging_iterator_after_erase = true; | |
233 } | |
234 } | |
235 | 225 |
236 iter = panels_.erase(iter); | 226 iter = panels_.erase(iter); |
237 | 227 |
238 if (update_original_dragging_iterator_after_erase) | 228 if (update_iterator_after_erase) |
239 dragging_panel_original_iterator_ = iter; | 229 dragging_panel_original_iterator_ = iter; |
240 | 230 |
241 if (!disable_layout_refresh_) | 231 if (!disable_layout_refresh_) |
242 RefreshLayout(); | 232 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
| |
243 | |
244 return true; | |
245 } | 233 } |
246 | 234 |
247 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { | 235 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { |
248 // Panels with temporary layout cannot be shown as active. | 236 // Panels with temporary layout cannot be shown as active. |
249 return !panel->has_temporary_layout(); | 237 return !panel->has_temporary_layout(); |
250 } | 238 } |
251 | 239 |
252 bool DockedPanelStrip::CanDragPanel(const Panel* panel) const { | 240 bool DockedPanelStrip::CanDragPanel(const Panel* panel) const { |
253 // Only the panels having temporary layout can't be dragged. | 241 // Only the panels having temporary layout can't be dragged. |
254 return !panel->has_temporary_layout(); | 242 return !panel->has_temporary_layout(); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 new_bounds.set_y( | 685 new_bounds.set_y( |
698 GetBottomPositionForExpansionState(panel->expansion_state()) - | 686 GetBottomPositionForExpansionState(panel->expansion_state()) - |
699 new_bounds.height()); | 687 new_bounds.height()); |
700 panel->SetPanelBounds(new_bounds); | 688 panel->SetPanelBounds(new_bounds); |
701 } | 689 } |
702 | 690 |
703 rightmost_position = x - kPanelsHorizontalSpacing; | 691 rightmost_position = x - kPanelsHorizontalSpacing; |
704 } | 692 } |
705 | 693 |
706 // Add/remove panels from/to overflow. A change in work area or the | 694 // Add/remove panels from/to overflow. A change in work area or the |
707 // resize/removal of a panel may affect how many panels fit in the strip. | 695 // 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
| |
708 OverflowPanelStrip* overflow_strip = panel_manager_->overflow_strip(); | |
709 if (panel_iter != panels_.end()) { | 696 if (panel_iter != panels_.end()) { |
710 // Prevent layout refresh when panel is removed from this strip. | 697 // Prevent layout refresh when panel is removed from this strip. |
711 disable_layout_refresh_ = true; | 698 disable_layout_refresh_ = true; |
712 | 699 |
713 // Keep track of panels to move to overflow in a separate storage since | 700 // Keep track of panels to move to overflow in a separate storage since |
714 // removing it from the list will invalidate the iterator. | 701 // removing it from the list will invalidate the iterator. |
715 std::vector<Panel*> panels_to_move_to_overflow; | 702 std::vector<Panel*> panels_to_move_to_overflow; |
716 for (; panel_iter != panels_.end(); ++panel_iter) | 703 for (; panel_iter != panels_.end(); ++panel_iter) |
717 panels_to_move_to_overflow.push_back(*panel_iter); | 704 panels_to_move_to_overflow.push_back(*panel_iter); |
718 | 705 |
719 // Move panels to overflow in reverse to maintain their order. | 706 // Move panels to overflow in reverse to maintain their order. |
720 for (std::vector<Panel*>::reverse_iterator iter = | 707 for (std::vector<Panel*>::reverse_iterator iter = |
721 panels_to_move_to_overflow.rbegin(); | 708 panels_to_move_to_overflow.rbegin(); |
722 iter != panels_to_move_to_overflow.rend(); ++iter) { | 709 iter != panels_to_move_to_overflow.rend(); ++iter) { |
723 (*iter)->MoveToStrip(overflow_strip); | 710 panel_manager_->ChangePanelLayout(*iter, PanelStrip::IN_OVERFLOW); |
724 } | 711 } |
725 | 712 |
726 disable_layout_refresh_ = false; | 713 disable_layout_refresh_ = false; |
727 } else { | 714 } else { |
728 // Attempt to add more panels from overflow to the strip. | 715 // Attempt to add more panels from overflow to the strip. |
716 OverflowPanelStrip* overflow_strip = panel_manager_->overflow_strip(); | |
729 Panel* overflow_panel; | 717 Panel* overflow_panel; |
730 while ((overflow_panel = overflow_strip->first_panel()) && | 718 while ((overflow_panel = overflow_strip->first_panel()) && |
731 GetRightMostAvailablePosition() >= | 719 GetRightMostAvailablePosition() >= |
732 display_area_.x() + overflow_panel->restored_size().width()) { | 720 display_area_.x() + overflow_panel->restored_size().width()) { |
733 overflow_panel->MoveToStrip(this); | 721 panel_manager_->ChangePanelLayout(overflow_panel, PanelStrip::DOCKED); |
734 } | 722 } |
735 } | 723 } |
736 } | 724 } |
737 | 725 |
738 void DockedPanelStrip::DelayedMovePanelToOverflow(Panel* panel) { | 726 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
| |
739 if (panels_in_temporary_layout_.erase(panel)) { | 727 if (panels_in_temporary_layout_.erase(panel)) { |
740 DCHECK(panel->has_temporary_layout()); | 728 DCHECK(panel->has_temporary_layout()); |
741 panel->MoveToStrip(panel_manager_->overflow_strip()); | 729 panel_manager_->ChangePanelLayout(panel, PanelStrip::IN_OVERFLOW); |
742 } | 730 } |
743 } | 731 } |
744 | 732 |
745 void DockedPanelStrip::CloseAll() { | 733 void DockedPanelStrip::CloseAll() { |
746 // This should only be called at the end of tests to clean up. | 734 // This should only be called at the end of tests to clean up. |
747 DCHECK(panels_in_temporary_layout_.empty()); | 735 DCHECK(panels_in_temporary_layout_.empty()); |
748 | 736 |
749 // Make a copy of the iterator as closing panels can modify the vector. | 737 // Make a copy of the iterator as closing panels can modify the vector. |
750 Panels panels_copy = panels_; | 738 Panels panels_copy = panels_; |
751 | 739 |
752 // Start from the bottom to avoid reshuffling. | 740 // Start from the bottom to avoid reshuffling. |
753 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 741 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
754 iter != panels_copy.rend(); ++iter) | 742 iter != panels_copy.rend(); ++iter) |
755 (*iter)->Close(); | 743 (*iter)->Close(); |
756 } | 744 } |
OLD | NEW |