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_resize_controller.h" | 5 #include "chrome/browser/ui/panels/panel_resize_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/ui/panels/detached_panel_strip.h" | |
9 #include "chrome/browser/ui/panels/docked_panel_strip.h" | |
10 #include "chrome/browser/ui/panels/panel.h" | 8 #include "chrome/browser/ui/panels/panel.h" |
11 #include "chrome/browser/ui/panels/panel_manager.h" | 9 #include "chrome/browser/ui/panels/panel_manager.h" |
12 #include "chrome/browser/ui/panels/panel_strip.h" | 10 #include "chrome/browser/ui/panels/panel_strip.h" |
13 | 11 |
14 namespace { | 12 namespace { |
15 static bool ResizingLeft(panel::ResizingSides sides) { | 13 static bool ResizingLeft(panel::ResizingSides sides) { |
16 return sides == panel::RESIZE_TOP_LEFT || | 14 return sides == panel::RESIZE_TOP_LEFT || |
17 sides == panel::RESIZE_LEFT || | 15 sides == panel::RESIZE_LEFT || |
18 sides == panel::RESIZE_BOTTOM_LEFT; | 16 sides == panel::RESIZE_BOTTOM_LEFT; |
19 } | 17 } |
(...skipping 20 matching lines...) Expand all Loading... |
40 PanelResizeController::PanelResizeController(PanelManager* panel_manager) | 38 PanelResizeController::PanelResizeController(PanelManager* panel_manager) |
41 : panel_manager_(panel_manager), | 39 : panel_manager_(panel_manager), |
42 resizing_panel_(NULL), | 40 resizing_panel_(NULL), |
43 sides_resized_(panel::RESIZE_NONE) { | 41 sides_resized_(panel::RESIZE_NONE) { |
44 } | 42 } |
45 | 43 |
46 void PanelResizeController::StartResizing(Panel* panel, | 44 void PanelResizeController::StartResizing(Panel* panel, |
47 const gfx::Point& mouse_location, | 45 const gfx::Point& mouse_location, |
48 panel::ResizingSides sides) { | 46 panel::ResizingSides sides) { |
49 DCHECK(!IsResizing()); | 47 DCHECK(!IsResizing()); |
50 DCHECK(panel->panel_strip() && | 48 DCHECK_NE(panel::NOT_RESIZABLE, panel->CanResizeByMouse()); |
51 panel->panel_strip()->CanResizePanel(panel)); | |
52 | |
53 DCHECK_NE(panel::RESIZE_NONE, sides); | 49 DCHECK_NE(panel::RESIZE_NONE, sides); |
54 | 50 |
55 mouse_location_at_start_ = mouse_location; | 51 mouse_location_at_start_ = mouse_location; |
56 bounds_at_start_ = panel->GetBounds(); | 52 bounds_at_start_ = panel->GetBounds(); |
57 sides_resized_ = sides; | 53 sides_resized_ = sides; |
58 resizing_panel_ = panel; | 54 resizing_panel_ = panel; |
| 55 resizing_panel_->SetPreviewMode(true); |
59 } | 56 } |
60 | 57 |
61 void PanelResizeController::Resize(const gfx::Point& mouse_location) { | 58 void PanelResizeController::Resize(const gfx::Point& mouse_location) { |
62 DCHECK(IsResizing()); | 59 DCHECK(IsResizing()); |
63 if (resizing_panel_->panel_strip() == NULL || | 60 if (resizing_panel_->CanResizeByMouse() == panel::NOT_RESIZABLE) { |
64 !resizing_panel_->panel_strip()->CanResizePanel(resizing_panel_)) { | |
65 EndResizing(false); | 61 EndResizing(false); |
66 return; | 62 return; |
67 } | 63 } |
68 gfx::Rect bounds = resizing_panel_->GetBounds(); | 64 gfx::Rect bounds = resizing_panel_->GetBounds(); |
69 | 65 |
70 if (ResizingRight(sides_resized_)) { | 66 if (ResizingRight(sides_resized_)) { |
71 bounds.set_width(std::max(bounds_at_start_.width() + | 67 bounds.set_width(std::max(bounds_at_start_.width() + |
72 mouse_location.x() - mouse_location_at_start_.x(), 0)); | 68 mouse_location.x() - mouse_location_at_start_.x(), 0)); |
73 } | 69 } |
74 if (ResizingBottom(sides_resized_)) { | 70 if (ResizingBottom(sides_resized_)) { |
| 71 DCHECK_EQ(panel::ALL_SIDES, resizing_panel_->CanResizeByMouse()); |
75 bounds.set_height(std::max(bounds_at_start_.height() + | 72 bounds.set_height(std::max(bounds_at_start_.height() + |
76 mouse_location.y() - mouse_location_at_start_.y(), 0)); | 73 mouse_location.y() - mouse_location_at_start_.y(), 0)); |
77 } | 74 } |
78 if (ResizingLeft(sides_resized_)) { | 75 if (ResizingLeft(sides_resized_)) { |
79 bounds.set_width(std::max(bounds_at_start_.width() + | 76 bounds.set_width(std::max(bounds_at_start_.width() + |
80 mouse_location_at_start_.x() - mouse_location.x(), 0)); | 77 mouse_location_at_start_.x() - mouse_location.x(), 0)); |
81 } | 78 } |
82 if (ResizingTop(sides_resized_)) { | 79 if (ResizingTop(sides_resized_)) { |
83 bounds.set_height(std::max(bounds_at_start_.height() + | 80 bounds.set_height(std::max(bounds_at_start_.height() + |
84 mouse_location_at_start_.y() - mouse_location.y(), 0)); | 81 mouse_location_at_start_.y() - mouse_location.y(), 0)); |
(...skipping 19 matching lines...) Expand all Loading... |
104 } | 101 } |
105 | 102 |
106 void PanelResizeController::EndResizing(bool cancelled) { | 103 void PanelResizeController::EndResizing(bool cancelled) { |
107 DCHECK(IsResizing()); | 104 DCHECK(IsResizing()); |
108 | 105 |
109 if (cancelled) { | 106 if (cancelled) { |
110 panel_manager_->OnPanelResizedByMouse(resizing_panel_, | 107 panel_manager_->OnPanelResizedByMouse(resizing_panel_, |
111 bounds_at_start_); | 108 bounds_at_start_); |
112 } | 109 } |
113 | 110 |
| 111 resizing_panel_->SetPreviewMode(false); |
| 112 if (resizing_panel_->panel_strip()) |
| 113 resizing_panel_->panel_strip()->RefreshLayout(); |
| 114 |
114 // Do a thorough cleanup. | 115 // Do a thorough cleanup. |
115 resizing_panel_ = NULL; | 116 resizing_panel_ = NULL; |
116 sides_resized_ = panel::RESIZE_NONE; | 117 sides_resized_ = panel::RESIZE_NONE; |
117 bounds_at_start_ = gfx::Rect(); | 118 bounds_at_start_ = gfx::Rect(); |
118 mouse_location_at_start_ = gfx::Point(); | 119 mouse_location_at_start_ = gfx::Point(); |
119 } | 120 } |
120 | 121 |
121 void PanelResizeController::OnPanelClosed(Panel* panel) { | 122 void PanelResizeController::OnPanelClosed(Panel* panel) { |
122 if (!resizing_panel_) | 123 if (!resizing_panel_) |
123 return; | 124 return; |
124 | 125 |
125 // If the resizing panel is closed, abort the resize operation. | 126 // If the resizing panel is closed, abort the resize operation. |
126 if (resizing_panel_ == panel) | 127 if (resizing_panel_ == panel) |
127 EndResizing(false); | 128 EndResizing(false); |
128 } | 129 } |
OLD | NEW |