Chromium Code Reviews| Index: chrome/browser/ui/panels/panel_drag_controller.cc |
| diff --git a/chrome/browser/ui/panels/panel_drag_controller.cc b/chrome/browser/ui/panels/panel_drag_controller.cc |
| index 7cd099053250f7f231d2d5a9c357245f66f0f825..3b43b8880e3d3b493472aeeff000f40f90966eec 100644 |
| --- a/chrome/browser/ui/panels/panel_drag_controller.cc |
| +++ b/chrome/browser/ui/panels/panel_drag_controller.cc |
| @@ -5,11 +5,20 @@ |
| #include "chrome/browser/ui/panels/panel_drag_controller.h" |
| #include "base/logging.h" |
| +#include "chrome/browser/ui/panels/detached_panel_strip.h" |
| +#include "chrome/browser/ui/panels/docked_panel_strip.h" |
| #include "chrome/browser/ui/panels/panel.h" |
| +#include "chrome/browser/ui/panels/panel_manager.h" |
| #include "chrome/browser/ui/panels/panel_strip.h" |
| -PanelDragController::PanelDragController() |
| - : dragging_panel_(NULL) { |
| +// static |
| +const int PanelDragController::kDetachDockedPanelThreshold = 80; |
|
jennb
2012/03/08 23:41:09
Was there a spec change? I remember these as 60 an
jianli
2012/03/09 21:48:58
Changed to use the values in spec.
|
| +const int PanelDragController::kDockDetachedPanelThreshold = 10; |
| + |
| +PanelDragController::PanelDragController(PanelManager* panel_manager) |
| + : panel_manager_(panel_manager), |
| + dragging_panel_(NULL), |
| + dragging_panel_original_strip_(NULL) { |
| } |
| PanelDragController::~PanelDragController() { |
| @@ -21,20 +30,53 @@ void PanelDragController::StartDragging(Panel* panel, |
| DCHECK(panel->draggable()); |
| last_mouse_location_ = mouse_location; |
| + offset_from_mouse_location_on_drag_start_ = |
| + mouse_location.Subtract(panel->GetBounds().origin()); |
| dragging_panel_ = panel; |
| - dragging_panel_original_position_ = panel->GetBounds().origin(); |
| + dragging_panel_->SetPreviewMode(true); |
| + |
| + // Keep track of original strip and placement for the case that the drag is |
| + // cancelled. |
| + dragging_panel_original_strip_ = dragging_panel_->panel_strip(); |
| + dragging_panel_original_strip_->SavePanelPlacement(dragging_panel_); |
| - dragging_panel_->panel_strip()->StartDraggingPanel(panel); |
| + dragging_panel_original_strip_->StartDraggingPanelWithinStrip( |
| + dragging_panel_); |
| } |
| void PanelDragController::Drag(const gfx::Point& mouse_location) { |
| DCHECK(dragging_panel_); |
| - dragging_panel_->panel_strip()->DragPanel( |
| + PanelStrip* current_strip = dragging_panel_->panel_strip(); |
| + |
| + // We also need to compute target panel position together with target strip. |
| + // This is because target panel position needs to be computed in special way |
| + // when drag leaves docked strip and enters detached strip (see comment in |
|
jennb
2012/03/08 23:41:09
There's no comment in CanDragToDetachedStrip about
jianli
2012/03/09 21:48:58
Outdated comment removed.
|
| + // CanDragToDetachedStrip). |
| + gfx::Point target_panel_position; |
|
jennb
2012/03/08 23:41:09
Should have ComputeDragTargetStrip return target_p
jianli
2012/03/09 21:48:58
Done.
|
| + PanelStrip* target_strip = ComputeDragTagetStrip( |
| + mouse_location, &target_panel_position); |
| + if (target_strip != current_strip) { |
| + // End the dragging in old strip. |
| + current_strip->EndDraggingPanelWithinStrip(dragging_panel_, true); |
| + |
| + // Apply new panel position. |
| + gfx::Rect new_bounds(dragging_panel_->GetBounds()); |
| + new_bounds.set_origin(target_panel_position); |
| + dragging_panel_->SetPanelBounds(new_bounds); |
| + |
| + // Move the panel to new strip. |
| + panel_manager_->MovePanelToStrip(dragging_panel_, target_strip->type()); |
| + |
| + // Start the dragging in new strip. |
| + target_strip->StartDraggingPanelWithinStrip(dragging_panel_); |
| + } else { |
| + current_strip->DragPanelWithinStrip( |
| dragging_panel_, |
| mouse_location.x() - last_mouse_location_.x(), |
| mouse_location.y() - last_mouse_location_.y()); |
| + } |
| last_mouse_location_ = mouse_location; |
| } |
| @@ -42,12 +84,101 @@ void PanelDragController::Drag(const gfx::Point& mouse_location) { |
| void PanelDragController::EndDragging(bool cancelled) { |
| DCHECK(dragging_panel_); |
| - // The code in PanelStrip::EndDraggingPanel might call DragController to find |
| - // out if the drag has ended. So we need to reset |dragging_panel_| to reflect |
| - // this. |
| - Panel* panel = dragging_panel_; |
| + PanelStrip* current_strip = dragging_panel_->panel_strip(); |
| + if (cancelled) { |
| + // Abort the drag in current strip. |
| + current_strip->EndDraggingPanelWithinStrip(dragging_panel_, true); |
| + |
| + // Restore the dragging panel to its original strip if needed. |
| + if (current_strip != dragging_panel_original_strip_) { |
| + panel_manager_->MovePanelToStrip( |
|
jennb
2012/03/08 23:41:09
bounds have not been restored yet. docked_strip::A
jianli
2012/03/09 21:48:58
Per discussion, we added a new parameter to MovePa
|
| + dragging_panel_, dragging_panel_original_strip_->type()); |
| + } |
| + |
| + // We need to clear the preview mode before restoring to the saved placement |
| + // because otherwise the panel will remain as it is. |
| + dragging_panel_->SetPreviewMode(false); |
| + |
| + // Restore the dragging panel to its original placement. |
| + dragging_panel_original_strip_->RestorePanelToSavedPlacement(); |
| + } else { |
| + // We need to clear the preview mode first because in this mode, the panel |
|
jennb
2012/03/08 23:41:09
discard
end preview mode
end dragging
More readab
jianli
2012/03/09 21:48:58
Done.
|
| + // will remain as it is. |
| + dragging_panel_->SetPreviewMode(false); |
| + |
| + // End the drag. This will cause the panel to be moved to its finalized |
| + // position. |
| + current_strip->EndDraggingPanelWithinStrip(dragging_panel_, false); |
| + |
| + // The saved placement is not needed when the drag ends. |
| + dragging_panel_original_strip_->DiscardSavedPanelPlacement(); |
| + } |
| + |
| dragging_panel_ = NULL; |
| - panel->panel_strip()->EndDraggingPanel(panel, cancelled); |
| +} |
| + |
| +PanelStrip* PanelDragController::ComputeDragTagetStrip( |
| + const gfx::Point& mouse_location, gfx::Point* new_panel_position) const { |
| + if (CanDragToDockedStrip(mouse_location, new_panel_position)) |
| + return panel_manager_->docked_strip(); |
| + else if (CanDragToDetachedStrip(mouse_location, new_panel_position)) |
| + return panel_manager_->detached_strip(); |
| + else |
| + return dragging_panel_->panel_strip(); |
| +} |
| + |
| +bool PanelDragController::CanDragToDockedStrip( |
| + const gfx::Point& mouse_location, |
| + gfx::Point* new_panel_position) const { |
| + // It has to come from the detached strip. |
| + if (dragging_panel_->panel_strip()->type() != PanelStrip::DETACHED) |
| + return false; |
| + |
| + // Compute target panel position by assuming panel follows the mouse movement. |
| + gfx::Point target_panel_position = |
| + mouse_location.Subtract(offset_from_mouse_location_on_drag_start_); |
| + |
| + // The bottom of the panel should come very close to or fall below the bottom |
| + // of the docked area. |
| + if (GetOffsetToDockedAreaBottom(target_panel_position) > |
| + kDockDetachedPanelThreshold) |
| + return false; |
| + |
| + *new_panel_position = target_panel_position; |
| + return true; |
| +} |
| + |
| +bool PanelDragController::CanDragToDetachedStrip( |
| + const gfx::Point& mouse_location, |
| + gfx::Point* new_panel_position) const { |
| + // It has to come from the docked strip. |
| + if (dragging_panel_->panel_strip()->type() != PanelStrip::DOCKED) |
| + return false; |
| + |
| + // The minimized docked panel is not allowed to detach. |
| + if (dragging_panel_->expansion_state() != Panel::EXPANDED) |
|
jennb
2012/03/08 23:41:09
if dragging_panel_->IsMinimized()
jianli
2012/03/09 21:48:58
Done.
|
| + return false; |
| + |
| + // Compute target panel position by assuming panel follows the mouse movement. |
| + gfx::Point target_panel_position = |
| + mouse_location.Subtract(offset_from_mouse_location_on_drag_start_); |
| + |
| + // The panel should be dragged up high enough to pass certain threshold. |
| + if (GetOffsetToDockedAreaBottom(target_panel_position) < |
| + kDetachDockedPanelThreshold) |
| + return false; |
| + |
| + *new_panel_position = target_panel_position; |
| + return true; |
| +} |
| + |
| +int PanelDragController::GetOffsetToDockedAreaBottom( |
| + const gfx::Point& target_panel_position) const { |
|
jennb
2012/03/08 23:41:09
Should make this take a rect. It's confusing to sa
jianli
2012/03/09 21:48:58
Done.
|
| + int target_panel_bottom = |
| + target_panel_position.y() + dragging_panel_->GetBounds().height(); |
| + int docked_area_bottom = |
| + panel_manager_->docked_strip()->display_area().bottom(); |
| + return docked_area_bottom - target_panel_bottom; |
| } |
| void PanelDragController::OnPanelClosed(Panel* panel) { |