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 2a21cd28b7ffdf9af6b959ce845b07a30c172a51..630847358a9d3061ed357d92d696b4746a69993d 100644 |
--- a/chrome/browser/ui/panels/panel_drag_controller.cc |
+++ b/chrome/browser/ui/panels/panel_drag_controller.cc |
@@ -5,41 +5,148 @@ |
#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; |
+const int PanelDragController::kDockDetachedPanelThreshold = 10; |
+ |
+PanelDragController::PanelDragController(PanelManager* panel_manager) |
+ : panel_manager_(panel_manager), |
+ dragging_panel_(NULL), |
+ dragging_panel_original_strip_(NULL) { |
} |
PanelDragController::~PanelDragController() { |
} |
-void PanelDragController::StartDragging(Panel* panel) { |
+void PanelDragController::StartDragging(Panel* panel, |
+ const gfx::Point& mouse_location) { |
DCHECK(!dragging_panel_); |
DCHECK(panel->draggable()); |
dragging_panel_ = panel; |
- dragging_panel_original_position_ = panel->GetBounds().origin(); |
+ last_mouse_location_ = mouse_location; |
+ |
+ // 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); |
+ if (dragging_panel_original_strip_->type() == PanelStrip::DOCKED) |
+ mouse_location_on_docked_ = last_mouse_location_; |
+ dragging_panel_original_strip_->StartDraggingPanelLocally(dragging_panel_); |
} |
-void PanelDragController::Drag(int delta_x, int delta_y) { |
+void PanelDragController::Drag(const gfx::Point& mouse_location) { |
DCHECK(dragging_panel_); |
- dragging_panel_->panel_strip()->DragPanel(dragging_panel_, delta_x, delta_y); |
+ PanelStrip* current_strip = dragging_panel_->panel_strip(); |
+ |
+ gfx::Point target_panel_position; |
jennb
2012/03/03 02:19:33
Add comment explaining why target panel position
jianli
2012/03/07 19:14:31
Done.
|
+ PanelStrip* target_strip = ComputeDragTagetStrip( |
+ mouse_location, &target_panel_position); |
+ if (target_strip != current_strip) { |
+ current_strip->EndDraggingPanelLocally(dragging_panel_, true); |
+ current_strip->RemovePanel(dragging_panel_); |
+ target_strip->AddDraggingPanel(dragging_panel_, target_panel_position); |
+ if (target_strip->type() == PanelStrip::DOCKED) |
+ mouse_location_on_docked_ = mouse_location; |
+ } else { |
+ current_strip->DragPanelLocally( |
+ dragging_panel_, |
+ mouse_location.x() - last_mouse_location_.x(), |
+ mouse_location.y() - last_mouse_location_.y()); |
+ } |
+ |
+ last_mouse_location_ = 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(); |
+ current_strip->EndDraggingPanelLocally(dragging_panel_, cancelled); |
+ |
+ if (cancelled) { |
+ // If the dragging panel is not in original strip, put it back. |
+ if (current_strip != dragging_panel_original_strip_) { |
+ current_strip->RemovePanel(dragging_panel_); |
jennb
2012/03/03 02:19:33
Try to go through PanelManager to move panel betwe
jianli
2012/03/07 19:14:31
Done.
|
+ dragging_panel_->set_panel_strip(dragging_panel_original_strip_); |
+ dragging_panel_original_strip_->AddPanel(dragging_panel_); |
jennb
2012/03/03 02:19:33
Add followed by Load - will this appear to the use
jianli
2012/03/07 19:14:31
Fixed per discussion.
|
+ } |
+ |
+ // Restore the dragging panel to its original placement. |
+ dragging_panel_original_strip_->LoadSavedPanelPlacement(); |
+ } else { |
+ // 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; |
+ |
+ // The bottom of the panel should come very close to or fall below the bottom |
+ // of the docked area. |
+ int new_panel_bottom = dragging_panel_->GetBounds().bottom() + |
+ mouse_location.y() - last_mouse_location_.y(); |
+ int docked_area_bottom = |
+ panel_manager_->docked_strip()->display_area().bottom(); |
+ if (docked_area_bottom - new_panel_bottom > kDockDetachedPanelThreshold) |
+ return false; |
+ |
+ *new_panel_position = dragging_panel_->GetBounds().origin(); |
+ new_panel_position->Offset( |
+ mouse_location.x() - last_mouse_location_.x(), |
+ mouse_location.y() - last_mouse_location_.y()); |
+ 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) |
+ return false; |
+ |
+ // The panel should be dragged up higher enough to pass certain threshold. |
jennb
2012/03/03 02:19:33
high enough
jianli
2012/03/07 19:14:31
Done.
|
+ int delta = mouse_location.y() - mouse_location_on_docked_.y(); |
jennb
2012/03/03 02:19:33
if (mouse_location.y() >= mouse_location_on_docked
jianli
2012/03/07 19:14:31
Done.
|
+ if (-delta < kDetachDockedPanelThreshold) |
+ return false; |
+ |
+ *new_panel_position = dragging_panel_->GetBounds().origin(); |
+ new_panel_position->Offset( |
jennb
2012/03/03 02:19:33
I don't understand the commenting in these lines.
jianli
2012/03/07 19:14:31
Comment updated.
|
+ // The x coordinate is updated when the mouse drags in the docked strip. |
+ mouse_location.x() - last_mouse_location_.x(), |
+ // The y coordinate is intact when the mouse drags in the docked strip. |
+ mouse_location.y() - mouse_location_on_docked_.y()); |
+ return true; |
} |
void PanelDragController::OnPanelClosed(Panel* panel) { |