add native resize animation support to nsIDOMChromeWindow. b=347452 r=mento r=jst sr=pav

This commit is contained in:
joshmoz@gmail.com 2007-04-05 17:11:41 -07:00
parent 55b69c6783
commit 087aa65283
9 changed files with 113 additions and 11 deletions

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* Johnny Stenback <jst@netscape.com> (original author)
* Josh Aas <josh@mozilla.com> (animation API)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -40,22 +41,26 @@
interface nsIBrowserDOMWindow;
[scriptable, uuid(445fa0fc-2151-4cb4-83d3-34c3e39453de)]
[scriptable, uuid(E3985A99-F9D6-4576-8EF8-9A5DCE42EFFA)]
interface nsIDOMChromeWindow : nsISupports
{
const unsigned short STATE_MAXIMIZED = 1;
const unsigned short STATE_MINIMIZED = 2;
const unsigned short STATE_NORMAL = 3;
attribute DOMString title;
readonly attribute unsigned short windowState;
const unsigned short RESIZE_ANIMATION_OFF = 0;
const unsigned short RESIZE_ANIMATION_SLIDE = 1;
attribute unsigned short animatedResize;
attribute DOMString title;
readonly attribute unsigned short windowState;
/**
* browserDOMWindow provides access to yet another layer of
* utility functions implemented by chrome script. It will be null
* for DOMWindows not corresponding to browsers.
*/
attribute nsIBrowserDOMWindow browserDOMWindow;
attribute nsIBrowserDOMWindow browserDOMWindow;
void getAttention();

View File

@ -7662,6 +7662,30 @@ nsGlobalChromeWindow::SetTitle(const nsAString& aTitle)
return nsdoc->SetTitle(aTitle);
}
// returns NS_ERROR_NOT_IMPLEMENTED if animation is not implemented on widget
// or platform
NS_IMETHODIMP
nsGlobalChromeWindow::SetAnimatedResize(PRUint16 aAnimation)
{
nsCOMPtr<nsIWidget> widget = GetMainWidget();
if (!widget)
return NS_ERROR_FAILURE;
return widget->SetAnimatedResize(aAnimation);
}
// returns NS_ERROR_NOT_IMPLEMENTED if animation is not implemented on widget
// or platform
NS_IMETHODIMP
nsGlobalChromeWindow::GetAnimatedResize(PRUint16* aAnimation)
{
nsCOMPtr<nsIWidget> widget = GetMainWidget();
if (!widget)
return NS_ERROR_FAILURE;
return widget->GetAnimatedResize(aAnimation);
}
NS_IMETHODIMP
nsGlobalChromeWindow::GetWindowState(PRUint16* aWindowState)
{

View File

@ -98,10 +98,10 @@ typedef nsEventStatus (*PR_CALLBACK EVENT_CALLBACK)(nsGUIEvent *event);
#define NS_NATIVE_PLUGIN_PORT_CG 101
#endif
// ebdf8ccf-ada9-457c-ad6c-88e1cb9d4498
// B3F10C8D-4C07-4B1E-A1CD-B38696426205
#define NS_IWIDGET_IID \
{ 0xebdf8ccf, 0xada9, 0x457c, \
{ 0xad, 0x6c, 0x88, 0xe1, 0xcb, 0x9d, 0x44, 0x98 } }
{ 0xB3F10C8D, 0x4C07, 0x4B1E, \
{ 0xA1, 0xCD, 0xB3, 0x86, 0x96, 0x42, 0x62, 0x05 } }
// Hide the native window systems real window type so as to avoid
@ -1035,6 +1035,24 @@ class nsIWidget : public nsISupports {
virtual gfxASurface *GetThebesSurface() = 0;
#endif
/**
* Set a flag that makes any window resizes use native window animation.
* Ignored on any OS that doesn't support native animation.
*
* @param aAnimate Whether or not you want resizes to be animated.
* @return NS_ERROR_NOT_IMPLEMENTED if not implemented on widget or platform
*/
NS_IMETHOD SetAnimatedResize(PRUint16 aAnimation) = 0;
/**
* Get a flag that controls native window animation.
* Ignored on any OS that doesn't support native animation.
*
* @param aAnimate Whether or not resizes are animated.
* @return NS_ERROR_NOT_IMPLEMENTED if not implemented on widget or platform
*/
NS_IMETHOD GetAnimatedResize(PRUint16* aAnimation) = 0;
protected:
// keep the list of children. We also keep track of our siblings.
// The ownership model is as follows: parent holds a strong ref to

View File

@ -258,6 +258,9 @@ public:
NS_IMETHOD GetAttention(PRInt32 aCycleCount);
NS_IMETHOD SetAnimatedResize(PRUint16 aAnimation);
NS_IMETHOD GetAnimatedResize(PRUint16* aAnimation);
// nsIPluginWidget
NS_IMETHOD GetPluginClipRect(nsRect& outClipRect, nsPoint& outOrigin, PRBool& outWidgetVisible);
NS_IMETHOD StartDrawPlugin();

View File

@ -1551,6 +1551,18 @@ NS_IMETHODIMP nsChildView::GetAttention(PRInt32 aCycleCount)
}
NS_IMETHODIMP nsChildView::SetAnimatedResize(PRUint16 aAnimation)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsChildView::GetAnimatedResize(PRUint16* aAnimation)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#pragma mark -

View File

@ -151,7 +151,9 @@ public:
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) ;
NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
NS_IMETHOD GetAttention(PRInt32 aCycleCount);
NS_IMETHOD SetAnimatedResize(PRUint16 aAnimation);
NS_IMETHOD GetAnimatedResize(PRUint16* aAnimation);
// be notified that a some form of drag event needs to go into Gecko
virtual PRBool DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers);
@ -170,9 +172,9 @@ protected:
WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG]
nsCOMPtr<nsIMenuBar> mMenuBar;
NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow it's attached to
nsChildView* mPopupContentView; // if this is a popup, this is its content widget
nsChildView* mPopupContentView; // if this is a popup, this is its content widget
PRUint16 mAnimation; // the type of animation we will use when resizing
PRPackedBool mIsResizing; // we originated the resize, prevent infinite recursion
PRPackedBool mWindowMadeHere; // true if we created the window, false for embedding
PRPackedBool mVisible; // Whether or not we're visible.

View File

@ -51,6 +51,8 @@
#include "nsIXULWindow.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIDOMChromeWindow.h"
#include "unistd.h"
// defined in nsMenuBarX.mm
extern NSMenu* sApplicationMenu; // Application menu shared by all menubars
@ -85,6 +87,7 @@ nsCocoaWindow::nsCocoaWindow()
, mDelegate(nil)
, mSheetWindowParent(nil)
, mPopupContentView(nil)
, mAnimation(nsIDOMChromeWindow::RESIZE_ANIMATION_OFF)
, mIsResizing(PR_FALSE)
, mWindowMadeHere(PR_FALSE)
, mVisible(PR_FALSE)
@ -735,7 +738,14 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRep
newFrame.size.height = newHeight;
StartResizing();
[mWindow setFrame:newFrame display:NO];
if (mAnimation == nsIDOMChromeWindow::RESIZE_ANIMATION_SLIDE) {
[[mWindow contentView] setHidden:YES];
[mWindow setFrame:newFrame display:YES animate:YES];
[[mWindow contentView] setHidden:NO];
}
else {
[mWindow setFrame:newFrame display:NO];
}
StopResizing();
}
@ -1032,6 +1042,20 @@ NS_IMETHODIMP nsCocoaWindow::GetAttention(PRInt32 aCycleCount)
}
NS_IMETHODIMP nsCocoaWindow::SetAnimatedResize(PRUint16 aAnimation)
{
mAnimation = aAnimation;
return NS_OK;
}
NS_IMETHODIMP nsCocoaWindow::GetAnimatedResize(PRUint16* aAnimation)
{
*aAnimation = mAnimation;
return NS_OK;
}
@implementation WindowDelegate

View File

@ -844,6 +844,18 @@ nsBaseWidget::SetIcon(const nsAString&)
return NS_OK;
}
NS_IMETHODIMP
nsBaseWidget::SetAnimatedResize(PRUint16 aAnimation)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsBaseWidget::GetAnimatedResize(PRUint16* aAnimation)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/**
* Modifies aFile to point at an icon file with the given name and suffix. The
* suffix may correspond to a file extension with leading '.' if appropriate.

View File

@ -131,6 +131,8 @@ public:
NS_IMETHOD GetAttention(PRInt32 aCycleCount);
NS_IMETHOD GetLastInputEventTime(PRUint32& aTime);
NS_IMETHOD SetIcon(const nsAString &anIconSpec);
NS_IMETHOD SetAnimatedResize(PRUint16 aAnimation);
NS_IMETHOD GetAnimatedResize(PRUint16* aAnimation);
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
virtual void FreeNativeData(void * data, PRUint32 aDataType) {}//~~~