Chromium Code Reviews| 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 AutoReset<bool> pin(&minimizing_all_, true); | |
|
jianli
2012/04/26 18:06:57
nit: please add comment for this.
jennb
2012/04/27 00:30:11
Done.
| |
| 513 Panel* minimized_active_panel = NULL; | |
| 514 for (Panels::const_iterator iter = panels_.begin(); | |
| 515 iter != panels_.end(); ++iter) { | |
| 516 if ((*iter)->IsActive()) | |
| 517 minimized_active_panel = *iter; | |
| 518 MinimizePanel(*iter); | |
| 519 } | |
| 520 | |
| 521 // When a single panel is minimized, it is deactivated to ensure that | |
| 522 // a minimized panel does not have focus. However, when minimizing all, | |
| 523 // the deactivation is only done once after all panels are minimized, | |
| 524 // rather than per minimized panel, both for efficiency and to avoid | |
| 525 // temporary activations of random not-yet-minimized panels. | |
| 526 if (minimized_active_panel) { | |
|
jianli
2012/04/26 18:06:57
I think it might be a little bit safer to iterate
jennb
2012/04/27 00:30:11
If another panel is activated by the system while
jianli
2012/04/27 00:39:04
What if minimized_active_panel is closed before we
jennb
2012/04/27 16:47:45
The closure would happen on a separate pass of the
| |
| 527 minimized_active_panel->Deactivate(); | |
| 528 // Layout will be refreshed in response to (de)activation notification. | |
| 529 } | |
| 530 } | |
| 531 | |
| 532 void DockedPanelStrip::RestoreAll() { | |
| 533 for (Panels::const_iterator iter = panels_.begin(); | |
| 534 iter != panels_.end(); ++iter) { | |
| 535 RestorePanel(*iter); | |
| 536 } | |
| 537 } | |
| 538 | |
| 511 bool DockedPanelStrip::CanMinimizePanel(const Panel* panel) const { | 539 bool DockedPanelStrip::CanMinimizePanel(const Panel* panel) const { |
| 512 DCHECK_EQ(this, panel->panel_strip()); | 540 DCHECK_EQ(this, panel->panel_strip()); |
| 513 // Docked panels can be minimized. | 541 // Docked panels can be minimized. |
| 514 return true; | 542 return true; |
| 515 } | 543 } |
| 516 | 544 |
| 517 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { | 545 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { |
| 518 return panel->expansion_state() != Panel::EXPANDED; | 546 return panel->expansion_state() != Panel::EXPANDED; |
| 519 } | 547 } |
| 520 | 548 |
| 521 void DockedPanelStrip::UpdateMinimizedPanelCount() { | 549 void DockedPanelStrip::UpdateMinimizedPanelCount() { |
| 522 int prev_minimized_panel_count = minimized_panel_count_; | 550 int prev_minimized_panel_count = minimized_panel_count_; |
| 523 minimized_panel_count_ = 0; | 551 minimized_panel_count_ = 0; |
| 524 for (Panels::const_iterator panel_iter = panels_.begin(); | 552 for (Panels::const_iterator panel_iter = panels_.begin(); |
| 525 panel_iter != panels_.end(); ++panel_iter) { | 553 panel_iter != panels_.end(); ++panel_iter) { |
| 526 if ((*panel_iter)->expansion_state() != Panel::EXPANDED) | 554 if ((*panel_iter)->expansion_state() != Panel::EXPANDED) |
| 527 minimized_panel_count_++; | 555 minimized_panel_count_++; |
| 528 } | 556 } |
| 529 | 557 |
| 530 if (prev_minimized_panel_count == 0 && minimized_panel_count_ > 0) | 558 if (prev_minimized_panel_count == 0 && minimized_panel_count_ > 0) |
| 531 panel_manager_->mouse_watcher()->AddObserver(this); | 559 panel_manager_->mouse_watcher()->AddObserver(this); |
| 532 else if (prev_minimized_panel_count > 0 && minimized_panel_count_ == 0) | 560 else if (prev_minimized_panel_count > 0 && minimized_panel_count_ == 0) |
| 533 panel_manager_->mouse_watcher()->RemoveObserver(this); | 561 panel_manager_->mouse_watcher()->RemoveObserver(this); |
| 534 | 562 |
| 535 DCHECK_LE(minimized_panel_count_, num_panels()); | 563 DCHECK_LE(minimized_panel_count_, num_panels()); |
| 536 } | 564 } |
| 537 | 565 |
| 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( | 566 void DockedPanelStrip::ResizePanelWindow( |
| 565 Panel* panel, | 567 Panel* panel, |
| 566 const gfx::Size& preferred_window_size) { | 568 const gfx::Size& preferred_window_size) { |
| 567 DCHECK_EQ(this, panel->panel_strip()); | 569 DCHECK_EQ(this, panel->panel_strip()); |
| 568 // Make sure the new size does not violate panel's size restrictions. | 570 // Make sure the new size does not violate panel's size restrictions. |
| 569 gfx::Size new_size(preferred_window_size.width(), | 571 gfx::Size new_size(preferred_window_size.width(), |
| 570 preferred_window_size.height()); | 572 preferred_window_size.height()); |
| 571 panel->ClampSize(&new_size); | 573 panel->ClampSize(&new_size); |
| 572 | 574 |
| 573 if (new_size == panel->full_size()) | 575 if (new_size == panel->full_size()) |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 886 FROM_HERE, | 888 FROM_HERE, |
| 887 base::Bind(&DockedPanelStrip::RefreshLayout, | 889 base::Bind(&DockedPanelStrip::RefreshLayout, |
| 888 refresh_action_factory_.GetWeakPtr()), | 890 refresh_action_factory_.GetWeakPtr()), |
| 889 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( | 891 base::TimeDelta::FromMilliseconds(PanelManager::AdjustTimeInterval( |
| 890 kRefreshLayoutAfterActivePanelChangeDelayMs))); | 892 kRefreshLayoutAfterActivePanelChangeDelayMs))); |
| 891 } | 893 } |
| 892 | 894 |
| 893 bool DockedPanelStrip::HasPanel(Panel* panel) const { | 895 bool DockedPanelStrip::HasPanel(Panel* panel) const { |
| 894 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 896 return find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
| 895 } | 897 } |
| OLD | NEW |