This source file includes following definitions.
- HandleDrag
- FinalizeDrag
#include "chrome/browser/ui/panels/stacked_panel_drag_handler.h"
#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"
void StackedPanelDragHandler::HandleDrag(Panel* panel,
const gfx::Point& target_position,
bool in_orginal_collection) {
DCHECK_EQ(PanelCollection::STACKED, panel->collection()->type());
StackedPanelCollection* stack = panel->stack();
DCHECK(stack);
if (in_orginal_collection && panel != stack->top_panel())
return;
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 (!all_panels_under_drag)
delta_origin.set_y(0);
stack->MoveAllDraggingPanelsInstantly(delta_origin);
}
void StackedPanelDragHandler::FinalizeDrag(Panel* panel) {
DCHECK_EQ(PanelCollection::STACKED, panel->collection()->type());
StackedPanelCollection* stack = panel->stack();
DCHECK(stack);
if (stack->top_panel() != panel)
return;
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);
}