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

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

Issue 8827011: Panel strip refactor cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac/linux compile Created 9 years 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_strip.cc
diff --git a/chrome/browser/ui/panels/panel_strip.cc b/chrome/browser/ui/panels/panel_strip.cc
index 6d4efba0c611d0b5564caa5e41693ac5f912c459..df87fd5b1bfc42e32265b54e4ae660eab0b842ae 100644
--- a/chrome/browser/ui/panels/panel_strip.cc
+++ b/chrome/browser/ui/panels/panel_strip.cc
@@ -57,7 +57,6 @@ PanelStrip::PanelStrip(PanelManager* panel_manager)
dragging_panel_index_(kInvalidPanelIndex),
dragging_panel_original_x_(0),
delayed_titlebar_action_(NO_ACTION),
- remove_delays_for_testing_(false),
titlebar_action_factory_(this) {
}
@@ -81,6 +80,8 @@ void PanelStrip::SetDisplayArea(const gfx::Rect& new_area) {
}
void PanelStrip::AddPanel(Panel* panel) {
+ DCHECK_EQ(Panel::EXPANDED, panel->expansion_state());
+
// Always update limits, even for exiting panels, in case the maximums changed
// while panel was out of the strip.
int max_panel_width = GetMaxPanelWidth();
@@ -97,11 +98,10 @@ void PanelStrip::AddPanel(Panel* panel) {
int x;
while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) {
DCHECK(!panels_.empty());
- MovePanelToOverflow(panels_.back(), false);
+ panels_.back()->SetExpansionState(Panel::IN_OVERFLOW);
}
int y = display_area_.bottom() - height;
panel->SetPanelBounds(gfx::Rect(x, y, width, height));
- panel->SetExpansionState(Panel::EXPANDED);
} else {
// Initialize the newly created panel. Does not bump any panels from strip.
if (height == 0 && width == 0) {
@@ -136,21 +136,18 @@ void PanelStrip::AddPanel(Panel* panel) {
#if defined(OS_WIN)
if (x < display_area_.x()) {
x = display_area_.x();
- int delay_ms = remove_delays_for_testing_ ? 0 :
- kMoveNewPanelToOverflowDelayMilliseconds;
+ panel->set_temporary_layout(true);
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- base::Bind(&PanelStrip::MovePanelToOverflow,
+ base::Bind(&PanelStrip::MovePanelToOverflowAfterDelay,
base::Unretained(this),
- panel,
- true), // new panel
- delay_ms);
+ panel),
+ kMoveNewPanelToOverflowDelayMilliseconds);
}
#endif
panel->Initialize(gfx::Rect(x, y, width, height));
}
- DCHECK(panel->expansion_state() == Panel::EXPANDED);
panels_.push_back(panel);
}
@@ -198,7 +195,8 @@ bool PanelStrip::DoRemove(Panel* panel) {
if (iter == panels_.end())
return false;
- if (panel->expansion_state() != Panel::EXPANDED)
+ if (panel->expansion_state() == Panel::TITLE_ONLY ||
+ panel->expansion_state() == Panel::MINIMIZED)
jianli 2011/12/07 22:13:26 indentation.
jennb 2011/12/07 23:35:40 Done.
DecrementMinimizedPanels();
panels_.erase(iter);
@@ -343,8 +341,13 @@ void PanelStrip::OnPanelExpansionStateChanged(
Panel::ExpansionState expansion_state = panel->expansion_state();
switch (expansion_state) {
case Panel::EXPANDED:
- if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED)
+ if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) {
DecrementMinimizedPanels();
+ } else if (old_state == Panel::IN_OVERFLOW) {
+ panel_manager_->panel_overflow_strip()->Remove(panel);
+ AddPanel(panel);
+ panel->SetAppIconVisibility(true);
+ }
break;
case Panel::TITLE_ONLY:
size.set_height(panel->TitleOnlyHeight());
@@ -440,9 +443,28 @@ bool PanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const {
mouse_y >= display_area_.bottom())
return true;
+ // Bring up titlebars if any panel needs the titlebar up.
for (Panels::const_iterator iter = panels_.begin();
iter != panels_.end(); ++iter) {
- if ((*iter)->ShouldBringUpTitlebar(mouse_x, mouse_y))
+ Panel* panel = *iter;
+ Panel::ExpansionState state = panel->expansion_state();
+ // Skip the expanded panel.
+ if (state == Panel::EXPANDED)
+ continue;
+
+ // If the panel is showing titlebar only, we want to keep it up when it is
+ // being dragged.
+ if (state == Panel::TITLE_ONLY && is_dragging_panel())
+ return true;
+
+ // We do not want to bring up other minimized panels if the mouse is over
+ // the panel that pops up the titlebar to attract attention.
jianli 2011/12/07 22:13:26 extra spaces after "attract"
jennb 2011/12/07 23:35:40 Done.
+ if (panel->IsDrawingAttention())
+ continue;
+
+ gfx::Rect bounds = panel->GetBounds();
+ if (bounds.x() <= mouse_x && mouse_x <= bounds.right() &&
+ mouse_y >= bounds.y())
return true;
}
return false;
@@ -491,8 +513,6 @@ void PanelStrip::BringUpOrDownTitlebars(bool bring_up) {
// OnAutoHidingDesktopBarVisibilityChanged will handle this.
delayed_titlebar_action_ = bring_up ? BRING_UP : BRING_DOWN;
- if (remove_delays_for_testing_)
- task_delay_milliseconds = 0;
// If user moves the mouse in and out of mouse tracking area, we might have
// previously posted but not yet dispatched task in the queue. New action
@@ -596,10 +616,8 @@ void PanelStrip::Rearrange() {
// TODO(jianli): remove the guard when overflow support is enabled on other
// platforms. http://crbug.com/105073
#if defined(OS_WIN)
- if (x < display_area_.x()) {
- MovePanelsToOverflow(panel_index);
+ if (x < display_area_.x())
break;
- }
#endif
new_bounds.set_x(x);
@@ -614,33 +632,34 @@ void PanelStrip::Rearrange() {
// TODO(jianli): remove the guard when overflow support is enabled on other
// platforms. http://crbug.com/105073
#if defined(OS_WIN)
- if (panel_index == panels_.size())
- MovePanelsFromOverflowIfNeeded();
+ if (panel_index < panels_.size()) {
+ // Move panels to overflow in reverse to maintain their order.
jianli 2011/12/07 22:13:26 Better to add more comment to explain that we do n
jennb 2011/12/07 23:35:40 Done.
+ for (size_t overflow_index = panels_.size() - 1;
jianli 2011/12/07 22:13:26 Either add DCHECK to ensure panel_index is not 0,
jennb 2011/12/07 23:35:40 Done.
+ overflow_index >= panel_index; --overflow_index)
+ panels_[overflow_index]->SetExpansionState(Panel::IN_OVERFLOW);
+ } else {
+ // Attempt to add more panels from overflow to the strip.
+ PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip();
+ Panel* overflow_panel;
+ while ((overflow_panel = overflow_strip->first_panel()) &&
+ GetRightMostAvailablePosition() -
+ overflow_panel->restored_size().width() >= display_area_.x()) {
jianli 2011/12/07 22:13:26 4 more spaces before this line.
jennb 2011/12/07 23:35:40 Done.
+ overflow_panel->SetExpansionState(Panel::EXPANDED);
+ }
+ }
#endif
}
-void PanelStrip::MovePanelsToOverflow(size_t overflow_point) {
- DCHECK(overflow_point >= 0);
- // Move panels in reverse to maintain their order.
- for (size_t i = panels_.size() - 1; i >= overflow_point; --i)
- MovePanelToOverflow(panels_[i], false);
-}
-
-void PanelStrip::MovePanelToOverflow(Panel* panel, bool is_new) {
- if (!DoRemove(panel))
- return;
-
- panel_manager_->panel_overflow_strip()->AddPanel(panel, is_new);
-}
-
-void PanelStrip::MovePanelsFromOverflowIfNeeded() {
- PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip();
- Panel* overflow_panel;
- while ((overflow_panel = overflow_strip->first_panel()) &&
- GetRightMostAvailablePosition() -
- overflow_panel->restored_size().width() >= display_area_.x()) {
- overflow_strip->Remove(overflow_panel);
- AddPanel(overflow_panel);
+void PanelStrip::MovePanelToOverflowAfterDelay(Panel* panel) {
+ // Make sure panel still exists in the strip.
+ // Search in reverse as new panels are at the end of the strip.
+ for (Panels::reverse_iterator iter = panels_.rbegin();
+ iter != panels_.rend(); ++iter) {
+ if (*iter == panel) {
+ DCHECK(panel->temporary_layout());
+ panel->SetExpansionState(Panel::IN_OVERFLOW);
+ break;
+ }
}
}
« chrome/browser/ui/panels/panel_strip.h ('K') | « chrome/browser/ui/panels/panel_strip.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698