| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/panels/panel_strip.h" | 5 #include "chrome/browser/ui/panels/panel_strip.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/panels/panel_manager.h" | 13 #include "chrome/browser/ui/panels/panel_manager.h" |
| 14 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 14 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
| 15 #include "chrome/browser/ui/panels/panel_overflow_strip.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 // Invalid panel index. | 21 // Invalid panel index. |
| 21 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); | 22 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
| 22 | 23 |
| 23 // Width to height ratio is used to compute the default width or height | 24 // Width to height ratio is used to compute the default width or height |
| 24 // when only one value is provided. | 25 // when only one value is provided. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // Keep panel visible in the strip even if overlap would occur. | 133 // Keep panel visible in the strip even if overlap would occur. |
| 133 // Panel is moved to overflow from the strip after a delay. | 134 // Panel is moved to overflow from the strip after a delay. |
| 134 if (x < display_area_.x()) { | 135 if (x < display_area_.x()) { |
| 135 x = display_area_.x(); | 136 x = display_area_.x(); |
| 136 MessageLoop::current()->PostDelayedTask( | 137 MessageLoop::current()->PostDelayedTask( |
| 137 FROM_HERE, | 138 FROM_HERE, |
| 138 base::Bind(&PanelStrip::MovePanelToOverflow, | 139 base::Bind(&PanelStrip::MovePanelToOverflow, |
| 139 overflow_action_factory_.GetWeakPtr(), | 140 overflow_action_factory_.GetWeakPtr(), |
| 140 panel, | 141 panel, |
| 141 true), // new panel | 142 true), // new panel |
| 142 kMoveNewPanelToOverflowDelayMilliseconds); | 143 remove_delays_for_testing_ ? |
| 144 0 : kMoveNewPanelToOverflowDelayMilliseconds); |
| 143 } | 145 } |
| 144 panel->Initialize(gfx::Rect(x, y, width, height)); | 146 panel->Initialize(gfx::Rect(x, y, width, height)); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void PanelStrip::AddExistingPanel(Panel* panel) { | 149 void PanelStrip::AddExistingPanel(Panel* panel) { |
| 148 gfx::Size restored_size = panel->restored_size(); | 150 gfx::Size restored_size = panel->restored_size(); |
| 149 int height = restored_size.height(); | 151 int height = restored_size.height(); |
| 150 int width = restored_size.width(); | 152 int width = restored_size.width(); |
| 151 int x; | 153 int x; |
| 152 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { | 154 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 200 |
| 199 bool PanelStrip::DoRemove(Panel* panel) { | 201 bool PanelStrip::DoRemove(Panel* panel) { |
| 200 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); | 202 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); |
| 201 if (iter == panels_.end()) | 203 if (iter == panels_.end()) |
| 202 return false; | 204 return false; |
| 203 | 205 |
| 204 if (panel->expansion_state() != Panel::EXPANDED) | 206 if (panel->expansion_state() != Panel::EXPANDED) |
| 205 DecrementMinimizedPanels(); | 207 DecrementMinimizedPanels(); |
| 206 | 208 |
| 207 panels_.erase(iter); | 209 panels_.erase(iter); |
| 210 panel_manager_->OnPanelRemoved(panel); |
| 208 return true; | 211 return true; |
| 209 } | 212 } |
| 210 | 213 |
| 211 void PanelStrip::StartDragging(Panel* panel) { | 214 void PanelStrip::StartDragging(Panel* panel) { |
| 212 for (size_t i = 0; i < panels_.size(); ++i) { | 215 for (size_t i = 0; i < panels_.size(); ++i) { |
| 213 if (panels_[i] == panel) { | 216 if (panels_[i] == panel) { |
| 214 dragging_panel_index_ = i; | 217 dragging_panel_index_ = i; |
| 215 dragging_panel_bounds_ = panel->GetBounds(); | 218 dragging_panel_bounds_ = panel->GetBounds(); |
| 216 dragging_panel_original_x_ = dragging_panel_bounds_.x(); | 219 dragging_panel_original_x_ = dragging_panel_bounds_.x(); |
| 217 break; | 220 break; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 panels_[dragging_panel_index_]->SetPanelBounds( | 336 panels_[dragging_panel_index_]->SetPanelBounds( |
| 334 dragging_panel_bounds_); | 337 dragging_panel_bounds_); |
| 335 } | 338 } |
| 336 | 339 |
| 337 dragging_panel_index_ = kInvalidPanelIndex; | 340 dragging_panel_index_ = kInvalidPanelIndex; |
| 338 | 341 |
| 339 DelayedRemove(); | 342 DelayedRemove(); |
| 340 } | 343 } |
| 341 | 344 |
| 342 void PanelStrip::OnPanelExpansionStateChanged( | 345 void PanelStrip::OnPanelExpansionStateChanged( |
| 343 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { | 346 Panel* panel, Panel::ExpansionState old_state) { |
| 344 DCHECK_NE(new_state, old_state); | 347 DCHECK(panel->expansion_state() != Panel::IN_OVERFLOW); |
| 345 switch (new_state) { | 348 |
| 349 gfx::Size size = panel->restored_size(); |
| 350 switch (panel->expansion_state()) { |
| 346 case Panel::EXPANDED: | 351 case Panel::EXPANDED: |
| 347 DecrementMinimizedPanels(); | 352 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) |
| 353 DecrementMinimizedPanels(); |
| 354 break; |
| 355 case Panel::TITLE_ONLY: |
| 356 size.set_height(panel->TitleOnlyHeight()); |
| 357 if (old_state == Panel::EXPANDED) |
| 358 IncrementMinimizedPanels(); |
| 348 break; | 359 break; |
| 349 case Panel::MINIMIZED: | 360 case Panel::MINIMIZED: |
| 350 case Panel::TITLE_ONLY: | 361 size.set_height(Panel::kMinimizedPanelHeight); |
| 351 if (old_state == Panel::EXPANDED) | 362 if (old_state == Panel::EXPANDED) |
| 352 IncrementMinimizedPanels(); | 363 IncrementMinimizedPanels(); |
| 353 break; | 364 break; |
| 354 default: | 365 default: |
| 366 NOTREACHED(); |
| 355 break; | 367 break; |
| 356 } | 368 } |
| 369 |
| 370 int bottom = GetBottomPositionForExpansionState(panel->expansion_state()); |
| 371 gfx::Rect bounds = panel->GetBounds(); |
| 372 panel->SetPanelBounds( |
| 373 gfx::Rect(bounds.right() - size.width(), |
| 374 bottom - size.height(), |
| 375 size.width(), |
| 376 size.height())); |
| 357 } | 377 } |
| 358 | 378 |
| 359 void PanelStrip::IncrementMinimizedPanels() { | 379 void PanelStrip::IncrementMinimizedPanels() { |
| 360 minimized_panel_count_++; | 380 minimized_panel_count_++; |
| 361 if (minimized_panel_count_ == 1) | 381 if (minimized_panel_count_ == 1) |
| 362 panel_manager_->mouse_watcher()->AddObserver(this); | 382 panel_manager_->mouse_watcher()->AddObserver(this); |
| 363 DCHECK_LE(minimized_panel_count_, num_panels()); | 383 DCHECK_LE(minimized_panel_count_, num_panels()); |
| 364 } | 384 } |
| 365 | 385 |
| 366 void PanelStrip::DecrementMinimizedPanels() { | 386 void PanelStrip::DecrementMinimizedPanels() { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 DCHECK(overflow_point >= 0); | 616 DCHECK(overflow_point >= 0); |
| 597 // Move panels in reverse to maintain their order. | 617 // Move panels in reverse to maintain their order. |
| 598 for (size_t i = panels_.size() - 1; i >= overflow_point; --i) | 618 for (size_t i = panels_.size() - 1; i >= overflow_point; --i) |
| 599 MovePanelToOverflow(panels_[i], false); | 619 MovePanelToOverflow(panels_[i], false); |
| 600 } | 620 } |
| 601 | 621 |
| 602 void PanelStrip::MovePanelToOverflow(Panel* panel, bool is_new) { | 622 void PanelStrip::MovePanelToOverflow(Panel* panel, bool is_new) { |
| 603 if (!DoRemove(panel)) | 623 if (!DoRemove(panel)) |
| 604 return; | 624 return; |
| 605 | 625 |
| 606 // TODO(jianli): Replace with the real code using overflow strip. | 626 panel_manager_->panel_overflow_strip()->AddPanel(panel, is_new); |
| 607 // panel_manager_->panel_overflow_strip()->AddPanel(panel, is_new); | |
| 608 } | 627 } |
| 609 | 628 |
| 610 void PanelStrip::MovePanelsFromOverflowIfNeeded() { | 629 void PanelStrip::MovePanelsFromOverflowIfNeeded() { |
| 611 // TODO(jianli): Replace with the real code using overflow strip. | 630 PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip(); |
| 612 // PanelOverflowStrip* overflow = panel_manager_->panel_overflow_strip(); | 631 Panel* overflow_panel; |
| 613 // Panel* candidate; | 632 while ((overflow_panel = overflow_strip->first_panel()) && |
| 614 // while (candidate = overflow->FirstPanel() && | 633 GetRightMostAvailablePosition() - |
| 615 // GetRightMostAvailablePosition - | 634 overflow_panel->restored_size().width() >= display_area_.x()) { |
| 616 // candidate->GetRestoredSize().width() >= display_area_.x()) { | 635 overflow_strip->Remove(overflow_panel); |
| 617 // overflow->Remove(candidate); | 636 AddPanel(overflow_panel); |
| 618 // AddPanel(candidate); | 637 } |
| 619 // } | |
| 620 } | 638 } |
| 621 | 639 |
| 622 void PanelStrip::RemoveAll() { | 640 void PanelStrip::RemoveAll() { |
| 623 // This should not be called when we're in the process of dragging. | 641 // This should not be called when we're in the process of dragging. |
| 624 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); | 642 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); |
| 625 | 643 |
| 626 // Make a copy of the iterator as closing panels can modify the vector. | 644 // Make a copy of the iterator as closing panels can modify the vector. |
| 627 Panels panels_copy = panels_; | 645 Panels panels_copy = panels_; |
| 628 | 646 |
| 629 // Start from the bottom to avoid reshuffling. | 647 // Start from the bottom to avoid reshuffling. |
| 630 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 648 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
| 631 iter != panels_copy.rend(); ++iter) | 649 iter != panels_copy.rend(); ++iter) |
| 632 (*iter)->Close(); | 650 (*iter)->Close(); |
| 633 } | 651 } |
| 634 | 652 |
| 635 bool PanelStrip::is_dragging_panel() const { | 653 bool PanelStrip::is_dragging_panel() const { |
| 636 return dragging_panel_index_ != kInvalidPanelIndex; | 654 return dragging_panel_index_ != kInvalidPanelIndex; |
| 637 } | 655 } |
| OLD | NEW |