Bug 674370 - Make browser windows (and other document-like windows) zoom on creation on OS X 10.7. r=mstange,dao sr=bzbarsky

This commit is contained in:
Cameron McCormack 2012-02-17 14:47:39 +11:00
parent 8d23f9b616
commit 407103f6cc
12 changed files with 112 additions and 27 deletions

View File

@ -90,6 +90,7 @@
lightweightthemes="true"
lightweightthemesfooter="browser-bottombox"
windowtype="navigator:browser"
macanimationtype="document"
screenX="4" screenY="4"
browsingmode="normal"
persist="screenX screenY width height sizemode">

View File

@ -3816,7 +3816,7 @@ SessionStoreService.prototype = {
argString.data = "";
// Build feature string
let features = "chrome,dialog=no,all";
let features = "chrome,dialog=no,macsuppressanimation,all";
let winState = aState.windows[0];
WINDOW_ATTRIBUTES.forEach(function(aFeature) {
// Use !isNaN as an easy way to ignore sizemode and check for numbers

View File

@ -51,6 +51,7 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&window.title;"
windowtype="devtools:scratchpad"
macanimationtype="document"
screenX="4" screenY="4"
width="640" height="480"
persist="screenX screenY width height sizemode">

View File

@ -47,7 +47,7 @@ interface nsIDocShellTreeItem;
* containing an embedded Gecko web browser.
*/
[scriptable, uuid(BA434C60-9D52-11d3-AFB0-00A024FFC08C)]
[scriptable, uuid(E8C414C4-DC38-4BA3-AB4E-EC4CBBE22907)]
interface nsIWebBrowserChrome : nsISupports
{
const unsigned long STATUS_SCRIPT = 0x00000001;
@ -75,43 +75,47 @@ interface nsIWebBrowserChrome : nsISupports
/**
* Definitions for the chrome flags
*/
const unsigned long CHROME_DEFAULT = 0x00000001;
const unsigned long CHROME_WINDOW_BORDERS = 0x00000002;
const unsigned long CHROME_WINDOW_CLOSE = 0x00000004;
const unsigned long CHROME_WINDOW_RESIZE = 0x00000008;
const unsigned long CHROME_MENUBAR = 0x00000010;
const unsigned long CHROME_TOOLBAR = 0x00000020;
const unsigned long CHROME_LOCATIONBAR = 0x00000040;
const unsigned long CHROME_STATUSBAR = 0x00000080;
const unsigned long CHROME_PERSONAL_TOOLBAR = 0x00000100;
const unsigned long CHROME_SCROLLBARS = 0x00000200;
const unsigned long CHROME_TITLEBAR = 0x00000400;
const unsigned long CHROME_EXTRA = 0x00000800;
const unsigned long CHROME_DEFAULT = 0x00000001;
const unsigned long CHROME_WINDOW_BORDERS = 0x00000002;
const unsigned long CHROME_WINDOW_CLOSE = 0x00000004;
const unsigned long CHROME_WINDOW_RESIZE = 0x00000008;
const unsigned long CHROME_MENUBAR = 0x00000010;
const unsigned long CHROME_TOOLBAR = 0x00000020;
const unsigned long CHROME_LOCATIONBAR = 0x00000040;
const unsigned long CHROME_STATUSBAR = 0x00000080;
const unsigned long CHROME_PERSONAL_TOOLBAR = 0x00000100;
const unsigned long CHROME_SCROLLBARS = 0x00000200;
const unsigned long CHROME_TITLEBAR = 0x00000400;
const unsigned long CHROME_EXTRA = 0x00000800;
// createBrowserWindow specific flags
const unsigned long CHROME_WITH_SIZE = 0x00001000;
const unsigned long CHROME_WITH_POSITION = 0x00002000;
const unsigned long CHROME_WITH_SIZE = 0x00001000;
const unsigned long CHROME_WITH_POSITION = 0x00002000;
// special cases
const unsigned long CHROME_WINDOW_MIN = 0x00004000;
const unsigned long CHROME_WINDOW_POPUP = 0x00008000;
const unsigned long CHROME_WINDOW_MIN = 0x00004000;
const unsigned long CHROME_WINDOW_POPUP = 0x00008000;
const unsigned long CHROME_WINDOW_RAISED = 0x02000000;
const unsigned long CHROME_WINDOW_LOWERED = 0x04000000;
const unsigned long CHROME_CENTER_SCREEN = 0x08000000;
// Prevents new window animations on Mac OS X Lion. Ignored on other
// platforms.
const unsigned long CHROME_MAC_SUPPRESS_ANIMATION = 0x01000000;
const unsigned long CHROME_WINDOW_RAISED = 0x02000000;
const unsigned long CHROME_WINDOW_LOWERED = 0x04000000;
const unsigned long CHROME_CENTER_SCREEN = 0x08000000;
// Make the new window dependent on the parent. This flag is only
// meaningful if CHROME_OPENAS_CHROME is set; content windows should not be
// dependent.
const unsigned long CHROME_DEPENDENT = 0x10000000;
const unsigned long CHROME_DEPENDENT = 0x10000000;
// Note: The modal style bit just affects the way the window looks and does
// mean it's actually modal.
const unsigned long CHROME_MODAL = 0x20000000;
const unsigned long CHROME_OPENAS_DIALOG = 0x40000000;
const unsigned long CHROME_OPENAS_CHROME = 0x80000000;
const unsigned long CHROME_MODAL = 0x20000000;
const unsigned long CHROME_OPENAS_DIALOG = 0x40000000;
const unsigned long CHROME_OPENAS_CHROME = 0x80000000;
const unsigned long CHROME_ALL = 0x00000ffe;
const unsigned long CHROME_ALL = 0x00000ffe;
/**
* The chrome flags for this browser chrome. The implementation should

View File

@ -1527,6 +1527,9 @@ PRUint32 nsWindowWatcher::CalculateChromeFlags(const char *aFeatures,
else if (WinHasOption(aFeatures, "alwaysRaised", 0, nsnull))
chromeFlags |= nsIWebBrowserChrome::CHROME_WINDOW_RAISED;
chromeFlags |= WinHasOption(aFeatures, "macsuppressanimation", 0, nsnull) ?
nsIWebBrowserChrome::CHROME_MAC_SUPPRESS_ANIMATION : 0;
chromeFlags |= WinHasOption(aFeatures, "chrome", 0, nsnull) ?
nsIWebBrowserChrome::CHROME_OPENAS_CHROME : 0;
chromeFlags |= WinHasOption(aFeatures, "extrachrome", 0, nsnull) ?

View File

@ -197,6 +197,21 @@ typedef struct _nsCocoaWindowList {
- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
@end
#if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
enum {
NSWindowAnimationBehaviorDefault = 0,
NSWindowAnimationBehaviorNone = 2,
NSWindowAnimationBehaviorDocumentWindow = 3,
NSWindowAnimationBehaviorUtilityWindow = 4,
NSWindowAnimationBehaviorAlertPanel = 5
};
typedef NSInteger NSWindowAnimationBehavior;
@interface NSWindow (LionWindowFeatures)
- (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
@end
#endif
class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
{
private:
@ -266,6 +281,7 @@ public:
virtual void SetTransparencyMode(nsTransparencyMode aMode);
NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle);
virtual void SetShowsToolbarButton(bool aShow);
virtual void SetWindowAnimationType(WindowAnimationType aType);
NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive);
virtual void SetDrawsInTitlebar(bool aState);
virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
@ -335,12 +351,16 @@ protected:
PRInt32 mShadowStyle;
NSUInteger mWindowFilter;
WindowAnimationType mAnimationType;
bool mWindowMadeHere; // true if we created the window, false for embedding
bool mSheetNeedsShow; // if this is a sheet, are we waiting to be shown?
// this is used for sibling sheet contention only
bool mFullScreen;
bool mModal;
bool mIsAnimationSuppressed;
bool mInReportMoveEvent; // true if in a call to ReportMoveEvent().
PRInt32 mNumModalDescendents;

View File

@ -135,10 +135,12 @@ nsCocoaWindow::nsCocoaWindow()
, mPopupContentView(nil)
, mShadowStyle(NS_STYLE_WINDOW_SHADOW_DEFAULT)
, mWindowFilter(0)
, mAnimationType(nsIWidget::eGenericWindowAnimation)
, mWindowMadeHere(false)
, mSheetNeedsShow(false)
, mFullScreen(false)
, mModal(false)
, mIsAnimationSuppressed(false)
, mInReportMoveEvent(false)
, mNumModalDescendents(0)
{
@ -304,6 +306,8 @@ nsresult nsCocoaWindow::Create(nsIWidget *aParent,
return CreatePopupContentView(newBounds, aHandleEventFunction, aContext);
}
mIsAnimationSuppressed = aInitData->mIsAnimationSuppressed;
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
@ -745,6 +749,26 @@ NS_IMETHODIMP nsCocoaWindow::Show(bool bState)
}
else {
NS_OBJC_BEGIN_TRY_LOGONLY_BLOCK;
if (mWindowType == eWindowType_toplevel &&
[mWindow respondsToSelector:@selector(setAnimationBehavior:)]) {
NSWindowAnimationBehavior behavior;
if (mIsAnimationSuppressed) {
behavior = NSWindowAnimationBehaviorNone;
} else {
switch (mAnimationType) {
case nsIWidget::eDocumentWindowAnimation:
behavior = NSWindowAnimationBehaviorDocumentWindow;
break;
default:
NS_NOTREACHED("unexpected mAnimationType value");
// fall through
case nsIWidget::eGenericWindowAnimation:
behavior = NSWindowAnimationBehaviorDefault;
break;
}
}
[mWindow setAnimationBehavior:behavior];
}
[mWindow makeKeyAndOrderFront:nil];
NS_OBJC_END_TRY_LOGONLY_BLOCK;
SendSetZLevelEvent();
@ -1618,6 +1642,11 @@ void nsCocoaWindow::SetShowsToolbarButton(bool aShow)
NS_OBJC_END_TRY_ABORT_BLOCK;
}
void nsCocoaWindow::SetWindowAnimationType(nsIWidget::WindowAnimationType aType)
{
mAnimationType = aType;
}
NS_IMETHODIMP nsCocoaWindow::SetWindowTitlebarColor(nscolor aColor, bool aActive)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;

View File

@ -1017,6 +1017,20 @@ class nsIWidget : public nsISupports {
*/
virtual void SetShowsToolbarButton(bool aShow) = 0;
enum WindowAnimationType {
eGenericWindowAnimation,
eDocumentWindowAnimation
};
/**
* Sets the kind of top-level window animation this widget should have. On
* Mac OS X, this causes a particular kind of animation to be shown when the
* window is first made visible.
*
* Ignored on child widgets and on non-Mac platforms.
*/
virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;
/**
* Hide window chrome (borders, buttons) for this widget.
*

View File

@ -133,7 +133,8 @@ struct nsWidgetInitData {
mUnicode(true),
mRTL(false),
mNoAutoHide(false),
mIsDragPopup(false)
mIsDragPopup(false),
mIsAnimationSuppressed(false)
{
}
@ -148,6 +149,8 @@ struct nsWidgetInitData {
bool mRTL;
bool mNoAutoHide; // true for noautohide panels
bool mIsDragPopup; // true for drag feedback panels
bool mIsAnimationSuppressed; // true if window creation animation is
// suppressed, e.g. for session restore
};
#endif // nsWidgetInitData_h__

View File

@ -123,6 +123,7 @@ public:
virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects);
NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle);
virtual void SetShowsToolbarButton(bool aShow) {}
virtual void SetWindowAnimationType(WindowAnimationType aType) {}
NS_IMETHOD HideWindowChrome(bool aShouldHide);
NS_IMETHOD MakeFullScreen(bool aFullScreen);
virtual nsDeviceContext* GetDeviceContext();

View File

@ -308,6 +308,9 @@ nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent,
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_POPUP)
widgetInitData.mWindowType = eWindowType_popup;
if (aChromeMask & nsIWebBrowserChrome::CHROME_MAC_SUPPRESS_ANIMATION)
widgetInitData.mIsAnimationSuppressed = true;
#ifdef XP_MACOSX
// Mac OS X sheet support
// Adding CHROME_OPENAS_CHROME to sheetMask makes modal windows opened from

View File

@ -1412,6 +1412,12 @@ void nsXULWindow::SyncAttributesToWidget()
if (NS_SUCCEEDED(rv)) {
mWindow->SetShowsToolbarButton(attr.LowerCaseEqualsLiteral("true"));
}
// "macanimationtype" attribute
rv = windowElement->GetAttribute(NS_LITERAL_STRING("macanimationtype"), attr);
if (NS_SUCCEEDED(rv) && attr.EqualsLiteral("document")) {
mWindow->SetWindowAnimationType(nsIWidget::eDocumentWindowAnimation);
}
}
NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()