This source file includes following definitions.
- HandleDrag
- DragLeft
- DragRight
#include "chrome/browser/ui/panels/docked_panel_drag_handler.h"
#include "chrome/browser/ui/panels/docked_panel_collection.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
void DockedPanelDragHandler::HandleDrag(Panel* panel,
const gfx::Point& target_position) {
DCHECK_EQ(PanelCollection::DOCKED, panel->collection()->type());
DockedPanelCollection* collection =
static_cast<DockedPanelCollection*>(panel->collection());
gfx::Rect new_bounds(panel->GetBounds());
new_bounds.set_x(target_position.x());
int delta_x = new_bounds.x() - panel->GetBounds().x();
int bottom = collection->GetBottomPositionForExpansionState(
panel->expansion_state());
if (new_bounds.bottom() != bottom) {
new_bounds.set_y(target_position.y());
if (new_bounds.bottom() > bottom)
new_bounds.set_y(bottom - new_bounds.height());
}
panel->SetPanelBoundsInstantly(new_bounds);
if (delta_x) {
if (delta_x > 0)
DragRight(panel);
else
DragLeft(panel);
collection->RefreshLayout();
}
}
void DockedPanelDragHandler::DragLeft(Panel* panel) {
DockedPanelCollection* collection =
static_cast<DockedPanelCollection*>(panel->collection());
int dragging_panel_left_boundary = panel->GetBounds().x();
DockedPanelCollection::Panels::iterator dragging_panel_iterator =
find(collection->panels_.begin(), collection->panels_.end(), panel);
DockedPanelCollection::Panels::iterator current_panel_iterator =
dragging_panel_iterator;
++current_panel_iterator;
for (; current_panel_iterator != collection->panels_.end();
++current_panel_iterator) {
Panel* current_panel = *current_panel_iterator;
if (dragging_panel_left_boundary > current_panel->GetBounds().x() +
current_panel->GetBounds().width() / 2)
break;
*dragging_panel_iterator = current_panel;
*current_panel_iterator = panel;
dragging_panel_iterator = current_panel_iterator;
}
}
void DockedPanelDragHandler::DragRight(Panel* panel) {
DockedPanelCollection* collection =
static_cast<DockedPanelCollection*>(panel->collection());
int dragging_panel_right_boundary = panel->GetBounds().x() +
panel->GetBounds().width() - 1;
DockedPanelCollection::Panels::iterator dragging_panel_iterator =
find(collection->panels_.begin(), collection->panels_.end(), panel);
DockedPanelCollection::Panels::iterator current_panel_iterator =
dragging_panel_iterator;
while (current_panel_iterator != collection->panels_.begin()) {
current_panel_iterator--;
Panel* current_panel = *current_panel_iterator;
if (dragging_panel_right_boundary < current_panel->GetBounds().x() +
current_panel->GetBounds().width() / 2)
break;
*dragging_panel_iterator = current_panel;
*current_panel_iterator = panel;
dragging_panel_iterator = current_panel_iterator;
}
}