Index: chrome/browser/ui/panels/stacked_panel_drag_handler.cc |
diff --git a/chrome/browser/ui/panels/stacked_panel_drag_handler.cc b/chrome/browser/ui/panels/stacked_panel_drag_handler.cc |
index ede20012ebf22ad8c7c3e4a5f9e8e488b6ab1336..e09b65a840525fb456c1c7104edf007ec976d838 100644 |
--- a/chrome/browser/ui/panels/stacked_panel_drag_handler.cc |
+++ b/chrome/browser/ui/panels/stacked_panel_drag_handler.cc |
@@ -7,13 +7,76 @@ |
#include "base/logging.h" |
#include "chrome/browser/ui/panels/panel.h" |
#include "chrome/browser/ui/panels/panel_collection.h" |
+#include "chrome/browser/ui/panels/stacked_panel_collection.h" |
#include "ui/gfx/point.h" |
#include "ui/gfx/rect.h" |
// static |
void StackedPanelDragHandler::HandleDrag(Panel* panel, |
- const gfx::Point& target_position) { |
+ const gfx::Point& target_position, |
+ bool in_orginal_collection) { |
DCHECK_EQ(PanelCollection::STACKED, panel->collection()->type()); |
- // TODO(jianli): to be implemented. |
+ StackedPanelCollection* stack = panel->stack(); |
+ DCHECK(stack); |
+ |
+ // If the panel is in its original stack, only top panel is allowed to drag. |
+ if (in_orginal_collection && panel != stack->top_panel()) |
+ return; |
+ |
+ // Find out if all panels in the stack are being dragged. |
+ bool all_panels_under_drag = true; |
+ for (StackedPanelCollection::Panels::const_iterator iter = |
+ stack->panels().begin(); |
+ iter != stack->panels().end(); ++iter) { |
+ if (!(*iter)->in_preview_mode()) { |
+ all_panels_under_drag = false; |
+ break; |
+ } |
+ } |
+ |
+ gfx::Vector2d delta_origin = target_position - panel->GetBounds().origin(); |
+ |
+ // If not all panels in the stack are being dragged, it means that these |
+ // panels being dragged have just been added to this stack. Dragging these |
+ // panels should only cause the horizontal movement due to that y position |
+ // of these panels have already aligned. |
+ if (!all_panels_under_drag) |
+ delta_origin.set_y(0); |
+ |
+ stack->MoveAllDraggingPanelsInstantly(delta_origin); |
+} |
+ |
+// static |
+void StackedPanelDragHandler::FinalizeDrag(Panel* panel) { |
+ DCHECK_EQ(PanelCollection::STACKED, panel->collection()->type()); |
+ |
+ StackedPanelCollection* stack = panel->stack(); |
+ DCHECK(stack); |
+ |
+ // It is only needed when dragging a panel/stack to stack to the top of |
+ // another panel/stack. |
+ if (stack->top_panel() != panel) |
+ return; |
+ |
+ // Find the first non-dragging panel that is used to align all dragging panels |
+ // above it to have the same x position. This is because all dragging panels |
+ // are only aligned vertically when the stacking occurs. |
+ Panel* first_non_dragging_panel = NULL; |
+ for (StackedPanelCollection::Panels::const_iterator iter = |
+ stack->panels().begin(); |
+ iter != stack->panels().end(); ++iter) { |
+ Panel* panel = *iter; |
+ if (!panel->in_preview_mode()) { |
+ first_non_dragging_panel = panel; |
+ break; |
+ } |
+ } |
+ if (!first_non_dragging_panel) |
+ return; |
+ |
+ gfx::Vector2d delta_origin( |
+ first_non_dragging_panel->GetBounds().x() - panel->GetBounds().x(), |
+ 0); |
+ stack->MoveAllDraggingPanelsInstantly(delta_origin); |
} |