Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Unified Diff: chrome/browser/ui/panels/panel_manager.cc

Issue 7537030: Make panel adjust bounds per preferred size change notification on Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/panels/panel_manager.cc
===================================================================
--- chrome/browser/ui/panels/panel_manager.cc (revision 96104)
+++ chrome/browser/ui/panels/panel_manager.cc (working copy)
@@ -16,8 +16,10 @@
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.
+// TODO(jianli): Need to fix this to support smaller panel.
+const int kPanelMinWidthPixels = 100;
+const int kPanelMinHeightPixels = 100;
// Default width and height of a panel.
const int kPanelDefaultWidthPixels = 240;
@@ -110,6 +112,7 @@
Panel* panel = new Panel(browser, bounds);
panels_.push_back(panel);
+ UpdateMaxSizeForAllPanels();
return panel;
}
@@ -271,6 +274,72 @@
DelayedRemove();
}
+void PanelManager::OnPreferredWindowSizeChanged(
+ Panel* panel, const gfx::Size& preferred_window_size) {
+ gfx::Rect bounds = panel->GetBounds();
+ int restored_height = panel->GetRestoredHeight();
+
+ // The panel width:
+ // * cannot grow or shrink to go beyond [min_width, max_width]
+ // * cannot grow to take more than the available space and go beyond the left
+ // of the work area.
+ int new_width = preferred_window_size.width();
+ int max_width = panel->max_size().width();
+ if (new_width > max_width)
+ new_width = max_width;
+ if (new_width - bounds.width() > current_x_)
+ new_width = bounds.width() + current_x_;
+
+ if (new_width > bounds.width() ||
+ (new_width < bounds.width() &&
+ new_width > panel->min_size().width())) {
+ int delta = bounds.width() - new_width;
+ bounds.set_x(bounds.x() + delta);
+ bounds.set_width(new_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 or shrink to go beyond [min_height, max_height]
+ int new_height = preferred_window_size.height();
+ if (new_height > max_height_)
+ new_height = max_height_;
+
+ if (new_height > restored_height ||
+ (new_height < restored_height &&
+ new_height > panel->min_size().height())) {
+ // If the panel is not expanded, we only need to save the new restored
+ // height.
+ if (panel->expansion_state() == Panel::EXPANDED) {
+ bounds.set_y(bounds.y() - new_height + bounds.height());
+ bounds.set_height(new_height);
+ } else {
+ panel->SetRestoredHeight(new_height);
+ }
+ }
+
+ panel->SetPanelBounds(bounds);
+ current_x_ =
+ panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing;
+
+ UpdateMaxSizeForAllPanels();
+}
+
bool PanelManager::ShouldBringUpTitleBarForAllMinimizedPanels(
int mouse_x, int mouse_y) const {
for (Panels::const_iterator iter = panels_.begin();
@@ -310,6 +379,8 @@
if (new_bounds != (*iter)->GetBounds())
(*iter)->SetPanelBounds(new_bounds);
}
+
+ UpdateMaxSizeForAllPanels();
}
bool PanelManager::ComputeBoundsForNextPanel(gfx::Rect* bounds,
@@ -356,3 +427,16 @@
iter != panels_.rend(); ++iter)
(*iter)->Close();
}
+
+void PanelManager::UpdateMaxSizeForAllPanels() {
+ for (Panels::const_iterator iter = panels_.begin();
+ iter != panels_.end(); ++iter) {
+ Panel* panel = *iter;
+ // We arrange the panels from right to left on the screen. |current_x_| is
+ // the left-most point that panels occupy to. So we add |current_x_| for all
+ // panels to mean each of them can try to take over this available space.
+ int width_can_grow_to = panel->GetBounds().width() + current_x_;
+ panel->SetMaxSize(
+ gfx::Size(std::min(width_can_grow_to, max_width_), max_height_));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698