| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/docked_panel_strip.h" | 5 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 | 472 |
| 473 void DockedPanelStrip::OnPanelTitlebarClicked(Panel* panel, | 473 void DockedPanelStrip::OnPanelTitlebarClicked(Panel* panel, |
| 474 panel::ClickModifier modifier) { | 474 panel::ClickModifier modifier) { |
| 475 DCHECK_EQ(this, panel->panel_strip()); | 475 DCHECK_EQ(this, panel->panel_strip()); |
| 476 if (!IsPanelMinimized(panel)) | 476 if (!IsPanelMinimized(panel)) |
| 477 return; | 477 return; |
| 478 | 478 |
| 479 if (modifier == panel::APPLY_TO_ALL) | 479 if (modifier == panel::APPLY_TO_ALL) |
| 480 ToggleMinimizeAll(panel); | 480 RestoreAll(); |
| 481 else | 481 else |
| 482 RestorePanel(panel); | 482 RestorePanel(panel); |
| 483 } | 483 } |
| 484 | 484 |
| 485 void DockedPanelStrip::ActivatePanel(Panel* panel) { | 485 void DockedPanelStrip::ActivatePanel(Panel* panel) { |
| 486 DCHECK_EQ(this, panel->panel_strip()); | 486 DCHECK_EQ(this, panel->panel_strip()); |
| 487 | 487 |
| 488 // Make sure the panel is expanded when activated so the user input | 488 // Make sure the panel is expanded when activated so the user input |
| 489 // does not go into a collapsed window. | 489 // does not go into a collapsed window. |
| 490 panel->SetExpansionState(Panel::EXPANDED); | 490 panel->SetExpansionState(Panel::EXPANDED); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 501 | 501 |
| 502 panel->SetExpansionState(panel->IsDrawingAttention() ? | 502 panel->SetExpansionState(panel->IsDrawingAttention() ? |
| 503 Panel::TITLE_ONLY : Panel::MINIMIZED); | 503 Panel::TITLE_ONLY : Panel::MINIMIZED); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void DockedPanelStrip::RestorePanel(Panel* panel) { | 506 void DockedPanelStrip::RestorePanel(Panel* panel) { |
| 507 DCHECK_EQ(this, panel->panel_strip()); | 507 DCHECK_EQ(this, panel->panel_strip()); |
| 508 panel->SetExpansionState(Panel::EXPANDED); | 508 panel->SetExpansionState(Panel::EXPANDED); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void DockedPanelStrip::MinimizeAll() { |
| 512 // Set minimizing_all_ to prevent deactivation of each panel when it |
| 513 // is minimized. See comments in OnPanelExpansionStateChanged. |
| 514 AutoReset<bool> pin(&minimizing_all_, true); |
| 515 Panel* minimized_active_panel = NULL; |
| 516 for (Panels::const_iterator iter = panels_.begin(); |
| 517 iter != panels_.end(); ++iter) { |
| 518 if ((*iter)->IsActive()) |
| 519 minimized_active_panel = *iter; |
| 520 MinimizePanel(*iter); |
| 521 } |
| 522 |
| 523 // When a single panel is minimized, it is deactivated to ensure that |
| 524 // a minimized panel does not have focus. However, when minimizing all, |
| 525 // the deactivation is only done once after all panels are minimized, |
| 526 // rather than per minimized panel, both for efficiency and to avoid |
| 527 // temporary activations of random not-yet-minimized panels. |
| 528 if (minimized_active_panel) { |
| 529 minimized_active_panel->Deactivate(); |
| 530 // Layout will be refreshed in response to (de)activation notification. |
| 531 } |
| 532 } |
| 533 |
| 534 void DockedPanelStrip::RestoreAll() { |
| 535 for (Panels::const_iterator iter = panels_.begin(); |
| 536 iter != panels_.end(); ++iter) { |
| 537 RestorePanel(*iter); |
| 538 } |
| 539 } |
| 540 |
| 511 bool DockedPanelStrip::CanMinimizePanel(const Panel* panel) const { | 541 bool DockedPanelStrip::CanMinimizePanel(const Panel* panel) const { |
| 512 DCHECK_EQ(this, panel->panel_strip()); | 542 DCHECK_EQ(this, panel->panel_strip()); |
| 513 // Docked panels can be minimized. | 543 // Docked panels can be minimized. |
| 514 return true; | 544 return true; |
| 515 } | 545 } |
| 516 | 546 |
| 517 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { | 547 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { |
| 518 return panel->expansion_state() != Panel::EXPANDED; | 548 return panel->expansion_state() != Panel::EXPANDED; |
| 519 } | 549 } |
| 520 | 550 |
| 521 void DockedPanelStrip::UpdateMinimizedPanelCount() { | 551 void DockedPanelStrip::UpdateMinimizedPanelCount() { |
| 522 int prev_minimized_panel_count = minimized_panel_count_; | 552 int prev_minimized_panel_count = minimized_panel_count_; |
| 523 minimized_panel_count_ = 0; | 553 minimized_panel_count_ = 0; |
| 524 for (Panels::const_iterator panel_iter = panels_.begin(); | 554 for (Panels::const_iterator panel_iter = panels_.begin(); |
| 525 panel_iter != panels_.end(); ++panel_iter) { | 555 panel_iter != panels_.end(); ++panel_iter) { |
| 526 if ((*panel_iter)->expansion_state() != Panel::EXPANDED) | 556 if ((*panel_iter)->expansion_state() != Panel::EXPANDED) |
| 527 minimized_panel_count_++; | 557 minimized_panel_count_++; |
| 528 } | 558 } |
| 529 | 559 |
| 530 if (prev_minimized_panel_count == 0 && minimized_panel_count_ > 0) | 560 if (prev_minimized_panel_count == 0 && minimized_panel_count_ > 0) |
| 531 panel_manager_->mouse_watcher()->AddObserver(this); | 561 panel_manager_->mouse_watcher()->AddObserver(this); |
| 532 else if (prev_minimized_panel_count > 0 && minimized_panel_count_ == 0) | 562 else if (prev_minimized_panel_count > 0 && minimized_panel_count_ == 0) |
| 533 panel_manager_->mouse_watcher()->RemoveObserver(this); | 563 panel_manager_->mouse_watcher()->RemoveObserver(this); |
| 534 | 564 |
| 535 DCHECK_LE(minimized_panel_count_, num_panels()); | 565 DCHECK_LE(minimized_panel_count_, num_panels()); |
| 536 } | 566 } |
| 537 | 567 |
| 538 void DockedPanelStrip::ToggleMinimizeAll(Panel* panel) { | |
| 539 DCHECK_EQ(this, panel->panel_strip()); | |
| 540 AutoReset<bool> pin(&minimizing_all_, IsPanelMinimized(panel) ? false : true); | |
| 541 Panel* minimized_active_panel = NULL; | |
| 542 for (Panels::const_iterator iter = panels_.begin(); | |
| 543 iter != panels_.end(); ++iter) { | |
| 544 if (minimizing_all_) { | |
| 545 if ((*iter)->IsActive()) | |
| 546 minimized_active_panel = *iter; | |
| 547 MinimizePanel(*iter); | |
| 548 } else { | |
| 549 RestorePanel(*iter); | |
| 550 } | |
| 551 } | |
| 552 | |
| 553 // When a single panel is minimized, it is deactivated to ensure that | |
| 554 // a minimized panel does not have focus. However, when minimizing all, | |
| 555 // the deactivation is only done once after all panels are minimized, | |
| 556 // rather than per minimized panel, both for efficiency and to avoid | |
| 557 // temporary activations of random not-yet-minimized panels. | |
| 558 if (minimized_active_panel) { | |
| 559 minimized_active_panel->Deactivate(); | |
| 560 // Layout will be refreshed in response to (de)activation notification. | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 void DockedPanelStrip::ResizePanelWindow( | 568 void DockedPanelStrip::ResizePanelWindow( |
| 565 Panel* panel, | 569 Panel* panel, |
| 566 const gfx::Size& preferred_window_size) { | 570 const gfx::Size& preferred_window_size) { |
| 567 DCHECK_EQ(this, panel->panel_strip()); | 571 DCHECK_EQ(this, panel->panel_strip()); |
| 568 // Make sure the new size does not violate panel's size restrictions. | 572 // Make sure the new size does not violate panel's size restrictions. |
| 569 gfx::Size new_size(preferred_window_size.width(), | 573 gfx::Size new_size(preferred_window_size.width(), |
| 570 preferred_window_size.height()); | 574 preferred_window_size.height()); |
| 571 panel->ClampSize(&new_size); | 575 panel->ClampSize(&new_size); |
| 572 | 576 |
| 573 if (new_size == panel->full_size()) | 577 if (new_size == panel->full_size()) |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 FROM_HERE, | 890 FROM_HERE, |
| 887 base::Bind(&DockedPanelStrip::RefreshLayout, | 891 base::Bind(&DockedPanelStrip::RefreshLayout, |
| 888 refresh_action_factory_.GetWeakPtr()), | 892 refresh_action_factory_.GetWeakPtr()), |
| 889 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( | 893 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( |
| 890 kRefreshLayoutAfterActivePanelChangeDelayMs))); | 894 kRefreshLayoutAfterActivePanelChangeDelayMs))); |
| 891 } | 895 } |
| 892 | 896 |
| 893 bool DockedPanelStrip::HasPanel(Panel* panel) const { | 897 bool DockedPanelStrip::HasPanel(Panel* panel) const { |
| 894 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 898 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
| 895 } | 899 } |
| OLD | NEW |