hooking up window OS border control from JS/C++

This commit is contained in:
danm%netscape.com 1999-07-27 06:34:24 +00:00
Родитель d793008e33
Коммит 743f1947e6
22 изменённых файлов: 549 добавлений и 665 удалений

Просмотреть файл

@ -2122,6 +2122,10 @@ GlobalWindowImpl::CalculateChromeFlags(char *aFeatures) {
return NS_CHROME_ALL_CHROME;
PRBool presenceFlag = PR_FALSE;
// ((only) titlebars default to "on" if not mentioned)
chromeFlags |= WinHasOption(aFeatures, "titlebar", presenceFlag) ? NS_CHROME_TITLEBAR_ON : 0;
chromeFlags |= WinHasOption(aFeatures, "close", presenceFlag) ? NS_CHROME_WINDOW_CLOSE_ON : 0;
chromeFlags |= WinHasOption(aFeatures, "toolbar", presenceFlag) ? NS_CHROME_TOOL_BAR_ON : 0;
chromeFlags |= WinHasOption(aFeatures, "location", presenceFlag) ? NS_CHROME_LOCATION_BAR_ON : 0;
chromeFlags |= (WinHasOption(aFeatures, "directories", presenceFlag) | WinHasOption(aFeatures, "personalbar", presenceFlag))
@ -2130,7 +2134,13 @@ GlobalWindowImpl::CalculateChromeFlags(char *aFeatures) {
chromeFlags |= WinHasOption(aFeatures, "menubar", presenceFlag) ? NS_CHROME_MENU_BAR_ON : 0;
chromeFlags |= WinHasOption(aFeatures, "scrollbars", presenceFlag) ? NS_CHROME_SCROLLBARS_ON : 0;
chromeFlags |= WinHasOption(aFeatures, "resizable", presenceFlag) ? NS_CHROME_WINDOW_RESIZE_ON : 0;
chromeFlags |= NS_CHROME_WINDOW_CLOSE_ON;
// default to "on" if titlebar, closebox, or resizable aren't mentioned
if (!PL_strcasestr(aFeatures, "titlebar"))
chromeFlags |= NS_CHROME_TITLEBAR_ON;
if (!PL_strcasestr(aFeatures, "close"))
chromeFlags |= NS_CHROME_WINDOW_CLOSE_ON;
if (!PL_strcasestr(aFeatures, "resizable"))
chromeFlags |= NS_CHROME_WINDOW_RESIZE_ON;
// From this point onward, if the above features weren't specified at all,
// we will assume that all chrome is present.
@ -2157,9 +2167,6 @@ GlobalWindowImpl::CalculateChromeFlags(char *aFeatures) {
if (XP_STRCASESTR(aFeatures,"hotkeys")==NULL)
chromeFlags->disable_commands = FALSE;
}*/
/* If titlebar condition not specified, default to shown */
/*if (XP_STRCASESTR(aFeatures,"titlebar")==0)*/
chromeFlags |= NS_CHROME_TITLEBAR_ON;
/* XXX Add security check on z-ordering, modal, hide title, disable hotkeys */

Просмотреть файл

@ -834,8 +834,8 @@ nsEditorShell::CreateWindowWithURL(const char* urlStr)
if (NS_FAILED(rv) || !url)
goto done;
appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, getter_AddRefs(newWindow),
nsnull, nsnull, 615, 480);
appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, NS_CHROME_ALL_CHROME,
nsnull, 615, 480, getter_AddRefs(newWindow));
done:
/* Release the shell... */

Просмотреть файл

@ -834,8 +834,8 @@ nsEditorShell::CreateWindowWithURL(const char* urlStr)
if (NS_FAILED(rv) || !url)
goto done;
appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, getter_AddRefs(newWindow),
nsnull, nsnull, 615, 480);
appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, NS_CHROME_ALL_CHROME,
nsnull, 615, 480, getter_AddRefs(newWindow));
done:
/* Release the shell... */

Просмотреть файл

@ -24,6 +24,7 @@
/* rhp - for access to webshell */
#include "nsCOMPtr.h"
#include "nsIDOMWindow.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsIScriptGlobalObject.h"
@ -276,11 +277,11 @@ nsMessenger::Open3PaneWindow()
appShell->CreateTopLevelWindow(nsnull, // parent
url,
PR_TRUE,
getter_AddRefs(newWindow), // result widget
nsnull, // observer
NS_CHROME_ALL_CHROME,
nsnull, // callbacks
NS_SIZETOCONTENT, // width
NS_SIZETOCONTENT); // height
NS_SIZETOCONTENT, // width
NS_SIZETOCONTENT, // height
getter_AddRefs(newWindow)); // result widget
done:
NS_IF_RELEASE(url);
return NS_OK;

Просмотреть файл

@ -41,6 +41,7 @@ static NS_DEFINE_IID( kNetServiceCID, NS_NETSERVICE_CID );
#include "nsNeckoUtil.h"
#endif // NECKO
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
@ -182,11 +183,11 @@ nsPrefMigrationProgressDialog::CreateProfileProgressDialog()
rv = appShell->CreateTopLevelWindow( nsnull,
url,
PR_TRUE,
getter_AddRefs(newWindow),
nsnull,
NS_CHROME_ALL_CHROME,
this, // callbacks??
0,
0 );
0,
getter_AddRefs(newWindow));
if ( NS_SUCCEEDED( rv ) )
{

Просмотреть файл

@ -671,11 +671,29 @@ nsresult nsWindow::StandardWindowCreate(nsIWidget *aParent,
if (mWindowType == eWindowType_dialog) {
extendedStyle &= ~WS_EX_CLIENTEDGE;
} else if (mWindowType == eWindowType_popup) {
} else if (mWindowType == eWindowType_popup) {
extendedStyle = WS_EX_TOPMOST;
style = WS_POPUP;
mBorderlessParent = parent;
}
if (aInitData->mBorderStyle != eBorderStyle_all) {
if (aInitData->mBorderStyle == eBorderStyle_none ||
!(aInitData->mBorderStyle & eBorderStyle_title)) {
style &= ~WS_DLGFRAME;
style |= WS_POPUP;
}
if (aInitData->mBorderStyle == eBorderStyle_none ||
!(aInitData->mBorderStyle & eBorderStyle_close)) {
style &= ~WS_SYSMENU;
}
if (aInitData->mBorderStyle == eBorderStyle_none ||
!(aInitData->mBorderStyle & eBorderStyle_resizeh)) {
style &= ~WS_THICKFRAME;
style &= ~WS_MINIMIZEBOX;
style &= ~WS_MAXIMIZEBOX;
}
}
}
mHas3DBorder = (extendedStyle & WS_EX_CLIENTEDGE) > 0;

Просмотреть файл

@ -432,8 +432,9 @@ newWind(char* urlName)
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIWebShellWindow> newWindow;
appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, getter_AddRefs(newWindow),
nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT);
appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, NS_CHROME_ALL_CHROME,
nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(newWindow));
NS_RELEASE(url);
@ -500,10 +501,12 @@ nsBrowserAppCore::WalletEditor(nsIDOMWindow* aWin)
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aWin, &parent);
window = nsnull;
appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, &window,
nsnull, cb, 504, 436);
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
cb, 504, 436, &window);
if (window != nsnull) {
appShell->RunModalDialog(&window, nsnull, parent, nsnull, cb, 504, 436);
appShell->RunModalDialog(&window, parent, nsnull, NS_CHROME_ALL_CHROME,
cb, 504, 436);
NS_RELEASE(window);
}
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
@ -551,10 +554,12 @@ nsBrowserAppCore::SignonViewer(nsIDOMWindow* aWin)
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aWin, &parent);
window = nsnull;
appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, &window,
nsnull, cb, 504, 436);
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
cb, 504, 436, &window);
if (window != nsnull) {
appShell->RunModalDialog(&window, nsnull, parent, nsnull, cb, 504, 436);
appShell->RunModalDialog(&window, parent, nsnull, NS_CHROME_ALL_CHROME,
cb, 504, 436);
NS_RELEASE(window);
}
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
@ -601,11 +606,13 @@ nsBrowserAppCore::CookieViewer(nsIDOMWindow* aWin)
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aWin, &parent);
window = nsnull;
appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, &window,
nsnull, cb, 504, 436);
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
cb, 504, 436, &window);
if (window != nsnull) {
appShell->RunModalDialog(&window, nsnull, parent, nsnull, cb, 504, 436);
appShell->RunModalDialog(&window, parent, nsnull, NS_CHROME_ALL_CHROME,
cb, 504, 436);
NS_RELEASE(window);
}
@ -696,10 +703,12 @@ nsBrowserAppCore::WalletPreview(nsIDOMWindow* aWin, nsIDOMWindow* aForm)
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aWin, &parent);
window = nsnull;
appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, &window,
nsnull, cb, 504, 436);
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
cb, 504, 436, &window);
if (window != nsnull) {
appShell->RunModalDialog(&window, nsnull, parent, nsnull, cb, 504, 436);
appShell->RunModalDialog(&window, parent, nsnull, NS_CHROME_ALL_CHROME,
cb, 504, 436);
NS_RELEASE(window);
}
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
@ -1546,8 +1555,9 @@ nsBrowserAppCore::NewWindow()
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIWebShellWindow> newWindow;
appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, getter_AddRefs(newWindow),
nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT);
appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, NS_CHROME_ALL_CHROME,
nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(newWindow));
NS_RELEASE(url);
return NS_OK;
@ -1798,9 +1808,6 @@ nsBrowserAppCore::DoDialog()
{
// (adapted from nsToolkitCore)
nsresult rv;
nsIWebShellWindow *window;
window = nsnull;
nsCOMPtr<nsIURI> urlObj;
char * urlstr = "resource:/res/samples/Password.html";
@ -1824,9 +1831,9 @@ nsBrowserAppCore::DoDialog()
if (NS_FAILED(rv))
return rv;
rv = appShell->RunModalDialog(&window, urlObj, mWebShellWin, nsnull, nsnull, 300, 200);
if (NS_SUCCEEDED(rv))
NS_RELEASE(window);
rv = appShell->RunModalDialog(nsnull, mWebShellWin, urlObj,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
nsnull, 300, 200);
return rv;
}

Просмотреть файл

@ -33,6 +33,7 @@
#include "nsIURL.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#endif // NECKO
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsIWidget.h"
@ -167,8 +168,9 @@ nsToolkitCore::ShowDialog(const nsString& aUrl, nsIDOMWindow* aParent) {
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aParent, &parent);
window = nsnull;
appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, &window,
nsnull, nsnull, 615, 480);
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
nsnull, 615, 480, &window);
if (window != nsnull)
window->Show(PR_TRUE);
@ -201,8 +203,9 @@ nsToolkitCore::ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent) {
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aParent, &parent);
nsCOMPtr<nsIWebShellWindow> window;
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, getter_AddRefs(window),
nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT);
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, NS_CHROME_ALL_CHROME,
nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(window));
return rv;
}
@ -317,8 +320,9 @@ nsToolkitCore::ShowWindowWithArgs(const nsString& aUrl,
cb = nsDontQueryInterface<nsArgCallbacks>( new nsArgCallbacks( aArgs ) );
nsCOMPtr<nsIWebShellWindow> window;
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, getter_AddRefs(window),
nsnull, cb, NS_SIZETOCONTENT, NS_SIZETOCONTENT);
appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, NS_CHROME_ALL_CHROME,
cb, NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(window));
return rv;
}
@ -327,9 +331,6 @@ NS_IMETHODIMP
nsToolkitCore::ShowModalDialog(const nsString& aUrl, nsIDOMWindow* aParent) {
nsresult rv;
nsIWebShellWindow *window;
window = nsnull;
nsCOMPtr<nsIURI> urlObj;
#ifndef NECKO
@ -349,9 +350,9 @@ nsToolkitCore::ShowModalDialog(const nsString& aUrl, nsIDOMWindow* aParent) {
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aParent, &parent);
rv = appShell->RunModalDialog(&window, urlObj, parent, nsnull, nsnull, 615, 480);
if (NS_SUCCEEDED(rv))
NS_RELEASE(window);
rv = appShell->RunModalDialog(nsnull, parent, urlObj,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
nsnull, 615, 480);
return rv;
}

Просмотреть файл

@ -26,7 +26,6 @@
interface nsIWebShellWindow;
interface nsIURI;
interface nsIStreamObserver;
interface nsIXULWindowCallbacks;
interface nsICmdLineService;
@ -47,32 +46,104 @@ class nsIFactory;
interface nsIAppShellService : nsISupports
{
/**
* Required initialization routine.
* @param aCmdLineService is stored and passed to appshell components as
* they are initialized.
*/
void Initialize(in nsICmdLineService aCmdLineService);
/**
* Runs an application event loop: normally the main event pump which
* defines the lifetime of the application.
*/
void Run();
/**
* Required exit routine. Stops the event loop and cleanly shuts down
* the appshell components.
*/
void Shutdown();
/**
* Create a window.
* @param aParent the parent window. Can be null.
* @param aUrl the contents of the new window.
* @param aShowWindow the window remains invisible if PR_FALSE.
* @param aChromeMask chrome flags affecting the kind of OS border
* given to the window. see nsIBrowserWindow for
* bit/flag definitions.
* @param aCallbacks interface providing C++ hooks for window initialization
* before the window is made visible. Can be null.
* Deprecated.
* @param aInitialWidth width, in pixels, of the window. Width of window
* at creation. Can be overridden by the "width"
* tag in the XUL. Set to NS_SIZETOCONTENT to force
* the window to wrap to its contents.
* @param aInitialHeight like aInitialWidth, but subtly different.
* @param aResult the newly created window is returned here.
*/
void CreateTopLevelWindow(in nsIWebShellWindow aParent,
in nsIURI aUrl,
in boolean showWindow,
out nsIWebShellWindow aResult,
in nsIStreamObserver anObserver,
in PRUint32 aChromeMask,
in nsIXULWindowCallbacks aCallbacks,
in long aInitialWidth, in long aInitialHeight);
void CreateDialogWindow( in nsIWebShellWindow aParent,
in nsIURI aUrl,
in boolean showWindow,
out nsIWebShellWindow aResult,
in nsIStreamObserver anObserver,
in nsIXULWindowCallbacks aCallbacks,
in long aInitialWidth, in long aInitialHeight);
void RunModalDialog( out nsIWebShellWindow aWindow,
in nsIURI aUrl,
in long aInitialWidth, in long aInitialHeight,
out nsIWebShellWindow aResult);
/**
* Run a window modally.
* @param aWindow the window to run modally. If null or pointing to null,
* a new window is created. If aWindow != null, the window
* is returned from this method, but callers should use it
* carefully: it's been closed, and is therefore partially
* deconstructed. Note that all other parameters are ignored
* if an already created window is passed in.
* @param aParent the parent window. Can be null.
* @param aUrl the contents of the window.
* @param aChromeMask chrome flags affecting the kind of OS border
* given to the window. see nsIBrowserWindow for
* bit/flag definitions.
* @param aCallbacks interface providing C++ hooks for window initialization
* before the window is made visible. Deprecated.
* @param aInitialWidth width, in pixels, of the window. Width of window
* at creation. Can be overridden by the "width"
* tag in the XUL. Set to NS_SIZETOCONTENT to force
* the window to wrap to its contents.
* @param aInitialHeight like aInitialWidth.
*/
void RunModalDialog( inout nsIWebShellWindow aWindow,
in nsIWebShellWindow aParent,
in nsIStreamObserver anObserver,
in nsIURI aUrl,
in PRUint32 aChromeMask,
in nsIXULWindowCallbacks aCallbacks,
in long aInitialWidth, in long aInitialHeight);
/**
* Close a window.
* @param aWindow a window.
*/
void CloseTopLevelWindow(in nsIWebShellWindow aWindow);
/**
* Return the (singleton) application hidden window, automatically created
* and maintained by this AppShellService.
* @param aResult the hidden window. Do not unhide hidden window.
* Do not taunt hidden window.
*/
void GetHiddenWindow(out nsIWebShellWindow aResult);
/**
* Add a window to the application's registry of windows. These windows
* are generally shown in the Windows taskbar, and the application
* knows it can't quit until it's out of registered windows.
* @param aWindow yes
*/
void RegisterTopLevelWindow(in nsIWebShellWindow aWindow);
/**
* Remove a window from the application's window registry.
* @param aWindow you see the pattern
*/
void UnregisterTopLevelWindow(in nsIWebShellWindow aWindow);
};

Просмотреть файл

@ -31,6 +31,7 @@
#include "nsIAppShell.h"
#include "nsIWidget.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShellWindow.h"
#include "nsWebShellWindow.h"
@ -100,22 +101,18 @@ public:
NS_IMETHOD Run(void);
NS_IMETHOD Shutdown(void);
NS_IMETHOD CreateTopLevelWindow(nsIWebShellWindow * aParent,
nsIURI* aUrl,
PRBool showWindow,
nsIWebShellWindow** aResult, nsIStreamObserver* anObserver,
NS_IMETHOD CreateTopLevelWindow(nsIWebShellWindow *aParent,
nsIURI *aUrl,
PRBool aShowWindow,
PRUint32 aChromeMask,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight);
NS_IMETHOD CreateDialogWindow( nsIWebShellWindow * aParent,
nsIURI* aUrl,
PRBool showWindow,
nsIWebShellWindow** aResult, nsIStreamObserver* anObserver,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight);
PRInt32 aInitialWidth, PRInt32 aInitialHeight,
nsIWebShellWindow **aResult);
NS_IMETHOD RunModalDialog( nsIWebShellWindow **aWindow,
nsIURI* aUrl,
nsIWebShellWindow * aParent,
nsIStreamObserver* anObserver,
nsIWebShellWindow *aParent,
nsIURI *aUrl,
PRUint32 aChromeMask,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight);
NS_IMETHOD CloseTopLevelWindow(nsIWebShellWindow* aWindow);
@ -127,13 +124,13 @@ public:
protected:
virtual ~nsAppShellService();
NS_IMETHOD JustCreateTopWindow(nsIWebShellWindow * aParent,
nsIURI* aUrl,
PRBool showWindow,
nsIWebShellWindow** aResult,
nsIStreamObserver* anObserver,
NS_IMETHOD JustCreateTopWindow(nsIWebShellWindow *aParent,
nsIURI *aUrl,
PRBool aShowWindow,
PRUint32 aChromeMask,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight);
PRInt32 aInitialWidth, PRInt32 aInitialHeight,
nsIWebShellWindow **aResult);
void CreateHiddenWindow();
void InitializeComponent( const nsCID &aComponentCID );
void ShutdownComponent( const nsCID &aComponentCID );
@ -292,11 +289,11 @@ void nsAppShellService::CreateHiddenWindow()
#endif
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIWebShellWindow> newWindow;
rv = JustCreateTopWindow(nsnull, url, PR_FALSE, getter_AddRefs(newWindow),
nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT);
rv = JustCreateTopWindow(nsnull, url, PR_FALSE, NS_CHROME_ALL_CHROME,
nsnull, 100, 100, getter_AddRefs(newWindow));
if (NS_SUCCEEDED(rv)) {
mHiddenWindow = newWindow;
// Mac will want to register now, like CreateTopLevelWindow
// RegisterTopLevelWindow(newWindow); -- Mac only
}
NS_RELEASE(url);
}
@ -504,29 +501,22 @@ nsAppShellService::Shutdown(void)
/*
* Create a new top level window and display the given URL within it...
*
* @param aParent - parent for the window to be created (generally null;
* included for compatibility with dialogs).
* (currently unused).
* @param aURL - location of XUL window contents description
* @param aShowWindow - whether or not to show the window initially.
* @param anObserver - a stream observer to give to the new window
* @param aConstructionCallbacks - methods which will be called during
* window construction. can be null.
* @param aInitialWidth - width of window, in pixels (currently unused)
* @param aInitialHeight - height of window, in pixels (currently unused)
*/
NS_IMETHODIMP
nsAppShellService::CreateTopLevelWindow(nsIWebShellWindow *aParent,
nsIURI* aUrl, PRBool showWindow,
nsIWebShellWindow** aResult, nsIStreamObserver* anObserver,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight)
nsIURI *aUrl,
PRBool aShowWindow,
PRUint32 aChromeMask,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight,
nsIWebShellWindow **aResult)
{
nsresult rv;
rv = JustCreateTopWindow(aParent, aUrl, showWindow, aResult, anObserver,
aCallbacks, aInitialWidth, aInitialHeight);
rv = JustCreateTopWindow(aParent, aUrl, aShowWindow, aChromeMask,
aCallbacks, aInitialWidth, aInitialHeight,
aResult);
if (NS_SUCCEEDED(rv))
// the addref resulting from this is the owning addref for this window
@ -541,10 +531,12 @@ nsAppShellService::CreateTopLevelWindow(nsIWebShellWindow *aParent,
*/
NS_IMETHODIMP
nsAppShellService::JustCreateTopWindow(nsIWebShellWindow *aParent,
nsIURI* aUrl, PRBool showWindow,
nsIWebShellWindow** aResult, nsIStreamObserver* anObserver,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight)
nsIURI *aUrl,
PRBool aShowWindow,
PRUint32 aChromeMask,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight,
nsIWebShellWindow **aResult)
{
nsresult rv;
nsWebShellWindow* window;
@ -553,14 +545,25 @@ nsAppShellService::JustCreateTopWindow(nsIWebShellWindow *aParent,
*aResult = nsnull;
intrinsicallySized = PR_FALSE;
window = new nsWebShellWindow();
if (nsnull == window) {
if (!window)
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
else {
// temporarily disabling parentage because non-Windows platforms
// seem to be interpreting it in unexpected ways.
nsWidgetInitData widgetInitData;
widgetInitData.mWindowType = eWindowType_toplevel;
widgetInitData.mBorderStyle = eBorderStyle_all;
widgetInitData.mWindowType = aChromeMask & NS_CHROME_OPEN_AS_DIALOG ?
eWindowType_dialog : eWindowType_toplevel;
widgetInitData.mBorderStyle = eBorderStyle_border;
if (aChromeMask & NS_CHROME_TITLEBAR_ON)
widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_title);
if (aChromeMask & NS_CHROME_WINDOW_CLOSE_ON)
widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_close);
if (aChromeMask & NS_CHROME_WINDOW_RESIZE_ON)
widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_resizeh);
if (widgetInitData.mBorderStyle == eBorderStyle_border) // no additions
widgetInitData.mBorderStyle = eBorderStyle_all;
if (aInitialWidth == NS_SIZETOCONTENT ||
aInitialHeight == NS_SIZETOCONTENT) {
@ -571,7 +574,7 @@ nsAppShellService::JustCreateTopWindow(nsIWebShellWindow *aParent,
}
rv = window->Initialize((nsIWebShellWindow *) nsnull, mAppShell, aUrl,
showWindow, anObserver, aCallbacks,
aShowWindow, nsnull, aCallbacks,
aInitialWidth, aInitialHeight, widgetInitData);
if (NS_SUCCEEDED(rv)) {
@ -580,7 +583,7 @@ nsAppShellService::JustCreateTopWindow(nsIWebShellWindow *aParent,
rv = window->QueryInterface(kIWebShellWindowIID, (void **) aResult);
// if intrinsically sized, don't show until we have the size figured out
if (showWindow && !intrinsicallySized)
if (aShowWindow && !intrinsicallySized)
window->Show(PR_TRUE);
}
@ -608,61 +611,7 @@ nsAppShellService::GetHiddenWindow(nsIWebShellWindow **aWindow)
return rv ? NS_OK : NS_ERROR_FAILURE;
}
/*
* Like CreateTopLevelWindow, but with dialog window borders. This
* method is necessary because of the current misfortune that the window
* is created before its XUL description has been parsed, so the description
* can't affect attributes like window type.
*/
NS_IMETHODIMP
nsAppShellService::CreateDialogWindow(nsIWebShellWindow * aParent,
nsIURI* aUrl, PRBool showWindow,
nsIWebShellWindow** aResult, nsIStreamObserver* anObserver,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight)
{
nsresult rv;
nsWebShellWindow* window;
PRBool intrinsicallySized;
*aResult = nsnull;
intrinsicallySized = PR_FALSE;
window = new nsWebShellWindow();
if (nsnull == window) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
// temporarily disabling parentage because non-Windows platforms
// seem to be interpreting it in unexpected ways.
nsWidgetInitData widgetInitData;
widgetInitData.mWindowType = eWindowType_dialog;
widgetInitData.mBorderStyle = eBorderStyle_default;
if (aInitialWidth == NS_SIZETOCONTENT ||
aInitialHeight == NS_SIZETOCONTENT) {
aInitialWidth = 1;
aInitialHeight = 1;
intrinsicallySized = PR_TRUE;
window->SetIntrinsicallySized(PR_TRUE);
}
rv = window->Initialize((nsIWebShellWindow *) nsnull, mAppShell, aUrl,
showWindow, anObserver, aCallbacks,
aInitialWidth, aInitialHeight, widgetInitData);
if (NS_SUCCEEDED(rv)) {
rv = window->QueryInterface(kIWebShellWindowIID, (void **) aResult);
RegisterTopLevelWindow(window);
// if intrinsically sized, don't show until we have the size figured out
if (showWindow && !intrinsicallySized)
window->Show(PR_TRUE);
}
}
return rv;
}
/* CreateDialogWindow, run it modally, and destroy it. To make initial control
/* Create a Window, run it modally, and destroy it. To make initial control
settings or get information out of the dialog before dismissal, use
event handlers. This wrapper method is desirable because of the
complications creeping in to the modal window story: there's a lot of setup.
@ -674,14 +623,14 @@ nsAppShellService::CreateDialogWindow(nsIWebShellWindow * aParent,
this function exits, that window has been partially destroyed. We return it
anyway, in the hopes that it may be queried for results, somehow.
This may be a mistake. It is returned addrefed (by the QueryInterface
to nsIWebShellWindow in CreateDialogWindow).
to nsIWebShellWindow in CreateTopLevelWindow).
*/
NS_IMETHODIMP
nsAppShellService::RunModalDialog(
nsIWebShellWindow **aWindow,
nsIURI* aUrl,
nsIWebShellWindow * aParent,
nsIStreamObserver *anObserver,
nsIWebShellWindow *aParent,
nsIURI *aUrl,
PRUint32 aChromeMask,
nsIXULWindowCallbacks *aCallbacks,
PRInt32 aInitialWidth, PRInt32 aInitialHeight)
{
@ -704,8 +653,8 @@ nsAppShellService::RunModalDialog(
theWindow = *aWindow; // and rv is already some success indication
NS_ADDREF(theWindow);
} else
rv = CreateDialogWindow(aParent, aUrl, PR_TRUE, &theWindow, anObserver,
aCallbacks, aInitialWidth, aInitialHeight);
rv = CreateTopLevelWindow(aParent, aUrl, PR_TRUE, aChromeMask,
aCallbacks, aInitialWidth, aInitialHeight, &theWindow);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIWidget> parentWindowWidgetThing;

Просмотреть файл

@ -36,6 +36,7 @@
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#endif // NECKO
#include "nsIDOMToolkitCore.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShellWindow.h"
#include "nsIWebShell.h"
#include "nsIScriptContextOwner.h"
@ -1042,10 +1043,10 @@ nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks)
nsnull,
urlObj, // nsIURI* of chrome
PR_TRUE,
&aWindow,
nsnull,
NS_CHROME_ALL_CHROME,
inCallbacks, // callbacks
NS_SIZETOCONTENT, NS_SIZETOCONTENT);
NS_SIZETOCONTENT, NS_SIZETOCONTENT,
&aWindow);
if (NS_FAILED(rv))
return nsnull;
return aWindow;

Просмотреть файл

@ -34,6 +34,7 @@
#include "nsNeckoUtil.h"
#endif // NECKO
#include "nsIDOMHTMLInputElement.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShellWindow.h"
#include "nsIDOMEventReceiver.h"
#include "nsIURL.h"
@ -519,13 +520,15 @@ nsresult nsNetSupportDialog::DoDialog( nsString& inXULURL )
return result;
}
result = appShellService->CreateDialogWindow(nsnull, dialogURL, PR_TRUE,
&dialogWindow, nsnull, this, 300, 200);
result = appShellService->CreateTopLevelWindow(nsnull, dialogURL, PR_TRUE,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
this, 300, 200, &dialogWindow);
mWebShellWindow = dialogWindow;
if (NS_SUCCEEDED(result))
appShellService->RunModalDialog(&dialogWindow, dialogURL, nsnull,
nsnull, this, 300, 200);
appShellService->RunModalDialog(&dialogWindow, nsnull, dialogURL,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
this, 300, 200);
// cleanup
if ( mOKButton )

Просмотреть файл

@ -1403,19 +1403,15 @@ nsWebShellWindow::NewWebShell(PRUint32 aChromeMask, PRBool aVisible,
nsCOMPtr<nsIWebShellWindow> newWindow;
PRBool openAsDialog = ((aChromeMask & NS_CHROME_OPEN_AS_DIALOG) != 0);
// XXX Check modal chrome flag to run a modal dialog!
if ((aChromeMask & NS_CHROME_OPEN_AS_CHROME) != 0) {
// Just do a nice normal create of a web shell and
// return it immediately.
if (openAsDialog)
rv = appShell->CreateDialogWindow(nsnull, nsnull, PR_FALSE, getter_AddRefs(newWindow),
nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT);
else rv = appShell->CreateTopLevelWindow(nsnull, nsnull, PR_FALSE, getter_AddRefs(newWindow),
nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT);
rv = appShell->CreateTopLevelWindow(nsnull, nsnull, PR_FALSE, aChromeMask,
nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(newWindow));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIBrowserWindow> browser(do_QueryInterface(newWindow));
if (browser)
@ -1457,11 +1453,9 @@ nsWebShellWindow::NewWebShell(PRUint32 aChromeMask, PRBool aVisible,
#endif // NECKO
if (NS_SUCCEEDED(rv)) {
if (openAsDialog)
rv = appShell->CreateDialogWindow(nsnull, urlObj, PR_FALSE, getter_AddRefs(newWindow),
nsnull, nsnull, 615, 480);
else rv = appShell->CreateTopLevelWindow(nsnull, urlObj, PR_FALSE, getter_AddRefs(newWindow),
nsnull, nsnull, 615, 480);
rv = appShell->CreateTopLevelWindow(nsnull, urlObj, PR_FALSE, aChromeMask,
nsnull, 615, 480,
getter_AddRefs(newWindow));
}
nsIAppShell *subshell;

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsNeckoUtil.h"
#endif // NECKO
#include "nsIWidget.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShellWindow.h"
#include "nsIPref.h"
#include "plevent.h"
@ -648,9 +649,11 @@ int main(int argc, char* argv[])
goto done;
}
nsCOMPtr<nsIWebShellWindow> profWindow;
rv = profAppShell->CreateTopLevelWindow(nsnull, profURL, PR_TRUE, getter_AddRefs(profWindow),
nsnull, nsnull, profWinWidth, profWinHeight);
nsCOMPtr<nsIWebShellWindow> profWindow;
rv = profAppShell->CreateTopLevelWindow(nsnull, profURL,
PR_TRUE, NS_CHROME_ALL_CHROME,
nsnull, profWinWidth, profWinHeight,
getter_AddRefs(profWindow));
NS_RELEASE(profURL);
@ -698,8 +701,10 @@ int main(int argc, char* argv[])
if ( !useArgs ) {
nsCOMPtr<nsIWebShellWindow> newWindow;
rv = appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, getter_AddRefs(newWindow),
nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT);
rv = appShell->CreateTopLevelWindow(nsnull, url,
PR_TRUE, NS_CHROME_ALL_CHROME,
nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT,
getter_AddRefs(newWindow));
} else {
nsIDOMToolkitCore* toolkit = nsnull;
rv = nsServiceManager::GetService(kToolkitCoreCID,

Просмотреть файл

@ -30,8 +30,10 @@ EXPORT_RESOURCE_SAMPLES = \
$(srcdir)/dexanimdialog.xul \
$(srcdir)/dexparammaster.xul \
$(srcdir)/dexparamdialog.xul \
$(srcdir)/dexparamdialog.html \
$(srcdir)/dexsimplemaster.xul \
$(srcdir)/dexsimpledialog.xul \
$(srcdir)/dexopenchrome.xul \
$(srcdir)/tab.xul \
$(srcdir)/xpmenu.xul \
$(NULL)

Просмотреть файл

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE window>
<!-- DO NOT LOCALIZE: this file is source documentation; not part of the build -->
<!-- Sample interface for bringing up and passing parameters to a dialog -->
<xul:window
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title = "Chrome Features Test">
<html:script>
<![CDATA[
var featureList = new Array("close", "titlebar", "resizable", "scrollbars",
"chrome", "dialog", "modal",
"menubar", "toolbar", "status", "location");
function OpenWindow(extension) {
var ctr;
var features;
var element;
features = "";
// read checkboxes
for (ctr = 0; ctr < featureList.length; ctr++) {
element = document.getElementById(featureList[ctr]);
if (element.checked) {
if (features.length > 0)
features = features + ",";
features = features + featureList[ctr];
} else {
if (featureList[ctr] == "titlebar" || featureList[ctr] == "close" ||
featureList[ctr] == "resizable") {
if (features.length > 0)
features = features + ",";
features = features + featureList[ctr] + "=no";
}
}
}
dump("******* " + features + "\n");
window.openDialog("resource://res/samples/dexparamdialog."+extension,
"New", features, {remind:true});
}
]]>
</html:script>
<html:div>
<html:input type="checkbox" id="close"/>close<html:br/>
<html:input type="checkbox" id="titlebar"/>titlebar<html:br/>
<html:input type="checkbox" id="resizable"/>resizable<html:br/>
<html:input type="checkbox" id="scrollbars"/>scrollbars<html:br/>
<html:input type="checkbox" id="chrome"/>chrome<html:br/>
<html:input type="checkbox" id="dialog"/>dialog<html:br/>
<html:input type="checkbox" id="modal"/>modal<html:br/>
<html:input type="checkbox" id="menubar"/>menubar<html:br/>
<html:input type="checkbox" id="toolbar"/>toolbar<html:br/>
<html:input type="checkbox" id="status"/>status<html:br/>
<html:input type="checkbox" id="location"/>location<html:br/>
<xul:titledbutton value="Open HTML" onclick="OpenWindow('html')"
style="background-color:rgb(192,192,192);"/>
<xul:titledbutton value="Open XUL" onclick="OpenWindow('xul')"
style="background-color:rgb(192,192,192);"/>
</html:div>
</xul:window>

Просмотреть файл

@ -0,0 +1,210 @@
<html><body>
<script language="javascript">
var debug = true;
// Initialize controls from parameters sent through the URL
function SetFromURL() {
// dump a bunch of diagnostics
if (debug) {
dump("In SetFromURL...\n");
dump("param string is '" + location.search + "', length " +
location.search.length + "\n");
var debugSetting = GetNamedParam(location.search.substring(1,location.search.length), "remind");
if (debugSetting) {
dump("'remind' parameter = '" + debugSetting + "'\n");
} else
dump("'remind' setting not found\n");
if (document.getElementById("remind"))
dump("found 'remind' element in document\n");
else
dump("'remind' element missing from document\n");
dump("Finishing SetFromURL...\n");
}
// set checkbox from "remind=xxx" name=value pair
var params = location.search.substring(1, location.search.length);
var setting = GetNamedParam(params, "remind");
if (setting)
setting = setting.toLowerCase() == "true";
else
setting = false;
var checkbox = document.getElementById("remind");
if (checkbox)
checkbox.checked = setting;
// set prompt text from "prompt=xxx" name=value pair
var setting = GetNamedParam(params, "prompt");
control = document.getElementById("prompt");
if (control && setting) {
control = control.firstChild;
if (control && control.nodeType == 3) // TEXT_NODE
control.data = setting;
}
}
// Initialize controls from parameters sent through openDialog
function SetFromParams() {
// dump a bunch of diagnostics
if (debug) {
var debugSetting;
var debugControl;
dump("In SetFromParams...\n");
if (window.arguments) {
dump("arguments exist\n");
if (window.arguments[0]) {
dump(" arguments[0] exists\n");
if (window.arguments[0].remind) {
dump(" arguments[0].remind exists\n");
debugSetting = window.arguments[0].remind;
dump(" it's " + debugSetting +
", type " + typeof debugSetting + "\n");
} else
dump("arguments[0].remind does not exist\n");
if (window.arguments[0].prompt) {
dump(" arguments[0].prompt exists\n");
debugSetting = window.arguments[0].prompt;
dump(" it's " + debugSetting +
", type " + typeof debugSetting + "\n");
} else
dump("arguments[0].prompt does not exist (or it's just false)\n");
} else
dump("arguments[0] does not exist\n");
} else
dump("no arguments\n");
debugControl = document.getElementById("remind");
if (debugControl)
dump("found 'remind' element in document "+
typeof debugControl+"\n");
else
dump("'remind' element missing from document\n");
debugControl = document.getElementById("prompt");
if (debugControl) {
dump("found 'prompt' element in document "+
typeof debugControl+"\n");
debugControl = debugControl.firstChild;
if (debugControl) {
dump("found prompt's first child. type " + debugControl.nodeName + "\n");
} else
dump("couldn't find prompt's first child\n");
} else
dump("'prompt' element missing from document\n");
dump("Finishing SetFromParams...\n");
}
// look in arguments[0] for an object with interesting properties and values
// set checkbox from its value, if present
if (window.arguments && window.arguments[0]) {
var setting;
var control;
// set checkbox from the value of argment[0]'s "value" property
setting = window.arguments[0].remind;
if (setting) { // (exists and true)
control = document.getElementById("remind");
if (control)
control.checked = setting;
}
// set prompt from the value of argment[0]'s "prompt" property
setting = window.arguments[0].prompt;
if (setting) {
if (typeof setting == "string") {
control = document.getElementById("prompt");
if (control) {
control = control.firstChild;
if (control && control.nodeType == 3) // TEXT_NODE
control.data = setting;
}
}
}
}
}
// OK button handler
// return the setting of the "remind" checkbox in two equivalent ways
// and then close the window (disabled for now, since that crashes)
function DoOK() {
var checkbox = document.getElementById("remind");
if (checkbox) {
// attach a property to ourselves, which can be queried from outside
window.returnArguments = checkbox.checked;
// additionally, if we were given an openDialog parameter, set its value
if (window.arguments && window.arguments[0])
window.arguments[0].remind = checkbox.checked;
}
// var toolkitCore = GetToolkitCore();
// if (toolkitCore)
// toolkitCore.CloseWindow(window);
window.close();
}
function GetToolkitCore() {
var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
if (!toolkitCore) {
toolkitCore = new ToolkitCore();
if (toolkitCore)
toolkitCore.Init("ToolkitCore");
}
return toolkitCore;
}
// params is a list of name=value parameters separated by semicolons
// or ampersands. To pass parameters containing either character,
// string together parameters escape()d separately, separated by ;.
// this function returns the value of the named pair, or null
// if it found nothing.
function GetNamedParam(params, name) {
if (debug)
dump("GetNamedParam looking for '" + name + "' in '" + params + "'\n");
var re = new RegExp(name+" *=([^&;]+)");
var match = re(params);
if (match) {
if (debug)
dump(" matched regexp. found '" + match[1] + "'\n");
return unescape(match[1]);
}
return null;
}
function DumpWindow() {
dump("**********************************************\n");
for (prop in window)
dump(prop + "\n");
dump("----------------------------------------------\n");
}
</script>
<table>
<tr>
<td id="prompt">Give me your money</td>
</tr>
<tr>
<td>
<!-- note the html namespace on the id attribute, which
seems at this time to be required by getAttribute() -->
<input type="checkbox" id="remind"/>Remind me
</td>
</tr>
<tr>
<td>
<button onclick="DoOK()">OK</button>
</td>
</tr>
<tr>
<td>
<button onclick="SetFromURL()">Startup from URL</button>
</td>
</tr>
<tr>
<td>
<button onclick="SetFromParams()">Startup from Params</button>
</td>
</tr>
<tr>
<td>
<button onclick="DumpWindow()">Dump Window</button>
</td>
</tr>
</table>
</body></html>

Просмотреть файл

@ -26,8 +26,10 @@ install:: $(DLL)
$(MAKE_INSTALL) dexanimdialog.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexparammaster.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexparamdialog.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexparamdialog.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexsimplemaster.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexsimpledialog.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexopenchrome.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) tab.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) xpmenu.xul $(DIST)\bin\res\samples
@ -36,6 +38,9 @@ clobber::
rm -f $(DIST)\res\samples\dexanimdialog.xul
rm -f $(DIST)\res\samples\dexparammaster.xul
rm -f $(DIST)\res\samples\dexparamdialog.xul
rm -f $(DIST)\res\samples\dexparamdialog.html
rm -f $(DIST)\res\samples\dexsimplemaster.xul
rm -f $(DIST)\res\samples\dexsimpledialog.xul
rm -f $(DIST)\res\samples\dexopenchrome.xul
rm -f $(DIST)\res\samples\tab.xul
rm -f $(DIST)\res\samples\xpmenu.xul

Просмотреть файл

@ -182,7 +182,6 @@ NS_IMETHODIMP nsPrefWindow::showWindow(
return NS_ERROR_FAILURE;
// (code adapted from nsToolkitCore::ShowModal. yeesh.)
nsIWebShellWindow* window = nsnull;
nsCOMPtr<nsIURI> urlObj;
char * urlStr = "chrome://pref/content/";
nsresult rv;
@ -209,13 +208,9 @@ NS_IMETHODIMP nsPrefWindow::showWindow(
nsIXULWindowCallbacks *cb = nsnull;
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(currentFrontWin, &parent);
appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, &window,
nsnull, cb, 504, 436);
if (window != nsnull)
{
appShell->RunModalDialog(&window, nsnull, parent, nsnull, cb, 504, 436);
NS_RELEASE(window);
}
rv = appShell->RunModalDialog(nsnull, parent, nsnull,
NS_CHROME_ALL_CHROME | NS_CHROME_OPEN_AS_DIALOG,
cb, 504, 436);
return rv;
} // nsPrefWindow::showWindow()

Просмотреть файл

@ -36,6 +36,7 @@
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#endif // NECKO
#include "nsIDOMToolkitCore.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShellWindow.h"
#include "nsIWebShell.h"
#include "nsIScriptContextOwner.h"
@ -1042,10 +1043,10 @@ nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks)
nsnull,
urlObj, // nsIURI* of chrome
PR_TRUE,
&aWindow,
nsnull,
NS_CHROME_ALL_CHROME,
inCallbacks, // callbacks
NS_SIZETOCONTENT, NS_SIZETOCONTENT);
NS_SIZETOCONTENT, NS_SIZETOCONTENT,
&aWindow);
if (NS_FAILED(rv))
return nsnull;
return aWindow;

Просмотреть файл

@ -1,452 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDownloadProgressDialog.h"
#include "nsIAppShellComponentImpl.h"
#include "nsIServiceManager.h"
#include "nsIDocumentViewer.h"
#include "nsIContent.h"
#include "nsINameSpaceManager.h"
#include "nsIContentViewer.h"
#include "nsIDOMElement.h"
#ifndef NECKO
#include "nsINetService.h"
static NS_DEFINE_IID( kNetServiceCID, NS_NETSERVICE_CID );
#else
#include "nsNeckoUtil.h"
#include "nsIURL.h"
#include "nsIChannel.h"
#include "nsIEventQueueService.h"
#include "nsIProgressEventSink.h"
#include "nsIBufferInputStream.h"
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
#endif // NECKO
static NS_DEFINE_IID( kAppShellServiceCID, NS_APPSHELL_SERVICE_CID );
static nsresult setAttribute( nsIDOMXULDocument *, const char*, const char*, const nsString& );
void
nsDownloadProgressDialog::OnClose() {
// Close the window (if broadcaster/observer traffic isn't pending).
if( mWindow ) {
if ( mStopNotificationPending ) {
// Remember that we need to close the window when that
// notification completes.
mCloseRequested = PR_TRUE;
} else {
// Go ahead and close the window.
mWindow->Close();
}
}
}
void
nsDownloadProgressDialog::OnUnload() {
// Window was closed (or is closing), release it.
mWindow = 0;
}
void
nsDownloadProgressDialog::OnStart() {
// Load source stream into file.
#ifndef NECKO
nsINetService *inet = 0;
nsresult rv = nsServiceManager::GetService( kNetServiceCID,
nsINetService::GetIID(),
(nsISupports**)&inet );
if (NS_OK == rv) {
rv = inet->OpenStream( mUrl, this );
nsServiceManager::ReleaseService( kNetServiceCID, inet );
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: Error getting Net Service, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
#else
nsresult rv = NS_OpenURI(this, nsnull, mUrl);
NS_ASSERTION(NS_SUCCEEDED(rv), "OnStart doesn't return rv!");
#endif // NECKO
}
void
nsDownloadProgressDialog::OnStop() {
// Stop the netlib xfer.
mStopped = PR_TRUE;
}
// ctor
nsDownloadProgressDialog::nsDownloadProgressDialog( nsIURI *aURL,
const nsFileSpec &anOutputFileName )
: mUrl( nsDontQueryInterface<nsIURI>(aURL) ),
mDocument(),
mWindow(),
mOutput(0),
mFileName( anOutputFileName ),
mBufLen( 8192 ),
mBuffer( new char[ mBufLen ] ),
mStopped( PR_FALSE ),
mCloseRequested( PR_FALSE ),
mStopNotificationPending( PR_FALSE ) {
// Initialize ref count.
NS_INIT_REFCNT();
}
// dtor
nsDownloadProgressDialog::~nsDownloadProgressDialog() {
// Delete dynamically allocated members (file and buffer).
delete mOutput;
delete [] mBuffer;
}
// Open the dialog.
NS_IMETHODIMP
nsDownloadProgressDialog::Show() {
nsresult rv = NS_OK;
// Get app shell service.
nsIAppShellService *appShell;
rv = nsServiceManager::GetService( kAppShellServiceCID,
nsIAppShellService::GetIID(),
(nsISupports**)&appShell );
if ( NS_SUCCEEDED( rv ) ) {
// Open "download progress" dialog.
nsIURI *url;
char * urlStr = "resource:/res/samples/downloadProgress.xul";
#ifndef NECKO
rv = NS_NewURL( &url, urlStr );
#else
rv = NS_NewURI( &url, urlStr );
#endif // NECKO
if ( NS_SUCCEEDED(rv) ) {
// Create "save to disk" nsIXULCallbacks...
nsCOMPtr<nsIWebShellWindow> newWindow;
rv = appShell->CreateTopLevelWindow( nsnull,
url,
PR_TRUE,
getter_AddRefs(newWindow),
nsnull,
this,
0,
0 );
if ( NS_SUCCEEDED( rv ) ) {
mWindow = newWindow;
} else {
DEBUG_PRINTF( PR_STDOUT, "Error creating download progress dialog, rv=0x%X\n", (int)rv );
}
NS_RELEASE( url );
}
nsServiceManager::ReleaseService( kAppShellServiceCID, appShell );
} else {
DEBUG_PRINTF( PR_STDOUT, "Unable to get app shell service, rv=0x%X\n", (int)rv );
}
return rv;
}
// Do startup stuff from C++ side.
NS_IMETHODIMP
nsDownloadProgressDialog::ConstructBeforeJavaScript(nsIWebShell *aWebShell) {
nsresult rv = NS_OK;
// Get content viewer from the web shell.
nsCOMPtr<nsIContentViewer> contentViewer;
rv = aWebShell ? aWebShell->GetContentViewer(getter_AddRefs(contentViewer))
: NS_ERROR_NULL_POINTER;
if ( contentViewer ) {
// Up-cast to a document viewer.
nsCOMPtr<nsIDocumentViewer> docViewer( do_QueryInterface( contentViewer, &rv ) );
if ( docViewer ) {
// Get the document from the doc viewer.
nsCOMPtr<nsIDocument> document;
rv = docViewer->GetDocument(*getter_AddRefs(document));
if ( document ) {
// Upcast to XUL document.
mDocument = do_QueryInterface( document, &rv );
if ( mDocument ) {
// Add ourself as document observer.
document->AddObserver( this );
// Store instance information into dialog's DOM.
#ifdef NECKO
char *loc = 0;
mUrl->GetSpec( &loc );
rv = setAttribute( mDocument, "data.location", "value", loc );
nsCRT::free(loc);
#else
const char *loc = 0;
mUrl->GetSpec( &loc );
rv = setAttribute( mDocument, "data.location", "value", loc );
#endif
if ( NS_SUCCEEDED( rv ) ) {
rv = setAttribute( mDocument, "data.fileName", "value", nsString((const char*)mFileName) );
if ( NS_SUCCEEDED( rv ) ) {
rv = setAttribute( mDocument, "dialog.start", "ready", "true" );
}
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDOMXULDocument failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetDocument failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDocumentViewer failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetContentViewer failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
return rv;
}
NS_IMETHODIMP
#ifdef NECKO
nsDownloadProgressDialog::OnDataAvailable(nsIChannel* channel, nsISupports* aContext, nsIInputStream *aIStream,
PRUint32 offset, PRUint32 aLength)
#else
nsDownloadProgressDialog::OnDataAvailable(nsIURI* aURL, nsIInputStream *aIStream, PRUint32 aLength)
#endif
{
nsresult rv = NS_OK;
// Check for download cancelled by user.
if ( mStopped ) {
// Close the output file.
if ( mOutput ) {
mOutput->close();
}
// Close the input stream.
aIStream->Close();
} else {
// Allocate buffer space.
if ( aLength > mBufLen ) {
char *oldBuffer = mBuffer;
mBuffer = new char[ aLength ];
if ( mBuffer ) {
// Use new (bigger) buffer.
mBufLen = aLength;
// Delete old (smaller) buffer.
delete [] oldBuffer;
} else {
// Keep the one we've got.
mBuffer = oldBuffer;
}
}
// Read the data.
PRUint32 bytesRead;
rv = aIStream->Read( mBuffer, ( mBufLen > aLength ) ? aLength : mBufLen, &bytesRead );
if ( NS_SUCCEEDED(rv) ) {
// Write the data just read to the output stream.
if ( mOutput ) {
mOutput->write( mBuffer, bytesRead );
}
} else {
printf( "Error reading stream, rv=0x%X\n", (int)rv );
}
}
return rv;
}
NS_IMETHODIMP
#ifdef NECKO
nsDownloadProgressDialog::OnStartRequest(nsIChannel* channel, nsISupports* aContext)
#else
nsDownloadProgressDialog::OnStartRequest(nsIURI* aURL, const char *aContentType)
#endif
{
//nsresult rv = NS_OK;
return NS_OK;
}
NS_IMETHODIMP
#ifdef NECKO
nsDownloadProgressDialog::OnProgress(nsIChannel* channel, nsISupports* aContext,
PRUint32 aProgress, PRUint32 aProgressMax)
#else
nsDownloadProgressDialog::OnProgress(nsIURI* aURL, PRUint32 aProgress, PRUint32 aProgressMax)
#endif
{
//nsresult rv = NS_OK;
char buf[16];
PR_snprintf( buf, sizeof buf, "%lu", aProgressMax );
setAttribute( mDocument, "data.progress", "max", buf );
PR_snprintf( buf, sizeof buf, "%lu", aProgress );
setAttribute( mDocument, "data.progress", "value", buf );
return NS_OK;
}
NS_IMETHODIMP
#ifdef NECKO
nsDownloadProgressDialog::OnStatus(nsIChannel* channel, nsISupports* aContext,
const PRUnichar* aMsg)
#else
nsDownloadProgressDialog::OnStatus(nsIURI* aURL, const PRUnichar* aMsg)
#endif
{
//nsresult rv = NS_OK;
nsString msg = aMsg;
setAttribute( mDocument, "data.status", "value", aMsg );
return NS_OK;
}
NS_IMETHODIMP
#ifdef NECKO
nsDownloadProgressDialog::OnStopRequest(nsIChannel* channel, nsISupports* aContext,
nsresult aStatus, const PRUnichar* aMsg)
#else
nsDownloadProgressDialog::OnStopRequest(nsIURI* aURL, nsresult aStatus, const PRUnichar* aMsg)
#endif
{
nsresult rv = NS_OK;
// Close the output file.
if ( mOutput ) {
mOutput->close();
}
// Signal UI that download is complete.
mStopNotificationPending = PR_TRUE;
setAttribute( mDocument, "data.progress", "completed", "true" );
mStopNotificationPending = PR_FALSE;
// See if that notification triggered close request.
if ( mCloseRequested ) {
// Close the window now.
OnClose();
}
return rv;
}
// Handle attribute changing; we only care about the element "data.execute"
// which is used to signal command execution from the UI.
NS_IMETHODIMP
nsDownloadProgressDialog::AttributeChanged( nsIDocument *aDocument,
nsIContent* aContent,
nsIAtom* aAttribute,
PRInt32 aHint ) {
nsresult rv = NS_OK;
// Look for data.execute command changing.
nsString id;
nsCOMPtr<nsIAtom> atomId = nsDontQueryInterface<nsIAtom>( NS_NewAtom("id") );
aContent->GetAttribute( kNameSpaceID_None, atomId, id );
if ( id == "data.execute" ) {
nsString cmd;
nsCOMPtr<nsIAtom> atomCommand = nsDontQueryInterface<nsIAtom>( NS_NewAtom("command") );
// Get requested command.
aContent->GetAttribute( kNameSpaceID_None, atomCommand, cmd );
// Reset (immediately, to prevent feedback loop).
aContent->SetAttribute( kNameSpaceID_None, atomCommand, "", PR_FALSE );
if ( 0 ) {
} else if ( cmd == "start" ) {
OnStart();
} else if ( cmd == "stop" ) {
OnStop();
} else if ( cmd == "close" ) {
OnClose();
} else if ( cmd == "unload" ) {
OnUnload();
} else {
}
}
return rv;
}
// Standard implementations of addref/release/query_interface.
NS_IMPL_ADDREF( nsDownloadProgressDialog );
NS_IMPL_RELEASE( nsDownloadProgressDialog );
NS_IMETHODIMP
nsDownloadProgressDialog::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
#ifdef NECKO
if (aIID.Equals(nsIProgressEventSink::GetIID())) {
*aInstancePtr = (void*) ((nsIProgressEventSink*)this);
NS_ADDREF_THIS();
return NS_OK;
}
#endif
if (aIID.Equals(nsIStreamObserver::GetIID())) {
*aInstancePtr = (void*) ((nsIStreamObserver*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIStreamListener::GetIID())) {
*aInstancePtr = (void*) ((nsIStreamListener*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIDocumentObserver::GetIID())) {
*aInstancePtr = (void*) ((nsIDocumentObserver*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIXULWindowCallbacks::GetIID())) {
*aInstancePtr = (void*) ((nsIXULWindowCallbacks*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
// Utility to set element attribute.
static nsresult setAttribute( nsIDOMXULDocument *doc,
const char *id,
const char *name,
const nsString &value ) {
nsresult rv = NS_OK;
if ( doc ) {
// Find specified element.
nsCOMPtr<nsIDOMElement> elem;
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
if ( elem ) {
// Set the text attribute.
rv = elem->SetAttribute( name, value );
if ( NS_SUCCEEDED( rv ) ) {
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}

Просмотреть файл

@ -28,6 +28,7 @@
#include "nsIAppShellComponentImpl.h"
#include "nsIBrowserWindow.h"
#include "nsIServiceManager.h"
#include "nsIDocumentViewer.h"
#include "nsIContent.h"
@ -232,11 +233,11 @@ nsInstallProgressDialog::Open()
rv = appShell->CreateTopLevelWindow( nsnull,
url,
PR_TRUE,
getter_AddRefs(mWindow),
nsnull,
NS_CHROME_ALL_CHROME,
this, // callbacks??
0,
0 );
0,
getter_AddRefs(mWindow));
if ( NS_SUCCEEDED( rv ) )
{