Commit d7634c21 authored by jianli@chromium.org's avatar jianli@chromium.org

Add Panel::SetPanelBoundsInstantly for all platforms.

This is needed for panel overflow handling. PanelOverflowStrip (to be added in another patch) will control the hover animation for all overflow panels so that they can be synchronized well. SetPanelBoundsInstantly tells the panel to change bounds instantly without animation.

BUG=none
TEST=new test

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112576 0039d316-1c4b-4281-b951-d872f2087c98
parent 27129e9e
......@@ -38,6 +38,7 @@ class NativePanel {
virtual void ShowPanelInactive() = 0;
virtual gfx::Rect GetPanelBounds() const = 0;
virtual void SetPanelBounds(const gfx::Rect& bounds) = 0;
virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) = 0;
virtual void ClosePanel() = 0;
virtual void ActivatePanel() = 0;
virtual void DeactivatePanel() = 0;
......
......@@ -78,6 +78,18 @@ void Panel::SetPanelBounds(const gfx::Rect& bounds) {
content::NotificationService::NoDetails());
}
void Panel::SetPanelBoundsInstantly(const gfx::Rect& bounds) {
if (expansion_state_ == Panel::EXPANDED)
restored_size_ = bounds.size();
native_panel_->SetPanelBoundsInstantly(bounds);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PANEL_CHANGED_BOUNDS,
content::Source<Panel>(this),
content::NotificationService::NoDetails());
}
void Panel::SetAutoResizable(bool resizable) {
if (auto_resizable_ == resizable)
return;
......
......@@ -221,6 +221,9 @@ class Panel : public BrowserWindow,
// not allowed for Panel.
void SetPanelBounds(const gfx::Rect& bounds);
// Updates the panel bounds instantly without any animation.
void SetPanelBoundsInstantly(const gfx::Rect& bounds);
// Sets whether the panel will auto resize according to its content.
void SetAutoResizable(bool resizable);
......
......@@ -106,12 +106,17 @@ bool PanelBrowserView::CanMaximize() const {
}
void PanelBrowserView::SetBounds(const gfx::Rect& bounds) {
SetBoundsInternal(bounds, true);
}
void PanelBrowserView::SetBoundsInternal(const gfx::Rect& bounds,
bool animate) {
if (bounds_ == bounds)
return;
bounds_ = bounds;
// No animation if the panel is being dragged.
if (mouse_dragging_state_ == DRAGGING_STARTED) {
if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) {
::BrowserView::SetBounds(bounds);
return;
}
......@@ -231,7 +236,11 @@ gfx::Rect PanelBrowserView::GetPanelBounds() const {
}
void PanelBrowserView::SetPanelBounds(const gfx::Rect& bounds) {
SetBounds(bounds);
SetBoundsInternal(bounds, true);
}
void PanelBrowserView::SetPanelBoundsInstantly(const gfx::Rect& bounds) {
SetBoundsInternal(bounds, false);
}
void PanelBrowserView::ClosePanel() {
......
......@@ -79,6 +79,7 @@ class PanelBrowserView : public BrowserView,
virtual void ShowPanelInactive() OVERRIDE;
virtual gfx::Rect GetPanelBounds() const OVERRIDE;
virtual void SetPanelBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) OVERRIDE;
virtual void ClosePanel() OVERRIDE;
virtual void ActivatePanel() OVERRIDE;
virtual void DeactivatePanel() OVERRIDE;
......@@ -118,6 +119,8 @@ class PanelBrowserView : public BrowserView,
void StopDrawingAttention();
void SetBoundsInternal(const gfx::Rect& bounds, bool animate);
scoped_ptr<Panel> panel_;
gfx::Rect bounds_;
......
......@@ -32,6 +32,7 @@ class PanelBrowserWindowCocoa : public NativePanel,
virtual void ShowPanelInactive() OVERRIDE;
virtual gfx::Rect GetPanelBounds() const OVERRIDE;
virtual void SetPanelBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) OVERRIDE;
virtual void ClosePanel() OVERRIDE;
virtual void ActivatePanel() OVERRIDE;
virtual void DeactivatePanel() OVERRIDE;
......@@ -95,6 +96,8 @@ class PanelBrowserWindowCocoa : public NativePanel,
bool isClosed();
void setBoundsInternal(const gfx::Rect& bounds, bool animate);
scoped_ptr<Browser> browser_;
scoped_ptr<Panel> panel_;
......
......@@ -103,13 +103,22 @@ gfx::Rect PanelBrowserWindowCocoa::GetPanelBounds() const {
// |bounds| is the platform-independent screen coordinates, with (0,0) at
// top-left of the primary screen.
void PanelBrowserWindowCocoa::SetPanelBounds(const gfx::Rect& bounds) {
setBoundsInternal(bounds, true);
}
void PanelBrowserWindowCocoa::SetPanelBoundsInstantly(const gfx::Rect& bounds) {
setBoundsInternal(bounds, false);
}
void PanelBrowserWindowCocoa::setBoundsInternal(const gfx::Rect& bounds,
bool animate) {
if (bounds_ == bounds)
return;
bounds_ = bounds;
NSRect frame = ConvertCoordinatesToCocoa(bounds);
[controller_ setPanelFrame:frame];
[controller_ setPanelFrame:frame animate:animate];
}
void PanelBrowserWindowCocoa::ClosePanel() {
......
......@@ -244,10 +244,19 @@ gfx::Rect PanelBrowserWindowGtk::GetPanelBounds() const {
}
void PanelBrowserWindowGtk::SetPanelBounds(const gfx::Rect& bounds) {
SetBoundsInternal(bounds, true);
}
void PanelBrowserWindowGtk::SetPanelBoundsInstantly(const gfx::Rect& bounds) {
SetBoundsInternal(bounds, false);
}
void PanelBrowserWindowGtk::SetBoundsInternal(const gfx::Rect& bounds,
bool animate) {
if (bounds == bounds_)
return;
if (drag_widget_) {
if (drag_widget_ || !animate) {
DCHECK(!bounds_animator_.get() || !bounds_animator_->is_animating());
// If the current panel is being dragged, it should just move with the
// user drag, we should not animate.
......
......@@ -70,6 +70,7 @@ class PanelBrowserWindowGtk : public BrowserWindowGtk,
virtual void ShowPanelInactive() OVERRIDE;
virtual gfx::Rect GetPanelBounds() const OVERRIDE;
virtual void SetPanelBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) OVERRIDE;
virtual void ClosePanel() OVERRIDE;
virtual void ActivatePanel() OVERRIDE;
virtual void DeactivatePanel() OVERRIDE;
......@@ -118,6 +119,8 @@ class PanelBrowserWindowGtk : public BrowserWindowGtk,
void EndDrag(bool canceled);
void CleanupDragDrop();
void SetBoundsInternal(const gfx::Rect& bounds, bool animate);
GdkRectangle GetTitlebarRectForDrawAttention() const;
CHROMEGTK_CALLBACK_1(PanelBrowserWindowGtk, gboolean,
......
......@@ -882,6 +882,28 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_AutoResize) {
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AnimateBounds) {
Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100));
scoped_ptr<NativePanelTesting> panel_testing(
NativePanelTesting::Create(panel->native_panel()));
// Set bounds with animation.
gfx::Rect bounds = gfx::Rect(10, 20, 150, 160);
panel->SetPanelBounds(bounds);
EXPECT_TRUE(panel_testing->IsAnimatingBounds());
WaitForBoundsAnimationFinished(panel);
EXPECT_FALSE(panel_testing->IsAnimatingBounds());
EXPECT_EQ(bounds, panel->GetBounds());
// Set bounds without animation.
bounds = gfx::Rect(30, 40, 200, 220);
panel->SetPanelBoundsInstantly(bounds);
EXPECT_FALSE(panel_testing->IsAnimatingBounds());
EXPECT_EQ(bounds, panel->GetBounds());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) {
// Disable mouse watcher. We don't care about mouse movements in this test.
PanelManager* panel_manager = PanelManager::GetInstance();
......
......@@ -90,7 +90,9 @@ class PanelBrowserWindowCocoa;
// important in case of dragging a Panel when other Panels should 'slide out',
// indicating the potential drop slot.
// |frame| is in screen coordinates, same as [window frame].
- (void)setPanelFrame:(NSRect)frame;
// |animate| controls if the bounds animation is needed or not.
- (void)setPanelFrame:(NSRect)frame
animate:(BOOL)animate;
// Used by PanelTitlebarViewCocoa when user rearranges the Panels by dragging.
- (void)startDrag;
......
......@@ -405,7 +405,8 @@ enum {
windowShim_->panel()->manager()->Drag(deltaX);
}
- (void)setPanelFrame:(NSRect)frame {
- (void)setPanelFrame:(NSRect)frame
animate:(BOOL)animate {
// Setup the whole window as the tracking area so that we can get notified
// when the mouse enters or leaves the window. This will make us be able to
// show or hide settings button accordingly.
......@@ -421,7 +422,7 @@ enum {
[[[[self window] contentView] superview]
addTrackingArea:windowTrackingArea_.get()];
if (!animateOnBoundsChange_) {
if (!animateOnBoundsChange_ || !animate) {
[[self window] setFrame:frame display:YES animate:NO];
return;
}
......
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