Commit 14decadb authored by dimich@chromium.org's avatar dimich@chromium.org

Remove panel size limit when user resizes it.

BUG=123669
TEST=existing panel resize tests, modified

Review URL: https://chromiumcodereview.appspot.com/10260001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134559 0039d316-1c4b-4281-b951-d872f2087c98
parent bc8b93e0
......@@ -77,7 +77,7 @@ void DetachedPanelStrip::ResizePanelWindow(
// Make sure the new size does not violate panel's size restrictions.
gfx::Size new_size(preferred_window_size.width(),
preferred_window_size.height());
panel->ClampSize(&new_size);
new_size = panel->ClampSize(new_size);
// Update restored size.
if (new_size != panel->full_size())
......
......@@ -50,13 +50,15 @@ const int kDelayBeforeCollapsingFromTitleOnlyStateMs = 0;
// we refresh layout with a delay.
const int kRefreshLayoutAfterActivePanelChangeDelayMs = 200; // arbitrary
// The minimum panel width when it is "squeezed" in the docked strip
// due to lack of space.
const int kMinPanelWidthForDisplay = 26;
} // namespace
// static
const int DockedPanelStrip::kPanelMinWidth = 100;
// These numbers are semi-arbitrary.
// Motivation for 'width' is to make main buttons on the titlebar functional.
// Motivation for height is to allow autosized tightly-wrapped panel with a
// single line of text - so the height is set to be likely less then a titlebar,
// to make sure even small content is tightly wrapped.
const int DockedPanelStrip::kPanelMinWidth = 80;
const int DockedPanelStrip::kPanelMinHeight = 20;
DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager)
......@@ -161,6 +163,9 @@ void DockedPanelStrip::InsertNewlyCreatedPanel(Panel* panel) {
panel->Initialize(gfx::Rect(pt.x(), pt.y(), width, height));
panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight),
gfx::Size(max_panel_width, max_panel_height));
InsertExistingPanelAtDefaultPosition(panel, true /*update_bounds*/);
}
......@@ -572,7 +577,7 @@ void DockedPanelStrip::ResizePanelWindow(
// Make sure the new size does not violate panel's size restrictions.
gfx::Size new_size(preferred_window_size.width(),
preferred_window_size.height());
panel->ClampSize(&new_size);
new_size = panel->ClampSize(new_size);
if (new_size == panel->full_size())
return;
......@@ -851,7 +856,7 @@ int DockedPanelStrip::WidthToDisplayPanelInStrip(bool is_for_active_panel,
int full_width) const {
if (is_for_active_panel)
return full_width;
return std::max(kMinPanelWidthForDisplay,
return std::max(kPanelMinWidth,
static_cast<int>(floor(full_width * squeeze_factor)));
}
......@@ -868,13 +873,15 @@ void DockedPanelStrip::CloseAll() {
}
void DockedPanelStrip::UpdatePanelOnStripChange(Panel* panel) {
// Always update limits, even on existing panels, in case the limits changed
// while panel was out of the strip.
int max_panel_width = GetMaxPanelWidth();
int max_panel_height = GetMaxPanelHeight();
panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight),
gfx::Size(max_panel_width, max_panel_height));
// Update limits if the panel is still autosizable, in case the limit has
// changed. If the panel is not autoresizable, then it was resized
// by the user or by the app via API.
if (panel->auto_resizable()) {
int max_panel_width = GetMaxPanelWidth();
int max_panel_height = GetMaxPanelHeight();
panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight),
gfx::Size(max_panel_width, max_panel_height));
}
panel->set_attention_mode(Panel::USE_PANEL_ATTENTION);
panel->SetAppIconVisibility(true);
panel->SetAlwaysOnTop(true);
......
......@@ -136,11 +136,11 @@ void Panel::SetSizeRange(const gfx::Size& min_size, const gfx::Size& max_size) {
ConfigureAutoResize(browser()->GetSelectedWebContents());
}
void Panel::ClampSize(gfx::Size* size) const {
gfx::Size Panel::ClampSize(const gfx::Size& size) const {
// The panel width:
// * cannot grow or shrink to go beyond [min_width, max_width]
int new_width = size->width();
int new_width = size.width();
if (new_width > max_size_.width())
new_width = max_size_.width();
if (new_width < min_size_.width())
......@@ -148,13 +148,13 @@ void Panel::ClampSize(gfx::Size* size) const {
// The panel height:
// * cannot grow or shrink to go beyond [min_height, max_height]
int new_height = size->height();
int new_height = size.height();
if (new_height > max_size_.height())
new_height = max_size_.height();
if (new_height < min_size_.height())
new_height = min_size_.height();
size->SetSize(new_width, new_height);
return gfx::Size(new_width, new_height);
}
......
......@@ -299,7 +299,7 @@ class Panel : public BrowserWindow,
void EnableResizeByMouse(bool enable);
// Changes the preferred size to acceptable based on min_size() and max_size()
void ClampSize(gfx::Size* size) const;
gfx::Size ClampSize(const gfx::Size& size) const;
// Called when the panel's active state changes.
// |active| is true if panel became active.
......
......@@ -393,7 +393,9 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanelInactive) {
}
IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, PanelLayout) {
Panel* panel = CreatePanel("PanelTest");
// Create a fixed-size panel to avoid possible collapsing of the title
// if the enforced min sizes are too small.
Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 50));
views::View* title_icon = GetTitleIcon(panel);
views::View* title_text = GetTitleText(panel);
......
......@@ -235,15 +235,21 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanelToClampSize) {
panel_manager->EndResizingByMouse(false);
EXPECT_EQ(bounds, panel->GetBounds());
// Make sure the panel does not resize larger than its size.
// Make sure the panel can resize larger than its size. User is in control.
mouse_location = bounds.origin().Add(
gfx::Point(bounds.width(), bounds.height() - 2));
panel_manager->StartResizingByMouse(panel, mouse_location,
panel::RESIZE_BOTTOM_RIGHT);
mouse_location.Offset(500, 40);
// This drag would take us beyond max size.
int delta_x = panel->max_size().width() + 10 - panel->GetBounds().width();
int delta_y = panel->max_size().height() + 10 - panel->GetBounds().height();
mouse_location.Offset(delta_x, delta_y);
panel_manager->ResizeByMouse(mouse_location);
bounds.set_size(gfx::Size(panel->max_size().width(), bounds.height() + 40));
// The bounds if the max_size does not limit the resize.
bounds.set_size(gfx::Size(bounds.width() + delta_x,
bounds.height() + delta_y));
EXPECT_EQ(bounds, panel->GetBounds());
panel_manager->EndResizingByMouse(false);
......
......@@ -88,10 +88,22 @@ void PanelResizeController::Resize(const gfx::Point& mouse_location) {
mouse_location_at_start_.y() - mouse_location.y(), 0));
}
// Give the panel a chance to adjust the bounds before setting them.
gfx::Size size = bounds.size();
resizing_panel_->ClampSize(&size);
bounds.set_size(size);
// Update the max size of the panel so it's never smaller then the actual
// panel's size. Note that even if the user resizes the panel smaller later,
// the increased max size will still be in effect. Since it's not possible
// currently to switch the panel back to autosizing from user-resizable, it
// should not be a problem.
gfx::Size max_panel_size = resizing_panel_->max_size();
if (max_panel_size.width() < bounds.width())
max_panel_size.set_width(bounds.width());
if (max_panel_size.height() < bounds.height())
max_panel_size.set_height(bounds.height());
resizing_panel_->SetSizeRange(resizing_panel_->min_size(), max_panel_size);
// This effectively only clamps using the min size, since the max_size was
// updated above.
bounds.set_size(resizing_panel_->ClampSize(bounds.size()));
if (ResizingLeft(sides_resized_)) {
bounds.set_x(bounds_at_start_.x() -
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment