Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "ui/gfx/point.h" | 11 #include "ui/gfx/point.h" |
| 12 | 12 |
| 13 class Panel; | 13 class Panel; |
| 14 class PanelManager; | |
| 15 class PanelStrip; | |
| 14 | 16 |
| 15 // Responsible for handling drags initiated for all panels, including both | 17 // Responsible for handling drags initiated for all panels, including both |
| 16 // intra-strip and inter-strip drags. | 18 // intra-strip and inter-strip drags. |
| 17 class PanelDragController { | 19 class PanelDragController { |
| 18 public: | 20 public: |
| 19 PanelDragController(); | 21 explicit PanelDragController(PanelManager* panel_manager); |
| 20 ~PanelDragController(); | 22 ~PanelDragController(); |
| 21 | 23 |
| 22 // Drags the given panel. | 24 // Drags the given panel. |
| 23 // |mouse_location| is in screen coordinate system. | 25 // |mouse_location| is in screen coordinate system. |
| 24 void StartDragging(Panel* panel, const gfx::Point& mouse_location); | 26 void StartDragging(Panel* panel, const gfx::Point& mouse_location); |
| 25 void Drag(const gfx::Point& mouse_location); | 27 void Drag(const gfx::Point& mouse_location); |
| 26 void EndDragging(bool cancelled); | 28 void EndDragging(bool cancelled); |
| 27 | 29 |
| 28 // Asynchronous confirmation of panel having been closed. | 30 // Asynchronous confirmation of panel having been closed. |
| 29 void OnPanelClosed(Panel* panel); | 31 void OnPanelClosed(Panel* panel); |
| 30 | 32 |
| 31 bool IsDragging() const { return dragging_panel_ != NULL; } | 33 bool IsDragging() const { return dragging_panel_ != NULL; } |
| 32 | 34 |
| 33 Panel* dragging_panel() const { return dragging_panel_; } | 35 Panel* dragging_panel() const { return dragging_panel_; } |
| 34 gfx::Point dragging_panel_original_position() const { | 36 |
| 35 return dragging_panel_original_position_; | 37 #ifdef UNIT_TEST |
| 38 static int GetDetachDockedPanelThreshold() { | |
| 39 return kDetachDockedPanelThreshold; | |
| 36 } | 40 } |
| 37 | 41 |
| 42 static int GetDockDetachedPanelThreshold() { | |
| 43 return kDockDetachedPanelThreshold; | |
| 44 } | |
| 45 #endif | |
| 46 | |
| 38 private: | 47 private: |
| 48 // Used to figure out if the panel can be dragged to other strip. | |
| 49 PanelStrip* ComputeDragTagetStrip( | |
| 50 const gfx::Point& mouse_location, gfx::Point* new_panel_position) const; | |
| 51 bool CanDragToDockedStrip( | |
| 52 const gfx::Point& mouse_location, gfx::Point* new_panel_position) const; | |
| 53 bool CanDragToDetachedStrip( | |
| 54 const gfx::Point& mouse_location, gfx::Point* new_panel_position) const; | |
| 55 | |
| 56 PanelManager* panel_manager_; // Weak, owns us. | |
| 57 | |
| 39 // Panel currently being dragged. | 58 // Panel currently being dragged. |
| 40 Panel* dragging_panel_; | 59 Panel* dragging_panel_; |
| 41 | 60 |
| 42 // Original position, in screen coordinate system, of the panel being dragged. | 61 // The original panel strip when the drag is started. |
| 43 // This is used to get back to the original position when we cancel the | 62 PanelStrip* dragging_panel_original_strip_; |
| 44 // dragging. | |
| 45 gfx::Point dragging_panel_original_position_; | |
| 46 | 63 |
| 47 // The mouse location, in screen coordinates, when StartDragging or Drag was | 64 // The mouse location, in screen coordinates, when StartDragging or Drag was |
| 48 // pveviously called. | 65 // pveviously called. |
| 49 gfx::Point last_mouse_location_; | 66 gfx::Point last_mouse_location_; |
| 50 | 67 |
| 68 // The mouse location, in screen coordinates, when the drag starts at the | |
| 69 // docked strip. | |
| 70 gfx::Point mouse_location_on_docked_; | |
| 71 | |
| 72 // The minimum distance that the docked panel gets dragged up in order to | |
| 73 // make it free-floating. | |
|
Andrei
2012/03/07 22:55:13
Could we formulate the condition for detaching in
jianli
2012/03/08 01:18:26
Done.
| |
| 74 static const int kDetachDockedPanelThreshold; | |
| 75 | |
| 76 // Indicates how close the bottom of the detached panel is to the bottom of | |
| 77 // the docked area such that the detached panel becomes docked. | |
| 78 static const int kDockDetachedPanelThreshold; | |
|
Andrei
2012/03/07 22:55:13
Why do they start with a "k"? I thought "k" was re
jianli
2012/03/08 01:18:26
Per coding style guide, we tend to prefix any cons
| |
| 79 | |
| 51 DISALLOW_COPY_AND_ASSIGN(PanelDragController); | 80 DISALLOW_COPY_AND_ASSIGN(PanelDragController); |
| 52 }; | 81 }; |
| 53 | 82 |
| 54 #endif // CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ | 83 #endif // CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ |
| OLD | NEW |