| 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" | |
| 13 | 10 |
| 14 namespace { | 11 namespace { |
| 15 static bool ResizingLeft(panel::ResizingSides sides) { | 12 static bool ResizingLeft(panel::ResizingSides sides) { |
| 16 return sides == panel::RESIZE_TOP_LEFT || | 13 return sides == panel::RESIZE_TOP_LEFT || |
| 17 sides == panel::RESIZE_LEFT || | 14 sides == panel::RESIZE_LEFT || |
| 18 sides == panel::RESIZE_BOTTOM_LEFT; | 15 sides == panel::RESIZE_BOTTOM_LEFT; |
| 19 } | 16 } |
| 20 | 17 |
| 21 static bool ResizingRight(panel::ResizingSides sides) { | 18 static bool ResizingRight(panel::ResizingSides sides) { |
| 22 return sides == panel::RESIZE_TOP_RIGHT || | 19 return sides == panel::RESIZE_TOP_RIGHT || |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 PanelResizeController::PanelResizeController(PanelManager* panel_manager) | 37 PanelResizeController::PanelResizeController(PanelManager* panel_manager) |
| 41 : panel_manager_(panel_manager), | 38 : panel_manager_(panel_manager), |
| 42 resizing_panel_(NULL), | 39 resizing_panel_(NULL), |
| 43 sides_resized_(panel::RESIZE_NONE) { | 40 sides_resized_(panel::RESIZE_NONE) { |
| 44 } | 41 } |
| 45 | 42 |
| 46 void PanelResizeController::StartResizing(Panel* panel, | 43 void PanelResizeController::StartResizing(Panel* panel, |
| 47 const gfx::Point& mouse_location, | 44 const gfx::Point& mouse_location, |
| 48 panel::ResizingSides sides) { | 45 panel::ResizingSides sides) { |
| 49 DCHECK(!IsResizing()); | 46 DCHECK(!IsResizing()); |
| 50 DCHECK(panel->panel_strip() && | 47 DCHECK_NE(panel::RESIZE_NONE, sides); |
| 51 panel->panel_strip()->CanResizePanel(panel)); | |
| 52 | 48 |
| 53 DCHECK_NE(panel::RESIZE_NONE, sides); | 49 panel::Resizability resizability = panel->CanResizeByMouse(); |
| 50 DCHECK_NE(panel::NOT_RESIZABLE, resizability); |
| 51 if (panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM == resizability && |
| 52 ResizingBottom(sides)) { |
| 53 DLOG(WARNING) << "Resizing from bottom not allowed. Is this a test?"; |
| 54 return; |
| 55 } |
| 54 | 56 |
| 55 mouse_location_at_start_ = mouse_location; | 57 mouse_location_at_start_ = mouse_location; |
| 56 bounds_at_start_ = panel->GetBounds(); | 58 bounds_at_start_ = panel->GetBounds(); |
| 57 sides_resized_ = sides; | 59 sides_resized_ = sides; |
| 58 resizing_panel_ = panel; | 60 resizing_panel_ = panel; |
| 61 resizing_panel_->SetPreviewMode(true); |
| 59 } | 62 } |
| 60 | 63 |
| 61 void PanelResizeController::Resize(const gfx::Point& mouse_location) { | 64 void PanelResizeController::Resize(const gfx::Point& mouse_location) { |
| 62 DCHECK(IsResizing()); | 65 DCHECK(IsResizing()); |
| 63 if (resizing_panel_->panel_strip() == NULL || | 66 panel::Resizability resizability = resizing_panel_->CanResizeByMouse(); |
| 64 !resizing_panel_->panel_strip()->CanResizePanel(resizing_panel_)) { | 67 if (panel::NOT_RESIZABLE == resizability) { |
| 65 EndResizing(false); | 68 EndResizing(false); |
| 66 return; | 69 return; |
| 67 } | 70 } |
| 68 gfx::Rect bounds = resizing_panel_->GetBounds(); | 71 gfx::Rect bounds = resizing_panel_->GetBounds(); |
| 69 | 72 |
| 70 if (ResizingRight(sides_resized_)) { | 73 if (ResizingRight(sides_resized_)) { |
| 71 bounds.set_width(std::max(bounds_at_start_.width() + | 74 bounds.set_width(std::max(bounds_at_start_.width() + |
| 72 mouse_location.x() - mouse_location_at_start_.x(), 0)); | 75 mouse_location.x() - mouse_location_at_start_.x(), 0)); |
| 73 } | 76 } |
| 74 if (ResizingBottom(sides_resized_)) { | 77 if (ResizingBottom(sides_resized_)) { |
| 78 DCHECK_EQ(panel::RESIZABLE_ALL_SIDES, resizability); |
| 75 bounds.set_height(std::max(bounds_at_start_.height() + | 79 bounds.set_height(std::max(bounds_at_start_.height() + |
| 76 mouse_location.y() - mouse_location_at_start_.y(), 0)); | 80 mouse_location.y() - mouse_location_at_start_.y(), 0)); |
| 77 } | 81 } |
| 78 if (ResizingLeft(sides_resized_)) { | 82 if (ResizingLeft(sides_resized_)) { |
| 79 bounds.set_width(std::max(bounds_at_start_.width() + | 83 bounds.set_width(std::max(bounds_at_start_.width() + |
| 80 mouse_location_at_start_.x() - mouse_location.x(), 0)); | 84 mouse_location_at_start_.x() - mouse_location.x(), 0)); |
| 81 } | 85 } |
| 82 if (ResizingTop(sides_resized_)) { | 86 if (ResizingTop(sides_resized_)) { |
| 83 bounds.set_height(std::max(bounds_at_start_.height() + | 87 bounds.set_height(std::max(bounds_at_start_.height() + |
| 84 mouse_location_at_start_.y() - mouse_location.y(), 0)); | 88 mouse_location_at_start_.y() - mouse_location.y(), 0)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 96 | 100 |
| 97 if (ResizingTop(sides_resized_)) { | 101 if (ResizingTop(sides_resized_)) { |
| 98 bounds.set_y(bounds_at_start_.y() - | 102 bounds.set_y(bounds_at_start_.y() - |
| 99 (bounds.height() - bounds_at_start_.height())); | 103 (bounds.height() - bounds_at_start_.height())); |
| 100 } | 104 } |
| 101 | 105 |
| 102 if (bounds != resizing_panel_->GetBounds()) | 106 if (bounds != resizing_panel_->GetBounds()) |
| 103 panel_manager_->OnPanelResizedByMouse(resizing_panel_, bounds); | 107 panel_manager_->OnPanelResizedByMouse(resizing_panel_, bounds); |
| 104 } | 108 } |
| 105 | 109 |
| 106 void PanelResizeController::EndResizing(bool cancelled) { | 110 Panel* PanelResizeController::EndResizing(bool cancelled) { |
| 107 DCHECK(IsResizing()); | 111 DCHECK(IsResizing()); |
| 108 | 112 |
| 109 if (cancelled) { | 113 if (cancelled) { |
| 110 panel_manager_->OnPanelResizedByMouse(resizing_panel_, | 114 panel_manager_->OnPanelResizedByMouse(resizing_panel_, |
| 111 bounds_at_start_); | 115 bounds_at_start_); |
| 112 } | 116 } |
| 113 | 117 |
| 114 // Do a thorough cleanup. | 118 // Do a thorough cleanup. |
| 119 resizing_panel_->SetPreviewMode(false); |
| 120 Panel* resized_panel = resizing_panel_; |
| 115 resizing_panel_ = NULL; | 121 resizing_panel_ = NULL; |
| 116 sides_resized_ = panel::RESIZE_NONE; | 122 sides_resized_ = panel::RESIZE_NONE; |
| 117 bounds_at_start_ = gfx::Rect(); | 123 bounds_at_start_ = gfx::Rect(); |
| 118 mouse_location_at_start_ = gfx::Point(); | 124 mouse_location_at_start_ = gfx::Point(); |
| 125 return resized_panel; |
| 119 } | 126 } |
| 120 | 127 |
| 121 void PanelResizeController::OnPanelClosed(Panel* panel) { | 128 void PanelResizeController::OnPanelClosed(Panel* panel) { |
| 122 if (!resizing_panel_) | 129 if (!resizing_panel_) |
| 123 return; | 130 return; |
| 124 | 131 |
| 125 // If the resizing panel is closed, abort the resize operation. | 132 // If the resizing panel is closed, abort the resize operation. |
| 126 if (resizing_panel_ == panel) | 133 if (resizing_panel_ == panel) |
| 127 EndResizing(false); | 134 EndResizing(false); |
| 128 } | 135 } |
| OLD | NEW |