| 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_drag_controller.h" | 5 #include "chrome/browser/ui/panels/panel_drag_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/ui/panels/detached_panel_collection.h" | 8 #include "chrome/browser/ui/panels/detached_panel_collection.h" |
| 9 #include "chrome/browser/ui/panels/detached_panel_drag_handler.h" | 9 #include "chrome/browser/ui/panels/detached_panel_drag_handler.h" |
| 10 #include "chrome/browser/ui/panels/docked_panel_collection.h" | 10 #include "chrome/browser/ui/panels/docked_panel_collection.h" |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 gfx::Rect target_bounds = last_panel_to_unstack->GetBounds(); | 439 gfx::Rect target_bounds = last_panel_to_unstack->GetBounds(); |
| 440 target_bounds.Offset(delta); | 440 target_bounds.Offset(delta); |
| 441 gfx::Rect below_panel_bounds = panel_below_last_panel_to_unstack->GetBounds(); | 441 gfx::Rect below_panel_bounds = panel_below_last_panel_to_unstack->GetBounds(); |
| 442 if (GetVerticalDistance(target_bounds, below_panel_bounds) < | 442 if (GetVerticalDistance(target_bounds, below_panel_bounds) < |
| 443 kGluePanelsDistanceThreshold && | 443 kGluePanelsDistanceThreshold && |
| 444 GetHorizontalOverlap(target_bounds, below_panel_bounds) > | 444 GetHorizontalOverlap(target_bounds, below_panel_bounds) > |
| 445 kGluePanelsOverlapThreshold) { | 445 kGluePanelsOverlapThreshold) { |
| 446 return false; | 446 return false; |
| 447 } | 447 } |
| 448 | 448 |
| 449 // Move the panel (and all the panels below if in a stack) to the new | |
| 450 // position. | |
| 451 for (StackedPanelCollection::Panels::const_iterator iter = | |
| 452 dragging_stack->panels().begin(); | |
| 453 iter != dragging_stack->panels().end(); ++iter) { | |
| 454 if (!(*iter)->in_preview_mode()) | |
| 455 break; | |
| 456 (*iter)->MoveByInstantly(delta); | |
| 457 } | |
| 458 | |
| 459 int num_panels_in_stack = dragging_stack->num_panels(); | 449 int num_panels_in_stack = dragging_stack->num_panels(); |
| 460 DCHECK_GE(num_panels_in_stack, 2); | 450 DCHECK_GE(num_panels_in_stack, 2); |
| 461 | 451 |
| 462 // When a panel is removed from its stack, we always make it detached. If it | 452 // When a panel is removed from its stack, we always make it detached. If it |
| 463 // indeed should go to the docked collection, the subsequent TryDock will then | 453 // indeed should go to the docked collection, the subsequent TryDock will then |
| 464 // move it from the detached collection to the docked collection. | 454 // move it from the detached collection to the docked collection. |
| 465 DetachedPanelCollection* detached_collection = | 455 DetachedPanelCollection* detached_collection = |
| 466 panel_manager_->detached_collection(); | 456 panel_manager_->detached_collection(); |
| 467 | 457 |
| 468 // If there're only 2 panels in the stack, both panels should move out of the | 458 // If there're only 2 panels in the stack, both panels should move out of the |
| 469 // stack and the stack should be removed. | 459 // stack and the stack should be removed. |
| 470 if (num_panels_in_stack == 2) { | 460 if (num_panels_in_stack == 2) { |
| 471 DCHECK_EQ(1, num_panels_to_unstack); | 461 DCHECK_EQ(1, num_panels_to_unstack); |
| 472 MovePanelAndBelowToCollection(dragging_panel_, | 462 MovePanelAndBelowToCollection(dragging_panel_, |
| 473 detached_collection, | 463 detached_collection, |
| 474 PanelCollection::KNOWN_POSITION); | 464 PanelCollection::KNOWN_POSITION); |
| 465 dragging_panel_->MoveByInstantly(delta); |
| 475 return true; | 466 return true; |
| 476 } | 467 } |
| 477 | 468 |
| 478 DCHECK_GE(num_panels_in_stack, 3); | 469 DCHECK_GE(num_panels_in_stack, 3); |
| 479 | 470 |
| 480 // If only one panel (top panel) needs to unstack, move it out of the stack. | 471 // If only one panel (top panel) needs to unstack, move it out of the stack. |
| 481 if (num_panels_to_unstack == 1) { | 472 if (num_panels_to_unstack == 1) { |
| 482 panel_manager_->MovePanelToCollection(dragging_panel_, | 473 panel_manager_->MovePanelToCollection(dragging_panel_, |
| 483 panel_manager_->detached_collection(), | 474 detached_collection, |
| 484 PanelCollection::KNOWN_POSITION); | 475 PanelCollection::KNOWN_POSITION); |
| 476 dragging_panel_->MoveByInstantly(delta); |
| 485 return true; | 477 return true; |
| 486 } | 478 } |
| 487 | 479 |
| 488 // If all the panels except the bottom panel need to unstack, simply move | 480 // If all the panels except the bottom panel need to unstack, simply move |
| 489 // bottom panel out of the stack. | 481 // bottom panel out of the stack. |
| 490 if (num_panels_in_stack - num_panels_to_unstack == 1) { | 482 if (num_panels_in_stack - num_panels_to_unstack == 1) { |
| 491 panel_manager_->MovePanelToCollection(dragging_stack->bottom_panel(), | 483 panel_manager_->MovePanelToCollection(dragging_stack->bottom_panel(), |
| 492 panel_manager_->detached_collection(), | 484 detached_collection, |
| 493 PanelCollection::KNOWN_POSITION); | 485 PanelCollection::KNOWN_POSITION); |
| 486 dragging_panel_->stack()->MoveAllDraggingPanelsInstantly(delta); |
| 494 return true; | 487 return true; |
| 495 } | 488 } |
| 496 | 489 |
| 497 // Otherwise, move all unstacked panels to a new stack. | 490 // Otherwise, move all unstacked panels to a new stack. |
| 498 // Note that all the panels to move should be copied to a local list first | 491 // Note that all the panels to move should be copied to a local list first |
| 499 // because the stack collection will be modified during the move. | 492 // because the stack collection will be modified during the move. |
| 500 std::list<Panel*> panels_to_move; | 493 std::list<Panel*> panels_to_move; |
| 501 for (StackedPanelCollection::Panels::const_iterator iter = | 494 for (StackedPanelCollection::Panels::const_iterator iter = |
| 502 dragging_stack->panels().begin(); | 495 dragging_stack->panels().begin(); |
| 503 iter != dragging_stack->panels().end(); ++iter) { | 496 iter != dragging_stack->panels().end(); ++iter) { |
| 504 Panel* panel = *iter; | 497 Panel* panel = *iter; |
| 505 if (!panel->in_preview_mode()) | 498 if (!panel->in_preview_mode()) |
| 506 break; | 499 break; |
| 507 panels_to_move.push_back(panel); | 500 panels_to_move.push_back(panel); |
| 508 } | 501 } |
| 509 StackedPanelCollection* new_stack = panel_manager_->CreateStack(); | 502 StackedPanelCollection* new_stack = panel_manager_->CreateStack(); |
| 510 for (std::list<Panel*>::const_iterator iter = panels_to_move.begin(); | 503 for (std::list<Panel*>::const_iterator iter = panels_to_move.begin(); |
| 511 iter != panels_to_move.end(); ++iter) { | 504 iter != panels_to_move.end(); ++iter) { |
| 512 panel_manager_->MovePanelToCollection(*iter, | 505 panel_manager_->MovePanelToCollection(*iter, |
| 513 new_stack, | 506 new_stack, |
| 514 PanelCollection::KNOWN_POSITION); | 507 PanelCollection::KNOWN_POSITION); |
| 515 } | 508 } |
| 509 dragging_panel_->stack()->MoveAllDraggingPanelsInstantly(delta); |
| 516 | 510 |
| 517 return true; | 511 return true; |
| 518 } | 512 } |
| 519 | 513 |
| 520 // Check if a panel or a set of stacked panels (being dragged together from a | 514 // Check if a panel or a set of stacked panels (being dragged together from a |
| 521 // stack) can be dragged away from the panel above such that the former panel(s) | 515 // stack) can be dragged away from the panel above such that the former panel(s) |
| 522 // are not in the same stack as the latter panel. | 516 // are not in the same stack as the latter panel. |
| 523 bool PanelDragController::TryUnstackFromBottom( | 517 bool PanelDragController::TryUnstackFromBottom( |
| 524 const gfx::Point& target_position) { | 518 const gfx::Point& target_position) { |
| 525 // It has to be stacked. | 519 // It has to be stacked. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 539 Panel* above_panel = dragging_stack->GetPanelAbove(dragging_panel_); | 533 Panel* above_panel = dragging_stack->GetPanelAbove(dragging_panel_); |
| 540 DCHECK(above_panel); | 534 DCHECK(above_panel); |
| 541 gfx::Rect above_panel_bounds = above_panel->GetBounds(); | 535 gfx::Rect above_panel_bounds = above_panel->GetBounds(); |
| 542 if (GetVerticalDistance(above_panel_bounds, target_bounds) < | 536 if (GetVerticalDistance(above_panel_bounds, target_bounds) < |
| 543 kGluePanelsDistanceThreshold && | 537 kGluePanelsDistanceThreshold && |
| 544 GetHorizontalOverlap(above_panel_bounds, target_bounds) > | 538 GetHorizontalOverlap(above_panel_bounds, target_bounds) > |
| 545 kGluePanelsOverlapThreshold) { | 539 kGluePanelsOverlapThreshold) { |
| 546 return false; | 540 return false; |
| 547 } | 541 } |
| 548 | 542 |
| 549 // Move the panel (and all the panels below if in a stack) to the new | |
| 550 // position. | |
| 551 gfx::Vector2d delta = target_position - dragging_panel_->GetBounds().origin(); | 543 gfx::Vector2d delta = target_position - dragging_panel_->GetBounds().origin(); |
| 552 if (dragging_stack) | |
| 553 dragging_stack->MoveAllDraggingPanelsInstantly(delta); | |
| 554 else | |
| 555 dragging_panel_->MoveByInstantly(delta); | |
| 556 | 544 |
| 557 // If there're only 2 panels in the stack, both panels should move out the | 545 // If there're only 2 panels in the stack, both panels should move out the |
| 558 // stack and the stack should be removed. | 546 // stack and the stack should be removed. |
| 559 DetachedPanelCollection* detached_collection = | 547 DetachedPanelCollection* detached_collection = |
| 560 panel_manager_->detached_collection(); | 548 panel_manager_->detached_collection(); |
| 561 if (dragging_stack->num_panels() == 2) { | 549 if (dragging_stack->num_panels() == 2) { |
| 562 MovePanelAndBelowToCollection(dragging_stack->top_panel(), | 550 MovePanelAndBelowToCollection(dragging_stack->top_panel(), |
| 563 detached_collection, | 551 detached_collection, |
| 564 PanelCollection::KNOWN_POSITION); | 552 PanelCollection::KNOWN_POSITION); |
| 553 dragging_panel_->MoveByInstantly(delta); |
| 565 return true; | 554 return true; |
| 566 } | 555 } |
| 567 | 556 |
| 568 // There're at least 3 panels. | 557 // There're at least 3 panels. |
| 569 DCHECK_GE(dragging_stack->num_panels(), 3); | 558 DCHECK_GE(dragging_stack->num_panels(), 3); |
| 570 | 559 |
| 571 // If the dragging panel is bottom panel, move it out of the stack. | 560 // If the dragging panel is bottom panel, move it out of the stack. |
| 572 if (dragging_panel_ == dragging_stack->bottom_panel()) { | 561 if (dragging_panel_ == dragging_stack->bottom_panel()) { |
| 573 panel_manager_->MovePanelToCollection(dragging_panel_, | 562 panel_manager_->MovePanelToCollection(dragging_panel_, |
| 574 detached_collection, | 563 detached_collection, |
| 575 PanelCollection::KNOWN_POSITION); | 564 PanelCollection::KNOWN_POSITION); |
| 565 dragging_panel_->MoveByInstantly(delta); |
| 576 return true; | 566 return true; |
| 577 } | 567 } |
| 578 | 568 |
| 579 // If the dragging panel is the one below the top panel, move top panel | 569 // If the dragging panel is the one below the top panel, move top panel |
| 580 // out of the stack. | 570 // out of the stack. |
| 581 if (dragging_stack->GetPanelAbove(dragging_panel_) == | 571 if (dragging_stack->GetPanelAbove(dragging_panel_) == |
| 582 dragging_stack->top_panel()) { | 572 dragging_stack->top_panel()) { |
| 583 panel_manager_->MovePanelToCollection(dragging_stack->top_panel(), | 573 panel_manager_->MovePanelToCollection(dragging_stack->top_panel(), |
| 584 detached_collection, | 574 detached_collection, |
| 585 PanelCollection::KNOWN_POSITION); | 575 PanelCollection::KNOWN_POSITION); |
| 576 dragging_panel_->stack()->MoveAllDraggingPanelsInstantly(delta); |
| 586 return true; | 577 return true; |
| 587 } | 578 } |
| 588 | 579 |
| 589 // There're at least 4 panels. | 580 // There're at least 4 panels. |
| 590 DCHECK_GE(dragging_stack->num_panels(), 4); | 581 DCHECK_GE(dragging_stack->num_panels(), 4); |
| 591 | 582 |
| 592 // We can split them into 2 stacks by moving the dragging panel and all panels | 583 // We can split them into 2 stacks by moving the dragging panel and all panels |
| 593 // below to a new stack while keeping all panels above in the same stack. | 584 // below to a new stack while keeping all panels above in the same stack. |
| 594 StackedPanelCollection* new_stack = panel_manager_->CreateStack(); | 585 StackedPanelCollection* new_stack = panel_manager_->CreateStack(); |
| 595 MovePanelAndBelowToCollection(dragging_panel_, | 586 MovePanelAndBelowToCollection(dragging_panel_, |
| 596 new_stack, | 587 new_stack, |
| 597 PanelCollection::KNOWN_POSITION); | 588 PanelCollection::KNOWN_POSITION); |
| 589 dragging_panel_->stack()->MoveAllDraggingPanelsInstantly(delta); |
| 598 | 590 |
| 599 return true; | 591 return true; |
| 600 } | 592 } |
| 601 | 593 |
| 602 void PanelDragController::TrySnap(gfx::Point* target_position) { | 594 void PanelDragController::TrySnap(gfx::Point* target_position) { |
| 603 // Snapping does not apply to docked panels. | 595 // Snapping does not apply to docked panels. |
| 604 if (dragging_panel_->collection()->type() == PanelCollection::DOCKED) | 596 if (dragging_panel_->collection()->type() == PanelCollection::DOCKED) |
| 605 return; | 597 return; |
| 606 | 598 |
| 607 // Check if the panel can snap to other panel. | 599 // Check if the panel can snap to other panel. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 panel_manager_->detached_collection(), | 805 panel_manager_->detached_collection(), |
| 814 PanelCollection::KNOWN_POSITION); | 806 PanelCollection::KNOWN_POSITION); |
| 815 } | 807 } |
| 816 // Note that if the stack is the original collection, do not remove it now. | 808 // Note that if the stack is the original collection, do not remove it now. |
| 817 // This is because the original collection contains the information to | 809 // This is because the original collection contains the information to |
| 818 // restore the dragging panel to the right place when the drag is cancelled. | 810 // restore the dragging panel to the right place when the drag is cancelled. |
| 819 if (stack != dragging_panel_original_collection_) | 811 if (stack != dragging_panel_original_collection_) |
| 820 panel_manager_->RemoveStack(stack); | 812 panel_manager_->RemoveStack(stack); |
| 821 } | 813 } |
| 822 } | 814 } |
| OLD | NEW |