From e0450ccba0753c4d278c6bb244245bb18c151a8b Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Tue, 15 Aug 2000 20:01:20 +0000 Subject: [PATCH] treat width/height=* features to mean size of parent window. compatibility with Nav 4. bug 30394. --- dom/src/base/nsGlobalWindow.cpp | 134 +++++++++++++++----------------- dom/src/base/nsGlobalWindow.h | 2 +- 2 files changed, 65 insertions(+), 71 deletions(-) diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 1810db3a679a..079bcbcb5401 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -2895,9 +2895,9 @@ NS_IMETHODIMP GlobalWindowImpl::OpenInternal(JSContext* cx, jsval* argv, if (windowIsNew) { PRBool present = PR_FALSE; PRInt32 temp; - - if (!((temp = WinHasOption(options, "outerWidth", &present)) || present) && - !((temp = WinHasOption(options, "outerHeight", &present)) || present)) { + + if (!((temp = WinHasOption(options, "outerWidth", 0, &present)) || present) && + !((temp = WinHasOption(options, "outerHeight", 0, &present)) || present)) { nsCOMPtr newTreeOwner; newDocShellItem->GetTreeOwner(getter_AddRefs(newTreeOwner)); @@ -3040,29 +3040,29 @@ PRUint32 GlobalWindowImpl::CalculateChromeFlags(char* aFeatures, PRBool aDialog) chromeFlags = nsIWebBrowserChrome::windowBordersOn; - if(aDialog && WinHasOption(aFeatures, "all", &presenceFlag)) + if(aDialog && WinHasOption(aFeatures, "all", 0, &presenceFlag)) chromeFlags = nsIWebBrowserChrome::allChrome; /* Next, allow explicitly named options to override the initial settings */ - chromeFlags |= WinHasOption(aFeatures, "titlebar", &presenceFlag) ? + chromeFlags |= WinHasOption(aFeatures, "titlebar", 0, &presenceFlag) ? nsIWebBrowserChrome::titlebarOn : 0; - chromeFlags |= WinHasOption(aFeatures, "close", &presenceFlag) ? + chromeFlags |= WinHasOption(aFeatures, "close", 0, &presenceFlag) ? nsIWebBrowserChrome::windowCloseOn : 0; - chromeFlags |= WinHasOption(aFeatures, "toolbar", &presenceFlag) ? + chromeFlags |= WinHasOption(aFeatures, "toolbar", 0, &presenceFlag) ? nsIWebBrowserChrome::toolBarOn : 0; - chromeFlags |= WinHasOption(aFeatures, "location", &presenceFlag) ? + chromeFlags |= WinHasOption(aFeatures, "location", 0, &presenceFlag) ? nsIWebBrowserChrome::locationBarOn : 0; - chromeFlags |= (WinHasOption(aFeatures, "directories", &presenceFlag) || - WinHasOption(aFeatures, "personalbar", &presenceFlag)) ? + chromeFlags |= (WinHasOption(aFeatures, "directories", 0, &presenceFlag) || + WinHasOption(aFeatures, "personalbar", 0, &presenceFlag)) ? nsIWebBrowserChrome::personalToolBarOn : 0; - chromeFlags |= WinHasOption(aFeatures, "status", &presenceFlag) ? + chromeFlags |= WinHasOption(aFeatures, "status", 0, &presenceFlag) ? nsIWebBrowserChrome::statusBarOn : 0; - chromeFlags |= WinHasOption(aFeatures, "menubar", &presenceFlag) ? + chromeFlags |= WinHasOption(aFeatures, "menubar", 0, &presenceFlag) ? nsIWebBrowserChrome::menuBarOn : 0; - chromeFlags |= WinHasOption(aFeatures, "scrollbars", &presenceFlag) ? + chromeFlags |= WinHasOption(aFeatures, "scrollbars", 0, &presenceFlag) ? nsIWebBrowserChrome::scrollbarsOn : 0; - chromeFlags |= WinHasOption(aFeatures, "resizable", &presenceFlag) ? + chromeFlags |= WinHasOption(aFeatures, "resizable", 0, &presenceFlag) ? nsIWebBrowserChrome::windowResizeOn : 0; /* OK. @@ -3085,21 +3085,21 @@ PRUint32 GlobalWindowImpl::CalculateChromeFlags(char* aFeatures, PRBool aDialog) with the features that are more operating hints than appearance instructions. (Note modality implies dependence.) */ - if ( WinHasOption(aFeatures, "alwaysLowered", nsnull) || - WinHasOption(aFeatures, "z-lock", nsnull) ) + if (WinHasOption(aFeatures, "alwaysLowered", 0, nsnull) || + WinHasOption(aFeatures, "z-lock", 0, nsnull)) chromeFlags |= nsIWebBrowserChrome::windowLowered; - else if (WinHasOption(aFeatures, "alwaysRaised", nsnull)) + else if (WinHasOption(aFeatures, "alwaysRaised", 0, nsnull)) chromeFlags |= nsIWebBrowserChrome::windowRaised; - chromeFlags |= WinHasOption(aFeatures, "chrome", nsnull) ? + chromeFlags |= WinHasOption(aFeatures, "chrome", 0, nsnull) ? nsIWebBrowserChrome::openAsChrome : 0; - chromeFlags |= WinHasOption(aFeatures, "centerscreen", nsnull) ? + chromeFlags |= WinHasOption(aFeatures, "centerscreen", 0, nsnull) ? nsIWebBrowserChrome::centerScreen : 0; - chromeFlags |= WinHasOption(aFeatures, "dependent", nsnull) ? + chromeFlags |= WinHasOption(aFeatures, "dependent", 0, nsnull) ? nsIWebBrowserChrome::dependent : 0; - chromeFlags |= WinHasOption(aFeatures, "modal", nsnull) ? + chromeFlags |= WinHasOption(aFeatures, "modal", 0, nsnull) ? (nsIWebBrowserChrome::modal | nsIWebBrowserChrome::dependent) : 0; - chromeFlags |= WinHasOption(aFeatures, "dialog", nsnull) ? + chromeFlags |= WinHasOption(aFeatures, "dialog", 0, nsnull) ? nsIWebBrowserChrome::openAsDialog : 0; /* and dialogs need to have the last word. assume dialogs are dialogs, @@ -3113,7 +3113,6 @@ PRUint32 GlobalWindowImpl::CalculateChromeFlags(char* aFeatures, PRBool aDialog) /* missing chromeFlags->copy_history - chromeFlags->scrollbars */ /* Allow disabling of commands only if there is no menubar */ @@ -3170,9 +3169,9 @@ NS_IMETHODIMP GlobalWindowImpl::SizeOpenedDocShellItem(nsIDocShellTreeItem *aDoc PRBool positionSpecified = PR_FALSE; PRInt32 temp; - if((temp = WinHasOption(aFeatures, "left", &present)) || present) + if ((temp = WinHasOption(aFeatures, "left", 0, &present)) != 0 || present) chromeX = temp; - else if((temp = WinHasOption(aFeatures, "screenX", &present)) || present) + else if ((temp = WinHasOption(aFeatures, "screenX", 0, &present)) != 0 || present) chromeX = temp; if(present) @@ -3180,9 +3179,9 @@ NS_IMETHODIMP GlobalWindowImpl::SizeOpenedDocShellItem(nsIDocShellTreeItem *aDoc present = PR_FALSE; - if((temp = WinHasOption(aFeatures, "top", &present)) || present) + if ((temp = WinHasOption(aFeatures, "top", 0, &present)) != 0 || present) chromeY = temp; - else if((temp = WinHasOption(aFeatures, "screenY", &present)) || present) + else if ((temp = WinHasOption(aFeatures, "screenY", 0, &present)) != 0 || present) chromeY = temp; if(present) @@ -3194,48 +3193,40 @@ NS_IMETHODIMP GlobalWindowImpl::SizeOpenedDocShellItem(nsIDocShellTreeItem *aDoc PRBool sizeSpecified = PR_FALSE; - if((temp = WinHasOption(aFeatures, "outerWidth", &present)) || present) - { + if ((temp = WinHasOption(aFeatures, "outerWidth", chromeCX, &present)) != 0 || present) { chromeCX = temp; sizeChrome = PR_TRUE; sizeSpecified = PR_TRUE; - } + } present = PR_FALSE; - if((temp = WinHasOption(aFeatures, "outerHeight", &present)) || present) - { + if((temp = WinHasOption(aFeatures, "outerHeight", chromeCY, &present)) != 0 || present) { chromeCY = temp; sizeChrome = PR_TRUE; sizeSpecified = PR_TRUE; - } + } // We haven't switched to chrome sizing so we need to get the content area - if(!sizeChrome) - { - if((temp = WinHasOption(aFeatures, "width", &present)) || present) - { - contentCX = temp; - sizeSpecified = PR_TRUE; - } - else if((temp = WinHasOption(aFeatures, "innerWidth", &present)) || present) - { - contentCX = temp; - sizeSpecified = PR_TRUE; - } + if(!sizeChrome) { - if((temp = WinHasOption(aFeatures, "height", &present)) || present) - { - contentCY = temp; + if ((temp = WinHasOption(aFeatures, "width", chromeCX, &present)) != 0 || present) { + contentCX = temp; sizeSpecified = PR_TRUE; - } - else if((temp = WinHasOption(aFeatures, "innerHeight", &present)) || present) - { - contentCY = temp; + } else if ((temp = WinHasOption(aFeatures, "innerWidth", chromeCX, &present)) || present) { + contentCX = temp; sizeSpecified = PR_TRUE; - } } + if ((temp = WinHasOption(aFeatures, "height", chromeCY, &present)) != 0 || present) { + contentCY = temp; + sizeSpecified = PR_TRUE; + } else if ((temp = WinHasOption(aFeatures, "innerHeight", chromeCY, &present)) != 0 || present) { + contentCY = temp; + sizeSpecified = PR_TRUE; + } + } + nsresult res; PRBool enabled; PRInt32 screenWidth = 0, screenHeight = 0; @@ -3352,41 +3343,44 @@ NS_IMETHODIMP GlobalWindowImpl::CheckWindowName(JSContext* cx, nsString& aName) return NS_OK; } -PRInt32 GlobalWindowImpl::WinHasOption(char *options, const char *name, PRBool* aPresenceFlag) +PRInt32 GlobalWindowImpl::WinHasOption(char *aOptions, const char *aName, PRInt32 aDefault, PRBool* aPresenceFlag) { - if(!options) + if(!aOptions) return 0; char *comma, *equal; PRInt32 found = 0; - while(PR_TRUE) - { - while (nsCRT::IsAsciiSpace(*options)) - options++; + while(PR_TRUE) { + while (nsCRT::IsAsciiSpace(*aOptions)) + aOptions++; - comma = strchr(options, ','); + comma = strchr(aOptions, ','); if(comma) *comma = '\0'; - equal = strchr(options, '='); + equal = strchr(aOptions, '='); if(equal) *equal = '\0'; - if(nsCRT::strcasecmp(options, name) == 0) - { - if(aPresenceFlag) + if (nsCRT::strcasecmp(aOptions, aName) == 0) { + if (aPresenceFlag) *aPresenceFlag = PR_TRUE; - if(!equal || (nsCRT::strcasecmp(equal + 1, "yes") == 0)) - found = 1; + if (equal) + if (*(equal+1) == '*') + found = aDefault; + else if (nsCRT::strcasecmp(equal+1, "yes") == 0) + found = 1; + else + found = atoi(equal+1); else - found = atoi(equal + 1); - } + found = 1; + } if(equal) *equal = '='; if(comma) *comma = ','; if(found || !comma) break; - options = comma + 1; - } + aOptions = comma + 1; + } return found; } diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index 2978e9c5ec5b..6f54f2aecb62 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -187,7 +187,7 @@ protected: NS_IMETHOD ReadyOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem, nsIDOMWindow** aDOMWindow); NS_IMETHOD CheckWindowName(JSContext* cx, nsString& aName); - PRInt32 WinHasOption(char* options, const char* name, PRBool* aPresenceFlag); + PRInt32 WinHasOption(char* aOptions, const char* aName, PRInt32 aDefault, PRBool* aPresenceFlag); static void CloseWindow(nsISupports* aWindow); // Timeout Functions