diff --git a/mozilla/widget/public/nsIFileSpecWithUI.idl b/mozilla/widget/public/nsIFileSpecWithUI.idl index 0806a3081d8..9326f4a3a46 100644 --- a/mozilla/widget/public/nsIFileSpecWithUI.idl +++ b/mozilla/widget/public/nsIFileSpecWithUI.idl @@ -26,6 +26,7 @@ #include "nsIFileSpec.idl" #include "nsIComponentManager.idl" +#include "domstubs.idl" [scriptable, uuid(8ddf7681-139a-11d3-915f-dc1f8c138b7c)] interface nsIFileSpecWithUI : nsIFileSpec @@ -68,6 +69,8 @@ interface nsIFileSpecWithUI : nsIFileSpec string chooseFile(in string title); string chooseDirectory(in string title); + + attribute nsIDOMWindow parentWindow; }; %{C++ diff --git a/mozilla/widget/src/xpwidgets/nsFileSpecWithUIImpl.cpp b/mozilla/widget/src/xpwidgets/nsFileSpecWithUIImpl.cpp index ebddcea707a..2825601055a 100644 --- a/mozilla/widget/src/xpwidgets/nsFileSpecWithUIImpl.cpp +++ b/mozilla/widget/src/xpwidgets/nsFileSpecWithUIImpl.cpp @@ -24,6 +24,11 @@ #include "nsWidgetsCID.h" #include "nsIComponentManager.h" +#include "nsIDOMWindow.h" +#include "nsIScriptGlobalObject.h" +#include "nsIWebShell.h" +#include "nsIDocumentViewer.h" +#include "nsIPresShell.h" #undef NS_FILE_FAILURE #define NS_FILE_FAILURE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES,(0xFFFF)) @@ -60,8 +65,52 @@ static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); #include "nsIComponentManager.h" +// Get widget from DOM window. +// Note that this does not AddRef the resulting widget! +// +// This was cribbed from nsBaseFilePicker.cpp. I will +// echo the comment that appears there: aaaarrrrrrgh! +static nsIWidget *parentWidget( nsIDOMWindow *window ) { + nsIWidget *result = 0; + if ( window ) { + nsCOMPtr sgo = do_QueryInterface( window ); + if ( sgo ) { + nsCOMPtr webShell; + sgo->GetWebShell( getter_AddRefs( webShell ) ); + if ( webShell ) { + nsCOMPtr contentViewer; + webShell->GetContentViewer( getter_AddRefs( contentViewer ) ); + if ( contentViewer ) { + nsCOMPtr documentViewer = do_QueryInterface( contentViewer ); + if ( documentViewer ) { + nsCOMPtr presShell; + documentViewer->GetPresShell( *getter_AddRefs( presShell ) ); + if ( presShell ) { + nsCOMPtr viewManager; + presShell->GetViewManager( getter_AddRefs( viewManager ) ); + if ( viewManager ) { + nsIView *view; // GetRootView doesn't AddRef! + viewManager->GetRootView( view ); + if ( view ) { + nsCOMPtr widget; + view->GetWidget( *getter_AddRefs( widget ) ); + if ( widget ) { + result = widget.get(); + } + } + } + } + } + } + } + } + } + return result; +} + //---------------------------------------------------------------------------------------- nsFileSpecWithUIImpl::nsFileSpecWithUIImpl() + : mParentWindow( 0 ) //---------------------------------------------------------------------------------------- { NS_INIT_REFCNT(); @@ -77,6 +126,8 @@ nsFileSpecWithUIImpl::nsFileSpecWithUIImpl() nsFileSpecWithUIImpl::~nsFileSpecWithUIImpl() //---------------------------------------------------------------------------------------- { + // Release parent window. + NS_IF_RELEASE( mParentWindow ); } //---------------------------------------------------------------------------------------- @@ -108,7 +159,7 @@ NS_IMETHODIMP nsFileSpecWithUIImpl::ChooseOutputFile( nsString winTitle(windowTitle); - nsFileDlgResults result = fileWidget->PutFile(nsnull, winTitle, spec); + nsFileDlgResults result = fileWidget->PutFile(parentWidget(mParentWindow), winTitle, spec); if (result != nsFileDlgResults_OK) { if (result == nsFileDlgResults_Cancel) @@ -212,7 +263,6 @@ void nsFileSpecWithUIImpl::SetFileWidgetStartDir( nsIFileWidget *fileWidget ) { } } - //---------------------------------------------------------------------------------------- NS_IMETHODIMP nsFileSpecWithUIImpl::ChooseInputFile( const char *inTitle, @@ -236,7 +286,7 @@ NS_IMETHODIMP nsFileSpecWithUIImpl::ChooseInputFile( inExtraFilterTitle, inExtraFilter); SetFileWidgetStartDir(fileWidget); nsString winTitle(inTitle); - if (fileWidget->GetFile(nsnull, winTitle, spec) != nsFileDlgResults_OK) + if (fileWidget->GetFile(parentWidget(mParentWindow), winTitle, spec) != nsFileDlgResults_OK) rv = NS_FILE_FAILURE; else rv = mBaseFileSpec->SetFromFileSpec(spec); @@ -270,3 +320,30 @@ NS_IMETHODIMP nsFileSpecWithUIImpl::ChooseDirectory(const char *title, char **_r return GetURLString(_retval); } // nsFileSpecWithUIImpl::chooseDirectory +NS_IMETHODIMP +nsFileSpecWithUIImpl::GetParentWindow( nsIDOMWindow **aResult ) { + nsresult rv = NS_OK; + + if ( aResult ) { + *aResult = mParentWindow; + NS_IF_ADDREF( *aResult ); + } else { + rv = NS_ERROR_NULL_POINTER; + } + + return rv; +} + +NS_IMETHODIMP +nsFileSpecWithUIImpl::SetParentWindow( nsIDOMWindow *aParentWindow ) { + nsresult rv = NS_OK; + + // Release current parent. + NS_IF_RELEASE( mParentWindow ); + + // Set new parent. + mParentWindow = aParentWindow; + NS_IF_ADDREF( mParentWindow ); + + return rv; +} diff --git a/mozilla/widget/src/xpwidgets/nsFileSpecWithUIImpl.h b/mozilla/widget/src/xpwidgets/nsFileSpecWithUIImpl.h index ddef607a6bb..b182bed8664 100644 --- a/mozilla/widget/src/xpwidgets/nsFileSpecWithUIImpl.h +++ b/mozilla/widget/src/xpwidgets/nsFileSpecWithUIImpl.h @@ -266,6 +266,8 @@ protected: nsCOMPtr mBaseFileSpec; + nsIDOMWindow *mParentWindow; + }; // class nsFileSpecWithUIImpl #endif // nsIFileSpecWithUIImpl_h__