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/panel.h" | 8 #include "chrome/browser/ui/panels/panel.h" |
9 #include "chrome/browser/ui/panels/panel_manager.h" | 9 #include "chrome/browser/ui/panels/panel_manager.h" |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 81 } |
82 if (ResizingLeft(sides_resized_)) { | 82 if (ResizingLeft(sides_resized_)) { |
83 bounds.set_width(std::max(bounds_at_start_.width() + | 83 bounds.set_width(std::max(bounds_at_start_.width() + |
84 mouse_location_at_start_.x() - mouse_location.x(), 0)); | 84 mouse_location_at_start_.x() - mouse_location.x(), 0)); |
85 } | 85 } |
86 if (ResizingTop(sides_resized_)) { | 86 if (ResizingTop(sides_resized_)) { |
87 bounds.set_height(std::max(bounds_at_start_.height() + | 87 bounds.set_height(std::max(bounds_at_start_.height() + |
88 mouse_location_at_start_.y() - mouse_location.y(), 0)); | 88 mouse_location_at_start_.y() - mouse_location.y(), 0)); |
89 } | 89 } |
90 | 90 |
91 // Give the panel a chance to adjust the bounds before setting them. | 91 // Update the max size of the panel so it's never smaller then the actual |
92 gfx::Size size = bounds.size(); | 92 // panel's size. Note that even if the user resizes the panel smaller later, |
93 resizing_panel_->ClampSize(&size); | 93 // the increased max size will still be in effect. Since it's not possible |
94 bounds.set_size(size); | 94 // currently to switch the panel back to autosizing from user-resizable, it |
| 95 // should not be a problem. |
| 96 gfx::Size max_panel_size = resizing_panel_->max_size(); |
| 97 if (max_panel_size.width() < bounds.width()) |
| 98 max_panel_size.set_width(bounds.width()); |
| 99 if (max_panel_size.height() < bounds.height()) |
| 100 max_panel_size.set_height(bounds.height()); |
| 101 |
| 102 resizing_panel_->SetSizeRange(resizing_panel_->min_size(), max_panel_size); |
| 103 |
| 104 // This effectively only clamps using the min size, since the max_size was |
| 105 // updated above. |
| 106 bounds.set_size(resizing_panel_->ClampSize(bounds.size())); |
95 | 107 |
96 if (ResizingLeft(sides_resized_)) { | 108 if (ResizingLeft(sides_resized_)) { |
97 bounds.set_x(bounds_at_start_.x() - | 109 bounds.set_x(bounds_at_start_.x() - |
98 (bounds.width() - bounds_at_start_.width())); | 110 (bounds.width() - bounds_at_start_.width())); |
99 } | 111 } |
100 | 112 |
101 if (ResizingTop(sides_resized_)) { | 113 if (ResizingTop(sides_resized_)) { |
102 bounds.set_y(bounds_at_start_.y() - | 114 bounds.set_y(bounds_at_start_.y() - |
103 (bounds.height() - bounds_at_start_.height())); | 115 (bounds.height() - bounds_at_start_.height())); |
104 } | 116 } |
(...skipping 21 matching lines...) Expand all Loading... |
126 } | 138 } |
127 | 139 |
128 void PanelResizeController::OnPanelClosed(Panel* panel) { | 140 void PanelResizeController::OnPanelClosed(Panel* panel) { |
129 if (!resizing_panel_) | 141 if (!resizing_panel_) |
130 return; | 142 return; |
131 | 143 |
132 // If the resizing panel is closed, abort the resize operation. | 144 // If the resizing panel is closed, abort the resize operation. |
133 if (resizing_panel_ == panel) | 145 if (resizing_panel_ == panel) |
134 EndResizing(false); | 146 EndResizing(false); |
135 } | 147 } |
OLD | NEW |