Index: chrome/browser/ui/panels/panel_strip.cc |
diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_strip.cc |
similarity index 69% |
copy from chrome/browser/ui/panels/panel_manager.cc |
copy to chrome/browser/ui/panels/panel_strip.cc |
index 7e2fefdbb4373ca3532e2acbc32a02ad43a3792a..e62e34bb5383011e9bebd6f733f7be8853f810f3 100644 |
--- a/chrome/browser/ui/panels/panel_manager.cc |
+++ b/chrome/browser/ui/panels/panel_strip.cc |
@@ -2,18 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/panels/panel_manager.h" |
+#include "chrome/browser/ui/panels/panel_strip.h" |
#include <algorithm> |
#include "base/bind.h" |
#include "base/logging.h" |
-#include "base/memory/scoped_ptr.h" |
#include "base/message_loop.h" |
#include "chrome/browser/ui/browser.h" |
-#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/panels/panel_manager.h" |
#include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
-#include "chrome/browser/ui/window_sizer.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/notification_source.h" |
@@ -22,19 +20,12 @@ namespace { |
// Invalid panel index. |
const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
-// Width of spacing between first panel and the right edge of the screen. |
-// Leaving a larger gap at the edge of the screen allows access to UI |
-// elements located on the bottom right of windows. |
-const int kRightScreenEdgeSpacingWidth = 24; |
- |
// Width to height ratio is used to compute the default width or height |
// when only one value is provided. |
const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio |
-// Maxmium width and height of a panel based on the factor of the working |
-// area. |
+// Maxmium width of a panel is based on a factor of the entire panel strip. |
const double kPanelMaxWidthFactor = 0.35; |
-const double kPanelMaxHeightFactor = 0.5; |
// Occasionally some system, like Windows, might not bring up or down the bottom |
// bar when the mouse enters or leaves the bottom screen area. This is the |
@@ -51,83 +42,65 @@ const int kMillisecondsBeforeCollapsingFromTitleOnlyState = 0; |
} // namespace |
// static |
-const int PanelManager::kPanelMinWidth = 100; |
-const int PanelManager::kPanelMinHeight = 20; |
- |
-// static |
-PanelManager* PanelManager::GetInstance() { |
- static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER; |
- return instance.Pointer(); |
-} |
+const int PanelStrip::kPanelMinWidth = 100; |
+const int PanelStrip::kPanelMinHeight = 20; |
-PanelManager::PanelManager() |
- : minimized_panel_count_(0), |
+PanelStrip::PanelStrip(PanelManager* panel_manager) |
+ : panel_manager_(panel_manager), |
+ minimized_panel_count_(0), |
are_titlebars_up_(false), |
dragging_panel_index_(kInvalidPanelIndex), |
dragging_panel_original_x_(0), |
delayed_titlebar_action_(NO_ACTION), |
remove_delays_for_testing_(false), |
- titlebar_action_factory_(this), |
- auto_sizing_enabled_(true), |
- mouse_watching_disabled_(false) { |
- panel_mouse_watcher_.reset(PanelMouseWatcher::Create()); |
- auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); |
- OnDisplayChanged(); |
+ titlebar_action_factory_(this) { |
} |
-PanelManager::~PanelManager() { |
+PanelStrip::~PanelStrip() { |
DCHECK(panels_.empty()); |
DCHECK(panels_pending_to_remove_.empty()); |
DCHECK_EQ(0, minimized_panel_count_); |
} |
-void PanelManager::OnDisplayChanged() { |
- scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( |
- WindowSizer::CreateDefaultMonitorInfoProvider()); |
-#if defined(OS_MACOSX) |
- // On OSX, panels should be dropped all the way to the bottom edge of the |
- // screen (and overlap Dock). |
- gfx::Rect work_area = info_provider->GetPrimaryMonitorBounds(); |
-#else |
- gfx::Rect work_area = info_provider->GetPrimaryMonitorWorkArea(); |
-#endif |
- SetWorkArea(work_area); |
-} |
- |
-void PanelManager::SetWorkArea(const gfx::Rect& work_area) { |
- if (work_area == work_area_) |
+void PanelStrip::SetBounds(const gfx::Rect bounds) { |
+ if (strip_bounds_ == bounds) |
return; |
- work_area_ = work_area; |
- |
- auto_hiding_desktop_bar_->UpdateWorkArea(work_area_); |
- AdjustWorkAreaForAutoHidingDesktopBars(); |
+ strip_bounds_ = bounds; |
Rearrange(panels_.begin(), StartingRightPosition()); |
} |
-Panel* PanelManager::CreatePanel(Browser* browser) { |
- int width = browser->override_bounds().width(); |
- int height = browser->override_bounds().height(); |
+void PanelStrip::AddPanel(Panel* panel) { |
+ if (panel->initialized()) |
+ AddExistingPanel(panel); |
+ else |
+ AddNewPanel(panel); |
+ panels_.push_back(panel); |
+} |
- Panel* panel = new Panel(browser, gfx::Size(width, height)); |
+void PanelStrip::AddNewPanel(Panel* panel) { |
+ DCHECK(!panel->initialized()); |
int max_panel_width = GetMaxPanelWidth(); |
int max_panel_height = GetMaxPanelHeight(); |
panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
gfx::Size(max_panel_width, max_panel_height)); |
- // Auto resizable is enabled only if no initial size is provided. |
- bool auto_resize = (width == 0 && height == 0); |
- panel->SetAutoResizable(auto_resize); |
+ gfx::Size restored_size = panel->restored_size(); |
+ int height = restored_size.height(); |
+ int width = restored_size.width(); |
- // Adjust the width and height to fit into our constraint. |
- if (!auto_resize) { |
+ if (height == 0 && width == 0) { |
+ // Auto resizable is enabled only if no initial size is provided. |
+ panel->SetAutoResizable(true); |
+ } else { |
if (height == 0) |
height = width / kPanelDefaultWidthToHeightRatio; |
if (width == 0) |
width = height * kPanelDefaultWidthToHeightRatio; |
} |
+ // Constrain sizes to limits. |
if (width < kPanelMinWidth) |
width = kPanelMinWidth; |
else if (width > max_panel_width) |
@@ -137,58 +110,61 @@ Panel* PanelManager::CreatePanel(Browser* browser) { |
height = kPanelMinHeight; |
else if (height > max_panel_height) |
height = max_panel_height; |
- |
panel->set_restored_size(gfx::Size(width, height)); |
// Layout the new panel. |
- int y = adjusted_work_area_.bottom() - height; |
+ int y = strip_bounds_.bottom() - height; |
int x = GetRightMostAvailablePosition() - width; |
panel->Initialize(gfx::Rect(x, y, width, height)); |
+} |
- panels_.push_back(panel); |
- |
- content::NotificationService::current()->Notify( |
- chrome::NOTIFICATION_PANEL_ADDED, |
- content::Source<Panel>(panel), |
- content::NotificationService::NoDetails()); |
- |
- return panel; |
+void PanelStrip::AddExistingPanel(Panel* panel) { |
+ gfx::Size restored_size = panel->restored_size(); |
+ int height = restored_size.height(); |
+ int width = restored_size.width(); |
+ int x = GetRightMostAvailablePosition() - width; |
+ int y = strip_bounds_.bottom() - height; |
+ panel->SetPanelBounds(gfx::Rect(x, y, width, height)); |
} |
-int PanelManager::GetMaxPanelWidth() const { |
- return static_cast<int>(adjusted_work_area_.width() * kPanelMaxWidthFactor); |
+int PanelStrip::GetMaxPanelWidth() const { |
+ return static_cast<int>(strip_bounds_.width() * kPanelMaxWidthFactor); |
} |
-int PanelManager::GetMaxPanelHeight() const { |
- return static_cast<int>(adjusted_work_area_.height() * kPanelMaxHeightFactor); |
+int PanelStrip::GetMaxPanelHeight() const { |
+ return strip_bounds_.height(); |
} |
-int PanelManager::StartingRightPosition() const { |
- return adjusted_work_area_.right() - kRightScreenEdgeSpacingWidth; |
+int PanelStrip::StartingRightPosition() const { |
+ return strip_bounds_.right(); |
} |
-int PanelManager::GetRightMostAvailablePosition() const { |
+int PanelStrip::GetRightMostAvailablePosition() const { |
return panels_.empty() ? StartingRightPosition() : |
(panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); |
} |
-void PanelManager::Remove(Panel* panel) { |
+bool PanelStrip::Remove(Panel* panel) { |
+ if (find(panels_.begin(), panels_.end(), panel) == panels_.end()) |
+ return false; |
+ |
// If we're in the process of dragging, delay the removal. |
if (dragging_panel_index_ != kInvalidPanelIndex) { |
panels_pending_to_remove_.push_back(panel); |
- return; |
+ return true; |
} |
DoRemove(panel); |
+ return true; |
} |
-void PanelManager::DelayedRemove() { |
+void PanelStrip::DelayedRemove() { |
for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i) |
DoRemove(panels_pending_to_remove_[i]); |
panels_pending_to_remove_.clear(); |
} |
-void PanelManager::DoRemove(Panel* panel) { |
+void PanelStrip::DoRemove(Panel* panel) { |
Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); |
if (iter == panels_.end()) |
return; |
@@ -198,14 +174,10 @@ void PanelManager::DoRemove(Panel* panel) { |
gfx::Rect bounds = (*iter)->GetBounds(); |
Rearrange(panels_.erase(iter), bounds.right()); |
- |
- content::NotificationService::current()->Notify( |
- chrome::NOTIFICATION_PANEL_REMOVED, |
- content::Source<Panel>(panel), |
- content::NotificationService::NoDetails()); |
+ panel_manager_->OnPanelRemoved(panel); |
} |
-void PanelManager::StartDragging(Panel* panel) { |
+void PanelStrip::StartDragging(Panel* panel) { |
for (size_t i = 0; i < panels_.size(); ++i) { |
if (panels_[i] == panel) { |
dragging_panel_index_ = i; |
@@ -216,7 +188,7 @@ void PanelManager::StartDragging(Panel* panel) { |
} |
} |
-void PanelManager::Drag(int delta_x) { |
+void PanelStrip::Drag(int delta_x) { |
DCHECK(dragging_panel_index_ != kInvalidPanelIndex); |
if (!delta_x) |
@@ -235,7 +207,7 @@ void PanelManager::Drag(int delta_x) { |
DragLeft(); |
} |
-void PanelManager::DragLeft() { |
+void PanelStrip::DragLeft() { |
Panel* dragging_panel = panels_[dragging_panel_index_]; |
// This is the left corner of the dragging panel. We use it to check against |
@@ -278,7 +250,7 @@ void PanelManager::DragLeft() { |
} |
} |
-void PanelManager::DragRight() { |
+void PanelStrip::DragRight() { |
Panel* dragging_panel = panels_[dragging_panel_index_]; |
// This is the right corner of the dragging panel. We use it to check against |
@@ -320,7 +292,7 @@ void PanelManager::DragRight() { |
} |
} |
-void PanelManager::EndDragging(bool cancelled) { |
+void PanelStrip::EndDragging(bool cancelled) { |
DCHECK(dragging_panel_index_ != kInvalidPanelIndex); |
if (cancelled) { |
@@ -336,7 +308,7 @@ void PanelManager::EndDragging(bool cancelled) { |
DelayedRemove(); |
} |
-void PanelManager::OnPanelExpansionStateChanged( |
+void PanelStrip::OnPanelExpansionStateChanged( |
Panel::ExpansionState old_state, Panel::ExpansionState new_state) { |
DCHECK_NE(new_state, old_state); |
switch (new_state) { |
@@ -353,25 +325,22 @@ void PanelManager::OnPanelExpansionStateChanged( |
} |
} |
-void PanelManager::IncrementMinimizedPanels() { |
- if (!mouse_watching_disabled_ && !minimized_panel_count_) |
- panel_mouse_watcher_->AddObserver(this); |
+void PanelStrip::IncrementMinimizedPanels() { |
minimized_panel_count_++; |
+ if (minimized_panel_count_ == 1) |
+ panel_manager_->mouse_watcher()->AddObserver(this); |
DCHECK_LE(minimized_panel_count_, num_panels()); |
} |
-void PanelManager::DecrementMinimizedPanels() { |
+void PanelStrip::DecrementMinimizedPanels() { |
minimized_panel_count_--; |
DCHECK_GE(minimized_panel_count_, 0); |
- if (!mouse_watching_disabled_ && !minimized_panel_count_) |
- panel_mouse_watcher_->RemoveObserver(this); |
+ if (minimized_panel_count_ == 0) |
+ panel_manager_->mouse_watcher()->RemoveObserver(this); |
} |
-void PanelManager::OnPreferredWindowSizeChanged( |
+void PanelStrip::OnPreferredWindowSizeChanged( |
Panel* panel, const gfx::Size& preferred_window_size) { |
- if (!auto_sizing_enabled_) |
- return; |
- |
gfx::Rect bounds = panel->GetBounds(); |
// The panel width: |
@@ -427,14 +396,14 @@ void PanelManager::OnPreferredWindowSizeChanged( |
panel->SetPanelBounds(bounds); |
} |
-bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
+bool PanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
// We should always bring up the titlebar if the mouse is over the |
// visible auto-hiding bottom bar. |
- if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && |
- auto_hiding_desktop_bar_->GetVisibility( |
- AutoHidingDesktopBar::ALIGN_BOTTOM) == |
+ AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); |
+ if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && |
+ desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == |
AutoHidingDesktopBar::VISIBLE && |
- mouse_y >= adjusted_work_area_.bottom()) |
+ mouse_y >= strip_bounds_.bottom()) |
return true; |
for (Panels::const_iterator iter = panels_.begin(); |
@@ -445,7 +414,7 @@ bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
return false; |
} |
-void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
+void PanelStrip::BringUpOrDownTitlebars(bool bring_up) { |
if (are_titlebars_up_ == bring_up) |
return; |
are_titlebars_up_ = bring_up; |
@@ -455,9 +424,10 @@ void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
// If the auto-hiding bottom bar exists, delay the action until the bottom |
// bar is fully visible or hidden. We do not want both bottom bar and panel |
// titlebar to move at the same time but with different speeds. |
- if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
- AutoHidingDesktopBar::Visibility visibility = auto_hiding_desktop_bar_-> |
- GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); |
+ AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); |
+ if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
+ AutoHidingDesktopBar::Visibility visibility = |
+ desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); |
if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE |
: AutoHidingDesktopBar::HIDDEN)) { |
// Occasionally some system, like Windows, might not bring up or down the |
@@ -497,12 +467,12 @@ void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
titlebar_action_factory_.InvalidateWeakPtrs(); |
MessageLoop::current()->PostDelayedTask( |
FROM_HERE, |
- base::Bind(&PanelManager::DelayedBringUpOrDownTitlebarsCheck, |
+ base::Bind(&PanelStrip::DelayedBringUpOrDownTitlebarsCheck, |
titlebar_action_factory_.GetWeakPtr()), |
task_delay_milliseconds); |
} |
-void PanelManager::DelayedBringUpOrDownTitlebarsCheck() { |
+void PanelStrip::DelayedBringUpOrDownTitlebarsCheck() { |
// Task was already processed or cancelled - bail out. |
if (delayed_titlebar_action_ == NO_ACTION) |
return; |
@@ -520,7 +490,7 @@ void PanelManager::DelayedBringUpOrDownTitlebarsCheck() { |
DoBringUpOrDownTitlebars(need_to_bring_up_titlebars); |
} |
-void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { |
+void PanelStrip::DoBringUpOrDownTitlebars(bool bring_up) { |
for (Panels::const_iterator iter = panels_.begin(); |
iter != panels_.end(); ++iter) { |
Panel* panel = *iter; |
@@ -539,71 +509,27 @@ void PanelManager::DoBringUpOrDownTitlebars(bool bring_up) { |
} |
} |
-void PanelManager::AdjustWorkAreaForAutoHidingDesktopBars() { |
- // Note that we do not care about the desktop bar aligned to the top edge |
- // since panels could not reach so high due to size constraint. |
- adjusted_work_area_ = work_area_; |
- if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_LEFT)) { |
- int space = auto_hiding_desktop_bar_->GetThickness( |
- AutoHidingDesktopBar::ALIGN_LEFT); |
- adjusted_work_area_.set_x(adjusted_work_area_.x() + space); |
- adjusted_work_area_.set_width(adjusted_work_area_.width() - space); |
- } |
- if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_RIGHT)) { |
- int space = auto_hiding_desktop_bar_->GetThickness( |
- AutoHidingDesktopBar::ALIGN_RIGHT); |
- adjusted_work_area_.set_width(adjusted_work_area_.width() - space); |
- } |
-} |
- |
-int PanelManager::GetBottomPositionForExpansionState( |
+int PanelStrip::GetBottomPositionForExpansionState( |
Panel::ExpansionState expansion_state) const { |
- int bottom = adjusted_work_area_.bottom(); |
+ int bottom = strip_bounds_.bottom(); |
// If there is an auto-hiding desktop bar aligned to the bottom edge, we need |
// to move the title-only panel above the auto-hiding desktop bar. |
+ AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); |
if (expansion_state == Panel::TITLE_ONLY && |
- auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
- bottom -= auto_hiding_desktop_bar_->GetThickness( |
- AutoHidingDesktopBar::ALIGN_BOTTOM); |
+ desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { |
+ bottom -= desktop_bar->GetThickness(AutoHidingDesktopBar::ALIGN_BOTTOM); |
} |
return bottom; |
} |
-BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( |
- Panel* panel) const { |
- // Find the last active browser window that is not minimized. |
- BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); |
- BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); |
- for (; (iter != end); ++iter) { |
- Browser* browser = *iter; |
- if (panel->browser() != browser && !browser->window()->IsMinimized()) |
- return browser->window(); |
- } |
- |
- return NULL; |
-} |
- |
-void PanelManager::MoveToPanelStrip(Panel* panel) { |
- // TODO(jennb) - implement. |
-} |
- |
-void PanelManager::MoveToOverflowStrip(Panel* panel, bool is_new) { |
- // TODO(jianli) - implement. |
-} |
- |
-void PanelManager::OnMouseMove(const gfx::Point& mouse_position) { |
+void PanelStrip::OnMouseMove(const gfx::Point& mouse_position) { |
bool bring_up_titlebars = ShouldBringUpTitlebars(mouse_position.x(), |
mouse_position.y()); |
BringUpOrDownTitlebars(bring_up_titlebars); |
} |
-void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { |
- AdjustWorkAreaForAutoHidingDesktopBars(); |
- Rearrange(panels_.begin(), StartingRightPosition()); |
-} |
- |
-void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( |
+void PanelStrip::OnAutoHidingDesktopBarVisibilityChanged( |
AutoHidingDesktopBar::Alignment alignment, |
AutoHidingDesktopBar::Visibility visibility) { |
if (delayed_titlebar_action_ == NO_ACTION) |
@@ -619,8 +545,8 @@ void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( |
delayed_titlebar_action_ = NO_ACTION; |
} |
-void PanelManager::Rearrange(Panels::iterator iter_to_start, |
- int rightmost_position) { |
+void PanelStrip::Rearrange(Panels::iterator iter_to_start, |
+ int rightmost_position) { |
for (Panels::iterator iter = iter_to_start; iter != panels_.end(); ++iter) { |
Panel* panel = *iter; |
gfx::Rect new_bounds(panel->GetBounds()); |
@@ -628,14 +554,13 @@ void PanelManager::Rearrange(Panels::iterator iter_to_start, |
new_bounds.set_y( |
GetBottomPositionForExpansionState(panel->expansion_state()) - |
new_bounds.height()); |
- if (new_bounds != panel->GetBounds()) |
- panel->SetPanelBounds(new_bounds); |
+ panel->SetPanelBounds(new_bounds); |
rightmost_position = new_bounds.x() - kPanelsHorizontalSpacing; |
} |
} |
-void PanelManager::RemoveAll() { |
+void PanelStrip::RemoveAll() { |
// This should not be called when we're in the process of dragging. |
DCHECK(dragging_panel_index_ == kInvalidPanelIndex); |
@@ -648,6 +573,6 @@ void PanelManager::RemoveAll() { |
(*iter)->Close(); |
} |
-bool PanelManager::is_dragging_panel() const { |
+bool PanelStrip::is_dragging_panel() const { |
return dragging_panel_index_ != kInvalidPanelIndex; |
} |