Index: chrome/browser/ui/panels/panel_manager.cc |
=================================================================== |
--- chrome/browser/ui/panels/panel_manager.cc (revision 94932) |
+++ chrome/browser/ui/panels/panel_manager.cc (working copy) |
@@ -16,8 +16,9 @@ |
const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
// Minimum width and height of a panel. |
-const int kPanelMinWidthPixels = 64; |
-const int kPanelMinHeightPixels = 24; |
+// Note: The minimum size of a widget (see widget.cc) is fixed to 100x100. |
Dmitry Titov
2011/08/05 19:02:20
We do have notifications today with smaller sizes,
jianli
2011/08/09 19:56:16
Done.
|
+const int kPanelMinWidthPixels = 100; |
+const int kPanelMinHeightPixels = 100; |
// Default width and height of a panel. |
const int kPanelDefaultWidthPixels = 240; |
@@ -110,6 +111,7 @@ |
Panel* panel = new Panel(browser, bounds); |
panels_.push_back(panel); |
+ UpdateMaximumSizeForAllPanels(); |
return panel; |
} |
@@ -271,6 +273,69 @@ |
DelayedRemove(); |
} |
+void PanelManager::UpdatePreferredSize(Panel* panel, |
+ const gfx::Size& pref_size) { |
+ gfx::Size non_client_size = panel->GetNonClientAreaSize(); |
+ |
+ // We need to get and set the restored bounds since the preferred size change |
+ // might be triggered when the panel is not expanded. |
+ gfx::Rect bounds = panel->GetRestoredBounds(); |
+ |
+ // The panel width: |
+ // * cannot grow more than the maximum width |
+ // * cannot grow to take more than the available horizontal space |
Dmitry Titov
2011/08/05 19:02:20
what is exactly 'available horizontal space'? Not
jianli
2011/08/09 19:56:16
Updated comment.
|
+ // * cannot shrink to be smaller than the initial width |
+ int new_panel_width = pref_size.width() + non_client_size.width(); |
+ if (new_panel_width > max_width_) |
+ new_panel_width = max_width_; |
+ if (new_panel_width - bounds.width() > current_x_) |
+ new_panel_width = bounds.width() + current_x_; |
+ |
+ if (new_panel_width > bounds.width() || |
+ (new_panel_width < bounds.width() && |
+ new_panel_width > panel->initial_size_.width())) { |
+ int delta = bounds.width() - new_panel_width; |
+ bounds.set_x(bounds.x() + delta); |
+ bounds.set_width(new_panel_width); |
+ |
+ // Reposition all the panels on the left. |
+ int panel_index = -1; |
+ for (int i = 0; i < static_cast<int>(panels_.size()); ++i) { |
+ if (panels_[i] == panel) { |
+ panel_index = i; |
+ break; |
+ } |
+ } |
+ DCHECK(panel_index >= 0); |
+ for (int i = static_cast<int>(panels_.size()) -1; i > panel_index; |
+ --i) { |
+ gfx::Rect this_bounds = panels_[i]->GetBounds(); |
+ this_bounds.set_x(this_bounds.x() + delta); |
+ panels_[i]->SetPanelBounds(this_bounds); |
+ } |
+ } |
+ |
+ // The panel height: |
+ // * cannot grow more than the maximum height |
+ // * cannot shrink to be smaller than the initial height |
+ int new_panel_height = pref_size.height() + non_client_size.height(); |
+ if (new_panel_height > max_height_) |
+ new_panel_height = max_height_; |
+ |
+ if (new_panel_height > bounds.height() || |
+ (new_panel_height < bounds.height() && |
+ new_panel_height > panel->initial_size_.height())) { |
+ bounds.set_y(bounds.y() - new_panel_height + bounds.height()); |
+ bounds.set_height(new_panel_height); |
+ } |
+ |
+ panel->SetRestoredBounds(bounds); |
+ current_x_ = |
+ panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing; |
+ |
+ UpdateMaximumSizeForAllPanels(); |
+} |
+ |
bool PanelManager::ShouldBringUpTitleBarForAllMinimizedPanels( |
int mouse_x, int mouse_y) const { |
for (Panels::const_iterator iter = panels_.begin(); |
@@ -310,6 +375,8 @@ |
if (new_bounds != (*iter)->GetBounds()) |
(*iter)->SetPanelBounds(new_bounds); |
} |
+ |
+ UpdateMaximumSizeForAllPanels(); |
} |
bool PanelManager::ComputeBoundsForNextPanel(gfx::Rect* bounds, |
@@ -356,3 +423,13 @@ |
iter != panels_.rend(); ++iter) |
(*iter)->Close(); |
} |
+ |
+void PanelManager::UpdateMaximumSizeForAllPanels() { |
+ for (Panels::const_iterator iter = panels_.begin(); |
+ iter != panels_.end(); ++iter) { |
+ Panel* panel = *iter; |
+ int width_can_grow_to = panel->GetBounds().width() + current_x_; |
Dmitry Titov
2011/08/05 19:02:20
It is a bit unclear why we give the same area of t
jianli
2011/08/09 19:56:16
Added comment.
|
+ panel->SetMaximumSize( |
+ gfx::Size(std::min(width_can_grow_to, max_width_), max_height_)); |
+ } |
+} |