Commit 2141ba19 authored by jennb@chromium.org's avatar jennb@chromium.org

Enable user resizing for docked Panels (GTK and Mac).

Docked panels can be resized from all edges except the bottom.
Jianli will create a separate patch for Windows docked Panels.

This patch depends on http://codereview.chromium.org/10020057/ landing first.

BUG=None
TEST=Updated plus manual verification of resizing docked panels.

Review URL: http://codereview.chromium.org/10066032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132296 0039d316-1c4b-4281-b951-d872f2087c98
parent 08265d3f
...@@ -29,8 +29,8 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CheckDetachedPanelProperties) { ...@@ -29,8 +29,8 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, CheckDetachedPanelProperties) {
EXPECT_TRUE(panel1->draggable()); EXPECT_TRUE(panel1->draggable());
EXPECT_TRUE(panel2->draggable()); EXPECT_TRUE(panel2->draggable());
EXPECT_TRUE(panel1->CanResizeByMouse()); EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel1->CanResizeByMouse());
EXPECT_TRUE(panel2->CanResizeByMouse()); EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel2->CanResizeByMouse());
Panel::AttentionMode expected_attention_mode = Panel::AttentionMode expected_attention_mode =
static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION | static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
......
...@@ -163,14 +163,14 @@ void DetachedPanelStrip::EndDraggingPanelWithinStrip(Panel* panel, ...@@ -163,14 +163,14 @@ void DetachedPanelStrip::EndDraggingPanelWithinStrip(Panel* panel,
bool aborted) { bool aborted) {
} }
bool DetachedPanelStrip::CanResizePanel(const Panel* panel) const { panel::Resizability DetachedPanelStrip::GetPanelResizability(
return true; const Panel* panel) const {
return panel::RESIZABLE_ALL_SIDES;
} }
void DetachedPanelStrip::OnPanelResizedByMouse(Panel* panel, void DetachedPanelStrip::OnPanelResizedByMouse(Panel* panel,
const gfx::Rect& new_bounds) { const gfx::Rect& new_bounds) {
DCHECK_EQ(this, panel->panel_strip()); DCHECK_EQ(this, panel->panel_strip());
panel->set_restored_size(new_bounds.size());
panel->SetPanelBoundsInstantly(new_bounds); panel->SetPanelBoundsInstantly(new_bounds);
} }
......
...@@ -34,7 +34,8 @@ class DetachedPanelStrip : public PanelStrip { ...@@ -34,7 +34,8 @@ class DetachedPanelStrip : public PanelStrip {
virtual void ResizePanelWindow( virtual void ResizePanelWindow(
Panel* panel, Panel* panel,
const gfx::Size& preferred_window_size) OVERRIDE; const gfx::Size& preferred_window_size) OVERRIDE;
virtual bool CanResizePanel(const Panel* panel) const OVERRIDE; virtual panel::Resizability GetPanelResizability(
const Panel* panel) const OVERRIDE;
virtual void OnPanelResizedByMouse(Panel* panel, virtual void OnPanelResizedByMouse(Panel* panel,
const gfx::Rect& new_bounds) OVERRIDE; const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnPanelAttentionStateChanged(Panel* panel) OVERRIDE; virtual void OnPanelAttentionStateChanged(Panel* panel) OVERRIDE;
......
...@@ -434,14 +434,17 @@ void DockedPanelStrip::EndDraggingPanelWithinStrip(Panel* panel, bool aborted) { ...@@ -434,14 +434,17 @@ void DockedPanelStrip::EndDraggingPanelWithinStrip(Panel* panel, bool aborted) {
RefreshLayout(); RefreshLayout();
} }
bool DockedPanelStrip::CanResizePanel(const Panel* panel) const { panel::Resizability DockedPanelStrip::GetPanelResizability(
return false; const Panel* panel) const {
return (!panel->has_temporary_layout() &&
panel->expansion_state() == Panel::EXPANDED) ?
panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM : panel::NOT_RESIZABLE;
} }
void DockedPanelStrip::OnPanelResizedByMouse(Panel* panel, void DockedPanelStrip::OnPanelResizedByMouse(Panel* panel,
const gfx::Rect& new_bounds) { const gfx::Rect& new_bounds) {
DCHECK_EQ(this, panel->panel_strip()); DCHECK_EQ(this, panel->panel_strip());
NOTREACHED(); panel->SetPanelBoundsInstantly(new_bounds);
} }
...@@ -886,5 +889,5 @@ void DockedPanelStrip::UpdatePanelOnStripChange(Panel* panel) { ...@@ -886,5 +889,5 @@ void DockedPanelStrip::UpdatePanelOnStripChange(Panel* panel) {
panel->set_attention_mode(Panel::USE_PANEL_ATTENTION); panel->set_attention_mode(Panel::USE_PANEL_ATTENTION);
panel->SetAppIconVisibility(true); panel->SetAppIconVisibility(true);
panel->SetAlwaysOnTop(true); panel->SetAlwaysOnTop(true);
panel->EnableResizeByMouse(false); panel->EnableResizeByMouse(true);
} }
...@@ -50,7 +50,8 @@ class DockedPanelStrip : public PanelStrip, ...@@ -50,7 +50,8 @@ class DockedPanelStrip : public PanelStrip,
virtual void ResizePanelWindow( virtual void ResizePanelWindow(
Panel* panel, Panel* panel,
const gfx::Size& preferred_window_size) OVERRIDE; const gfx::Size& preferred_window_size) OVERRIDE;
virtual bool CanResizePanel(const Panel* panel) const OVERRIDE; virtual panel::Resizability GetPanelResizability(
const Panel* panel) const OVERRIDE;
virtual void OnPanelResizedByMouse(Panel* panel, virtual void OnPanelResizedByMouse(Panel* panel,
const gfx::Rect& new_bounds) OVERRIDE; const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnPanelAttentionStateChanged(Panel* panel) OVERRIDE; virtual void OnPanelAttentionStateChanged(Panel* panel) OVERRIDE;
......
...@@ -231,8 +231,9 @@ void OverflowPanelStrip::EndDraggingPanelWithinStrip(Panel* panel, ...@@ -231,8 +231,9 @@ void OverflowPanelStrip::EndDraggingPanelWithinStrip(Panel* panel,
NOTREACHED(); NOTREACHED();
} }
bool OverflowPanelStrip::CanResizePanel(const Panel* panel) const { panel::Resizability OverflowPanelStrip::GetPanelResizability(
return false; const Panel* panel) const {
return panel::NOT_RESIZABLE;
} }
void OverflowPanelStrip::OnPanelResizedByMouse(Panel* panel, void OverflowPanelStrip::OnPanelResizedByMouse(Panel* panel,
......
...@@ -39,7 +39,8 @@ class OverflowPanelStrip : public PanelStrip, ...@@ -39,7 +39,8 @@ class OverflowPanelStrip : public PanelStrip,
virtual void ResizePanelWindow( virtual void ResizePanelWindow(
Panel* panel, Panel* panel,
const gfx::Size& preferred_window_size) OVERRIDE; const gfx::Size& preferred_window_size) OVERRIDE;
virtual bool CanResizePanel(const Panel* panel) const OVERRIDE; virtual panel::Resizability GetPanelResizability(
const Panel* panel) const OVERRIDE;
virtual void OnPanelResizedByMouse(Panel* panel, virtual void OnPanelResizedByMouse(Panel* panel,
const gfx::Rect& new_bounds) OVERRIDE; const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnPanelAttentionStateChanged(Panel* panel) OVERRIDE; virtual void OnPanelAttentionStateChanged(Panel* panel) OVERRIDE;
......
...@@ -85,8 +85,11 @@ bool Panel::draggable() const { ...@@ -85,8 +85,11 @@ bool Panel::draggable() const {
return panel_strip_ && panel_strip_->CanDragPanel(this); return panel_strip_ && panel_strip_->CanDragPanel(this);
} }
bool Panel::CanResizeByMouse() const { panel::Resizability Panel::CanResizeByMouse() const {
return panel_strip_ && panel_strip_->CanResizePanel(this); if (!panel_strip_)
return panel::NOT_RESIZABLE;
return panel_strip_->GetPanelResizability(this);
} }
const Extension* Panel::GetExtension() const { const Extension* Panel::GetExtension() const {
......
...@@ -259,7 +259,7 @@ class Panel : public BrowserWindow, ...@@ -259,7 +259,7 @@ class Panel : public BrowserWindow,
bool draggable() const; bool draggable() const;
bool CanResizeByMouse() const; panel::Resizability CanResizeByMouse() const;
AttentionMode attention_mode() const { return attention_mode_; } AttentionMode attention_mode() const { return attention_mode_; }
void set_attention_mode(AttentionMode attention_mode) { void set_attention_mode(AttentionMode attention_mode) {
......
...@@ -1005,5 +1005,6 @@ bool PanelBrowserFrameView::EnsureSettingsMenuCreated() { ...@@ -1005,5 +1005,6 @@ bool PanelBrowserFrameView::EnsureSettingsMenuCreated() {
} }
bool PanelBrowserFrameView::CanResize() const { bool PanelBrowserFrameView::CanResize() const {
return panel_browser_view_->panel()->CanResizeByMouse(); return panel_browser_view_->panel()->CanResizeByMouse() !=
panel::NOT_RESIZABLE;
} }
...@@ -200,10 +200,11 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { ...@@ -200,10 +200,11 @@ class PanelBrowserViewTest : public BasePanelBrowserTest {
// Test minimizing/restoring an individual panel. // Test minimizing/restoring an individual panel.
EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
int initial_height = panel1->GetBounds().height(); int initial_height = panel1->GetBounds().height();
int titlebar_height = frame_view1->NonClientTopBorderHeight();
panel1->SetExpansionState(Panel::MINIMIZED); panel1->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
int titlebar_height = frame_view1->NonClientTopBorderHeight();
EXPECT_LT(panel1->GetBounds().height(), titlebar_height); EXPECT_LT(panel1->GetBounds().height(), titlebar_height);
EXPECT_GT(panel1->GetBounds().height(), 0); EXPECT_GT(panel1->GetBounds().height(), 0);
EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom()); EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom());
......
...@@ -109,8 +109,24 @@ bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) { ...@@ -109,8 +109,24 @@ bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) {
// This method is used by the base class to detect when the cursor has // This method is used by the base class to detect when the cursor has
// hit the window edge in order to change the cursor to a resize cursor // hit the window edge in order to change the cursor to a resize cursor
// and to detect when to initiate a resize drag. // and to detect when to initiate a resize drag.
return panel_->CanResizeByMouse() ? panel::Resizability resizability = panel_->CanResizeByMouse();
BrowserWindowGtk::GetWindowEdge(x, y, edge) : FALSE; if (panel::NOT_RESIZABLE == resizability)
return false;
if (!BrowserWindowGtk::GetWindowEdge(x, y, edge))
return FALSE;
// Special handling if bottom edge is not resizable.
if (panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM == resizability) {
if (*edge == GDK_WINDOW_EDGE_SOUTH)
return FALSE;
if (*edge == GDK_WINDOW_EDGE_SOUTH_WEST)
*edge = GDK_WINDOW_EDGE_WEST;
else if (*edge == GDK_WINDOW_EDGE_SOUTH_EAST)
*edge = GDK_WINDOW_EDGE_EAST;
}
return TRUE;
} }
void PanelBrowserWindowGtk::EnsureDragHelperCreated() { void PanelBrowserWindowGtk::EnsureDragHelperCreated() {
......
...@@ -29,6 +29,13 @@ namespace panel { ...@@ -29,6 +29,13 @@ namespace panel {
RESIZE_TOP_LEFT RESIZE_TOP_LEFT
}; };
// Ways a panel can be resized.
enum Resizability {
NOT_RESIZABLE,
RESIZABLE_ALL_SIDES,
RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM
};
} // namespace panel } // namespace panel
#endif // CHROME_BROWSER_UI_PANELS_PANEL_CONSTANTS_H_ #endif // CHROME_BROWSER_UI_PANELS_PANEL_CONSTANTS_H_
...@@ -187,7 +187,7 @@ void PanelManager::EndDragging(bool cancelled) { ...@@ -187,7 +187,7 @@ void PanelManager::EndDragging(bool cancelled) {
void PanelManager::StartResizingByMouse(Panel* panel, void PanelManager::StartResizingByMouse(Panel* panel,
const gfx::Point& mouse_location, const gfx::Point& mouse_location,
panel::ResizingSides sides) { panel::ResizingSides sides) {
if (panel->panel_strip() && panel->panel_strip()->CanResizePanel(panel) && if (panel->CanResizeByMouse() != panel::NOT_RESIZABLE &&
sides != panel::RESIZE_NONE) sides != panel::RESIZE_NONE)
resize_controller_->StartResizing(panel, mouse_location, sides); resize_controller_->StartResizing(panel, mouse_location, sides);
} }
...@@ -198,8 +198,11 @@ void PanelManager::ResizeByMouse(const gfx::Point& mouse_location) { ...@@ -198,8 +198,11 @@ void PanelManager::ResizeByMouse(const gfx::Point& mouse_location) {
} }
void PanelManager::EndResizingByMouse(bool cancelled) { void PanelManager::EndResizingByMouse(bool cancelled) {
if (resize_controller_->IsResizing()) if (resize_controller_->IsResizing()) {
resize_controller_->EndResizing(cancelled); Panel* resized_panel = resize_controller_->EndResizing(cancelled);
if (!cancelled && resized_panel->panel_strip())
resized_panel->panel_strip()->RefreshLayout();
}
} }
void PanelManager::OnPanelExpansionStateChanged(Panel* panel) { void PanelManager::OnPanelExpansionStateChanged(Panel* panel) {
...@@ -239,9 +242,9 @@ void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { ...@@ -239,9 +242,9 @@ void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) {
void PanelManager::OnPanelResizedByMouse(Panel* panel, void PanelManager::OnPanelResizedByMouse(Panel* panel,
const gfx::Rect& new_bounds) { const gfx::Rect& new_bounds) {
panel->set_restored_size(new_bounds.size());
panel->panel_strip()->OnPanelResizedByMouse(panel, new_bounds); panel->panel_strip()->OnPanelResizedByMouse(panel, new_bounds);
panel->SetAutoResizable(false); panel->SetAutoResizable(false);
} }
void PanelManager::MovePanelToStrip( void PanelManager::MovePanelToStrip(
......
...@@ -250,10 +250,13 @@ IN_PROC_BROWSER_TEST_F(PanelOverflowBrowserTest, CheckPanelProperties) { ...@@ -250,10 +250,13 @@ IN_PROC_BROWSER_TEST_F(PanelOverflowBrowserTest, CheckPanelProperties) {
EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel3->attention_mode()); EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel3->attention_mode());
EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel4->attention_mode()); EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel4->attention_mode());
EXPECT_FALSE(panel1->CanResizeByMouse()); EXPECT_EQ(panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM,
EXPECT_FALSE(panel2->CanResizeByMouse()); panel1->CanResizeByMouse());
EXPECT_FALSE(panel3->CanResizeByMouse()); EXPECT_EQ(panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM,
EXPECT_FALSE(panel4->CanResizeByMouse()); panel2->CanResizeByMouse());
EXPECT_EQ(panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM,
panel3->CanResizeByMouse());
EXPECT_EQ(panel::NOT_RESIZABLE, panel4->CanResizeByMouse());
// Make sure last panel really did overflow. // Make sure last panel really did overflow.
WaitForLayoutModeChanged(panel4, PanelStrip::IN_OVERFLOW); WaitForLayoutModeChanged(panel4, PanelStrip::IN_OVERFLOW);
......
...@@ -27,23 +27,86 @@ class PanelResizeBrowserTest : public BasePanelBrowserTest { ...@@ -27,23 +27,86 @@ class PanelResizeBrowserTest : public BasePanelBrowserTest {
} }
}; };
IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelsAreNotResizable) { IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) {
PanelManager* panel_manager = PanelManager::GetInstance(); PanelManager* panel_manager = PanelManager::GetInstance();
Panel* panel = CreatePanel("Panel"); Panel* panel = CreatePanel("Panel");
EXPECT_FALSE(panel->CanResizeByMouse()); EXPECT_EQ(panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM,
panel->CanResizeByMouse());
gfx::Rect bounds = panel->GetBounds(); gfx::Rect bounds = panel->GetBounds();
// Try resizing by the top left corner; verify resize won't work. // Try resizing by the top left corner.
gfx::Point mouse_location = bounds.origin(); gfx::Point mouse_location = bounds.origin();
panel_manager->StartResizingByMouse(panel, mouse_location, panel_manager->StartResizingByMouse(panel, mouse_location,
panel::RESIZE_TOP_LEFT); panel::RESIZE_TOP_LEFT);
mouse_location.Offset(-20, -20); mouse_location.Offset(-20, -10);
panel_manager->ResizeByMouse(mouse_location);
bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10));
bounds.Offset(-20, -10);
EXPECT_EQ(bounds, panel->GetBounds());
panel_manager->EndResizingByMouse(false);
EXPECT_EQ(bounds, panel->GetBounds());
// Try resizing by the top.
mouse_location = bounds.origin().Add(gfx::Point(10, 1));
panel_manager->StartResizingByMouse(panel, mouse_location,
panel::RESIZE_TOP);
mouse_location.Offset(5, -10);
panel_manager->ResizeByMouse(mouse_location);
bounds.set_height(bounds.height() + 10);
bounds.Offset(0, -10);
EXPECT_EQ(bounds, panel->GetBounds());
panel_manager->EndResizingByMouse(false);
EXPECT_EQ(bounds, panel->GetBounds());
// Try resizing by the left side.
mouse_location = bounds.origin().Add(gfx::Point(1, 30));
panel_manager->StartResizingByMouse(panel, mouse_location,
panel::RESIZE_LEFT);
mouse_location.Offset(-5, 25);
panel_manager->ResizeByMouse(mouse_location);
bounds.set_width(bounds.width() + 5);
bounds.Offset(-5, 0);
EXPECT_EQ(bounds, panel->GetBounds());
panel_manager->EndResizingByMouse(false);
EXPECT_EQ(bounds, panel->GetBounds());
// Try resizing by the top right side.
mouse_location = bounds.origin().Add(gfx::Point(bounds.width() - 1, 2));
panel_manager->StartResizingByMouse(panel, mouse_location,
panel::RESIZE_TOP_RIGHT);
mouse_location.Offset(30, 20);
panel_manager->ResizeByMouse(mouse_location);
bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20));
bounds.Offset(0, 20);
EXPECT_EQ(bounds, panel->GetBounds());
panel_manager->EndResizingByMouse(false);
WaitForBoundsAnimationFinished(panel);
bounds.Offset(-30, 0); // Layout of panel adjusted in docked strip.
EXPECT_EQ(bounds, panel->GetBounds());
// Try resizing by the right side.
mouse_location = bounds.origin().Add(gfx::Point(bounds.width() - 1, 30));
panel_manager->StartResizingByMouse(panel, mouse_location,
panel::RESIZE_RIGHT);
mouse_location.Offset(5, 25);
panel_manager->ResizeByMouse(mouse_location); panel_manager->ResizeByMouse(mouse_location);
bounds.set_width(bounds.width() + 5);
EXPECT_EQ(bounds, panel->GetBounds()); EXPECT_EQ(bounds, panel->GetBounds());
panel_manager->EndResizingByMouse(false); panel_manager->EndResizingByMouse(false);
WaitForBoundsAnimationFinished(panel);
bounds.Offset(-5, 0); // Layout of panel adjusted in docked strip.
EXPECT_EQ(bounds, panel->GetBounds()); EXPECT_EQ(bounds, panel->GetBounds());
// Try resizing by the bottom side; verify resize won't work. // Try resizing by the bottom side; verify resize won't work.
...@@ -57,6 +120,17 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelsAreNotResizable) { ...@@ -57,6 +120,17 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelsAreNotResizable) {
panel_manager->EndResizingByMouse(false); panel_manager->EndResizingByMouse(false);
EXPECT_EQ(bounds, panel->GetBounds()); EXPECT_EQ(bounds, panel->GetBounds());
// Try resizing by the bottom left corner; verify resize won't work.
mouse_location = bounds.origin().Add(gfx::Point(1, bounds.height() - 1));
panel_manager->StartResizingByMouse(panel, mouse_location,
panel::RESIZE_BOTTOM_LEFT);
mouse_location.Offset(-10, 15);
panel_manager->ResizeByMouse(mouse_location);
EXPECT_EQ(bounds, panel->GetBounds());
panel_manager->EndResizingByMouse(false);
EXPECT_EQ(bounds, panel->GetBounds());
// Try resizing by the bottom right corner; verify resize won't work. // Try resizing by the bottom right corner; verify resize won't work.
mouse_location = bounds.origin().Add( mouse_location = bounds.origin().Add(
gfx::Point(bounds.width() - 2, bounds.height())); gfx::Point(bounds.width() - 2, bounds.height()));
...@@ -76,7 +150,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanel) { ...@@ -76,7 +150,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanel) {
PanelManager* panel_manager = PanelManager::GetInstance(); PanelManager* panel_manager = PanelManager::GetInstance();
Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
EXPECT_TRUE(panel->CanResizeByMouse()); EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse());
gfx::Rect bounds = panel->GetBounds(); gfx::Rect bounds = panel->GetBounds();
...@@ -143,7 +217,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanelToClampSize) { ...@@ -143,7 +217,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanelToClampSize) {
PanelManager* panel_manager = PanelManager::GetInstance(); PanelManager* panel_manager = PanelManager::GetInstance();
Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
EXPECT_TRUE(panel->CanResizeByMouse()); EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse());
gfx::Rect bounds = panel->GetBounds(); gfx::Rect bounds = panel->GetBounds();
...@@ -245,7 +319,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeAndCancel) { ...@@ -245,7 +319,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeAndCancel) {
Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
PanelResizeController* resize_controller = panel_manager->resize_controller(); PanelResizeController* resize_controller = panel_manager->resize_controller();
EXPECT_TRUE(panel->CanResizeByMouse()); EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse());
gfx::Rect original_bounds = panel->GetBounds(); gfx::Rect original_bounds = panel->GetBounds();
......
...@@ -5,11 +5,8 @@ ...@@ -5,11 +5,8 @@
#include "chrome/browser/ui/panels/panel_resize_controller.h" #include "chrome/browser/ui/panels/panel_resize_controller.h"
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/ui/panels/detached_panel_strip.h"
#include "chrome/browser/ui/panels/docked_panel_strip.h"
#include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h" #include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/panel_strip.h"
namespace { namespace {
static bool ResizingLeft(panel::ResizingSides sides) { static bool ResizingLeft(panel::ResizingSides sides) {
...@@ -47,21 +44,27 @@ void PanelResizeController::StartResizing(Panel* panel, ...@@ -47,21 +44,27 @@ void PanelResizeController::StartResizing(Panel* panel,
const gfx::Point& mouse_location, const gfx::Point& mouse_location,
panel::ResizingSides sides) { panel::ResizingSides sides) {
DCHECK(!IsResizing()); DCHECK(!IsResizing());
DCHECK(panel->panel_strip() &&
panel->panel_strip()->CanResizePanel(panel));
DCHECK_NE(panel::RESIZE_NONE, sides); DCHECK_NE(panel::RESIZE_NONE, sides);
panel::Resizability resizability = panel->CanResizeByMouse();
DCHECK_NE(panel::NOT_RESIZABLE, resizability);
if (panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM == resizability &&
ResizingBottom(sides)) {
DLOG(WARNING) << "Resizing from bottom not allowed. Is this a test?";
return;
}
mouse_location_at_start_ = mouse_location; mouse_location_at_start_ = mouse_location;
bounds_at_start_ = panel->GetBounds(); bounds_at_start_ = panel->GetBounds();
sides_resized_ = sides; sides_resized_ = sides;
resizing_panel_ = panel; resizing_panel_ = panel;
resizing_panel_->SetPreviewMode(true);
} }
void PanelResizeController::Resize(const gfx::Point& mouse_location) { void PanelResizeController::Resize(const gfx::Point& mouse_location) {
DCHECK(IsResizing()); DCHECK(IsResizing());
if (resizing_panel_->panel_strip() == NULL || panel::Resizability resizability = resizing_panel_->CanResizeByMouse();
!resizing_panel_->panel_strip()->CanResizePanel(resizing_panel_)) { if (panel::NOT_RESIZABLE == resizability) {
EndResizing(false); EndResizing(false);
return; return;
} }
...@@ -72,6 +75,7 @@ void PanelResizeController::Resize(const gfx::Point& mouse_location) { ...@@ -72,6 +75,7 @@ void PanelResizeController::Resize(const gfx::Point& mouse_location) {
mouse_location.x() - mouse_location_at_start_.x(), 0)); mouse_location.x() - mouse_location_at_start_.x(), 0));
} }
if (ResizingBottom(sides_resized_)) { if (ResizingBottom(sides_resized_)) {
DCHECK_EQ(panel::RESIZABLE_ALL_SIDES, resizability);
bounds.set_height(std::max(bounds_at_start_.height() + bounds.set_height(std::max(bounds_at_start_.height() +
mouse_location.y() - mouse_location_at_start_.y(), 0)); mouse_location.y() - mouse_location_at_start_.y(), 0));
} }
...@@ -103,7 +107,7 @@ void PanelResizeController::Resize(const gfx::Point& mouse_location) { ...@@ -103,7 +107,7 @@ void PanelResizeController::Resize(const gfx::Point& mouse_location) {
panel_manager_->OnPanelResizedByMouse(resizing_panel_, bounds); panel_manager_->OnPanelResizedByMouse(resizing_panel_, bounds);
} }
void PanelResizeController::EndResizing(bool cancelled) { Panel* PanelResizeController::EndResizing(bool cancelled) {
DCHECK(IsResizing()); DCHECK(IsResizing());
if (cancelled) { if (cancelled) {
...@@ -112,10 +116,13 @@ void PanelResizeController::EndResizing(bool cancelled) { ...@@ -112,10 +116,13 @@ void PanelResizeController::EndResizing(bool cancelled) {
} }
// Do a thorough cleanup. // Do a thorough cleanup.
resizing_panel_->SetPreviewMode(false);
Panel* resized_panel = resizing_panel_;
resizing_panel_ = NULL; resizing_panel_ = NULL;
sides_resized_ = panel::RESIZE_NONE; sides_resized_ = panel::RESIZE_NONE;
bounds_at_start_ = gfx::Rect(); bounds_at_start_ = gfx::Rect();
mouse_location_at_start_ = gfx::Point(); mouse_location_at_start_ = gfx::Point();
return resized_panel;
} }
void PanelResizeController::OnPanelClosed(Panel* panel) { void PanelResizeController::OnPanelClosed(Panel* panel) {
......
...@@ -29,7 +29,9 @@ class PanelResizeController { ...@@ -29,7 +29,9 @@ class PanelResizeController {
const gfx::Point& mouse_location, const gfx::Point& mouse_location,
panel::ResizingSides sides); panel::ResizingSides sides);
void Resize(const gfx::Point& mouse_location); void Resize(const gfx::Point& mouse_location);
void EndResizing(bool cancelled);
// Returns the panel that was resized.
Panel* EndResizing(bool cancelled);
// Asynchronous confirmation of panel having been closed. // Asynchronous confirmation of panel having been closed.
void OnPanelClosed(Panel* panel); void OnPanelClosed(Panel* panel);
......
...@@ -63,8 +63,10 @@ class PanelStrip { ...@@ -63,8 +63,10 @@ class PanelStrip {
virtual void ResizePanelWindow(Panel* panel, virtual void ResizePanelWindow(Panel* panel,
const gfx::Size& preferred_window_size) = 0; const gfx::Size& preferred_window_size) = 0;
// Returns true if |panel| can be resized by the user when in this strip. // Returns the sides from which |panel| can be resized by the user
virtual bool CanResizePanel(const Panel* panel) const = 0; // if |panel| is resizable in this strip.
virtual panel::Resizability GetPanelResizability(
const Panel* panel) const = 0;
// Change panel's bounds and take care of all possible side effects // Change panel's bounds and take care of all possible side effects
// in ths strip as a result of the panel being resized by the user. // in ths strip as a result of the panel being resized by the user.
......
...@@ -172,7 +172,8 @@ enum { ...@@ -172,7 +172,8 @@ enum {
// |pointInWindow| is in window coordinates. // |pointInWindow| is in window coordinates.
- (panel::ResizingSides)edgeHitTest:(NSPoint)pointInWindow { - (panel::ResizingSides)edgeHitTest:(NSPoint)pointInWindow {
DCHECK(panel_->CanResizeByMouse()); panel::Resizability resizability = panel_->CanResizeByMouse();
DCHECK_NE(panel::NOT_RESIZABLE, resizability);
NSPoint point = [self convertPoint:pointInWindow fromView:nil]; NSPoint point = [self convertPoint:pointInWindow fromView:nil];
BOOL flipped = [self isFlipped]; BOOL flipped = [self isFlipped];
...@@ -182,16 +183,20 @@ enum { ...@@ -182,16 +183,20 @@ enum {
return panel::RESIZE_RIGHT; return panel::RESIZE_RIGHT;
if (NSMouseInRect(point, topCursorRect_, flipped)) if (NSMouseInRect(point, topCursorRect_, flipped))
return panel::RESIZE_TOP; return panel::RESIZE_TOP;
if (NSMouseInRect(point, bottomCursorRect_, flipped))
return panel::RESIZE_BOTTOM;
if (NSMouseInRect(point, topLeftCursorRect_, flipped)) if (NSMouseInRect(point, topLeftCursorRect_, flipped))
return panel::RESIZE_TOP_LEFT; return panel::RESIZE_TOP_LEFT;
if (NSMouseInRect(point, topRightCursorRect_, flipped)) if (NSMouseInRect(point, topRightCursorRect_, flipped))
return panel::RESIZE_TOP_RIGHT; return panel::RESIZE_TOP_RIGHT;
if (NSMouseInRect(point, bottomLeftCursorRect_, flipped))
return panel::RESIZE_BOTTOM_LEFT; // Bottom edge is not always resizable.
if (NSMouseInRect(point, bottomRightCursorRect_, flipped)) if (panel::RESIZABLE_ALL_SIDES == resizability) {
return panel::RESIZE_BOTTOM_RIGHT; if (NSMouseInRect(point, bottomCursorRect_, flipped))
return panel::RESIZE_BOTTOM;
if (NSMouseInRect(point, bottomLeftCursorRect_, flipped))
return panel::RESIZE_BOTTOM_LEFT;
if (NSMouseInRect(point, bottomRightCursorRect_, flipped))
return panel::RESIZE_BOTTOM_RIGHT;
}
return panel::RESIZE_NONE; return panel::RESIZE_NONE;
} }
...@@ -204,7 +209,7 @@ enum { ...@@ -204,7 +209,7 @@ enum {
// |point| is in coordinate system of the parent view. // |point| is in coordinate system of the parent view.
- (NSView*)hitTest:(NSPoint)point { - (NSView*)hitTest:(NSPoint)point {
// If panel is not resizable, let the mouse events fall through. // If panel is not resizable, let the mouse events fall through.
if (!panel_->CanResizeByMouse()) if (panel::NOT_RESIZABLE == panel_->CanResizeByMouse())
return nil; return nil;
NSPoint pointInWindow = [[self superview] convertPoint:point toView:nil]; NSPoint pointInWindow = [[self superview] convertPoint:point toView:nil];
...@@ -214,7 +219,7 @@ enum { ...@@ -214,7 +219,7 @@ enum {
- (void)mouseDown:(NSEvent*)event { - (void)mouseDown:(NSEvent*)event {
// If the panel is not resizable, hitTest should have failed and no mouse // If the panel is not resizable, hitTest should have failed and no mouse
// events should have came here. // events should have came here.
DCHECK(panel_->CanResizeByMouse()); DCHECK_NE(panel::NOT_RESIZABLE, panel_->CanResizeByMouse());
[self prepareForDrag:event]; [self prepareForDrag:event];
} }
...@@ -365,7 +370,8 @@ enum { ...@@ -365,7 +370,8 @@ enum {
} }
- (void)resetCursorRects { - (void)resetCursorRects {
if(!panel_->CanResizeByMouse()) panel::Resizability resizability = panel_->CanResizeByMouse();
if (panel::NOT_RESIZABLE == resizability)
return; return;
NSRect bounds = [self bounds]; NSRect bounds = [self bounds];
...@@ -389,11 +395,6 @@ enum { ...@@ -389,11 +395,6 @@ enum {
kWidthOfMouseResizeArea); kWidthOfMouseResizeArea);
[self addCursorRect:topCursorRect_ cursor:northSouthCursor_]; [self addCursorRect:topCursorRect_ cursor:northSouthCursor_];
// Bottom horizontal edge.
bottomCursorRect_ = topCursorRect_;
bottomCursorRect_.origin.y = NSMinY(bounds);
[self addCursorRect:bottomCursorRect_ cursor:northSouthCursor_];
// Top left corner. // Top left corner.
topLeftCursorRect_ = NSMakeRect(NSMinX(bounds), topLeftCursorRect_ = NSMakeRect(NSMinX(bounds),
NSMaxY(bounds) - kWidthOfMouseResizeArea, NSMaxY(bounds) - kWidthOfMouseResizeArea,
...@@ -406,6 +407,15 @@ enum { ...@@ -406,6 +407,15 @@ enum {
topRightCursorRect_.origin.x = NSMaxX(bounds) - kWidthOfMouseResizeArea; topRightCursorRect_.origin.x = NSMaxX(bounds) - kWidthOfMouseResizeArea;
[self addCursorRect:topRightCursorRect_ cursor:northEastSouthWestCursor_]; [self addCursorRect:topRightCursorRect_ cursor:northEastSouthWestCursor_];
// Bottom edge is not always resizable.
if (panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM == resizability)
return;
// Bottom horizontal edge.
bottomCursorRect_ = topCursorRect_;
bottomCursorRect_.origin.y = NSMinY(bounds);
[self addCursorRect:bottomCursorRect_ cursor:northSouthCursor_];
// Bottom right corner. // Bottom right corner.
bottomRightCursorRect_ = topRightCursorRect_; bottomRightCursorRect_ = topRightCursorRect_;
bottomRightCursorRect_.origin.y = NSMinY(bounds); bottomRightCursorRect_.origin.y = NSMinY(bounds);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment