| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/panels/panel_drag_controller.h" | 5 #include "chrome/browser/ui/panels/panel_drag_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/ui/panels/panel.h" | 8 #include "chrome/browser/ui/panels/panel.h" |
| 9 #include "chrome/browser/ui/panels/panel_strip.h" | 9 #include "chrome/browser/ui/panels/panel_strip.h" |
| 10 | 10 |
| 11 PanelDragController::PanelDragController() | 11 PanelDragController::PanelDragController() |
| 12 : dragging_panel_(NULL) { | 12 : dragging_panel_(NULL) { |
| 13 } | 13 } |
| 14 | 14 |
| 15 PanelDragController::~PanelDragController() { | 15 PanelDragController::~PanelDragController() { |
| 16 } | 16 } |
| 17 | 17 |
| 18 void PanelDragController::StartDragging(Panel* panel) { | 18 void PanelDragController::StartDragging(Panel* panel, |
| 19 const gfx::Point& mouse_location) { |
| 19 DCHECK(!dragging_panel_); | 20 DCHECK(!dragging_panel_); |
| 20 DCHECK(panel->draggable()); | 21 DCHECK(panel->draggable()); |
| 21 | 22 |
| 23 last_mouse_location_ = mouse_location; |
| 24 |
| 22 dragging_panel_ = panel; | 25 dragging_panel_ = panel; |
| 23 dragging_panel_original_position_ = panel->GetBounds().origin(); | 26 dragging_panel_original_position_ = panel->GetBounds().origin(); |
| 24 | 27 |
| 25 dragging_panel_->panel_strip()->StartDraggingPanel(panel); | 28 dragging_panel_->panel_strip()->StartDraggingPanel(panel); |
| 26 } | 29 } |
| 27 | 30 |
| 28 void PanelDragController::Drag(int delta_x, int delta_y) { | 31 void PanelDragController::Drag(const gfx::Point& mouse_location) { |
| 29 DCHECK(dragging_panel_); | 32 DCHECK(dragging_panel_); |
| 30 | 33 |
| 31 dragging_panel_->panel_strip()->DragPanel(dragging_panel_, delta_x, delta_y); | 34 dragging_panel_->panel_strip()->DragPanel( |
| 35 dragging_panel_, |
| 36 mouse_location.x() - last_mouse_location_.x(), |
| 37 mouse_location.y() - last_mouse_location_.y()); |
| 38 |
| 39 last_mouse_location_ = mouse_location; |
| 32 } | 40 } |
| 33 | 41 |
| 34 void PanelDragController::EndDragging(bool cancelled) { | 42 void PanelDragController::EndDragging(bool cancelled) { |
| 35 DCHECK(dragging_panel_); | 43 DCHECK(dragging_panel_); |
| 36 | 44 |
| 37 // The code in PanelStrip::EndDraggingPanel might call DragController to find | 45 // The code in PanelStrip::EndDraggingPanel might call DragController to find |
| 38 // out if the drag has ended. So we need to reset |dragging_panel_| to reflect | 46 // out if the drag has ended. So we need to reset |dragging_panel_| to reflect |
| 39 // this. | 47 // this. |
| 40 Panel* panel = dragging_panel_; | 48 Panel* panel = dragging_panel_; |
| 41 dragging_panel_ = NULL; | 49 dragging_panel_ = NULL; |
| 42 panel->panel_strip()->EndDraggingPanel(panel, cancelled); | 50 panel->panel_strip()->EndDraggingPanel(panel, cancelled); |
| 43 } | 51 } |
| 44 | 52 |
| 45 void PanelDragController::OnPanelClosed(Panel* panel) { | 53 void PanelDragController::OnPanelClosed(Panel* panel) { |
| 46 if (!dragging_panel_) | 54 if (!dragging_panel_) |
| 47 return; | 55 return; |
| 48 | 56 |
| 49 // If the dragging panel is closed, abort the drag. | 57 // If the dragging panel is closed, abort the drag. |
| 50 if (dragging_panel_ == panel) | 58 if (dragging_panel_ == panel) |
| 51 EndDragging(false); | 59 EndDragging(false); |
| 52 } | 60 } |
| OLD | NEW |