summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/panels/panel_manager.cc
diff options
context:
space:
mode:
authorjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-03 01:11:24 +0000
committerjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-03 01:11:24 +0000
commit21965e2a68ffb2d4107492e8f739e4391dbe7f38 (patch)
tree7054c0d00c48b333bae9d5e1ebe8f750b81cf244 /chrome/browser/ui/panels/panel_manager.cc
parentfae1ecd61e45ced03f447a53674e4ba1cd9f77a0 (diff)
downloadchromium_src-21965e2a68ffb2d4107492e8f739e4391dbe7f38.zip
chromium_src-21965e2a68ffb2d4107492e8f739e4391dbe7f38.tar.gz
chromium_src-21965e2a68ffb2d4107492e8f739e4391dbe7f38.tar.bz2
Cleanup to keep panel from manipulating its panel strip assignment directly.
Only PanelManager adds/removes panels from panel strips. Only exception is in tests. BUG=None TEST=Existing tests. Review URL: http://codereview.chromium.org/9560002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/panels/panel_manager.cc')
-rw-r--r--chrome/browser/ui/panels/panel_manager.cc62
1 files changed, 59 insertions, 3 deletions
diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc
index bb8323a..22195b6 100644
--- a/chrome/browser/ui/panels/panel_manager.cc
+++ b/chrome/browser/ui/panels/panel_manager.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/panels/panel_manager.h"
+#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -64,7 +65,8 @@ bool PanelManager::ShouldUsePanels(const std::string& extension_id) {
PanelManager::PanelManager()
: panel_mouse_watcher_(PanelMouseWatcher::Create()),
auto_sizing_enabled_(true),
- is_full_screen_(false) {
+ is_full_screen_(false),
+ is_processing_overflow_(false) {
detached_strip_.reset(new DetachedPanelStrip(this));
docked_strip_.reset(new DockedPanelStrip(this));
overflow_strip_.reset(new OverflowPanelStrip(this));
@@ -117,7 +119,7 @@ Panel* PanelManager::CreatePanel(Browser* browser) {
int width = browser->override_bounds().width();
int height = browser->override_bounds().height();
Panel* panel = new Panel(browser, gfx::Size(width, height));
- panel->MoveToStrip(docked_strip_.get());
+ docked_strip_->AddPanel(panel);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PANEL_ADDED,
@@ -147,10 +149,11 @@ void PanelManager::CheckFullScreenMode() {
}
void PanelManager::OnPanelClosed(Panel* panel) {
- if (num_panels() == 0)
+ if (num_panels() == 1)
full_screen_mode_timer_.Stop();
drag_controller_->OnPanelClosed(panel);
+ panel->panel_strip()->RemovePanel(panel);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PANEL_CLOSED,
@@ -185,6 +188,59 @@ void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) {
panel->SetAutoResizable(false);
}
+void PanelManager::MovePanelToStrip(Panel* panel,
+ PanelStrip::Type new_layout) {
+ DCHECK(panel);
+ PanelStrip* current_strip = panel->panel_strip();
+ DCHECK(current_strip);
+ DCHECK_NE(current_strip->type(), new_layout);
+ current_strip->RemovePanel(panel);
+
+ PanelStrip* target_strip = NULL;
+ switch (new_layout) {
+ case PanelStrip::DETACHED:
+ target_strip = detached_strip_.get();
+ break;
+ case PanelStrip::DOCKED:
+ target_strip = docked_strip_.get();
+ break;
+ case PanelStrip::IN_OVERFLOW:
+ target_strip = overflow_strip_.get();
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ target_strip->AddPanel(panel);
+
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_PANEL_CHANGED_LAYOUT_MODE,
+ content::Source<Panel>(panel),
+ content::NotificationService::NoDetails());
+}
+
+void PanelManager::MovePanelsToOverflow(Panel* last_panel_to_move) {
+ AutoReset<bool> processing_overflow(&is_processing_overflow_, true);
+ // Move panels to overflow in reverse to maintain their order.
+ Panel* bumped_panel;
+ while ((bumped_panel = docked_strip_->last_panel())) {
+ MovePanelToStrip(bumped_panel, PanelStrip::IN_OVERFLOW);
+ if (bumped_panel == last_panel_to_move)
+ break;
+ }
+ DCHECK(!docked_strip_->panels().empty());
+}
+
+void PanelManager::MovePanelsOutOfOverflowIfCanFit() {
+ if (is_processing_overflow_)
+ return;
+
+ Panel* overflow_panel;
+ while ((overflow_panel = overflow_strip_->first_panel()) &&
+ docked_strip_->CanFitPanel(overflow_panel))
+ MovePanelToStrip(overflow_panel, PanelStrip::DOCKED);
+}
+
bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const {
return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y);
}