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/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" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 gfx::Rect old_area = display_area_; | 74 gfx::Rect old_area = display_area_; |
| 75 display_area_ = new_area; | 75 display_area_ = new_area; |
| 76 | 76 |
| 77 if (panels_.empty()) | 77 if (panels_.empty()) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 Rearrange(); | 80 Rearrange(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void PanelStrip::AddPanel(Panel* panel) { | 83 void PanelStrip::AddPanel(Panel* panel) { |
| 84 DCHECK_NE(Panel::IN_OVERFLOW, panel->expansion_state()); | 84 DCHECK_NE(Panel::IN_OVERFLOW, panel->strip_owner()); |
| 85 | 85 |
| 86 // Always update limits, even for exiting panels, in case the maximums changed | 86 // Always update limits, even for exiting panels, in case the maximums changed |
| 87 // while panel was out of the strip. | 87 // while panel was out of the strip. |
| 88 int max_panel_width = GetMaxPanelWidth(); | 88 int max_panel_width = GetMaxPanelWidth(); |
| 89 int max_panel_height = GetMaxPanelHeight(); | 89 int max_panel_height = GetMaxPanelHeight(); |
| 90 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), | 90 panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), |
| 91 gfx::Size(max_panel_width, max_panel_height)); | 91 gfx::Size(max_panel_width, max_panel_height)); |
| 92 | 92 |
| 93 gfx::Size restored_size = panel->restored_size(); | 93 gfx::Size restored_size = panel->restored_size(); |
| 94 int height = restored_size.height(); | 94 int height = restored_size.height(); |
| 95 int width = restored_size.width(); | 95 int width = restored_size.width(); |
| 96 | 96 |
| 97 if (panel->initialized()) { | 97 if (panel->initialized()) { |
| 98 // Bump panels in the strip to make room for this panel. | 98 // Bump panels in the strip to make room for this panel. |
| 99 int x; | 99 int x; |
| 100 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { | 100 while ((x = GetRightMostAvailablePosition() - width) < display_area_.x()) { |
| 101 DCHECK(!panels_.empty()); | 101 DCHECK(!panels_.empty()); |
| 102 panels_.back()->SetExpansionState(Panel::IN_OVERFLOW); | 102 panels_.back()->SetStripOwner(Panel::IN_OVERFLOW); |
| 103 } | 103 } |
| 104 int y = display_area_.bottom() - height; | 104 int y = display_area_.bottom() - height; |
| 105 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | 105 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); |
| 106 | |
| 107 if (panel->expansion_state() == Panel::TITLE_ONLY || | |
|
jennb
2012/01/19 18:41:21
I expected to see this in the new On...Changed() h
| |
| 108 panel->expansion_state() == Panel::MINIMIZED) | |
| 109 IncrementMinimizedPanels(); | |
| 106 } else { | 110 } else { |
| 107 // Initialize the newly created panel. Does not bump any panels from strip. | 111 // Initialize the newly created panel. Does not bump any panels from strip. |
| 108 if (height == 0 && width == 0) { | 112 if (height == 0 && width == 0) { |
| 109 // Auto resizable is enabled only if no initial size is provided. | 113 // Auto resizable is enabled only if no initial size is provided. |
| 110 panel->SetAutoResizable(true); | 114 panel->SetAutoResizable(true); |
| 111 } else { | 115 } else { |
| 112 if (height == 0) | 116 if (height == 0) |
| 113 height = width / kPanelDefaultWidthToHeightRatio; | 117 height = width / kPanelDefaultWidthToHeightRatio; |
| 114 if (width == 0) | 118 if (width == 0) |
| 115 width = height * kPanelDefaultWidthToHeightRatio; | 119 width = height * kPanelDefaultWidthToHeightRatio; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 // If we're in the process of dragging, delay the removal. | 190 // If we're in the process of dragging, delay the removal. |
| 187 if (dragging_panel_index_ != kInvalidPanelIndex) { | 191 if (dragging_panel_index_ != kInvalidPanelIndex) { |
| 188 panels_pending_to_remove_.push_back(panel); | 192 panels_pending_to_remove_.push_back(panel); |
| 189 return true; | 193 return true; |
| 190 } | 194 } |
| 191 | 195 |
| 192 DoRemove(panel); | 196 DoRemove(panel); |
| 193 | 197 |
| 194 // Don't rearrange the strip if a panel is being moved from the panel strip | 198 // Don't rearrange the strip if a panel is being moved from the panel strip |
| 195 // to the overflow strip. | 199 // to the overflow strip. |
| 196 if (panel->expansion_state() != Panel::IN_OVERFLOW) | 200 if (panel->strip_owner() == Panel::DOCKED) |
| 197 Rearrange(); | 201 Rearrange(); |
| 198 | 202 |
| 199 return true; | 203 return true; |
| 200 } | 204 } |
| 201 | 205 |
| 202 void PanelStrip::DelayedRemove() { | 206 void PanelStrip::DelayedRemove() { |
| 203 for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i) | 207 for (size_t i = 0; i < panels_pending_to_remove_.size(); ++i) |
| 204 DoRemove(panels_pending_to_remove_[i]); | 208 DoRemove(panels_pending_to_remove_[i]); |
| 205 panels_pending_to_remove_.clear(); | 209 panels_pending_to_remove_.clear(); |
| 206 Rearrange(); | 210 Rearrange(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 } else { | 348 } else { |
| 345 panels_[dragging_panel_index_]->SetPanelBounds( | 349 panels_[dragging_panel_index_]->SetPanelBounds( |
| 346 dragging_panel_bounds_); | 350 dragging_panel_bounds_); |
| 347 } | 351 } |
| 348 | 352 |
| 349 dragging_panel_index_ = kInvalidPanelIndex; | 353 dragging_panel_index_ = kInvalidPanelIndex; |
| 350 | 354 |
| 351 DelayedRemove(); | 355 DelayedRemove(); |
| 352 } | 356 } |
| 353 | 357 |
| 354 void PanelStrip::OnPanelExpansionStateChanged(Panel* panel) { | 358 void PanelStrip::OnPanelStripOwnerChanged(Panel* panel, |
| 359 Panel::StripOwner old_owner) { | |
| 360 Panel::StripOwner strip_owner = panel->strip_owner(); | |
| 361 Panel::ExpansionState expansion_state = panel->expansion_state(); | |
| 362 switch (strip_owner) { | |
| 363 case Panel::DOCKED: | |
| 364 if (old_owner == Panel::IN_OVERFLOW) { | |
| 365 panel_manager_->panel_overflow_strip()->Remove(panel); | |
| 366 AddPanel(panel); | |
| 367 panel->SetAppIconVisibility(true); | |
| 368 panel->set_draggable(true); | |
| 369 UpdateBoundsPerExpansionState(panel); | |
| 370 } | |
| 371 break; | |
| 372 case Panel::DETACHED: | |
| 373 case Panel::IN_OVERFLOW: | |
| 374 DCHECK_EQ(Panel::DOCKED, old_owner); | |
| 375 break; | |
| 376 default: | |
| 377 NOTREACHED(); | |
| 378 break; | |
| 379 } | |
| 380 } | |
| 381 | |
| 382 void PanelStrip::OnPanelExpansionStateChanged(Panel* panel, | |
| 383 Panel::ExpansionState old_state) { | |
| 384 DCHECK_EQ(Panel::DOCKED, panel->strip_owner()); | |
| 385 | |
| 386 switch (panel->expansion_state()) { | |
| 387 case Panel::EXPANDED: | |
| 388 DecrementMinimizedPanels(); | |
| 389 break; | |
| 390 case Panel::TITLE_ONLY: | |
| 391 case Panel::MINIMIZED: | |
| 392 if (old_state == Panel::EXPANDED) | |
| 393 IncrementMinimizedPanels(); | |
| 394 break; | |
| 395 default: | |
| 396 NOTREACHED(); | |
| 397 break; | |
| 398 } | |
| 399 | |
| 400 UpdateBoundsPerExpansionState(panel); | |
| 401 } | |
| 402 | |
| 403 void PanelStrip::UpdateBoundsPerExpansionState(Panel* panel) { | |
| 355 gfx::Size size = panel->restored_size(); | 404 gfx::Size size = panel->restored_size(); |
| 356 Panel::ExpansionState expansion_state = panel->expansion_state(); | 405 Panel::ExpansionState expansion_state = panel->expansion_state(); |
| 357 Panel::ExpansionState old_state = panel->old_expansion_state(); | |
| 358 if (old_state == Panel::IN_OVERFLOW) { | |
| 359 panel_manager_->panel_overflow_strip()->Remove(panel); | |
| 360 AddPanel(panel); | |
| 361 panel->SetAppIconVisibility(true); | |
| 362 panel->set_draggable(true); | |
| 363 } | |
| 364 switch (expansion_state) { | 406 switch (expansion_state) { |
| 365 case Panel::EXPANDED: | 407 case Panel::EXPANDED: |
| 366 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) | |
| 367 DecrementMinimizedPanels(); | |
| 368 break; | 408 break; |
| 369 case Panel::TITLE_ONLY: | 409 case Panel::TITLE_ONLY: |
| 370 size.set_height(panel->TitleOnlyHeight()); | 410 size.set_height(panel->TitleOnlyHeight()); |
| 371 if (old_state == Panel::EXPANDED || old_state == Panel::IN_OVERFLOW) | |
| 372 IncrementMinimizedPanels(); | |
| 373 break; | 411 break; |
| 374 case Panel::MINIMIZED: | 412 case Panel::MINIMIZED: |
| 375 size.set_height(Panel::kMinimizedPanelHeight); | 413 size.set_height(Panel::kMinimizedPanelHeight); |
| 376 if (old_state == Panel::EXPANDED || old_state == Panel::IN_OVERFLOW) | |
| 377 IncrementMinimizedPanels(); | |
| 378 break; | |
| 379 case Panel::IN_OVERFLOW: | |
| 380 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) | |
| 381 DecrementMinimizedPanels(); | |
| 382 break; | 414 break; |
| 383 default: | 415 default: |
| 384 NOTREACHED(); | 416 NOTREACHED(); |
| 385 break; | 417 break; |
| 386 } | 418 } |
| 387 | 419 |
| 388 int bottom = GetBottomPositionForExpansionState(expansion_state); | 420 int bottom = GetBottomPositionForExpansionState(expansion_state); |
| 389 gfx::Rect bounds = panel->GetBounds(); | 421 gfx::Rect bounds = panel->GetBounds(); |
| 390 panel->SetPanelBounds( | 422 panel->SetPanelBounds( |
| 391 gfx::Rect(bounds.right() - size.width(), | 423 gfx::Rect(bounds.right() - size.width(), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 if (new_height < panel->min_size().height()) | 458 if (new_height < panel->min_size().height()) |
| 427 new_height = panel->min_size().height(); | 459 new_height = panel->min_size().height(); |
| 428 | 460 |
| 429 // Update restored size. | 461 // Update restored size. |
| 430 gfx::Size new_size(new_width, new_height); | 462 gfx::Size new_size(new_width, new_height); |
| 431 if (new_size != panel->restored_size()) | 463 if (new_size != panel->restored_size()) |
| 432 panel->set_restored_size(new_size); | 464 panel->set_restored_size(new_size); |
| 433 | 465 |
| 434 // Only need to adjust bounds height when panel is expanded. | 466 // Only need to adjust bounds height when panel is expanded. |
| 435 gfx::Rect bounds = panel->GetBounds(); | 467 gfx::Rect bounds = panel->GetBounds(); |
| 436 Panel::ExpansionState expansion_state = panel->expansion_state(); | |
| 437 if (new_height != bounds.height() && | 468 if (new_height != bounds.height() && |
| 438 expansion_state == Panel::EXPANDED) { | 469 panel->strip_owner() == Panel::DOCKED && |
| 470 panel->expansion_state() == Panel::EXPANDED) { | |
| 439 bounds.set_y(bounds.bottom() - new_height); | 471 bounds.set_y(bounds.bottom() - new_height); |
| 440 bounds.set_height(new_height); | 472 bounds.set_height(new_height); |
| 441 } | 473 } |
| 442 | 474 |
| 443 // Only need to adjust width if panel is in the panel strip. | 475 // Only need to adjust width if panel is in the panel strip. |
| 444 int delta_x = bounds.width() - new_width; | 476 int delta_x = bounds.width() - new_width; |
| 445 if (delta_x != 0 && expansion_state != Panel::IN_OVERFLOW) { | 477 if (delta_x != 0 && panel->strip_owner() == Panel::DOCKED) { |
| 446 bounds.set_width(new_width); | 478 bounds.set_width(new_width); |
| 447 bounds.set_x(bounds.x() + delta_x); | 479 bounds.set_x(bounds.x() + delta_x); |
| 448 } | 480 } |
| 449 | 481 |
| 450 if (bounds != panel->GetBounds()) | 482 if (bounds != panel->GetBounds()) |
| 451 panel->SetPanelBounds(bounds); | 483 panel->SetPanelBounds(bounds); |
| 452 | 484 |
| 453 // Only need to rearrange if panel's width changed. | 485 // Only need to rearrange if panel's width changed. |
| 454 if (delta_x != 0) | 486 if (delta_x != 0) |
| 455 Rearrange(); | 487 Rearrange(); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 | 682 |
| 651 // TODO(jianli): remove the guard when overflow support is enabled on other | 683 // TODO(jianli): remove the guard when overflow support is enabled on other |
| 652 // platforms. http://crbug.com/105073 | 684 // platforms. http://crbug.com/105073 |
| 653 #if defined(OS_WIN) | 685 #if defined(OS_WIN) |
| 654 // Add/remove panels from/to overflow. A change in work area or the | 686 // Add/remove panels from/to overflow. A change in work area or the |
| 655 // resize/removal of a panel may affect how many panels fit in the strip. | 687 // resize/removal of a panel may affect how many panels fit in the strip. |
| 656 if (panel_index < panels_.size()) { | 688 if (panel_index < panels_.size()) { |
| 657 // Move panels to overflow in reverse to maintain their order. | 689 // Move panels to overflow in reverse to maintain their order. |
| 658 for (size_t overflow_index = panels_.size() - 1; | 690 for (size_t overflow_index = panels_.size() - 1; |
| 659 overflow_index >= panel_index; --overflow_index) | 691 overflow_index >= panel_index; --overflow_index) |
| 660 panels_[overflow_index]->SetExpansionState(Panel::IN_OVERFLOW); | 692 panels_[overflow_index]->SetStripOwner(Panel::IN_OVERFLOW); |
| 661 } else { | 693 } else { |
| 662 // Attempt to add more panels from overflow to the strip. | 694 // Attempt to add more panels from overflow to the strip. |
| 663 PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip(); | 695 PanelOverflowStrip* overflow_strip = panel_manager_->panel_overflow_strip(); |
| 664 Panel* overflow_panel; | 696 Panel* overflow_panel; |
| 665 while ((overflow_panel = overflow_strip->first_panel()) && | 697 while ((overflow_panel = overflow_strip->first_panel()) && |
| 666 GetRightMostAvailablePosition() >= | 698 GetRightMostAvailablePosition() >= |
| 667 display_area_.x() + overflow_panel->restored_size().width()) { | 699 display_area_.x() + overflow_panel->restored_size().width()) { |
| 668 // We need to get back to the previous expansion state. | 700 // We need to get back to the previous expansion state. |
| 669 Panel::ExpansionState expansion_state_to_restore = | 701 Panel::ExpansionState expansion_state_to_restore = |
| 670 overflow_panel->old_expansion_state(); | 702 overflow_panel->expansion_state(); |
| 671 if (expansion_state_to_restore == Panel::MINIMIZED || | 703 if (expansion_state_to_restore == Panel::MINIMIZED || |
| 672 expansion_state_to_restore == Panel::TITLE_ONLY) { | 704 expansion_state_to_restore == Panel::TITLE_ONLY) { |
| 673 expansion_state_to_restore = are_titlebars_up_ ? Panel::TITLE_ONLY | 705 expansion_state_to_restore = are_titlebars_up_ ? Panel::TITLE_ONLY |
| 674 : Panel::MINIMIZED; | 706 : Panel::MINIMIZED; |
| 675 } | 707 } |
| 676 overflow_panel->SetExpansionState(expansion_state_to_restore); | 708 overflow_panel->SetExpansionState(expansion_state_to_restore); |
| 709 overflow_panel->SetStripOwner(Panel::DOCKED); | |
| 677 } | 710 } |
| 678 } | 711 } |
| 679 #endif | 712 #endif |
| 680 } | 713 } |
| 681 | 714 |
| 682 void PanelStrip::DelayedMovePanelToOverflow(Panel* panel) { | 715 void PanelStrip::DelayedMovePanelToOverflow(Panel* panel) { |
| 683 if (panels_in_temporary_layout_.erase(panel)) { | 716 if (panels_in_temporary_layout_.erase(panel)) { |
| 684 DCHECK(panel->has_temporary_layout()); | 717 DCHECK(panel->has_temporary_layout()); |
| 685 panel->SetExpansionState(Panel::IN_OVERFLOW); | 718 panel->SetStripOwner(Panel::IN_OVERFLOW); |
| 686 } | 719 } |
| 687 } | 720 } |
| 688 | 721 |
| 689 void PanelStrip::RemoveAll() { | 722 void PanelStrip::RemoveAll() { |
| 690 // This should only be called at the end of tests to clean up. | 723 // This should only be called at the end of tests to clean up. |
| 691 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); | 724 DCHECK(dragging_panel_index_ == kInvalidPanelIndex); |
| 692 DCHECK(panels_in_temporary_layout_.empty()); | 725 DCHECK(panels_in_temporary_layout_.empty()); |
| 693 | 726 |
| 694 // Make a copy of the iterator as closing panels can modify the vector. | 727 // Make a copy of the iterator as closing panels can modify the vector. |
| 695 Panels panels_copy = panels_; | 728 Panels panels_copy = panels_; |
| 696 | 729 |
| 697 // Start from the bottom to avoid reshuffling. | 730 // Start from the bottom to avoid reshuffling. |
| 698 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 731 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
| 699 iter != panels_copy.rend(); ++iter) | 732 iter != panels_copy.rend(); ++iter) |
| 700 (*iter)->Close(); | 733 (*iter)->Close(); |
| 701 } | 734 } |
| 702 | 735 |
| 703 bool PanelStrip::is_dragging_panel() const { | 736 bool PanelStrip::is_dragging_panel() const { |
| 704 return dragging_panel_index_ != kInvalidPanelIndex; | 737 return dragging_panel_index_ != kInvalidPanelIndex; |
| 705 } | 738 } |
| OLD | NEW |