diff options
author | jennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-22 02:23:09 +0000 |
---|---|---|
committer | jennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-22 02:23:09 +0000 |
commit | 6b66e586e7d23e504a69fe0d964a4bcd566e90fd (patch) | |
tree | 5056b9e64a1d60e37c2bb61fe6f3b7c1ee5b7878 /chrome | |
parent | c0e9e19f313f9bcf893fce686464f8bc2013cdf7 (diff) | |
download | chromium_src-6b66e586e7d23e504a69fe0d964a4bcd566e90fd.zip chromium_src-6b66e586e7d23e504a69fe0d964a4bcd566e90fd.tar.gz chromium_src-6b66e586e7d23e504a69fe0d964a4bcd566e90fd.tar.bz2 |
Change panel overflow to not close any open panels. Extra panels that don't fit on screen are allowed to be opened off-screen. On Linux, the WM may force the overflow panels to remain on-screen using overlapping.
Maximum panel width is no longer affected by the remaining available screen area now that panels are allowed to overflow the available screen area.
BUG=100185
TEST=PanelBrowserTest.CreatePanelOnOverflow
Review URL: http://codereview.chromium.org/8375012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106840 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/ui/panels/panel_browsertest.cc | 53 | ||||
-rw-r--r-- | chrome/browser/ui/panels/panel_manager.cc | 82 | ||||
-rw-r--r-- | chrome/browser/ui/panels/panel_manager.h | 8 |
3 files changed, 36 insertions, 107 deletions
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc index e4b0b2c..3795277 100644 --- a/chrome/browser/ui/panels/panel_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browsertest.cc @@ -80,47 +80,44 @@ class PanelBrowserTest : public BasePanelBrowserTest { gfx::Rect(0, 0, 200, 200)); ASSERT_EQ(3, panel_manager->num_panels()); - // Test closing the leftmost panel that is from same extension. - ui_test_utils::WindowedNotificationObserver signal( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel2->browser())); + // Open a panel that would overflow. Panel* panel4 = CreatePanelWithBounds( web_app::GenerateApplicationNameFromExtensionId(extension2->id()), gfx::Rect(0, 0, 280, 200)); - signal.Wait(); - ASSERT_EQ(3, panel_manager->num_panels()); + ASSERT_EQ(4, panel_manager->num_panels()); EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x()); - EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); + EXPECT_GT(0, panel4->GetBounds().x()); - // Test closing the leftmost panel. - ui_test_utils::WindowedNotificationObserver signal2( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel4->browser())); + // Open another panel that would overflow. Panel* panel5 = CreatePanelWithBounds( web_app::GenerateApplicationNameFromExtensionId(extension3->id()), gfx::Rect(0, 0, 300, 200)); - signal2.Wait(); + ASSERT_EQ(5, panel_manager->num_panels()); + EXPECT_LT(panel5->GetBounds().right(), panel4->GetBounds().x()); + EXPECT_GT(0, panel5->GetBounds().x()); + + // Close a visible panel. Expect an overflow panel to slide over. + CloseWindowAndWait(panel2->browser()); + ASSERT_EQ(4, panel_manager->num_panels()); + EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x()); + EXPECT_LE(0, panel4->GetBounds().x()); + EXPECT_GT(0, panel5->GetBounds().x()); + + // Close another visible panel. Remaining overflow panel should slide over + // but still not enough room to be fully visible. + CloseWindowAndWait(panel3->browser()); ASSERT_EQ(3, panel_manager->num_panels()); - EXPECT_LT(panel5->GetBounds().right(), panel3->GetBounds().x()); - EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); + EXPECT_LT(panel5->GetBounds().right(), panel4->GetBounds().x()); + EXPECT_GT(0, panel5->GetBounds().x()); - // Test closing 2 leftmost panels. - ui_test_utils::WindowedNotificationObserver signal3( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel3->browser())); - ui_test_utils::WindowedNotificationObserver signal4( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel5->browser())); - Panel* panel6 = CreatePanelWithBounds( - web_app::GenerateApplicationNameFromExtensionId(extension3->id()), - gfx::Rect(0, 0, 500, 200)); - signal3.Wait(); - signal4.Wait(); + // Closing one more panel makes room for all panels to fit on screen. + CloseWindowAndWait(panel4->browser()); ASSERT_EQ(2, panel_manager->num_panels()); - EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); + EXPECT_LT(panel5->GetBounds().right(), panel1->GetBounds().x()); + EXPECT_LE(0, panel5->GetBounds().x()); panel1->Close(); - panel6->Close(); + panel5->Close(); } int horizontal_spacing() { diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc index 0715ed7..5bb2bc8 100644 --- a/chrome/browser/ui/panels/panel_manager.cc +++ b/chrome/browser/ui/panels/panel_manager.cc @@ -80,26 +80,6 @@ void PanelManager::SetWorkArea(const gfx::Rect& work_area) { Rearrange(panels_.begin(), adjusted_work_area_.right()); } -void PanelManager::FindAndClosePanelOnOverflow(const Extension* extension) { - Panel* panel_to_close = NULL; - - // Try to find the left-most panel invoked from the same extension and close - // it. - for (Panels::reverse_iterator iter = panels_.rbegin(); - iter != panels_.rend(); ++iter) { - if (extension == (*iter)->GetExtension()) { - panel_to_close = *iter; - break; - } - } - - // If none is found, just pick the left-most panel. - if (!panel_to_close) - panel_to_close = panels_.back(); - - panel_to_close->Close(); -} - Panel* PanelManager::CreatePanel(Browser* browser) { // Adjust the width and height to fit into our constraint. int width = browser->override_bounds().width(); @@ -123,25 +103,13 @@ Panel* PanelManager::CreatePanel(Browser* browser) { else if (height > max_panel_height) height = max_panel_height; - // Compute the origin. Ensure that it falls within the adjusted work area by - // closing other panels if needed. int y = adjusted_work_area_.bottom() - height; - - const Extension* extension = NULL; - int x; - while ((x = GetRightMostAvailablePosition() - width) < - adjusted_work_area_.x() ) { - if (!extension) - extension = Panel::GetExtensionFromBrowser(browser); - FindAndClosePanelOnOverflow(extension); - } + int x = GetRightMostAvailablePosition() - width; // Now create the panel with the computed bounds. Panel* panel = new Panel(browser, gfx::Rect(x, y, width, height)); + panel->SetMaxSize(gfx::Size(max_panel_width, max_panel_height)); panels_.push_back(panel); - - UpdateMaxSizeForAllPanels(); - return panel; } @@ -357,18 +325,12 @@ void PanelManager::OnPreferredWindowSizeChanged( // 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(); if (new_width > panel->max_size().width()) new_width = panel->max_size().width(); if (new_width < panel->min_size().width()) new_width = panel->min_size().width(); - int right_most_available_position = GetRightMostAvailablePosition(); - if (new_width - bounds.width() > right_most_available_position) - new_width = bounds.width() + right_most_available_position; - if (new_width != bounds.width()) { int delta = bounds.width() - new_width; bounds.set_x(bounds.x() + delta); @@ -409,8 +371,6 @@ void PanelManager::OnPreferredWindowSizeChanged( } panel->SetPanelBounds(bounds); - - UpdateMaxSizeForAllPanels(); } bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { @@ -570,20 +530,16 @@ void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( void PanelManager::Rearrange(Panels::iterator iter_to_start, int rightmost_position) { - if (iter_to_start != panels_.end()) { - for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { - Panel* panel = *iter; - gfx::Rect new_bounds(panel->GetBounds()); - new_bounds.set_x(rightmost_position - new_bounds.width()); - new_bounds.set_y(adjusted_work_area_.bottom() - new_bounds.height()); - if (new_bounds != panel->GetBounds()) - panel->SetPanelBounds(new_bounds); - - rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; - } - } + for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { + Panel* panel = *iter; + gfx::Rect new_bounds(panel->GetBounds()); + new_bounds.set_x(rightmost_position - new_bounds.width()); + new_bounds.set_y(adjusted_work_area_.bottom() - new_bounds.height()); + if (new_bounds != panel->GetBounds()) + panel->SetPanelBounds(new_bounds); - UpdateMaxSizeForAllPanels(); + rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; + } } void PanelManager::RemoveAll() { @@ -603,19 +559,3 @@ bool PanelManager::is_dragging_panel() const { return dragging_panel_index_ != kInvalidPanelIndex; } -void PanelManager::UpdateMaxSizeForAllPanels() { - if (!auto_sizing_enabled_) - return; - - for (Panels::const_iterator iter = panels_.begin(); - iter != panels_.end(); ++iter) { - Panel* panel = *iter; - // A panel can at most grow to take over all the available space that is - // returned by GetRightMostAvailablePosition. - int width_can_grow_to = - panel->GetBounds().width() + GetRightMostAvailablePosition(); - panel->SetMaxSize(gfx::Size( - std::min(width_can_grow_to, GetMaxPanelWidth()), - GetMaxPanelHeight())); - } -} diff --git a/chrome/browser/ui/panels/panel_manager.h b/chrome/browser/ui/panels/panel_manager.h index 243f60c..b419c8f 100644 --- a/chrome/browser/ui/panels/panel_manager.h +++ b/chrome/browser/ui/panels/panel_manager.h @@ -148,10 +148,6 @@ class PanelManager : public PanelMouseWatcher::Observer, // area being changed or a panel being closed. void Rearrange(Panels::iterator iter_to_start, int rightmost_position); - // Finds one panel to close so that we may have space for the new panel - // created by |extension|. - void FindAndClosePanelOnOverflow(const Extension* extension); - // Help functions to drag the given panel. void DragLeft(); void DragRight(); @@ -168,10 +164,6 @@ class PanelManager : public PanelMouseWatcher::Observer, int GetMaxPanelHeight() const; int GetRightMostAvailablePosition() const; - // Updates the maximum size of each panel as the result of adding, removing, - // or sizing panels. - void UpdateMaxSizeForAllPanels(); - Panels panels_; // Stores the panels that are pending to remove. We want to delay the removal |