зеркало из https://github.com/mozilla/pjs.git
Remove the long-deprecated nsIWebShell interface. Bug 273319, r=biesi, sr=jst.
This commit is contained in:
Родитель
2100a66919
Коммит
3203d0d58e
|
@ -55,7 +55,6 @@
|
|||
#include "nsIDocShellTreeOwner.h"
|
||||
#include "nsIDocShellLoadInfo.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
@ -502,6 +501,8 @@ nsFrameLoader::EnsureDocShell()
|
|||
parentAsNode->AddChild(docShellAsItem);
|
||||
|
||||
if (isContent) {
|
||||
// XXXbz why is this in content code, exactly? We should handle
|
||||
// this some other way.....
|
||||
nsCOMPtr<nsIDocShellTreeOwner> parentTreeOwner;
|
||||
parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner));
|
||||
|
||||
|
@ -514,15 +515,6 @@ nsFrameLoader::EnsureDocShell()
|
|||
}
|
||||
}
|
||||
|
||||
// connect the container...
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
nsCOMPtr<nsIWebShellContainer> outerContainer =
|
||||
do_QueryInterface(parentAsWebNav);
|
||||
|
||||
if (outerContainer) {
|
||||
webShell->SetContainer(outerContainer);
|
||||
}
|
||||
|
||||
// Make sure all shells have links back to the content element
|
||||
// in the nearest enclosing chrome shell.
|
||||
nsCOMPtr<nsIChromeEventHandler> chromeEventHandler;
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsDocShell.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsWebShell.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
|
@ -191,7 +190,6 @@ nsWebShell::~nsWebShell()
|
|||
|
||||
mContentViewer=nsnull;
|
||||
mDeviceContext=nsnull;
|
||||
NS_IF_RELEASE(mContainer);
|
||||
|
||||
if (mScriptGlobal) {
|
||||
mScriptGlobal->SetDocShell(nsnull);
|
||||
|
@ -247,9 +245,7 @@ NS_IMPL_ADDREF_INHERITED(nsWebShell, nsDocShell)
|
|||
NS_IMPL_RELEASE_INHERITED(nsWebShell, nsDocShell)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsWebShell)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebShell)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebShellServices)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebShellContainer)
|
||||
NS_INTERFACE_MAP_ENTRY(nsILinkHandler)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIClipboardCommands)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDocShell)
|
||||
|
@ -272,24 +268,6 @@ nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr)
|
|||
return nsDocShell::GetInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebShell::SetContainer(nsIWebShellContainer* aContainer)
|
||||
{
|
||||
NS_IF_RELEASE(mContainer);
|
||||
mContainer = aContainer;
|
||||
NS_IF_ADDREF(mContainer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebShell::GetContainer(nsIWebShellContainer*& aResult)
|
||||
{
|
||||
aResult = mContainer;
|
||||
NS_IF_ADDREF(mContainer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsEventStatus PR_CALLBACK
|
||||
nsWebShell::HandleEvent(nsGUIEvent *aEvent)
|
||||
{
|
||||
|
@ -687,7 +665,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
|
|||
// someone is so very very rude as to bring this window down
|
||||
// during this load handler.
|
||||
//
|
||||
nsCOMPtr<nsIWebShell> kungFuDeathGrip(this);
|
||||
nsCOMPtr<nsIDocShell> kungFuDeathGrip(this);
|
||||
nsDocShell::EndPageLoad(aProgress, channel, aStatus);
|
||||
|
||||
// Test if this is the top frame or a subframe
|
||||
|
@ -1141,15 +1119,6 @@ NS_IMETHODIMP nsWebShell::Create()
|
|||
return nsDocShell::Create();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebShell::Destroy()
|
||||
{
|
||||
nsDocShell::Destroy();
|
||||
|
||||
NS_IF_RELEASE(mContainer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
unsigned long nsWebShell::gNumberOfWebShells = 0;
|
||||
#endif
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
|
||||
#include "nsError.h"
|
||||
#include "nsIWebShellServices.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsILinkHandler.h"
|
||||
#include "nsIClipboardCommands.h"
|
||||
#include "nsDocShell.h"
|
||||
|
@ -62,9 +61,11 @@ typedef enum {
|
|||
|
||||
#define NS_ERROR_WEBSHELL_REQUEST_REJECTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL,1001)
|
||||
|
||||
// Class ID for webshell
|
||||
#define NS_WEB_SHELL_CID \
|
||||
{ 0xa6cf9059, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
class nsWebShell : public nsDocShell,
|
||||
public nsIWebShell,
|
||||
public nsIWebShellContainer,
|
||||
public nsIWebShellServices,
|
||||
public nsILinkHandler,
|
||||
public nsIClipboardCommands
|
||||
|
@ -80,16 +81,6 @@ public:
|
|||
NS_DECL_NSICLIPBOARDCOMMANDS
|
||||
NS_DECL_NSIWEBSHELLSERVICES
|
||||
|
||||
// nsIWebShell
|
||||
NS_IMETHOD SetContainer(nsIWebShellContainer* aContainer);
|
||||
NS_IMETHOD GetContainer(nsIWebShellContainer*& aResult);
|
||||
|
||||
// nsIWebShellContainer::GetContainer overrides an
|
||||
// nsIDocumentLoader method, so redeclare and forward
|
||||
NS_IMETHOD GetContainer(nsISupports** aContainer) {
|
||||
return nsDocLoader::GetContainer(aContainer);
|
||||
}
|
||||
|
||||
// nsILinkHandler
|
||||
NS_IMETHOD OnLinkClick(nsIContent* aContent,
|
||||
nsLinkVerb aVerb,
|
||||
|
@ -112,7 +103,6 @@ public:
|
|||
NS_IMETHOD GetLinkState(nsIURI* aLinkURI, nsLinkState& aState);
|
||||
|
||||
NS_IMETHOD Create();
|
||||
NS_IMETHOD Destroy();
|
||||
|
||||
// nsWebShell
|
||||
nsresult GetEventQueue(nsIEventQueue **aQueue);
|
||||
|
@ -124,7 +114,6 @@ public:
|
|||
friend struct OnLinkClickEvent;
|
||||
|
||||
protected:
|
||||
// void GetRootWebShellEvenIfChrome(nsIWebShell** aResult);
|
||||
void InitFrameData();
|
||||
|
||||
// helpers for executing commands
|
||||
|
@ -143,8 +132,6 @@ protected:
|
|||
|
||||
PRThread *mThread;
|
||||
|
||||
nsIWebShellContainer* mContainer;
|
||||
|
||||
eCharsetReloadState mCharsetReloadState;
|
||||
|
||||
nsISupports* mHistoryState; // Weak reference. Session history owns this.
|
||||
|
|
|
@ -117,7 +117,6 @@
|
|||
#include "nsIWebBrowser.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIWebBrowserFind.h" // For window.find()
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWindowMediator.h" // For window.find()
|
||||
#include "nsIComputedDOMStyle.h"
|
||||
#include "nsIEntropyCollector.h"
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include "nsIDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "nsGlobalWindow.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellLoadInfo.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
|
|
|
@ -522,7 +522,6 @@ EmbedPrivate::Paste()
|
|||
clipboard->Paste();
|
||||
}
|
||||
|
||||
#include <nsIWebShell.h>
|
||||
void
|
||||
EmbedPrivate::SelectAll()
|
||||
{
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIFocusController.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
|
@ -92,7 +91,6 @@
|
|||
#include "nsIEventSink.h"
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID);
|
||||
static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
|
||||
static NS_DEFINE_CID(kChildCID, NS_CHILD_CID);
|
||||
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
|
@ -1128,7 +1126,7 @@ NS_IMETHODIMP nsWebBrowser::Create()
|
|||
nsnull, nsnull, nsnull, &widgetInit);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_CreateInstance(kWebShellCID));
|
||||
nsCOMPtr<nsIDocShell> docShell(do_CreateInstance("@mozilla.org/webshell;1"));
|
||||
NS_ENSURE_SUCCESS(SetDocShell(docShell), NS_ERROR_FAILURE);
|
||||
|
||||
// get the system default window background colour
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDOMHTMLInputElement.h"
|
||||
#include "nsIFormControl.h"
|
||||
#include "nsIDocShell.h"
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "nsIDocumentViewer.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIContentViewerContainer.h"
|
||||
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsIScrollableView.h"
|
||||
|
|
|
@ -60,7 +60,6 @@
|
|||
#include "nsNetUtil.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIScriptContext.h"
|
||||
|
||||
|
|
|
@ -49,10 +49,10 @@ class nsIParser;
|
|||
|
||||
/*
|
||||
This interface is defined to be serverd as an Adaptor between
|
||||
nsIWebShell, nsICharsetDetector and nsIParserFilter
|
||||
nsIWebShellServices, nsICharsetDetector and nsIParserFilter
|
||||
|
||||
It make the nsICharsetDetector implementation independent from the
|
||||
nsIParserFilter and nsIWebShell
|
||||
nsIParserFilter and nsIWebShellServices
|
||||
*/
|
||||
|
||||
class nsICharsetDetectionAdaptor : public nsISupports {
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICHARSETDETECTIONADAPTOR_IID)
|
||||
/*
|
||||
Initialize it by setup the nsICharsetDetector and the
|
||||
nsIWebShell
|
||||
nsIWebShellServices
|
||||
*/
|
||||
NS_IMETHOD Init(nsIWebShellServices* aWebShell, nsICharsetDetector *aDetector,
|
||||
nsIDocument* aDocument, nsIParser* aParser,
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
#include "nsStyleConsts.h"
|
||||
#include "nsTableOuterFrame.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsHTMLContainerFrame.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsLayoutAtoms.h"
|
||||
|
|
|
@ -180,7 +180,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
|
|||
#include "nsINodeInfo.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsIWebShell.h"
|
||||
|
||||
//focus
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
|
|
|
@ -47,7 +47,6 @@ class nsIPresShell;
|
|||
class nsIDocument;
|
||||
class nsStyleSet;
|
||||
class nsIContent;
|
||||
class nsIWebShell;
|
||||
|
||||
// {D0B7F354-D575-43fd-903D-5AA35A193EDA}
|
||||
#define NS_IDOCUMENT_VIEWER_PRINT_IID \
|
||||
|
|
|
@ -52,7 +52,6 @@ struct nsRect;
|
|||
struct nsHTMLReflowState;
|
||||
struct nsSize;
|
||||
class nsIAtom;
|
||||
class nsIWebShell;
|
||||
class nsHTMLFramesetBorderFrame;
|
||||
struct nsGUIEvent;
|
||||
class nsHTMLFramesetFrame;
|
||||
|
|
|
@ -54,7 +54,6 @@ class nsPresContext;
|
|||
class nsITextContent;
|
||||
class nsIURI;
|
||||
class nsString;
|
||||
class nsIWebShell;
|
||||
class nsIPresShell;
|
||||
class nsIChannel;
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
#ifdef OJI
|
||||
#include "nsIJVMPluginTagInfo.h"
|
||||
#endif
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIEventListener.h"
|
||||
#include "nsIScrollableView.h"
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#include "nsCSSRendering.h"
|
||||
#include "prprf.h" // For PR_snprintf()
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIDocShellTreeOwner.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
|
|
|
@ -104,7 +104,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro
|
|||
#include "nsINodeInfo.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsIWebShell.h"
|
||||
|
||||
// Focus
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
|
@ -410,7 +409,7 @@ nsPrintEngine::GetNewPresentation(nsCOMPtr<nsIPresShell>& aShell,
|
|||
// Start at "1" and skip the FrameSet document itself
|
||||
for (PRInt32 i=1;i<cnt;i++) {
|
||||
nsPrintObject* po = (nsPrintObject *)mPrt->mPrintObject->mKids[i];
|
||||
nsCOMPtr<nsIDOMWindow> domWin(do_GetInterface(po->mWebShell));
|
||||
nsCOMPtr<nsIDOMWindow> domWin(do_GetInterface(po->mDocShell));
|
||||
if (domWin.get() == mPrt->mCurrentFocusWin.get()) {
|
||||
prtObjToDisplay = po;
|
||||
break;
|
||||
|
@ -423,7 +422,7 @@ nsPrintEngine::GetNewPresentation(nsCOMPtr<nsIPresShell>& aShell,
|
|||
// Start at "1" and skip the FrameSet document itself
|
||||
for (PRInt32 i=1;i<cnt;i++) {
|
||||
nsPrintObject* po = (nsPrintObject *)mPrt->mPrintObject->mKids[i];
|
||||
nsCOMPtr<nsIDOMWindow> domWin(do_GetInterface(po->mWebShell));
|
||||
nsCOMPtr<nsIDOMWindow> domWin(do_GetInterface(po->mDocShell));
|
||||
if (domWin.get() == mPrt->mCurrentFocusWin.get()) {
|
||||
nscoord width;
|
||||
nscoord height;
|
||||
|
@ -543,7 +542,7 @@ static void DumpViews(nsIDocShell* aDocShell, FILE* out);
|
|||
static void DumpLayoutData(char* aTitleStr, char* aURLStr,
|
||||
nsPresContext* aPresContext,
|
||||
nsIDeviceContext * aDC, nsIFrame * aRootFrame,
|
||||
nsIWebShell * aWebShell, FILE* aFD);
|
||||
nsIDocShell * aDocShell, FILE* aFD);
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
|
@ -628,7 +627,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
|
|||
// Check to see if there is a "regular" selection
|
||||
PRBool isSelection = IsThereARangeSelection(mPrt->mCurrentFocusWin);
|
||||
|
||||
// Create a list for storing the WebShells that need to be printed
|
||||
// Create a list for storing the DocShells that need to be printed
|
||||
if (mPrt->mPrintDocList == nsnull) {
|
||||
mPrt->mPrintDocList = new nsVoidArray();
|
||||
if (mPrt->mPrintDocList == nsnull) {
|
||||
|
@ -640,8 +639,8 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
|
|||
mPrt->mPrintDocList->Clear();
|
||||
}
|
||||
|
||||
// Get the webshell for this documentviewer
|
||||
nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));
|
||||
// Get the docshell for this documentviewer
|
||||
nsCOMPtr<nsIDocShell> webContainer(do_QueryInterface(mContainer));
|
||||
|
||||
// Add Root Doc to Tree and List
|
||||
mPrt->mPrintObject = new nsPrintObject();
|
||||
|
@ -666,8 +665,8 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
|
|||
MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject);
|
||||
|
||||
// Get whether the doc contains a frameset
|
||||
// Also, check to see if the currently focus webshell
|
||||
// is a child of this webshell
|
||||
// Also, check to see if the currently focus docshell
|
||||
// is a child of this docshell
|
||||
mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurrentFocusWin, mPrt->mIsParentAFrameSet);
|
||||
|
||||
CheckForHiddenFrameSetFrames();
|
||||
|
@ -1093,7 +1092,7 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings,
|
|||
// Check to see if there is a "regular" selection
|
||||
PRBool isSelection = IsThereARangeSelection(mPrt->mCurrentFocusWin);
|
||||
|
||||
// Create a list for storing the WebShells that need to be printed
|
||||
// Create a list for storing the DocShells that need to be printed
|
||||
if (!mPrt->mPrintDocList) {
|
||||
mPrt->mPrintDocList = new nsVoidArray();
|
||||
if (!mPrt->mPrintDocList) {
|
||||
|
@ -1106,8 +1105,8 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings,
|
|||
mPrt->mPrintDocList->Clear();
|
||||
}
|
||||
|
||||
// Get the webshell for this documentviewer
|
||||
nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));
|
||||
// Get the docshell for this documentviewer
|
||||
nsCOMPtr<nsIDocShell> webContainer(do_QueryInterface(mContainer));
|
||||
|
||||
// Add Root Doc to Tree and List
|
||||
mPrt->mPrintObject = new nsPrintObject();
|
||||
|
@ -1130,8 +1129,8 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings,
|
|||
MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject);
|
||||
|
||||
// Get whether the doc contains a frameset
|
||||
// Also, check to see if the currently focus webshell
|
||||
// is a child of this webshell
|
||||
// Also, check to see if the currently focus docshell
|
||||
// is a child of this docshell
|
||||
mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurrentFocusWin, mPrt->mIsParentAFrameSet);
|
||||
|
||||
CheckForHiddenFrameSetFrames();
|
||||
|
@ -1260,7 +1259,7 @@ nsPrintEngine::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum)
|
|||
NS_IMETHODIMP
|
||||
nsPrintEngine::GetIsFramesetDocument(PRBool *aIsFramesetDocument)
|
||||
{
|
||||
nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));
|
||||
nsCOMPtr<nsIDocShell> webContainer(do_QueryInterface(mContainer));
|
||||
*aIsFramesetDocument = IsParentAFrameSet(webContainer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1272,14 +1271,14 @@ nsPrintEngine::GetIsIFrameSelected(PRBool *aIsIFrameSelected)
|
|||
{
|
||||
*aIsIFrameSelected = PR_FALSE;
|
||||
|
||||
// Get the webshell for this documentviewer
|
||||
nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));
|
||||
// Get the docshell for this documentviewer
|
||||
nsCOMPtr<nsIDocShell> webContainer(do_QueryInterface(mContainer));
|
||||
// Get the currently focused window
|
||||
nsCOMPtr<nsIDOMWindow> currentFocusWin = FindFocusedDOMWindow();
|
||||
if (currentFocusWin && webContainer) {
|
||||
// Get whether the doc contains a frameset
|
||||
// Also, check to see if the currently focus webshell
|
||||
// is a child of this webshell
|
||||
// Also, check to see if the currently focus docshell
|
||||
// is a child of this docshell
|
||||
PRPackedBool isParentFrameSet;
|
||||
*aIsIFrameSelected = IsThereAnIFrameSelected(webContainer, currentFocusWin, isParentFrameSet);
|
||||
}
|
||||
|
@ -1711,14 +1710,12 @@ nsPrintEngine::IsThereARangeSelection(nsIDOMWindow* aDOMWin)
|
|||
|
||||
//---------------------------------------------------------------------
|
||||
PRBool
|
||||
nsPrintEngine::IsParentAFrameSet(nsIWebShell * aParent)
|
||||
nsPrintEngine::IsParentAFrameSet(nsIDocShell * aParent)
|
||||
{
|
||||
NS_ASSERTION(aParent, "Pointer is null!");
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aParent));
|
||||
NS_ASSERTION(docShell, "nsIDocShell can't be null");
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
docShell->GetPresShell(getter_AddRefs(shell));
|
||||
aParent->GetPresShell(getter_AddRefs(shell));
|
||||
NS_ASSERTION(shell, "shell can't be null");
|
||||
|
||||
// See if if the incoming doc is the root document
|
||||
|
@ -1788,10 +1785,10 @@ nsPrintEngine::BuildDocTree(nsIDocShellTreeNode * aParentNode,
|
|||
if (viewer) {
|
||||
nsCOMPtr<nsIContentViewerFile> viewerFile(do_QueryInterface(viewer));
|
||||
if (viewerFile) {
|
||||
nsCOMPtr<nsIWebShell> childWebShell(do_QueryInterface(child));
|
||||
nsCOMPtr<nsIDocShell> childDocShell(do_QueryInterface(child));
|
||||
nsCOMPtr<nsIDocShellTreeNode> childNode(do_QueryInterface(child));
|
||||
nsPrintObject * po = new nsPrintObject();
|
||||
if (NS_FAILED(po->Init(childWebShell))) {
|
||||
if (NS_FAILED(po->Init(childDocShell))) {
|
||||
NS_ASSERTION(0, "Failed initializing the Print Object");
|
||||
}
|
||||
po->mParent = aPO;
|
||||
|
@ -1930,10 +1927,10 @@ nsPrintEngine::MapContentForPO(nsPrintObject* aRootObject,
|
|||
nsIPresShell *presShell = subDoc->GetShellAt(0);
|
||||
|
||||
nsCOMPtr<nsISupports> container = subDoc->GetContainer();
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(container));
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
||||
|
||||
if (presShell && webShell) {
|
||||
nsPrintObject * po = FindPrintObjectByWS(aRootObject, webShell);
|
||||
if (presShell && docShell) {
|
||||
nsPrintObject * po = FindPrintObjectByDS(aRootObject, docShell);
|
||||
NS_ASSERTION(po, "PO can't be null!");
|
||||
|
||||
if (po) {
|
||||
|
@ -1977,20 +1974,20 @@ nsPrintEngine::MapContentForPO(nsPrintObject* aRootObject,
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Recursively finds a nsPrintObject that has the aWebShell
|
||||
nsPrintObject * nsPrintEngine::FindPrintObjectByWS(nsPrintObject* aPO, nsIWebShell * aWebShell)
|
||||
// Recursively finds a nsPrintObject that has the aDocShell
|
||||
nsPrintObject * nsPrintEngine::FindPrintObjectByDS(nsPrintObject* aPO, nsIDocShell * aDocShell)
|
||||
{
|
||||
NS_ASSERTION(aPO, "Pointer is null!");
|
||||
NS_ASSERTION(aWebShell, "Pointer is null!");
|
||||
NS_ASSERTION(aDocShell, "Pointer is null!");
|
||||
|
||||
if (aPO->mWebShell == aWebShell) {
|
||||
if (aPO->mDocShell == aDocShell) {
|
||||
return aPO;
|
||||
}
|
||||
PRInt32 cnt = aPO->mKids.Count();
|
||||
for (PRInt32 i=0;i<cnt;i++) {
|
||||
nsPrintObject* kid = (nsPrintObject*)aPO->mKids.ElementAt(i);
|
||||
NS_ASSERTION(kid, "nsPrintObject can't be null!");
|
||||
nsPrintObject* po = FindPrintObjectByWS(kid, aWebShell);
|
||||
nsPrintObject* po = FindPrintObjectByDS(kid, aDocShell);
|
||||
if (po != nsnull) {
|
||||
return po;
|
||||
}
|
||||
|
@ -2000,11 +1997,11 @@ nsPrintObject * nsPrintEngine::FindPrintObjectByWS(nsPrintObject* aPO, nsIWebShe
|
|||
|
||||
//---------------------------------------------------------------------
|
||||
PRBool
|
||||
nsPrintEngine::IsThereAnIFrameSelected(nsIWebShell* aWebShell,
|
||||
nsPrintEngine::IsThereAnIFrameSelected(nsIDocShell* aDocShell,
|
||||
nsIDOMWindow* aDOMWin,
|
||||
PRPackedBool& aIsParentFrameSet)
|
||||
{
|
||||
aIsParentFrameSet = IsParentAFrameSet(aWebShell);
|
||||
aIsParentFrameSet = IsParentAFrameSet(aDocShell);
|
||||
PRBool iFrameIsSelected = PR_FALSE;
|
||||
if (mPrt && mPrt->mPrintObject) {
|
||||
nsPrintObject* po = FindPrintObjectByDOMWin(mPrt->mPrintObject, aDOMWin);
|
||||
|
@ -2013,12 +2010,12 @@ nsPrintEngine::IsThereAnIFrameSelected(nsIWebShell* aWebShell,
|
|||
// First, check to see if we are a frameset
|
||||
if (!aIsParentFrameSet) {
|
||||
// Check to see if there is a currenlt focused frame
|
||||
// if so, it means the selected frame is either the main webshell
|
||||
// if so, it means the selected frame is either the main docshell
|
||||
// or an IFRAME
|
||||
if (aDOMWin) {
|
||||
// Get the main webshell's DOMWin to see if it matches
|
||||
// Get the main docshell's DOMWin to see if it matches
|
||||
// the frame that is selected
|
||||
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(aWebShell);
|
||||
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(aDocShell);
|
||||
if (domWin != aDOMWin) {
|
||||
iFrameIsSelected = PR_TRUE; // we have a selected IFRAME
|
||||
}
|
||||
|
@ -2464,9 +2461,9 @@ nsPrintEngine::SetupToPrintContent(nsIDeviceContext* aDContext,
|
|||
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_BEGINDOC, rv, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// This will print the webshell document
|
||||
// This will print the docshell document
|
||||
// when it completes asynchronously in the DonePrintingPages method
|
||||
// it will check to see if there are more webshells to be printed and
|
||||
// it will check to see if there are more docshells to be printed and
|
||||
// then PrintDocContent will be called again.
|
||||
|
||||
if (mIsDoingPrinting) {
|
||||
|
@ -2717,7 +2714,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink)
|
|||
mPresContext->CompatibilityMode());
|
||||
|
||||
if (!containerIsSet) {
|
||||
nsCOMPtr<nsISupports> supps(do_QueryInterface(aPO->mWebShell));
|
||||
nsCOMPtr<nsISupports> supps(do_QueryInterface(aPO->mDocShell));
|
||||
aPO->mPresContext->SetContainer(supps);
|
||||
}
|
||||
|
||||
|
@ -2729,8 +2726,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink)
|
|||
presShell->CaptureHistoryState(getter_AddRefs(layoutState), PR_TRUE);
|
||||
|
||||
// set it on the new pres shell
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aPO->mWebShell));
|
||||
docShell->SetLayoutHistoryState(layoutState);
|
||||
aPO->mDocShell->SetLayoutHistoryState(layoutState);
|
||||
|
||||
// turn off animated GIFs
|
||||
if (aPO->mPresContext) {
|
||||
|
@ -3010,7 +3006,7 @@ nsPrintEngine::CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPage
|
|||
//-----------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Called for each WebShell that needs to be printed
|
||||
// Called for each DocShell that needs to be printed
|
||||
PRBool
|
||||
nsPrintEngine::PrintDocContent(nsPrintObject* aPO, nsresult& aStatus)
|
||||
{
|
||||
|
@ -3085,19 +3081,19 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDon
|
|||
PR_PL(("**************************** %s ****************************\n", gFrameTypesStr[aPO->mFrameType]));
|
||||
PR_PL(("****** In DV::DoPrint PO: %p aDoSyncPrinting: %s \n", aPO, PRT_YESNO(aDoSyncPrinting)));
|
||||
|
||||
nsIWebShell* webShell = aPO->mWebShell.get();
|
||||
nsIDocShell* docShell = aPO->mDocShell;
|
||||
nsIPresShell* poPresShell = aPO->mPresShell;
|
||||
nsPresContext* poPresContext = aPO->mPresContext;
|
||||
nsIView* poRootView = aPO->mRootView;
|
||||
|
||||
NS_ASSERTION(webShell, "The WebShell can't be NULL!");
|
||||
NS_ASSERTION(docShell, "The DocShell can't be NULL!");
|
||||
NS_ASSERTION(poPresContext, "PrintObject has not been reflowed");
|
||||
|
||||
if (mPrt->mPrintProgressParams) {
|
||||
SetDocAndURLIntoProgress(aPO, mPrt->mPrintProgressParams);
|
||||
}
|
||||
|
||||
if (webShell != nsnull) {
|
||||
if (docShell) {
|
||||
|
||||
PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages;
|
||||
nsresult rv;
|
||||
|
@ -3248,7 +3244,7 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO, PRBool aDoSyncPrinting, PRBool& aDon
|
|||
char * docStr;
|
||||
char * urlStr;
|
||||
GetDocTitleAndURL(aPO, docStr, urlStr);
|
||||
DumpLayoutData(docStr, urlStr, poPresContext, mPrt->mPrintDocDC, rootFrame, webShell, nsnull);
|
||||
DumpLayoutData(docStr, urlStr, poPresContext, mPrt->mPrintDocDC, rootFrame, docShell, nsnull);
|
||||
if (docStr) nsMemory::Free(docStr);
|
||||
if (urlStr) nsMemory::Free(urlStr);
|
||||
}
|
||||
|
@ -3383,7 +3379,7 @@ nsPrintEngine::SetDocAndURLIntoProgress(nsPrintObject* aPO,
|
|||
NS_ASSERTION(aPO, "Must have vaild nsPrintObject");
|
||||
NS_ASSERTION(aParams, "Must have vaild nsIPrintProgressParams");
|
||||
|
||||
if (!aPO || !aPO->mWebShell || !aParams) {
|
||||
if (!aPO || !aPO->mDocShell || !aParams) {
|
||||
return;
|
||||
}
|
||||
const PRUint32 kTitleLength = 64;
|
||||
|
@ -3990,22 +3986,22 @@ nsPrintEngine::IsWindowsInOurSubTree(nsIDOMWindow * aDOMWindow)
|
|||
{
|
||||
PRBool found = PR_FALSE;
|
||||
|
||||
// now check to make sure it is in "our" tree of webshells
|
||||
// now check to make sure it is in "our" tree of docshells
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWindow));
|
||||
if (scriptObj) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
do_QueryInterface(scriptObj->GetDocShell());
|
||||
|
||||
if (docShellAsItem) {
|
||||
// get this DocViewer webshell
|
||||
nsCOMPtr<nsIWebShell> thisDVWebShell(do_QueryInterface(mContainer));
|
||||
// get this DocViewer docshell
|
||||
nsCOMPtr<nsIDocShell> thisDVDocShell(do_QueryInterface(mContainer));
|
||||
while (!found) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellParent;
|
||||
docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent));
|
||||
|
||||
nsCOMPtr<nsIWebShell> parentWebshell(do_QueryInterface(docShellParent));
|
||||
if (parentWebshell) {
|
||||
if (parentWebshell == thisDVWebShell) {
|
||||
nsCOMPtr<nsIDocShell> parentDocshell(do_QueryInterface(docShellParent));
|
||||
if (parentDocshell) {
|
||||
if (parentDocshell == thisDVDocShell) {
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
|
@ -4145,7 +4141,7 @@ nsPrintEngine::FindPrintObjectByDOMWin(nsPrintObject* aPO,
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domWin(do_GetInterface(aPO->mWebShell));
|
||||
nsCOMPtr<nsIDOMWindow> domWin(do_GetInterface(aPO->mDocShell));
|
||||
if (domWin && domWin == aDOMWin) {
|
||||
return aPO;
|
||||
}
|
||||
|
@ -4251,7 +4247,7 @@ nsPrintEngine::EnablePOsForPrinting()
|
|||
//
|
||||
// XXX this is sort of a hack right here to make the page
|
||||
// not try to reposition itself when printing selection
|
||||
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(po->mWebShell);
|
||||
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(po->mDocShell);
|
||||
if (!IsThereARangeSelection(domWin)) {
|
||||
printRangeType = nsIPrintSettings::kRangeAllPages;
|
||||
mPrt->mPrintSettings->SetPrintRange(printRangeType);
|
||||
|
@ -4265,7 +4261,7 @@ nsPrintEngine::EnablePOsForPrinting()
|
|||
for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {
|
||||
nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i);
|
||||
NS_ASSERTION(po, "nsPrintObject can't be null!");
|
||||
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(po->mWebShell);
|
||||
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(po->mDocShell);
|
||||
if (IsThereARangeSelection(domWin)) {
|
||||
mPrt->mCurrentFocusWin = domWin;
|
||||
SetPrintPO(po, PR_TRUE);
|
||||
|
@ -4298,7 +4294,7 @@ nsPrintEngine::EnablePOsForPrinting()
|
|||
//
|
||||
// XXX this is sort of a hack right here to make the page
|
||||
// not try to reposition itself when printing selection
|
||||
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(po->mWebShell);
|
||||
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(po->mDocShell);
|
||||
if (!IsThereARangeSelection(domWin)) {
|
||||
printRangeType = nsIPrintSettings::kRangeAllPages;
|
||||
mPrt->mPrintSettings->SetPrintRange(printRangeType);
|
||||
|
@ -4790,7 +4786,7 @@ void DumpLayoutData(char* aTitleStr,
|
|||
nsPresContext* aPresContext,
|
||||
nsIDeviceContext * aDC,
|
||||
nsIFrame * aRootFrame,
|
||||
nsIWebShell * aWebShell,
|
||||
nsIDocShekk * aDocShell,
|
||||
FILE* aFD = nsnull)
|
||||
{
|
||||
if (!kPrintingLogMod || kPrintingLogMod->level != DUMP_LAYOUT_LEVEL) return;
|
||||
|
@ -4806,7 +4802,7 @@ void DumpLayoutData(char* aTitleStr,
|
|||
#endif
|
||||
|
||||
NS_ASSERTION(aRootFrame, "Pointer is null!");
|
||||
NS_ASSERTION(aWebShell, "Pointer is null!");
|
||||
NS_ASSERTION(aDocShell, "Pointer is null!");
|
||||
|
||||
// Dump all the frames and view to a a file
|
||||
char filename[256];
|
||||
|
@ -4829,10 +4825,9 @@ void DumpLayoutData(char* aTitleStr,
|
|||
} else {
|
||||
printf("View is null!\n");
|
||||
}
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebShell));
|
||||
if (docShell) {
|
||||
if (aDocShell) {
|
||||
fprintf(fd, "--------------- All Views ----------------\n");
|
||||
DumpViews(docShell, fd);
|
||||
DumpViews(aDocShell, fd);
|
||||
fprintf(fd, "---------------------------------------\n\n");
|
||||
}
|
||||
if (aFD == nsnull) {
|
||||
|
@ -4850,7 +4845,7 @@ static void DumpPrintObjectsList(nsVoidArray * aDocList)
|
|||
|
||||
const char types[][3] = {"DC", "FR", "IF", "FS"};
|
||||
PR_PL(("Doc List\n***************************************************\n"));
|
||||
PR_PL(("T P A H PO WebShell Seq Page Root Page# Rect\n"));
|
||||
PR_PL(("T P A H PO DocShell Seq Page Root Page# Rect\n"));
|
||||
PRInt32 cnt = aDocList->Count();
|
||||
for (PRInt32 i=0;i<cnt;i++) {
|
||||
nsPrintObject* po = (nsPrintObject*)aDocList->ElementAt(i);
|
||||
|
@ -4868,7 +4863,7 @@ static void DumpPrintObjectsList(nsVoidArray * aDocList)
|
|||
}
|
||||
|
||||
PR_PL(("%s %d %d %d %p %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType],
|
||||
po->IsPrintable(), po->mPrintAsIs, po->mHasBeenPrinted, po, po->mWebShell.get(), po->mSeqFrame,
|
||||
po->IsPrintable(), po->mPrintAsIs, po->mHasBeenPrinted, po, po->mDocShell.get(), po->mSeqFrame,
|
||||
po->mPageFrame, rootFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height));
|
||||
}
|
||||
}
|
||||
|
@ -4884,14 +4879,14 @@ static void DumpPrintObjectsTree(nsPrintObject * aPO, int aLevel, FILE* aFD)
|
|||
const char types[][3] = {"DC", "FR", "IF", "FS"};
|
||||
if (aLevel == 0) {
|
||||
fprintf(fd, "DocTree\n***************************************************\n");
|
||||
fprintf(fd, "T PO WebShell Seq Page Page# Rect\n");
|
||||
fprintf(fd, "T PO DocShell Seq Page Page# Rect\n");
|
||||
}
|
||||
PRInt32 cnt = aPO->mKids.Count();
|
||||
for (PRInt32 i=0;i<cnt;i++) {
|
||||
nsPrintObject* po = (nsPrintObject*)aPO->mKids.ElementAt(i);
|
||||
NS_ASSERTION(po, "nsPrintObject can't be null!");
|
||||
for (PRInt32 k=0;k<aLevel;k++) fprintf(fd, " ");
|
||||
fprintf(fd, "%s %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], po, po->mWebShell.get(), po->mSeqFrame,
|
||||
fprintf(fd, "%s %p %p %p %p %d %d,%d,%d,%d\n", types[po->mFrameType], po, po->mDocShell.get(), po->mSeqFrame,
|
||||
po->mPageFrame, po->mPageNum, po->mRect.x, po->mRect.y, po->mRect.width, po->mRect.height);
|
||||
}
|
||||
}
|
||||
|
@ -4942,7 +4937,7 @@ static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,
|
|||
fd = fopen("tree_layout.txt", "w");
|
||||
fprintf(fd, "DocTree\n***************************************************\n");
|
||||
fprintf(fd, "***************************************************\n");
|
||||
fprintf(fd, "T PO WebShell Seq Page Page# Rect\n");
|
||||
fprintf(fd, "T PO DocShell Seq Page Page# Rect\n");
|
||||
} else {
|
||||
fd = aFD;
|
||||
}
|
||||
|
@ -4952,13 +4947,13 @@ static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,
|
|||
rootFrame = aPO->mPresShell->FrameManager()->GetRootFrame();
|
||||
}
|
||||
for (PRInt32 k=0;k<aLevel;k++) fprintf(fd, " ");
|
||||
fprintf(fd, "%s %p %p %p %p %d %d,%d,%d,%d\n", types[aPO->mFrameType], aPO, aPO->mWebShell.get(), aPO->mSeqFrame,
|
||||
fprintf(fd, "%s %p %p %p %p %d %d,%d,%d,%d\n", types[aPO->mFrameType], aPO, aPO->mDocShell.get(), aPO->mSeqFrame,
|
||||
aPO->mPageFrame, aPO->mPageNum, aPO->mRect.x, aPO->mRect.y, aPO->mRect.width, aPO->mRect.height);
|
||||
if (aPO->IsPrintable()) {
|
||||
char * docStr;
|
||||
char * urlStr;
|
||||
GetDocTitleAndURL(aPO, docStr, urlStr);
|
||||
DumpLayoutData(docStr, urlStr, aPO->mPresContext, aDC, rootFrame, aPO->mWebShell, fd);
|
||||
DumpLayoutData(docStr, urlStr, aPO->mPresContext, aDC, rootFrame, aPO->mDocShell, fd);
|
||||
if (docStr) nsMemory::Free(docStr);
|
||||
if (urlStr) nsMemory::Free(urlStr);
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ public:
|
|||
nsresult ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink);
|
||||
nsresult CalcPageFrameLocation(nsIPresShell * aPresShell,
|
||||
nsPrintObject* aPO);
|
||||
nsPrintObject * FindPrintObjectByWS(nsPrintObject* aPO, nsIWebShell * aWebShell);
|
||||
nsPrintObject * FindPrintObjectByDS(nsPrintObject* aPO, nsIDocShell * aDocShell);
|
||||
void MapContentForPO(nsPrintObject* aRootObject,
|
||||
nsIPresShell* aPresShell,
|
||||
nsIContent* aContent);
|
||||
|
@ -215,8 +215,8 @@ public:
|
|||
PRUint32 aDelay);
|
||||
|
||||
PRBool IsWindowsInOurSubTree(nsIDOMWindow * aDOMWindow);
|
||||
PRBool IsParentAFrameSet(nsIWebShell * aParent);
|
||||
PRBool IsThereAnIFrameSelected(nsIWebShell* aWebShell,
|
||||
PRBool IsParentAFrameSet(nsIDocShell * aParent);
|
||||
PRBool IsThereAnIFrameSelected(nsIDocShell* aDocShell,
|
||||
nsIDOMWindow* aDOMWin,
|
||||
PRPackedBool& aIsParentFrameSet);
|
||||
|
||||
|
|
|
@ -80,11 +80,9 @@ nsPrintObject::~nsPrintObject()
|
|||
//------------------------------------------------------------------
|
||||
// Resets PO by destroying the presentation
|
||||
nsresult
|
||||
nsPrintObject::Init(nsIWebShell* aWebShell)
|
||||
nsPrintObject::Init(nsIDocShell* aDocShell)
|
||||
{
|
||||
mWebShell = aWebShell;
|
||||
|
||||
mDocShell = do_QueryInterface(mWebShell);
|
||||
mDocShell = aDocShell;
|
||||
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
||||
|
||||
mDocShell->GetPresShell(getter_AddRefs(mDisplayPresShell));
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
#include "nsIPresShell.h"
|
||||
#include "nsStyleSet.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIWidget.h"
|
||||
|
@ -67,13 +66,12 @@ public:
|
|||
~nsPrintObject(); // non-virtual
|
||||
|
||||
// Methods
|
||||
nsresult Init(nsIWebShell* aWebShell);
|
||||
nsresult Init(nsIDocShell* aDocShell);
|
||||
|
||||
PRBool IsPrintable() { return !mDontPrint; }
|
||||
void DestroyPresentation();
|
||||
|
||||
// Data Members
|
||||
nsCOMPtr<nsIWebShell> mWebShell;
|
||||
nsCOMPtr<nsIDocShell> mDocShell;
|
||||
nsCOMPtr<nsIPresShell> mDisplayPresShell;
|
||||
nsCOMPtr<nsPresContext> mDisplayPresContext;
|
||||
|
|
|
@ -84,8 +84,9 @@ interface nsIMsgMessageService : nsISupports {
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// DisplayMessage: When you want a message displayed....
|
||||
// aMessageURI is a uri representing the message to display.
|
||||
// aDisplayConsumer is (for now) a nsIWebshell which we'll use to load
|
||||
// the message into.
|
||||
// aDisplayConsumer is (for now) an nsIDocShell which we'll use to load
|
||||
// the message into.
|
||||
// XXXbz Should it be an nsIWebNavigation or something?
|
||||
// aCharsetOverride (optional) character set over ride to force the message to
|
||||
// use.
|
||||
//
|
||||
|
@ -142,8 +143,9 @@ interface nsIMsgMessageService : nsISupports {
|
|||
// DisplayMessageForPrinting: When you want a message displayed in a
|
||||
// format that is suitable for printing....
|
||||
// aMessageURI is a uri representing the message to display.
|
||||
// aDisplayConsumer is (for now) a nsIWebshell which we'll use to load
|
||||
// the message into.
|
||||
// aDisplayConsumer is (for now) a nsIDocShell which we'll use to load
|
||||
// the message into.
|
||||
// XXXbz should it be an nsIWebNavigation?
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
void DisplayMessageForPrinting(in string aMessageURI, in nsISupports aDisplayConsumer,
|
||||
|
|
|
@ -79,7 +79,6 @@
|
|||
#include "nsLayoutCID.h"
|
||||
#include "nsIMarkupDocumentViewer.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIWebShell.h"
|
||||
|
||||
// embedding
|
||||
#include "nsIWebBrowserPrint.h"
|
||||
|
@ -569,8 +568,7 @@ nsMessenger::OpenURL(const char *aURL)
|
|||
|
||||
if (NS_SUCCEEDED(rv) && messageService)
|
||||
{
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
messageService->DisplayMessage(aURL, webShell, mMsgWindow, nsnull, nsnull, nsnull);
|
||||
messageService->DisplayMessage(aURL, mDocShell, mMsgWindow, nsnull, nsnull, nsnull);
|
||||
mLastDisplayURI = aURL; // remember the last uri we displayed....
|
||||
}
|
||||
//If it's not something we know about, then just load the url.
|
||||
|
@ -1518,8 +1516,7 @@ NS_IMETHODIMP nsMessenger::SetDocumentCharset(const char *characterSet)
|
|||
|
||||
if (NS_SUCCEEDED(rv) && messageService)
|
||||
{
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
messageService->DisplayMessage(mLastDisplayURI.get(), webShell, mMsgWindow, nsnull, characterSet, nsnull);
|
||||
messageService->DisplayMessage(mLastDisplayURI.get(), mDocShell, mMsgWindow, nsnull, characterSet, nsnull);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#include "nsEscape.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
|
@ -66,9 +65,8 @@
|
|||
#include "nsMsgPrintEngine.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIXULWindow.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
|
||||
|
@ -314,25 +312,15 @@ nsMsgPrintEngine::ShowWindow(PRBool aShow)
|
|||
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIWebShell> webShell =
|
||||
nsCOMPtr <nsIDocShellTreeItem> treeItem =
|
||||
do_QueryInterface(globalScript->GetDocShell(), &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIWebShellContainer> webShellContainer;
|
||||
rv = webShell->GetContainer(*getter_AddRefs(webShellContainer));
|
||||
nsCOMPtr <nsIDocShellTreeOwner> treeOwner;
|
||||
rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
if (webShellContainer) {
|
||||
nsCOMPtr <nsIWebShellWindow> webShellWindow = do_QueryInterface(webShellContainer, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(webShell, &rv));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
if (treeOwner) {
|
||||
// disable (enable) the window
|
||||
nsCOMPtr<nsIBaseWindow> baseWindow;
|
||||
baseWindow = do_QueryInterface(treeOwner, &rv);
|
||||
|
@ -342,7 +330,7 @@ nsMsgPrintEngine::ShowWindow(PRBool aShow)
|
|||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
// hide or show the window
|
||||
rv = webShellWindow->Show(aShow);
|
||||
baseWindow->SetVisibility(aShow);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -561,8 +549,7 @@ nsMsgPrintEngine::FireThatLoadOperation(nsString *uri)
|
|||
|
||||
if (NS_SUCCEEDED(rv) && messageService)
|
||||
{
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
rv = messageService->DisplayMessageForPrinting(tString, webShell, nsnull, nsnull, nsnull);
|
||||
rv = messageService->DisplayMessageForPrinting(tString, mDocShell, nsnull, nsnull, nsnull);
|
||||
}
|
||||
//If it's not something we know about, then just load try loading it directly.
|
||||
else
|
||||
|
|
|
@ -66,8 +66,6 @@
|
|||
#include "nsMsgI18N.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsISupportsObsolete.h"
|
||||
// XXX Remove
|
||||
#include "nsIWebShell.h"
|
||||
|
||||
// used to dispatch urls to default protocol handlers
|
||||
#include "nsCExternalHandlerService.h"
|
||||
|
|
|
@ -62,7 +62,6 @@
|
|||
#include "nsIMsgMailSession.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIAuthPrompt.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
@ -866,9 +865,7 @@ nsMsgIncomingServer::GetPasswordWithUI(const PRUnichar * aPromptMessage, const
|
|||
rv = aMsgWindow->GetRootDocShell(getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
dialog = do_GetInterface(webShell, &rv);
|
||||
dialog = do_GetInterface(docShell, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "nsReadableUtils.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
|
|
|
@ -63,8 +63,6 @@
|
|||
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIXULWindow.h"
|
||||
|
@ -78,6 +76,8 @@
|
|||
#include "nsMsgBaseCID.h"
|
||||
#include "nsIMsgAccountManager.h"
|
||||
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
|
||||
#ifdef MSGCOMP_TRACE_PERFORMANCE
|
||||
#include "prlog.h"
|
||||
#include "nsIMsgHdr.h"
|
||||
|
@ -826,14 +826,14 @@ nsresult nsMsgComposeService::ShowCachedComposeWindow(nsIDOMWindowInternal *aCom
|
|||
|
||||
nsIDocShell *docShell = globalScript->GetDocShell();
|
||||
|
||||
nsCOMPtr <nsIWebShell> webShell = do_QueryInterface(docShell, &rv);
|
||||
nsCOMPtr <nsIDocShellTreeItem> treeItem = do_QueryInterface(docShell, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIWebShellContainer> webShellContainer;
|
||||
rv = webShell->GetContainer(*getter_AddRefs(webShellContainer));
|
||||
nsCOMPtr <nsIDocShellTreeOwner> treeOwner;
|
||||
rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
if (webShellContainer) {
|
||||
if (treeOwner) {
|
||||
|
||||
// the window need to be sticky before we hide it.
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
|
@ -844,16 +844,6 @@ nsresult nsMsgComposeService::ShowCachedComposeWindow(nsIDOMWindowInternal *aCom
|
|||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
// disable (enable) the cached window
|
||||
nsCOMPtr <nsIWebShellWindow> webShellWindow = do_QueryInterface(webShellContainer, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docShell, &rv));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> baseWindow;
|
||||
baseWindow = do_QueryInterface(treeOwner, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
@ -861,7 +851,7 @@ nsresult nsMsgComposeService::ShowCachedComposeWindow(nsIDOMWindowInternal *aCom
|
|||
baseWindow->SetEnabled(aShow);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIXULWindow> xulWindow = do_QueryInterface(webShellWindow, &rv);
|
||||
nsCOMPtr <nsIXULWindow> xulWindow = do_GetInterface(treeOwner, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIWindowMediator> windowMediator =
|
||||
|
@ -875,7 +865,7 @@ nsresult nsMsgComposeService::ShowCachedComposeWindow(nsIDOMWindowInternal *aCom
|
|||
}
|
||||
|
||||
// hide (show) the cached window
|
||||
rv = webShellWindow->Show(aShow);
|
||||
rv = baseWindow->SetVisibility(aShow);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
// if hiding, remove the window from the mediator,
|
||||
|
|
|
@ -86,7 +86,6 @@
|
|||
#include "nsIMsgStatusFeedback.h"
|
||||
#include "nsIMsgMailSession.h"
|
||||
#include "nsTextFormatter.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsMailHeaders.h"
|
||||
#include "nsIDocShell.h"
|
||||
|
|
|
@ -73,7 +73,6 @@
|
|||
|
||||
#include "nsIMsgWindow.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
|
||||
|
@ -1383,10 +1382,7 @@ nsMsgNewsFolder::GetGroupPasswordWithUI(const PRUnichar * aPromptMessage, const
|
|||
rv = aMsgWindow->GetRootDocShell(getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
dialog = do_GetInterface(webShell, &rv);
|
||||
dialog = do_GetInterface(docShell, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else
|
||||
|
@ -1454,9 +1450,7 @@ nsMsgNewsFolder::GetGroupUsernameWithUI(const PRUnichar * aPromptMessage, const
|
|||
nsCOMPtr<nsIDocShell> docShell;
|
||||
rv = aMsgWindow->GetRootDocShell(getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
dialog = do_GetInterface(webShell, &rv);
|
||||
dialog = do_GetInterface(docShell, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#include "nsXPCOM.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsString.h"
|
||||
class nsIWebShell;
|
||||
class nsIDocShell;
|
||||
|
||||
extern "C" NS_EXPORT int DebugRobot(nsVoidArray * workList, nsIWebShell * ww);
|
||||
//XXXbz is this even used? There is no DebugRobot() with this
|
||||
//signature in the tree!
|
||||
|
||||
extern "C" NS_EXPORT int DebugRobot(nsVoidArray * workList, nsIDocShell * ww);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
|
|
@ -1,427 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// Special stuff for the Macintosh implementation of command-line service.
|
||||
|
||||
#include "nsCommandLineServiceMac.h"
|
||||
|
||||
// Mozilla
|
||||
#include "nsDebug.h"
|
||||
#include "nsILocalFileMac.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIAppStartup.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsICloseAllWindows.h"
|
||||
#include "nsIPrefService.h"
|
||||
|
||||
#include "nsAEEventHandling.h"
|
||||
#include "nsXPFEComponentsCID.h"
|
||||
|
||||
// NSPR
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include "prenv.h"
|
||||
#ifdef XP_MAC
|
||||
#include "pprio.h" // PR_Init_Log
|
||||
#endif
|
||||
|
||||
// the static instance
|
||||
nsMacCommandLine nsMacCommandLine::sMacCommandLine;
|
||||
|
||||
/*
|
||||
* ReadLine --
|
||||
*
|
||||
* Read in a line of text, terminated by CR or LF, from inStream into buf.
|
||||
* The terminating CR or LF is not included. The text in buf is terminated
|
||||
* by a null byte.
|
||||
* Returns the number of bytes in buf. If EOF and zero bytes were read, returns -1.
|
||||
*/
|
||||
|
||||
static PRInt32 ReadLine(FILE* inStream, char* buf, PRInt32 bufSize)
|
||||
{
|
||||
PRInt32 charsRead = 0;
|
||||
int c;
|
||||
|
||||
if (bufSize < 2)
|
||||
return -1;
|
||||
|
||||
while (charsRead < (bufSize-1)) {
|
||||
c = getc(inStream);
|
||||
if (c == EOF || c == '\n' || c == '\r')
|
||||
break;
|
||||
buf[charsRead++] = c;
|
||||
}
|
||||
buf[charsRead] = '\0';
|
||||
|
||||
return (c == EOF && !charsRead) ? -1 : charsRead;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsMacCommandLine::nsMacCommandLine()
|
||||
: mArgs(NULL)
|
||||
, mArgsAllocated(0)
|
||||
, mArgsUsed(0)
|
||||
, mStartedUp(PR_FALSE)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsMacCommandLine::~nsMacCommandLine()
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
ShutdownAEHandlerClasses();
|
||||
if (mArgs) {
|
||||
for (PRUint32 i = 0; i < mArgsUsed; i++)
|
||||
free(mArgs[i]);
|
||||
free(mArgs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsMacCommandLine::Initialize(int& argc, char**& argv)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
mArgs = static_cast<char **>(malloc(kArgsGrowSize * sizeof(char *)));
|
||||
if (!mArgs)
|
||||
return NS_ERROR_FAILURE;
|
||||
mArgs[0] = nsnull;
|
||||
mArgsAllocated = kArgsGrowSize;
|
||||
mArgsUsed = 0;
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
// Here, we may actually get useful args.
|
||||
// Copy them first to mArgv.
|
||||
for (int arg = 0; arg < argc; arg++)
|
||||
AddToCommandLine(argv[arg]);
|
||||
#else
|
||||
// init the args buffer with the program name
|
||||
AddToCommandLine("mozilla");
|
||||
#endif
|
||||
|
||||
// Set up AppleEvent handling.
|
||||
OSErr err = CreateAEHandlerClasses(false);
|
||||
if (err != noErr) return NS_ERROR_FAILURE;
|
||||
|
||||
// Snarf all the odoc and pdoc apple-events.
|
||||
//
|
||||
// 1. If they are odoc for 'CMDL' documents, read them into the buffer ready for
|
||||
// parsing (concatenating multiple files).
|
||||
//
|
||||
// 2. If they are any other kind of document, convert them into -url command-line
|
||||
// parameters or -print parameters, with file URLs.
|
||||
|
||||
EventRecord anEvent;
|
||||
for (short i = 1; i < 5; i++)
|
||||
::WaitNextEvent(0, &anEvent, 0, nsnull);
|
||||
|
||||
while (::EventAvail(highLevelEventMask, &anEvent))
|
||||
{
|
||||
::WaitNextEvent(highLevelEventMask, &anEvent, 0, nsnull);
|
||||
if (anEvent.what == kHighLevelEvent)
|
||||
{
|
||||
// here we process startup odoc/pdoc events, which can
|
||||
// add items to the command line.
|
||||
err = ::AEProcessAppleEvent(&anEvent);
|
||||
}
|
||||
}
|
||||
|
||||
if (GetCurrentKeyModifiers() & optionKey)
|
||||
AddToCommandLine("-p");
|
||||
|
||||
// we've started up now
|
||||
mStartedUp = PR_TRUE;
|
||||
|
||||
argc = mArgsUsed;
|
||||
argv = mArgs;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsMacCommandLine::AddToCommandLine(const char* inArgText)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (mArgsUsed >= mArgsAllocated) {
|
||||
// realloc does not free the given pointer if allocation fails.
|
||||
char **temp = static_cast<char **>(realloc(mArgs, (mArgsAllocated + kArgsGrowSize) * sizeof(char *)));
|
||||
if (!temp)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
mArgs = temp;
|
||||
mArgsAllocated += kArgsGrowSize;
|
||||
}
|
||||
char *temp2 = strdup(inArgText);
|
||||
if (!temp2)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
mArgs[mArgsUsed++] = temp2;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsMacCommandLine::AddToCommandLine(const char* inOptionString, const FSSpec& inFileSpec)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// Convert the filespec to a URL
|
||||
FSSpec nonConstSpec = inFileSpec;
|
||||
nsCOMPtr<nsILocalFileMac> inFile;
|
||||
nsresult rv = NS_NewLocalFileWithFSSpec(&nonConstSpec, PR_TRUE, getter_AddRefs(inFile));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCAutoString specBuf;
|
||||
rv = NS_GetURLSpecFromFile(inFile, specBuf);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
AddToCommandLine(inOptionString);
|
||||
AddToCommandLine(specBuf.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsMacCommandLine::AddToEnvironmentVars(const char* inArgText)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
(void)PR_SetEnv(inArgText);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
OSErr nsMacCommandLine::HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFileType)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsCOMPtr<nsILocalFileMac> inFile;
|
||||
nsresult rv = NS_NewLocalFileWithFSSpec(&inFileSpec, PR_TRUE, getter_AddRefs(inFile));
|
||||
if (NS_FAILED(rv))
|
||||
return errAEEventNotHandled;
|
||||
|
||||
if (!mStartedUp)
|
||||
{
|
||||
// Is it the right type to be a command-line file?
|
||||
if (inFileType == 'TEXT' || inFileType == 'CMDL')
|
||||
{
|
||||
// Can we open the file?
|
||||
FILE *fp = 0;
|
||||
rv = inFile->OpenANSIFileDesc("r", &fp);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
Boolean foundArgs = false;
|
||||
Boolean foundEnv = false;
|
||||
char chars[1024];
|
||||
static const char kCommandLinePrefix[] = "ARGS:";
|
||||
static const char kEnvVarLinePrefix[] = "ENV:";
|
||||
|
||||
while (ReadLine(fp, chars, sizeof(chars)) != -1)
|
||||
{ // See if there are any command line or environment var settings
|
||||
if (PL_strstr(chars, kCommandLinePrefix) == chars)
|
||||
{
|
||||
(void)AddToCommandLine(chars + sizeof(kCommandLinePrefix) - 1);
|
||||
foundArgs = true;
|
||||
}
|
||||
else if (PL_strstr(chars, kEnvVarLinePrefix) == chars)
|
||||
{
|
||||
(void)AddToEnvironmentVars(chars + sizeof(kEnvVarLinePrefix) - 1);
|
||||
foundEnv = true;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
#ifndef XP_MACOSX
|
||||
// If we found any environment vars we need to re-init NSPR's logging
|
||||
// so that it knows what the new vars are
|
||||
if (foundEnv)
|
||||
PR_Init_Log();
|
||||
#endif
|
||||
// If we found a command line or environment vars we want to return now
|
||||
// raather than trying to open the file as a URL
|
||||
if (foundArgs || foundEnv)
|
||||
return noErr;
|
||||
}
|
||||
}
|
||||
// If it's not a command-line argument, and we are starting up the application,
|
||||
// add a command-line "-url" argument to the global list. This means that if
|
||||
// the app is opened with documents on the mac, they'll be handled the same
|
||||
// way as if they had been typed on the command line in Unix or DOS.
|
||||
return AddToCommandLine("-url", inFileSpec);
|
||||
}
|
||||
|
||||
// Final case: we're not just starting up. How do we handle this?
|
||||
nsCAutoString specBuf;
|
||||
rv = NS_GetURLSpecFromFile(inFile, specBuf);
|
||||
if (NS_FAILED(rv))
|
||||
return errAEEventNotHandled;
|
||||
|
||||
return OpenURL(specBuf.get());
|
||||
}
|
||||
|
||||
OSErr nsMacCommandLine::OpenURL(const char* aURL)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
|
||||
nsXPIDLCString browserURL;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = prefBranch->GetCharPref("browser.chromeURL", getter_Copies(browserURL));
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("browser.chromeURL not supplied! How is the app supposed to know what the main window is?");
|
||||
browserURL.Assign("chrome://navigator/content/navigator.xul");
|
||||
}
|
||||
|
||||
rv = OpenWindow(browserURL.get(), NS_ConvertASCIItoUCS2(aURL).get());
|
||||
if (NS_FAILED(rv))
|
||||
return errAEEventNotHandled;
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
OSErr nsMacCommandLine::HandlePrintOneDoc(const FSSpec& inFileSpec, OSType fileType)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// If we are starting up the application,
|
||||
// add a command-line "-print" argument to the global list. This means that if
|
||||
// the app is opened with documents on the mac, they'll be handled the same
|
||||
// way as if they had been typed on the command line in Unix or DOS.
|
||||
if (!mStartedUp)
|
||||
return AddToCommandLine("-print", inFileSpec);
|
||||
|
||||
// Final case: we're not just starting up. How do we handle this?
|
||||
NS_NOTYETIMPLEMENTED("Write Me");
|
||||
return errAEEventNotHandled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsMacCommandLine::OpenWindow(const char *chrome, const PRUnichar *url)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
||||
nsCOMPtr<nsISupportsString> urlWrapper(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
||||
if (!wwatch || !urlWrapper)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
urlWrapper->SetData(nsDependentString(url));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> newWindow;
|
||||
nsresult rv;
|
||||
rv = wwatch->OpenWindow(0, chrome, "_blank",
|
||||
"chrome,dialog=no,all", urlWrapper,
|
||||
getter_AddRefs(newWindow));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
OSErr nsMacCommandLine::DispatchURLToNewBrowser(const char* url)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
OSErr err = errAEEventNotHandled;
|
||||
if (mStartedUp)
|
||||
return OpenURL(url);
|
||||
else {
|
||||
err = AddToCommandLine("-url");
|
||||
if (err == noErr)
|
||||
err = AddToCommandLine(url);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
OSErr nsMacCommandLine::Quit(TAskSave askSave)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsICloseAllWindows> closer =
|
||||
do_CreateInstance("@mozilla.org/appshell/closeallwindows;1", &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return errAEEventNotHandled;
|
||||
|
||||
PRBool doQuit;
|
||||
rv = closer->CloseAll(askSave != eSaveNo, &doQuit);
|
||||
if (NS_FAILED(rv) || !doQuit)
|
||||
return errAEEventNotHandled;
|
||||
|
||||
nsCOMPtr<nsIAppStartup> appStartup =
|
||||
(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return errAEEventNotHandled;
|
||||
|
||||
(void)appStartup->Quit(nsIAppStartup::eAttemptQuit);
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================================
|
||||
// InitializeMacCommandLine
|
||||
// The only external entry point to this file.
|
||||
//========================================================================================
|
||||
|
||||
#pragma mark -
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult InitializeMacCommandLine(int& argc, char**& argv)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
|
||||
nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine();
|
||||
return cmdLine.Initialize(argc, argv);
|
||||
} // InitializeMac
|
|
@ -63,7 +63,6 @@ XPIDLSRCS = \
|
|||
|
||||
EXPORTS = \
|
||||
nsILinkHandler.h \
|
||||
nsIWebShell.h \
|
||||
nsIWebShellServices.h \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIContentViewerFile.h"
|
||||
#include "nsIContentViewerContainer.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIDocument.h"
|
||||
|
@ -800,13 +801,6 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID)
|
|||
|
||||
case VIEW_SOURCE:
|
||||
{
|
||||
// PRInt32 theIndex;
|
||||
// nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
// webShell->GetHistoryIndex(theIndex);
|
||||
// nsXPIDLString theURL;
|
||||
// webShell->GetURL(theIndex, getter_Copies(theURL));
|
||||
// nsAutoString theString(theURL);
|
||||
// mApp->ViewSource(theString);
|
||||
//XXX Find out how the string is allocated, and perhaps delete it...
|
||||
}
|
||||
break;
|
||||
|
@ -1278,7 +1272,7 @@ nsBrowserWindow::~nsBrowserWindow()
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS4(nsBrowserWindow, nsIBaseWindow, nsIInterfaceRequestor, nsIProgressEventSink, nsIWebShellContainer)
|
||||
NS_IMPL_ISUPPORTS3(nsBrowserWindow, nsIBaseWindow, nsIInterfaceRequestor, nsIProgressEventSink)
|
||||
|
||||
nsresult
|
||||
nsBrowserWindow::GetInterface(const nsIID& aIID,
|
||||
|
@ -1352,8 +1346,6 @@ nsBrowserWindow::Init(nsIAppShell* aAppShell,
|
|||
|
||||
mDocShell = do_GetInterface(mWebBrowser);
|
||||
mDocShell->SetAllowPlugins(aAllowPlugins);
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
webShell->SetContainer((nsIWebShellContainer*) this);
|
||||
webBrowserWin->SetVisibility(PR_TRUE);
|
||||
|
||||
if (nsIWebBrowserChrome::CHROME_MENUBAR & aChromeMask) {
|
||||
|
@ -1424,8 +1416,6 @@ nsnull, r.x, r.y, r.width, r.height);
|
|||
webBrowserWin->Create();
|
||||
mDocShell = do_GetInterface(mWebBrowser);
|
||||
mDocShell->SetAllowPlugins(aAllowPlugins);
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
webShell->SetContainer((nsIWebShellContainer*) this);
|
||||
webBrowserWin->SetVisibility(PR_TRUE);
|
||||
if (nsIWebBrowserChrome::CHROME_MENUBAR & aChromeMask) {
|
||||
rv = CreateMenuBar(r.width);
|
||||
|
@ -1837,20 +1827,16 @@ nsBrowserWindow::GetChrome(PRUint32& aChromeMaskResult)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::GetWebShell(nsIWebShell*& aResult)
|
||||
nsBrowserWindow::GetDocShell(nsIDocShell*& aResult)
|
||||
{
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
aResult = webShell;
|
||||
NS_IF_ADDREF(aResult);
|
||||
NS_IF_ADDREF(aResult = mDocShell);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::GetContentWebShell(nsIWebShell **aResult)
|
||||
nsBrowserWindow::GetContentDocShell(nsIDocShell **aResult)
|
||||
{
|
||||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));
|
||||
*aResult = webShell;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
NS_IF_ADDREF(*aResult = mDocShell);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1867,133 +1853,6 @@ nsBrowserWindow::ShowMenuBar(PRBool aShow)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL,
|
||||
nsLoadType aReason)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::ProgressLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
PRInt32 aProgress,
|
||||
PRInt32 aProgressMax)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::EndLoadURL(nsIWebShell* aShell,
|
||||
const PRUnichar* aURL,
|
||||
nsresult aStatus)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::NewWebShell(PRUint32 aChromeMask,
|
||||
PRBool aVisible,
|
||||
nsIWebShell*& aNewWebShell)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (mWebCrawler) {
|
||||
if (mWebCrawler->Crawling() || mWebCrawler->LoadingURLList()) {
|
||||
// Do not fly javascript popups when we are crawling
|
||||
aNewWebShell = nsnull;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
// Create new window. By default, the refcnt will be 1 because of
|
||||
// the registration of the browser window in gBrowsers.
|
||||
nsNativeBrowserWindow* browser;
|
||||
NS_NEWXPCOM(browser, nsNativeBrowserWindow);
|
||||
|
||||
if (nsnull != browser)
|
||||
{
|
||||
nsRect bounds;
|
||||
GetContentBounds(bounds);
|
||||
|
||||
browser->SetApp(mApp);
|
||||
|
||||
// Assume no controls for now
|
||||
rv = browser->Init(mAppShell, bounds, aChromeMask, mAllowPlugins);
|
||||
if (NS_OK == rv)
|
||||
{
|
||||
// Default is to startup hidden
|
||||
if (aVisible) {
|
||||
browser->SetVisibility(PR_TRUE);
|
||||
}
|
||||
nsIWebShell *shell;
|
||||
rv = browser->GetWebShell(shell);
|
||||
aNewWebShell = shell;
|
||||
}
|
||||
else
|
||||
{
|
||||
browser->Destroy();
|
||||
}
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserWindow::FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult)
|
||||
{
|
||||
PRInt32 i, n = gBrowsers ? gBrowsers->Count() : 0;
|
||||
|
||||
aResult = nsnull;
|
||||
nsString aNameStr(aName);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers->ElementAt(i);
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
|
||||
if (NS_OK == bw->GetWebShell(*getter_AddRefs(webShell))) {
|
||||
nsXPIDLString name;
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
|
||||
if (NS_OK == docShellAsItem->GetName(getter_Copies(name))) {
|
||||
if (aNameStr.Equals(name)) {
|
||||
aResult = webShell;
|
||||
NS_ADDREF(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(mDocShell));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> result;
|
||||
if (NS_OK == docShellAsNode->FindChildWithName(aName, PR_TRUE, PR_FALSE, nsnull,
|
||||
getter_AddRefs(result))) {
|
||||
if (result) {
|
||||
CallQueryInterface(result, &aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1,310 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* 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"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef nsBrowserWindow_h___
|
||||
#define nsBrowserWindow_h___
|
||||
|
||||
// Local Includes
|
||||
#include "nsWebBrowserChrome.h"
|
||||
#include "nsThrobber.h"
|
||||
|
||||
// Helper Classes
|
||||
|
||||
// Interfaces Needed
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prtime.h"
|
||||
|
||||
#include "nsIXPBaseWindow.h"
|
||||
#include "nsPrintSetupDialog.h"
|
||||
#include "nsTableInspectorDialog.h"
|
||||
#include "nsImageInspectorDialog.h"
|
||||
#include "nsITextWidget.h"
|
||||
|
||||
#include "nsIPrintSettings.h"
|
||||
|
||||
class nsILabel;
|
||||
class nsICheckButton;
|
||||
class nsIButton;
|
||||
class nsThrobber;
|
||||
class nsViewerApp;
|
||||
class nsIDocumentViewer;
|
||||
class nsPresContext;
|
||||
class nsIPresShell;
|
||||
class nsIContentConnector;
|
||||
class nsWebCrawler;
|
||||
class nsIContent;
|
||||
|
||||
#define SAMPLES_BASE_URL "resource:/res/samples"
|
||||
|
||||
/**
|
||||
* Abstract base class for our test app's browser windows
|
||||
*/
|
||||
class nsBrowserWindow : public nsIBaseWindow,
|
||||
public nsIInterfaceRequestor,
|
||||
public nsIProgressEventSink,
|
||||
public nsIWebShellContainer
|
||||
{
|
||||
friend class nsWebBrowserChrome;
|
||||
|
||||
public:
|
||||
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIBASEWINDOW
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
protected:
|
||||
void DestroyWidget(nsISupports* aWidget);
|
||||
|
||||
public:
|
||||
|
||||
// nsIBrowserWindow
|
||||
NS_IMETHOD Init(nsIAppShell* aAppShell,
|
||||
const nsRect& aBounds,
|
||||
PRUint32 aChromeMask,
|
||||
PRBool aAllowPlugins = PR_TRUE);
|
||||
|
||||
// virtual method for platform-specific initialization
|
||||
NS_IMETHOD InitNativeWindow() { return NS_OK; }
|
||||
|
||||
// nsIBrowserWindow
|
||||
NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY);
|
||||
NS_IMETHOD SizeContentTo(PRInt32 aWidth, PRInt32 aHeight);
|
||||
NS_IMETHOD SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight,
|
||||
PRBool aWidthTransient, PRBool aHeightTransient);
|
||||
NS_IMETHOD GetContentBounds(nsRect& aBounds);
|
||||
NS_IMETHOD GetWindowBounds(nsRect& aBounds);
|
||||
NS_IMETHOD SetChrome(PRUint32 aNewChromeMask);
|
||||
NS_IMETHOD GetChrome(PRUint32& aChromeMaskResult);
|
||||
NS_IMETHOD SetProgress(PRInt32 aProgress, PRInt32 aProgressMax);
|
||||
NS_IMETHOD ShowMenuBar(PRBool aShow);
|
||||
NS_IMETHOD GetWebShell(nsIWebShell*& aResult);
|
||||
NS_IMETHOD GetContentWebShell(nsIWebShell **aResult);
|
||||
|
||||
// nsIProgressEventSink
|
||||
NS_DECL_NSIPROGRESSEVENTSINK
|
||||
|
||||
// nsIWebShellContainer
|
||||
NS_IMETHOD WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason);
|
||||
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL);
|
||||
NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax);
|
||||
NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsresult aStatus);
|
||||
NS_IMETHOD NewWebShell(PRUint32 aChromeMask,
|
||||
PRBool aVisible,
|
||||
nsIWebShell *&aNewWebShell);
|
||||
NS_IMETHOD ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode);
|
||||
NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult);
|
||||
|
||||
// nsBrowserWindow
|
||||
void SetWebCrawler(nsWebCrawler* aWebCrawler);
|
||||
virtual nsresult CreateMenuBar(PRInt32 aWidth) = 0;
|
||||
virtual nsresult GetMenuBarHeight(PRInt32 * aHeightOut);
|
||||
virtual nsresult CreateToolBar(PRInt32 aWidth);
|
||||
virtual nsresult CreateStatusBar(PRInt32 aWidth);
|
||||
void Layout(PRInt32 aWidth, PRInt32 aHeight);
|
||||
void Back();
|
||||
void Forward();
|
||||
void GoTo(const PRUnichar* aURL);
|
||||
void StartThrobber();
|
||||
void StopThrobber();
|
||||
void LoadThrobberImages();
|
||||
void DestroyThrobberImages();
|
||||
virtual nsEventStatus DispatchMenuItem(PRInt32 aID) = 0;
|
||||
virtual nsresult GetWindow(nsIWidget** aWindow);
|
||||
|
||||
void DoFileOpen();
|
||||
void DoCopy();
|
||||
void DoPaste();
|
||||
void DoJSConsole();
|
||||
void DoPrefs();
|
||||
void DoEditorMode(nsIDocShell* aDocShell);
|
||||
void DoEditorTest(nsIDocShell* aDocShell, PRInt32 aCommandID);
|
||||
nsIPresShell* GetPresShell();
|
||||
|
||||
void DoFind();
|
||||
NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
|
||||
NS_IMETHOD ForceRefresh();
|
||||
|
||||
void DoTreeView();
|
||||
void DoToolbarDemo();
|
||||
|
||||
void ShowPrintPreview(PRInt32 aID);
|
||||
void DoPrint(void);
|
||||
void DoTableInspector(void);
|
||||
void DoImageInspector(void);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
void DumpContent(FILE *out = stdout);
|
||||
void DumpFrames(FILE *out = stdout, nsString *aFilter = nsnull);
|
||||
void DumpViews(FILE *out = stdout);
|
||||
void DumpWebShells(FILE *out = stdout);
|
||||
void DumpStyleSheets(FILE *out = stdout);
|
||||
void DumpStyleContexts(FILE *out = stdout);
|
||||
void DumpReflowStats(FILE *out = stdout);
|
||||
void DisplayReflowStats(PRBool aIsOn);
|
||||
void ToggleFrameBorders();
|
||||
void ToggleVisualEventDebugging();
|
||||
void ToggleBoolPrefAndRefresh(const char * aPrefName);
|
||||
|
||||
void DoDebugSave();
|
||||
void DoToggleSelection();
|
||||
void DoDebugRobot();
|
||||
void DoSiteWalker();
|
||||
nsEventStatus DispatchDebugMenu(PRInt32 aID);
|
||||
#endif
|
||||
void SetBoolPref(const char * aPrefName, PRBool aValue);
|
||||
void SetStringPref(const char * aPrefName, const nsString& aValue);
|
||||
void GetStringPref(const char * aPrefName, nsString& aValue);
|
||||
|
||||
nsEventStatus DispatchStyleMenu(PRInt32 aID);
|
||||
void SetCompatibilityMode(PRUint32 aMode);
|
||||
|
||||
nsEventStatus ProcessDialogEvent(nsGUIEvent *aEvent);
|
||||
|
||||
// Initialize a second view on a different browser windows document
|
||||
// viewer.
|
||||
nsresult Init(nsIAppShell* aAppShell,
|
||||
const nsRect& aBounds,
|
||||
PRUint32 aChromeMask,
|
||||
PRBool aAllowPlugins,
|
||||
nsIDocumentViewer* aDocViewer,
|
||||
nsPresContext* aPresContext);
|
||||
|
||||
void SetApp(nsViewerApp* aApp) {
|
||||
mApp = aApp;
|
||||
}
|
||||
|
||||
static void CloseAllWindows();
|
||||
|
||||
void SetShowLoadTimes(PRBool aOn) {
|
||||
mShowLoadTimes = aOn;
|
||||
}
|
||||
|
||||
nsViewerApp* mApp;
|
||||
nsWebCrawler* mWebCrawler;
|
||||
|
||||
PRUint32 mChromeMask;
|
||||
nsString mTitle;
|
||||
|
||||
nsCOMPtr<nsIWidget> mWindow;
|
||||
nsCOMPtr<nsIDocShell> mDocShell;
|
||||
nsCOMPtr<nsIWebBrowser> mWebBrowser;
|
||||
|
||||
nsCOMPtr<nsILocalFile> mOpenFileDirectory;
|
||||
|
||||
PRTime mLoadStartTime;
|
||||
PRBool mShowLoadTimes;
|
||||
|
||||
// "Toolbar"
|
||||
nsITextWidget* mLocation;
|
||||
nsIButton* mBack;
|
||||
nsIButton* mForward;
|
||||
nsThrobber* mThrobber;
|
||||
|
||||
// "Status bar"
|
||||
nsITextWidget* mStatus;
|
||||
|
||||
nsIXPBaseWindow * mXPDialog;
|
||||
nsIXPBaseWindow * mTableInspectorDialog;
|
||||
nsIXPBaseWindow * mImageInspectorDialog;
|
||||
PrintSetupInfo mPrintSetupInfo;
|
||||
|
||||
nsTableInspectorDialog * mTableInspector;
|
||||
nsImageInspectorDialog * mImageInspector;
|
||||
|
||||
//for creating more instances
|
||||
nsIAppShell* mAppShell;
|
||||
PRBool mAllowPlugins;
|
||||
|
||||
// Global window collection
|
||||
static nsVoidArray *gBrowsers;
|
||||
static void AddBrowser(nsBrowserWindow* aBrowser);
|
||||
static void RemoveBrowser(nsBrowserWindow* aBrowser);
|
||||
static nsBrowserWindow* FindBrowserFor(nsIWidget* aWidget, PRIntn aWhich);
|
||||
|
||||
protected:
|
||||
nsIDOMDocument* GetDOMDocument(nsIDocShell *aDocShell);
|
||||
NS_IMETHOD EnsureWebBrowserChrome();
|
||||
|
||||
nsBrowserWindow();
|
||||
virtual ~nsBrowserWindow();
|
||||
|
||||
nsWebBrowserChrome* mWebBrowserChrome;
|
||||
PRBool mHaveMenuBar;
|
||||
|
||||
nsCOMPtr<nsIPrintSettings> mPrintSettings;
|
||||
};
|
||||
|
||||
// XXX This is bad; because we can't hang a closure off of the event
|
||||
// callback we have no way to store our This pointer; therefore we
|
||||
// have to hunt to find the browswer that events belong too!!!
|
||||
|
||||
// aWhich for FindBrowserFor
|
||||
#define FIND_WINDOW 0
|
||||
#define FIND_BACK 1
|
||||
#define FIND_FORWARD 2
|
||||
#define FIND_LOCATION 3
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsNativeBrowserWindow : public nsBrowserWindow {
|
||||
public:
|
||||
nsNativeBrowserWindow();
|
||||
~nsNativeBrowserWindow();
|
||||
|
||||
virtual nsresult CreateMenuBar(PRInt32 aWidth);
|
||||
virtual nsEventStatus DispatchMenuItem(PRInt32 aID);
|
||||
virtual nsresult GetMenuBarHeight(PRInt32 * aHeightOut);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD InitNativeWindow();
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsBrowserWindow_h___ */
|
|
@ -46,7 +46,6 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsWebCrawler.h"
|
||||
#include "nsViewerApp.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDocument.h"
|
||||
|
@ -235,18 +234,17 @@ void
|
|||
nsWebCrawler::DumpRegressionData()
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
nsCOMPtr<nsIWebShell> webshell;
|
||||
mBrowser->GetWebShell(*getter_AddRefs(webshell));
|
||||
if (! webshell)
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
mBrowser->GetDocShell(*getter_AddRefs(docshell));
|
||||
if (! docshell)
|
||||
return;
|
||||
|
||||
if (mOutputDir.Length() > 0) {
|
||||
nsIPresShell* shell = GetPresShell(webshell);
|
||||
nsCOMPtr<nsIPresShell> shell = GetPresShell(docshell);
|
||||
if (!shell) return;
|
||||
if ( mPrinterTestType > 0 ) {
|
||||
nsCOMPtr <nsIContentViewer> viewer;
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(webshell));
|
||||
docShell->GetContentViewer(getter_AddRefs(viewer));
|
||||
docshell->GetContentViewer(getter_AddRefs(viewer));
|
||||
|
||||
if (viewer){
|
||||
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
|
||||
|
@ -321,7 +319,6 @@ nsWebCrawler::DumpRegressionData()
|
|||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -334,11 +331,10 @@ nsWebCrawler::LoadNextURLCallback(nsITimer *aTimer, void *aClosure)
|
|||
// if we are doing printing regression tests, check to see
|
||||
// if we can print (a previous job is not printing)
|
||||
if (self->mPrinterTestType > 0) {
|
||||
nsCOMPtr<nsIWebShell> webshell;
|
||||
self->mBrowser->GetWebShell(*getter_AddRefs(webshell));
|
||||
if (webshell){
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
self->mBrowser->GetDocShell(*getter_AddRefs(docShell));
|
||||
if (docShell){
|
||||
nsCOMPtr <nsIContentViewer> viewer;
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(webshell));
|
||||
docShell->GetContentViewer(getter_AddRefs(viewer));
|
||||
if (viewer){
|
||||
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
|
||||
|
@ -377,9 +373,8 @@ nsWebCrawler::OnStateChange(nsIWebProgress* aWebProgress,
|
|||
{
|
||||
// Make sure that we're being notified for _our_ shell, and not some
|
||||
// subshell that's been created e.g. for an IFRAME.
|
||||
nsCOMPtr<nsIWebShell> shell;
|
||||
mBrowser->GetWebShell(*getter_AddRefs(shell));
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(shell);
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
mBrowser->GetDocShell(*getter_AddRefs(docShell));
|
||||
if (docShell) {
|
||||
nsCOMPtr<nsIWebProgress> progress = do_GetInterface(docShell);
|
||||
if (aWebProgress != progress)
|
||||
|
@ -433,7 +428,7 @@ nsWebCrawler::OnStateChange(nsIWebProgress* aWebProgress,
|
|||
printf("+++ %s: done loading (%lld msec)\n", spec.get(), delta);
|
||||
|
||||
// Make sure the document bits make it to the screen at least once
|
||||
nsCOMPtr<nsIPresShell> shell = dont_AddRef(GetPresShell());
|
||||
nsCOMPtr<nsIPresShell> shell = GetPresShell();
|
||||
if (shell) {
|
||||
// Force the presentation shell to update the display
|
||||
shell->FlushPendingNotifications(Flush_Display);
|
||||
|
@ -614,9 +609,8 @@ void
|
|||
nsWebCrawler::Start()
|
||||
{
|
||||
// Enable observing each URL load...
|
||||
nsCOMPtr<nsIWebShell> shell;
|
||||
mBrowser->GetWebShell(*getter_AddRefs(shell));
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(shell));
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
mBrowser->GetDocShell(*getter_AddRefs(docShell));
|
||||
if (docShell) {
|
||||
nsCOMPtr<nsIWebProgress> progress(do_GetInterface(docShell));
|
||||
if (progress) {
|
||||
|
@ -812,10 +806,9 @@ nsWebCrawler::FindURLsIn(nsIDocument* aDocument, nsIContent* aNode)
|
|||
void
|
||||
nsWebCrawler::FindMoreURLs()
|
||||
{
|
||||
nsCOMPtr<nsIWebShell> shell;
|
||||
mBrowser->GetWebShell(*getter_AddRefs(shell));
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
mBrowser->GetDocShell(*getter_AddRefs(docShell));
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(shell));
|
||||
if (docShell) {
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
docShell->GetContentViewer(getter_AddRefs(cv));
|
||||
|
@ -860,8 +853,6 @@ nsWebCrawler::LoadNextURL(PRBool aQueueLoad)
|
|||
if (nsnull != url) {
|
||||
if (OkToLoad(*url)) {
|
||||
RecordLoadedURL(*url);
|
||||
nsIWebShell* webShell;
|
||||
mBrowser->GetWebShell(webShell);
|
||||
if (aQueueLoad) {
|
||||
// Call stop to cancel any pending URL Refreshes...
|
||||
/// webShell->Stop();
|
||||
|
@ -870,10 +861,11 @@ nsWebCrawler::LoadNextURL(PRBool aQueueLoad)
|
|||
else {
|
||||
mCurrentURL = *url;
|
||||
mStartLoad = PR_Now();
|
||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(webShell));
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
mBrowser->GetDocShell(*getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
|
||||
webNav->LoadURI(url->get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
|
||||
}
|
||||
NS_RELEASE(webShell);
|
||||
|
||||
if (mMaxPages > 0) {
|
||||
--mMaxPages;
|
||||
|
@ -893,35 +885,16 @@ nsWebCrawler::LoadNextURL(PRBool aQueueLoad)
|
|||
|
||||
}
|
||||
|
||||
nsIPresShell*
|
||||
nsWebCrawler::GetPresShell(nsIWebShell* aWebShell)
|
||||
already_AddRefed<nsIPresShell>
|
||||
nsWebCrawler::GetPresShell(nsIDocShell* aDocShell)
|
||||
{
|
||||
nsIWebShell* webShell = aWebShell;
|
||||
if (webShell) {
|
||||
NS_ADDREF(webShell);
|
||||
}
|
||||
else {
|
||||
mBrowser->GetWebShell(webShell);
|
||||
}
|
||||
nsIPresShell* shell = nsnull;
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(webShell));
|
||||
if (nsnull != webShell) {
|
||||
nsIContentViewer* cv = nsnull;
|
||||
docShell->GetContentViewer(&cv);
|
||||
if (nsnull != cv) {
|
||||
nsIDocumentViewer* docv = nsnull;
|
||||
cv->QueryInterface(NS_GET_IID(nsIDocumentViewer), (void**) &docv);
|
||||
if (nsnull != docv) {
|
||||
nsCOMPtr<nsPresContext> cx;
|
||||
docv->GetPresContext(getter_AddRefs(cx));
|
||||
if (nsnull != cx) {
|
||||
NS_IF_ADDREF(shell = cx->GetPresShell());
|
||||
}
|
||||
NS_RELEASE(docv);
|
||||
}
|
||||
NS_RELEASE(cv);
|
||||
}
|
||||
NS_RELEASE(webShell);
|
||||
nsCOMPtr<nsIDocShell> docShell(aDocShell);
|
||||
if (!docShell) {
|
||||
mBrowser->GetDocShell(*getter_AddRefs(docShell));
|
||||
}
|
||||
if (docShell) {
|
||||
docShell->GetPresShell(&shell);
|
||||
}
|
||||
return shell;
|
||||
}
|
||||
|
@ -1103,14 +1076,13 @@ LoadEvent::DeleteMe(LoadEvent* e)
|
|||
void
|
||||
nsWebCrawler::GoToQueuedURL(const nsString& aURL)
|
||||
{
|
||||
nsIWebShell* webShell;
|
||||
mBrowser->GetWebShell(webShell);
|
||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(webShell));
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
mBrowser->GetDocShell(*getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
|
||||
if (webNav) {
|
||||
mCurrentURL = aURL;
|
||||
mStartLoad = PR_Now();
|
||||
webNav->LoadURI(aURL.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
|
||||
NS_RELEASE(webShell);
|
||||
}
|
||||
mQueuedLoadURLs--;
|
||||
|
||||
|
|
|
@ -1,210 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Ryner <bryner@brianryner.com>
|
||||
*
|
||||
* 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"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef nsWebCrawler_h___
|
||||
#define nsWebCrawler_h___
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsBrowserWindow.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
|
||||
class nsIContent;
|
||||
class nsIDocument;
|
||||
class nsITimer;
|
||||
class nsIURI;
|
||||
class nsIPresShell;
|
||||
class nsViewerApp;
|
||||
class AtomHashTable;
|
||||
|
||||
class nsWebCrawler : public nsIWebProgressListener,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
// Make a new web-crawler for the given viewer. Note: the web
|
||||
// crawler does not addref the viewer.
|
||||
nsWebCrawler(nsViewerApp* aViewer);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIWebProgressListener
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
|
||||
// Add a url to load
|
||||
void AddURL(const nsString& aURL);
|
||||
|
||||
// Add a domain that is safe to load url's from
|
||||
void AddSafeDomain(const nsString& aDomain);
|
||||
|
||||
// Add a domain that must be avoided
|
||||
void AddAvoidDomain(const nsString& aDomain);
|
||||
|
||||
void SetBrowserWindow(nsBrowserWindow* aWindow);
|
||||
void GetBrowserWindow(nsBrowserWindow** aWindow);
|
||||
|
||||
void SetPrintTest(PRInt32 aTestType) { mPrinterTestType = aTestType; }
|
||||
|
||||
void RegressionOutput(PRInt32 aRegressionOutputLevel) { mRegressionOutputLevel = aRegressionOutputLevel; }
|
||||
|
||||
void EnableJiggleLayout() {
|
||||
mJiggleLayout = PR_TRUE;
|
||||
}
|
||||
|
||||
// If set to TRUE the loader will post an exit message on exit
|
||||
void SetExitOnDone(PRBool aPostExit) {
|
||||
mPostExit = aPostExit;
|
||||
}
|
||||
|
||||
// Start loading documents
|
||||
void Start();
|
||||
|
||||
// Enable the crawler; when a document contains links to other
|
||||
// documents the crawler will go to them subject to the limitations
|
||||
// on the total crawl count and the domain name checks.
|
||||
void EnableCrawler();
|
||||
|
||||
void SetRecordFile(FILE* aFile) {
|
||||
mRecord = aFile;
|
||||
}
|
||||
|
||||
void SetMaxPages(PRInt32 aMax) {
|
||||
mMaxPages = aMax;
|
||||
}
|
||||
|
||||
void SetOutputDir(const nsString& aOutputDir);
|
||||
|
||||
void DumpRegressionData();
|
||||
void SetRegressionDir(const nsString& aOutputDir);
|
||||
|
||||
void SetEnableRegression(PRBool aSetting) {
|
||||
mRegressing = aSetting;
|
||||
}
|
||||
|
||||
static void
|
||||
LoadNextURLCallback(nsITimer* aTimer, void* aClosure);
|
||||
|
||||
void LoadNextURL(PRBool aQueueLoad);
|
||||
|
||||
nsresult QueueLoadURL(const nsString& aURL);
|
||||
|
||||
void GoToQueuedURL(const nsString& aURL);
|
||||
|
||||
static void
|
||||
QueueExitCallback(nsITimer* atimer, void* aClosure);
|
||||
|
||||
void QueueExit();
|
||||
|
||||
void Exit();
|
||||
|
||||
void SetVerbose(PRBool aSetting) {
|
||||
mVerbose = aSetting;
|
||||
}
|
||||
|
||||
PRBool Crawling() const {
|
||||
return mCrawl;
|
||||
}
|
||||
|
||||
PRBool LoadingURLList() const {
|
||||
return mHaveURLList;
|
||||
}
|
||||
|
||||
void IncludeStyleData(PRBool aIncludeStyle) {
|
||||
mIncludeStyleInfo = aIncludeStyle;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~nsWebCrawler();
|
||||
|
||||
void FindURLsIn(nsIDocument* aDocument, nsIContent* aNode);
|
||||
|
||||
void FindMoreURLs();
|
||||
|
||||
PRBool OkToLoad(const nsString& aURLSpec);
|
||||
|
||||
void RecordLoadedURL(const nsString& aURLSpec);
|
||||
|
||||
/** generate an output name from a URL */
|
||||
FILE* GetOutputFile(nsIURI *aURL, nsString& aOutputName);
|
||||
|
||||
nsIPresShell* GetPresShell(nsIWebShell* aWebShell = nsnull);
|
||||
|
||||
void PerformRegressionTest(const nsString& aOutputName);
|
||||
|
||||
nsBrowserWindow* mBrowser;
|
||||
nsViewerApp* mViewer;
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
FILE* mRecord;
|
||||
nsCOMPtr<nsIAtom> mLinkTag;
|
||||
nsCOMPtr<nsIAtom> mFrameTag;
|
||||
nsCOMPtr<nsIAtom> mIFrameTag;
|
||||
nsCOMPtr<nsIAtom> mHrefAttr;
|
||||
nsCOMPtr<nsIAtom> mSrcAttr;
|
||||
nsCOMPtr<nsIAtom> mBaseHrefAttr;
|
||||
AtomHashTable* mVisited;
|
||||
nsString mOutputDir;
|
||||
|
||||
PRBool mCrawl;
|
||||
PRBool mHaveURLList;
|
||||
PRBool mJiggleLayout;
|
||||
PRBool mPostExit;
|
||||
PRInt32 mDelay;
|
||||
PRInt32 mMaxPages;
|
||||
|
||||
nsString mCurrentURL;
|
||||
nsCOMPtr<nsIURI> mLastURL;
|
||||
|
||||
PRTime mStartLoad;
|
||||
PRBool mVerbose;
|
||||
PRBool mRegressing;
|
||||
PRInt32 mPrinterTestType;
|
||||
PRInt32 mRegressionOutputLevel;
|
||||
nsString mRegressionDir;
|
||||
PRBool mIncludeStyleInfo;
|
||||
|
||||
nsVoidArray mPendingURLs;
|
||||
nsVoidArray mSafeDomains;
|
||||
nsVoidArray mAvoidDomains;
|
||||
|
||||
PRInt32 mQueuedLoadURLs;
|
||||
};
|
||||
|
||||
#endif /* nsWebCrawler_h___ */
|
|
@ -1,744 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsCOMPtr.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsXPBaseWindow.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIAppShell.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsViewerApp.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIWindowListener.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsGUIEvent.h"
|
||||
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIDocShellTreeNode.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
#include <ctype.h> // tolower
|
||||
|
||||
// XXX For font setting below
|
||||
#include "nsFont.h"
|
||||
//#include "nsUnitConversion.h"
|
||||
//#include "nsIDeviceContext.h"
|
||||
|
||||
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
|
||||
static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
||||
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
|
||||
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
|
||||
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
||||
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsXPBaseWindow::nsXPBaseWindow() :
|
||||
mContentRoot(nsnull),
|
||||
mWindowListener(nsnull),
|
||||
mDocIsLoaded(PR_FALSE),
|
||||
mAppShell(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsXPBaseWindow::~nsXPBaseWindow()
|
||||
{
|
||||
NS_IF_RELEASE(mContentRoot);
|
||||
NS_IF_RELEASE(mAppShell);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMPL_ADDREF(nsXPBaseWindow)
|
||||
NS_IMPL_RELEASE(nsXPBaseWindow)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtrResult = NULL;
|
||||
|
||||
if (aIID.Equals(kIXPBaseWindowIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIXPBaseWindow*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIWebShellContainerIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIWebShellContainer*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMMouseListenerIID)) {
|
||||
NS_ADDREF_THIS(); // Increase reference count for caller
|
||||
*aInstancePtrResult = (void *)((nsIDOMMouseListener*)this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
NS_ADDREF_THIS();
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)((nsIXPBaseWindow*)this));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
static nsEventStatus PR_CALLBACK
|
||||
HandleXPDialogEvent(nsGUIEvent *aEvent)
|
||||
{
|
||||
nsEventStatus result = nsEventStatus_eIgnore;
|
||||
|
||||
nsXPBaseWindow* baseWin;
|
||||
aEvent->widget->GetClientData(((void*&)baseWin));
|
||||
|
||||
if (nsnull != baseWin) {
|
||||
nsSizeEvent* sizeEvent;
|
||||
switch(aEvent->message) {
|
||||
case NS_SIZE:
|
||||
sizeEvent = (nsSizeEvent*)aEvent;
|
||||
baseWin->Layout(sizeEvent->windowSize->width,
|
||||
sizeEvent->windowSize->height);
|
||||
result = nsEventStatus_eConsumeNoDefault;
|
||||
break;
|
||||
|
||||
case NS_DESTROY: {
|
||||
//nsViewerApp* app = baseWin->mApp;
|
||||
result = nsEventStatus_eConsumeDoDefault;
|
||||
baseWin->Close();
|
||||
NS_RELEASE(baseWin);
|
||||
}
|
||||
return result;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//NS_RELEASE(baseWin);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::Init(nsXPBaseWindowType aType,
|
||||
nsIAppShell* aAppShell,
|
||||
const nsString& aDialogURL,
|
||||
const nsString& aTitle,
|
||||
const nsRect& aBounds,
|
||||
PRUint32 aChromeMask,
|
||||
PRBool aAllowPlugins)
|
||||
{
|
||||
mAllowPlugins = aAllowPlugins;
|
||||
mWindowType = aType;
|
||||
mAppShell = aAppShell;
|
||||
NS_IF_ADDREF(mAppShell);
|
||||
|
||||
// Create top level window
|
||||
nsresult rv;
|
||||
rv = CallCreateInstance(kWindowCID, &mWindow);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
mWindow->SetClientData(this);
|
||||
|
||||
nsWidgetInitData initData;
|
||||
initData.mWindowType = eWindowType_toplevel;
|
||||
initData.mBorderStyle = eBorderStyle_default;
|
||||
|
||||
nsRect r(0, 0, aBounds.width, aBounds.height);
|
||||
mWindow->Create((nsIWidget*)NULL, r, HandleXPDialogEvent,
|
||||
nsnull, aAppShell, nsnull, &initData);
|
||||
mWindow->GetBounds(r);
|
||||
|
||||
// Create web shell
|
||||
rv = CallCreateInstance(kWebShellCID, &mWebShell);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
r.x = r.y = 0;
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
||||
docShell->SetAllowPlugins(aAllowPlugins);
|
||||
nsCOMPtr<nsIBaseWindow> docShellWin(do_QueryInterface(mWebShell));
|
||||
|
||||
rv = docShellWin->InitWindow(nsnull, mWindow, r.x, r.y, r.width, r.height);
|
||||
docShellWin->Create();
|
||||
mWebShell->SetContainer((nsIWebShellContainer*) this);
|
||||
docShellWin->SetVisibility(PR_TRUE);
|
||||
|
||||
// Now lay it all out
|
||||
Layout(r.width, r.height);
|
||||
|
||||
// Load URL to Load GUI
|
||||
mDialogURL = aDialogURL;
|
||||
LoadURL(mDialogURL);
|
||||
|
||||
SetTitle(aTitle.get());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void nsXPBaseWindow::ForceRefresh()
|
||||
{
|
||||
nsIPresShell* shell;
|
||||
GetPresShell(shell);
|
||||
if (nsnull != shell) {
|
||||
nsIViewManager *vm = shell->GetViewManager();
|
||||
if (vm) {
|
||||
nsIView* root;
|
||||
vm->GetRootView(root);
|
||||
if (nsnull != root) {
|
||||
vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void nsXPBaseWindow::Layout(PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
nsRect rr(0, 0, aWidth, aHeight);
|
||||
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell));
|
||||
webShellWin->SetPositionAndSize(rr.x, rr.y, rr.width, rr.height, PR_FALSE);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::SetLocation(PRInt32 aX, PRInt32 aY)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != mWindow, "null window");
|
||||
mWindow->Move(aX, aY);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::SetDimensions(PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != mWindow, "null window");
|
||||
|
||||
// XXX We want to do this in one shot
|
||||
mWindow->Resize(aWidth, aHeight, PR_FALSE);
|
||||
Layout(aWidth, aHeight);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::GetBounds(nsRect& aBounds)
|
||||
{
|
||||
mWindow->GetBounds(aBounds);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsXPBaseWindow::GetWindowBounds(nsRect& aBounds)
|
||||
{
|
||||
//XXX This needs to be non-client bounds when it exists.
|
||||
mWindow->GetBounds(aBounds);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::SetVisible(PRBool aIsVisible)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != mWindow, "null window");
|
||||
mWindow->Show(aIsVisible);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::Close()
|
||||
{
|
||||
if (nsnull != mWindowListener) {
|
||||
mWindowListener->Destroy(this);
|
||||
}
|
||||
|
||||
if (nsnull != mWebShell) {
|
||||
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell));
|
||||
webShellWin->Destroy();
|
||||
NS_RELEASE(mWebShell);
|
||||
}
|
||||
|
||||
if (nsnull != mWindow) {
|
||||
nsIWidget* w = mWindow;
|
||||
NS_RELEASE(w);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::GetWebShell(nsIWebShell*& aResult)
|
||||
{
|
||||
aResult = mWebShell;
|
||||
NS_IF_ADDREF(mWebShell);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::SetTitle(const PRUnichar* aTitle)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != mWindow, "null window");
|
||||
mTitle = aTitle;
|
||||
nsAutoString newTitle(aTitle);
|
||||
mWindow->SetTitle(newTitle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::GetTitle(const PRUnichar** aResult)
|
||||
{
|
||||
*aResult = ToNewUnicode(mTitle);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::LoadURL(const nsString& aURL)
|
||||
{
|
||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebShell));
|
||||
webNav->LoadURI(aURL.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsresult aStatus)
|
||||
{
|
||||
// Find the Root Conent Node for this Window
|
||||
nsIPresShell* shell;
|
||||
GetPresShell(shell);
|
||||
if (nsnull != shell) {
|
||||
nsIDocument *doc = shell->GetDocument();
|
||||
if (doc) {
|
||||
NS_IF_ADDREF(mContentRoot = doc->GetRootContent());
|
||||
mDocIsLoaded = PR_TRUE;
|
||||
if (nsnull != mWindowListener) {
|
||||
mWindowListener->Initialize(this);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPBaseWindow::FindWebShellWithName(const PRUnichar* aName,
|
||||
nsIWebShell*& aResult)
|
||||
{
|
||||
aResult = nsnull;
|
||||
|
||||
nsString aNameStr(aName);
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
GetWebShell(*getter_AddRefs(webShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(webShell));
|
||||
if (webShell) {
|
||||
nsXPIDLString name;
|
||||
if (NS_SUCCEEDED(docShellAsItem->GetName(getter_Copies(name)))) {
|
||||
if (aNameStr.Equals(name)) {
|
||||
aResult = webShell;
|
||||
NS_ADDREF(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(webShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> result;
|
||||
if (NS_OK == docShellAsNode->FindChildWithName(aName, PR_TRUE, PR_FALSE,
|
||||
nsnull, getter_AddRefs(result))) {
|
||||
if (result) {
|
||||
CallQueryInterface(result, &aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXPBaseWindow::FocusAvailable(nsIWebShell* aFocusedWebShell, PRBool& aFocusTaken)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::AddEventListener(nsIDOMNode * aNode)
|
||||
{
|
||||
nsIDOMEventReceiver * receiver;
|
||||
|
||||
NS_PRECONDITION(nsnull != aNode, "adding event listener to null node");
|
||||
|
||||
if (NS_OK == aNode->QueryInterface(kIDOMEventReceiverIID, (void**) &receiver)) {
|
||||
receiver->AddEventListenerByIID((nsIDOMMouseListener*)this, kIDOMMouseListenerIID);
|
||||
NS_RELEASE(receiver);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::RemoveEventListener(nsIDOMNode * aNode)
|
||||
{
|
||||
nsIDOMEventReceiver * receiver;
|
||||
|
||||
NS_PRECONDITION(nsnull != aNode, "removing event listener from null node");
|
||||
|
||||
if (NS_OK == aNode->QueryInterface(kIDOMEventReceiverIID, (void**) &receiver)) {
|
||||
receiver->RemoveEventListenerByIID(this, kIDOMMouseListenerIID);
|
||||
NS_RELEASE(receiver);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::AddWindowListener(nsIWindowListener * aWindowListener)
|
||||
{
|
||||
if (nsnull != mWindowListener) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mWindowListener = aWindowListener;
|
||||
if (mDocIsLoaded && nsnull != mWindowListener) {
|
||||
mWindowListener->Initialize(this);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
// Get the HTML Document
|
||||
NS_IMETHODIMP nsXPBaseWindow::GetDocument(nsIDOMHTMLDocument *& aDocument)
|
||||
{
|
||||
nsIDOMHTMLDocument *htmlDoc = nsnull;
|
||||
nsIPresShell *shell = nsnull;
|
||||
GetPresShell(shell);
|
||||
if (nsnull != shell) {
|
||||
nsIDocument *doc = shell->GetDocument();
|
||||
if (doc) {
|
||||
doc->QueryInterface(kIDOMHTMLDocumentIID,(void **)&htmlDoc);
|
||||
}
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
|
||||
aDocument = htmlDoc;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::NewWebShell(PRUint32 aChromeMask,
|
||||
PRBool aVisible,
|
||||
nsIWebShell*& aNewWebShell)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Create new window. By default, the refcnt will be 1 because of
|
||||
// the registration of the browser window in gBrowsers.
|
||||
nsXPBaseWindow* dialogWindow;
|
||||
NS_NEWXPCOM(dialogWindow, nsXPBaseWindow);
|
||||
|
||||
if (nsnull != dialogWindow) {
|
||||
nsRect bounds;
|
||||
GetBounds(bounds);
|
||||
|
||||
rv = dialogWindow->Init(mWindowType, mAppShell, mDialogURL, mTitle, bounds, aChromeMask, mAllowPlugins);
|
||||
if (NS_OK == rv) {
|
||||
if (aVisible) {
|
||||
dialogWindow->SetVisible(PR_TRUE);
|
||||
}
|
||||
nsIWebShell *shell;
|
||||
rv = dialogWindow->GetWebShell(shell);
|
||||
aNewWebShell = shell;
|
||||
} else {
|
||||
dialogWindow->Close();
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPBaseWindow::ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsXPBaseWindow::GetPresShell(nsIPresShell*& aPresShell)
|
||||
{
|
||||
aPresShell = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
||||
if (docShell) {
|
||||
nsIContentViewer* cv = nsnull;
|
||||
docShell->GetContentViewer(&cv);
|
||||
if (nsnull != cv) {
|
||||
nsIDocumentViewer* docv = nsnull;
|
||||
cv->QueryInterface(kIDocumentViewerIID, (void**) &docv);
|
||||
if (nsnull != docv) {
|
||||
nsCOMPtr<nsPresContext> cx;
|
||||
docv->GetPresContext(getter_AddRefs(cx));
|
||||
if (nsnull != cx) {
|
||||
NS_IF_ADDREF(aPresShell = cx->GetPresShell());
|
||||
}
|
||||
NS_RELEASE(docv);
|
||||
}
|
||||
NS_RELEASE(cv);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
//-- nsIDOMMouseListener
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::MouseUp(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::MouseDown(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
if (nsnull != mWindowListener) {
|
||||
PRBool status;
|
||||
mWindowListener->MouseClick(aMouseEvent, this, status);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::MouseOver(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
nsresult nsXPBaseWindow::MouseOut(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Factory code for creating nsXPBaseWindow's
|
||||
//----------------------------------------------------------------------
|
||||
class nsXPBaseWindowFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFACTORY
|
||||
|
||||
nsXPBaseWindowFactory();
|
||||
virtual ~nsXPBaseWindowFactory();
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsXPBaseWindowFactory::nsXPBaseWindowFactory()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsXPBaseWindowFactory::~nsXPBaseWindowFactory()
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsresult
|
||||
nsXPBaseWindowFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = NULL;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = (void *)(nsISupports*)this;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = (void *)(nsIFactory*)this;
|
||||
}
|
||||
|
||||
if (*aResult == NULL) {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS(); // Increase reference count for caller
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsXPBaseWindowFactory)
|
||||
NS_IMPL_RELEASE(nsXPBaseWindowFactory)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsresult
|
||||
nsXPBaseWindowFactory::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPBaseWindow *inst;
|
||||
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
*aResult = NULL;
|
||||
if (nsnull != aOuter) {
|
||||
rv = NS_ERROR_NO_AGGREGATION;
|
||||
goto done;
|
||||
}
|
||||
|
||||
NS_NEWXPCOM(inst, nsXPBaseWindow);
|
||||
if (inst == NULL) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto done;
|
||||
}
|
||||
|
||||
NS_ADDREF(inst);
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
|
||||
done:
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsresult
|
||||
nsXPBaseWindowFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
nsresult
|
||||
NS_NewXPBaseWindowFactory(nsIFactory** aFactory)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsXPBaseWindowFactory* inst;
|
||||
NS_NEWXPCOM(inst, nsXPBaseWindowFactory);
|
||||
if (nsnull == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
NS_ADDREF(inst);
|
||||
}
|
||||
*aFactory = inst;
|
||||
return rv;
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef nsXPBaseWindow_h___
|
||||
#define nsXPBaseWindow_h___
|
||||
|
||||
#include "nsIXPBaseWindow.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
class nsViewerApp;
|
||||
class nsIPresShell;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class nsXPBaseWindow : public nsIXPBaseWindow,
|
||||
public nsIWebShellContainer,
|
||||
public nsIDOMMouseListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
||||
|
||||
nsXPBaseWindow();
|
||||
virtual ~nsXPBaseWindow();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBrowserWindow
|
||||
NS_IMETHOD Init(nsXPBaseWindowType aType,
|
||||
nsIAppShell* aAppShell,
|
||||
const nsString& aDialogURL,
|
||||
const nsString& aTitle,
|
||||
const nsRect& aBounds,
|
||||
PRUint32 aChromeMask,
|
||||
PRBool aAllowPlugins = PR_TRUE);
|
||||
|
||||
|
||||
NS_IMETHOD SetLocation(PRInt32 aX, PRInt32 aY);
|
||||
NS_IMETHOD SetDimensions(PRInt32 aWidth, PRInt32 aHeight);
|
||||
|
||||
NS_IMETHOD GetWindowBounds(nsRect& aBounds);
|
||||
NS_IMETHOD GetBounds(nsRect& aBounds);
|
||||
NS_IMETHOD SetVisible(PRBool aIsVisible);
|
||||
NS_IMETHOD Close();
|
||||
NS_IMETHOD SetTitle(const PRUnichar* aTitle);
|
||||
NS_IMETHOD GetTitle(const PRUnichar** aResult);
|
||||
NS_IMETHOD GetWebShell(nsIWebShell*& aResult);
|
||||
NS_IMETHOD GetPresShell(nsIPresShell*& aPresShell);
|
||||
|
||||
//NS_IMETHOD HandleEvent(nsGUIEvent * anEvent);
|
||||
|
||||
NS_IMETHOD LoadURL(const nsString &aURL);
|
||||
|
||||
// nsIWebShellContainer
|
||||
NS_IMETHOD WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason);
|
||||
NS_IMETHOD BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL);
|
||||
NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax);
|
||||
NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsresult aStatus);
|
||||
NS_IMETHOD NewWebShell(PRUint32 aChromeMask,
|
||||
PRBool aVisible,
|
||||
nsIWebShell *&aNewWebShell);
|
||||
NS_IMETHOD ContentShellAdded(nsIWebShell* aChildShell, nsIContent* frameNode);
|
||||
NS_IMETHOD FindWebShellWithName(const PRUnichar* aName, nsIWebShell*& aResult);
|
||||
NS_IMETHOD FocusAvailable(nsIWebShell* aFocusedWebShell, PRBool& aFocusTaken);
|
||||
|
||||
void Layout(PRInt32 aWidth, PRInt32 aHeight);
|
||||
|
||||
void ForceRefresh();
|
||||
|
||||
//nsEventStatus ProcessDialogEvent(nsGUIEvent *aEvent);
|
||||
|
||||
|
||||
void SetApp(nsViewerApp* aApp) {
|
||||
mApp = aApp;
|
||||
}
|
||||
|
||||
// DOM Element & Node Interfaces
|
||||
NS_IMETHOD GetDocument(nsIDOMHTMLDocument *& aDocument);
|
||||
NS_IMETHOD AddEventListener(nsIDOMNode * aNode);
|
||||
NS_IMETHOD RemoveEventListener(nsIDOMNode * aNode);
|
||||
NS_IMETHOD AddWindowListener(nsIWindowListener * aWindowListener);
|
||||
|
||||
// nsIDOMEventListener
|
||||
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIDOMMouseListener (is derived from nsIDOMEventListener)
|
||||
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
|
||||
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
|
||||
NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
|
||||
NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent);
|
||||
NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent);
|
||||
NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent);
|
||||
|
||||
protected:
|
||||
void GetContentRoot(); //Gets the Root Content node after Doc is loaded
|
||||
nsIContent * mContentRoot; // Points at the Root Content Node
|
||||
|
||||
|
||||
protected:
|
||||
nsViewerApp* mApp;
|
||||
|
||||
nsString mTitle;
|
||||
nsString mDialogURL;
|
||||
|
||||
nsIWidget* mWindow;
|
||||
nsIWebShell* mWebShell;
|
||||
|
||||
nsIWindowListener * mWindowListener; // XXX Someday this will be a list
|
||||
PRBool mDocIsLoaded;
|
||||
|
||||
//for creating more instances
|
||||
nsIAppShell* mAppShell; //not addref'ed!
|
||||
PRBool mAllowPlugins;
|
||||
|
||||
nsXPBaseWindowType mWindowType;
|
||||
|
||||
};
|
||||
|
||||
// XXX This is bad; because we can't hang a closure off of the event
|
||||
// callback we have no way to store our This pointer; therefore we
|
||||
// have to hunt to find the browswer that events belong too!!!
|
||||
|
||||
// aWhich for FindBrowserFor
|
||||
#define FIND_WINDOW 0
|
||||
#define FIND_BACK 1
|
||||
#define FIND_FORWARD 2
|
||||
#define FIND_LOCATION 3
|
||||
|
||||
|
||||
|
||||
#endif /* nsXPBaseWindow_h___ */
|
|
@ -1,157 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef nsIXPBaseWindow_h___
|
||||
#define nsIXPBaseWindow_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIAppShell;
|
||||
class nsIFactory;
|
||||
class nsIWebShell;
|
||||
class nsString;
|
||||
class nsIPresShell;
|
||||
class nsIDOMElement;
|
||||
class nsIDOMNode;
|
||||
class nsIWindowListener;
|
||||
class nsIDOMHTMLDocument;
|
||||
|
||||
struct nsRect;
|
||||
|
||||
#define NS_IXPBASE_WINDOW_IID \
|
||||
{ 0x36c1fe51, 0x6f3e, 0x11d2, { 0x8d, 0xca, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
|
||||
|
||||
#define NS_XPBASE_WINDOW_CID \
|
||||
{ 0x36c1fe51, 0x6f3e, 0x11d2, { 0x8d, 0xca, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
|
||||
|
||||
enum nsXPBaseWindowType {
|
||||
///creates a window
|
||||
eXPBaseWindowType_window,
|
||||
///creates a dialog
|
||||
eXPBaseWindowType_dialog,
|
||||
///creates a modal dialog
|
||||
eXPBaseWindowType_modalDialog
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* BaseWindow for HTML Dialog Boxes and Windows. The desciption of the dialog box
|
||||
* or window is encoded in a HTML File. The Contents of the HTML file and the current
|
||||
* settings for form elements are accessed through the W3C DOM interfaces.
|
||||
* Access to the nsIDOM classes is done through C++ rather than JavaScript. However,
|
||||
* JavaScript event handlers can be used with the HTML File as well.
|
||||
* The BaseWindow contains methods for:
|
||||
*
|
||||
* 1) loading a HTML file
|
||||
* 2) Initializing the default values for form elements.
|
||||
* 3) attaching an event listener to process click events.
|
||||
* 4) Getting a handle to the HTMLDocumentElement to access nsIDOMElements.
|
||||
*/
|
||||
|
||||
class nsIXPBaseWindow : public nsISupports {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Initialize the window or dialog box.
|
||||
* @param aType see nsXPBaseWindowType's above
|
||||
* @param aAppShell application shell
|
||||
* @param aPref Preferences
|
||||
* @param aDialogURL URL of HTML file describing the dialog or window
|
||||
* @param aTitle Title of the dialog box or window
|
||||
* @param aBounds x, y, width, and height of the window or dialog box
|
||||
* XXX: aChrome is probably not needed for dialog boxes and windows, this is a holdover
|
||||
* from the nsBrowserWindow.
|
||||
* @param aChrome Chrome mask for toolbars and statusbars.
|
||||
* @param aAllowPlugins if TRUE then plugins can be referenced in the HTML file.
|
||||
*/
|
||||
|
||||
NS_IMETHOD Init(nsXPBaseWindowType aType,
|
||||
nsIAppShell* aAppShell,
|
||||
const nsString& aDialogURL,
|
||||
const nsString& aTitle,
|
||||
const nsRect& aBounds,
|
||||
PRUint32 aChromeMask,
|
||||
PRBool aAllowPlugins = PR_TRUE) = 0;
|
||||
|
||||
/**
|
||||
* Set the location the window or dialog box on the screen
|
||||
* @param aX horizontal location of the upper left
|
||||
* corner of the window in pixels from the screen.
|
||||
* @param aY vertical location of the upper left
|
||||
* corner of the window in pixels from the screen.
|
||||
*/
|
||||
|
||||
NS_IMETHOD SetLocation(PRInt32 aX, PRInt32 aY) = 0;
|
||||
|
||||
/**
|
||||
* Set the width and height of the window or dialog box in pixels
|
||||
* @param aWidth width of the window or dialog box in pixels.
|
||||
* @param aHeight height of the window or dialog box in pixels.
|
||||
*/
|
||||
|
||||
NS_IMETHOD SetDimensions(PRInt32 aWidth, PRInt32 aHeight) = 0;
|
||||
|
||||
NS_IMETHOD GetBounds(nsRect& aResult) = 0;
|
||||
|
||||
NS_IMETHOD GetWindowBounds(nsRect& aResult) = 0;
|
||||
|
||||
NS_IMETHOD SetVisible(PRBool aIsVisible) = 0;
|
||||
|
||||
NS_IMETHOD Close() = 0;
|
||||
|
||||
NS_IMETHOD SetTitle(const PRUnichar* aTitle) = 0;
|
||||
|
||||
NS_IMETHOD GetTitle(const PRUnichar** aResult) = 0;
|
||||
|
||||
NS_IMETHOD GetWebShell(nsIWebShell*& aResult) = 0;
|
||||
|
||||
NS_IMETHOD LoadURL(const nsString &aURL) = 0;
|
||||
|
||||
NS_IMETHOD GetPresShell(nsIPresShell*& aPresShell) = 0;
|
||||
|
||||
NS_IMETHOD GetDocument(nsIDOMHTMLDocument *& aDocument) = 0;
|
||||
|
||||
NS_IMETHOD AddEventListener(nsIDOMNode * aNode) = 0;
|
||||
|
||||
NS_IMETHOD RemoveEventListener(nsIDOMNode * aNode) = 0;
|
||||
|
||||
NS_IMETHOD AddWindowListener(nsIWindowListener * aWindowListener) = 0;
|
||||
|
||||
// XXX minimize, maximize
|
||||
// XXX event control: enable/disable window close box, stick to glass, modal
|
||||
};
|
||||
|
||||
#endif /* nsIXPBaseWindow_h___ */
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
|
||||
class nsIMenuBar;
|
||||
class nsIMenu;
|
||||
|
@ -70,7 +70,7 @@ class nsIMenu : public nsISupports {
|
|||
*
|
||||
*/
|
||||
NS_IMETHOD Create ( nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode ) = 0;
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) = 0;
|
||||
|
||||
/**
|
||||
* Get the Menu's Parent
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIMenu.h"
|
||||
#include "nsIWebShell.h"
|
||||
|
||||
class nsIWidget;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
|
||||
|
@ -81,7 +81,7 @@ class nsIMenuItem : public nsISupports {
|
|||
*/
|
||||
NS_IMETHOD Create ( nsIMenu* aParent, const nsString & aLabel, PRBool isSeparator,
|
||||
EMenuItemType aItemType, PRBool aEnabled,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode ) = 0;
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) = 0;
|
||||
|
||||
/**
|
||||
* Get the MenuItem label
|
||||
|
|
|
@ -83,7 +83,7 @@ class nsIMenuListener : public nsISupports {
|
|||
|
||||
virtual nsEventStatus MenuConstruct( const nsMenuEvent & aMenuEvent,
|
||||
nsIWidget* aParentWindow, void* aNode,
|
||||
void* aWebShell) = 0;
|
||||
void* aDocShell) = 0;
|
||||
|
||||
virtual nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent) = 0;
|
||||
|
||||
|
|
|
@ -201,14 +201,13 @@ nsMenuBarX::SetRebuild(PRBool aNeedsRebuild)
|
|||
}
|
||||
|
||||
void
|
||||
nsMenuBarX :: GetDocument ( nsIWebShell* inWebShell, nsIDocument** outDocument )
|
||||
nsMenuBarX :: GetDocument ( nsIDocShell* inDocShell, nsIDocument** outDocument )
|
||||
{
|
||||
*outDocument = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell ( do_QueryInterface(inWebShell) );
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
if ( docShell ) {
|
||||
docShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if ( inDocShell ) {
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
inDocShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if (cv) {
|
||||
// get the document
|
||||
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
||||
|
@ -226,17 +225,17 @@ nsMenuBarX :: GetDocument ( nsIWebShell* inWebShell, nsIDocument** outDocument )
|
|||
// Name says it all.
|
||||
//
|
||||
void
|
||||
nsMenuBarX :: RegisterAsDocumentObserver ( nsIWebShell* inWebShell )
|
||||
nsMenuBarX :: RegisterAsDocumentObserver ( nsIDocShell* inDocShell )
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
GetDocument(inWebShell, getter_AddRefs(doc));
|
||||
GetDocument(inDocShell, getter_AddRefs(doc));
|
||||
if (!doc)
|
||||
return;
|
||||
|
||||
// register ourselves
|
||||
nsCOMPtr<nsIDocumentObserver> observer ( do_QueryInterface(NS_STATIC_CAST(nsIMenuBar*,this)) );
|
||||
doc->AddObserver(observer);
|
||||
// also get pointer to doc, just in case webshell goes away
|
||||
// also get pointer to doc, just in case docshell goes away
|
||||
// we can still remove ourself as doc observer directly from doc
|
||||
mDocument = doc;
|
||||
} // RegisterAsDocumentObesrver
|
||||
|
@ -396,11 +395,11 @@ nsMenuBarX :: ExecuteCommand ( nsIContent* inDispatchTo )
|
|||
{
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
if ( inDispatchTo ) {
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell)
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell)
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext));
|
||||
MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext));
|
||||
|
||||
nsMouseEvent event(NS_XUL_COMMAND);
|
||||
|
||||
|
@ -437,9 +436,9 @@ nsMenuBarX :: HideItem ( nsIDOMDocument* inDoc, const nsAString & inID, nsIConte
|
|||
|
||||
nsEventStatus
|
||||
nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow,
|
||||
void * menubarNode, void * aWebShell )
|
||||
void * menubarNode, void * aDocShell )
|
||||
{
|
||||
mWebShellWeakRef = do_GetWeakReference(NS_STATIC_CAST(nsIWebShell*, aWebShell));
|
||||
mDocShellWeakRef = do_GetWeakReference(NS_STATIC_CAST(nsIDocShell*, aDocShell));
|
||||
nsIDOMNode* aDOMNode = NS_STATIC_CAST(nsIDOMNode*, menubarNode);
|
||||
mMenuBarContent = do_QueryInterface(aDOMNode); // strong ref
|
||||
NS_ASSERTION ( mMenuBarContent, "No content specified for this menubar" );
|
||||
|
@ -458,8 +457,8 @@ nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWin
|
|||
if ( err )
|
||||
return nsEventStatus_eIgnore;
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (webShell) RegisterAsDocumentObserver(webShell);
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (docShell) RegisterAsDocumentObserver(docShell);
|
||||
|
||||
// set this as a nsMenuListener on aParentWindow
|
||||
aParentWindow->AddMenuListener((nsIMenuListener *)this);
|
||||
|
@ -482,7 +481,7 @@ nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWin
|
|||
if ( pnsMenu ) {
|
||||
pnsMenu->Create(NS_STATIC_CAST(nsIMenuBar*, this), menuName, menuAccessKey,
|
||||
NS_STATIC_CAST(nsIChangeManager *, this),
|
||||
NS_REINTERPRET_CAST(nsIWebShell*, aWebShell), menu);
|
||||
NS_REINTERPRET_CAST(nsIDocShell*, aDocShell), menu);
|
||||
|
||||
// Make nsMenu a child of nsMenuBar. nsMenuBar takes ownership
|
||||
AddMenu(pnsMenu);
|
||||
|
@ -924,25 +923,24 @@ nsMenuBarX :: Unregister ( PRUint32 inCommandID )
|
|||
|
||||
|
||||
//
|
||||
// WebShellToPresContext
|
||||
// DocShellToPresContext
|
||||
//
|
||||
// Helper to dig out a pres context from a webshell. A common thing to do before
|
||||
// Helper to dig out a pres context from a docshell. A common thing to do before
|
||||
// sending an event into the dom.
|
||||
//
|
||||
// XXXbz this should be using DOM event apis!
|
||||
nsresult
|
||||
MenuHelpersX::WebShellToPresContext (nsIWebShell* inWebShell, nsPresContext** outContext )
|
||||
MenuHelpersX::DocShellToPresContext (nsIDocShell* inDocShell, nsPresContext** outContext )
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outContext);
|
||||
*outContext = nsnull;
|
||||
if (!inWebShell)
|
||||
if (!inDocShell)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsresult retval = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(inWebShell));
|
||||
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
||||
inDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
||||
if ( contentViewer ) {
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer ( do_QueryInterface(contentViewer) );
|
||||
if ( docViewer )
|
||||
|
@ -955,7 +953,7 @@ MenuHelpersX::WebShellToPresContext (nsIWebShell* inWebShell, nsPresContext** ou
|
|||
|
||||
return retval;
|
||||
|
||||
} // WebShellToPresContext
|
||||
} // DocShellToPresContext
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@ class nsIDOMNode;
|
|||
|
||||
namespace MenuHelpersX
|
||||
{
|
||||
// utility routine for getting a PresContext out of a webShell
|
||||
nsresult WebShellToPresContext ( nsIWebShell* inWebShell, nsPresContext** outContext ) ;
|
||||
// utility routine for getting a PresContext out of a docShell
|
||||
nsresult DocShellToPresContext ( nsIDocShell* inDocShell, nsPresContext** outContext ) ;
|
||||
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ public:
|
|||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void * menuNode, void * aWebShell);
|
||||
void * menuNode, void * aDocShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
@ -120,8 +120,8 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
void GetDocument ( nsIWebShell* inWebShell, nsIDocument** outDocument ) ;
|
||||
void RegisterAsDocumentObserver ( nsIWebShell* inWebShell ) ;
|
||||
void GetDocument ( nsIDocShell* inDocShell, nsIDocument** outDocument ) ;
|
||||
void RegisterAsDocumentObserver ( nsIDocShell* inDocShell ) ;
|
||||
|
||||
// Make our menubar conform to Aqua UI guidelines
|
||||
void AquifyMenuBar ( ) ;
|
||||
|
@ -150,7 +150,7 @@ protected:
|
|||
|
||||
PRBool mIsMenuBarAdded;
|
||||
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
|
||||
nsIDocument* mDocument; // pointer to document
|
||||
|
||||
MenuRef mRootMenu; // root menu, representing entire menu bar.
|
||||
|
|
|
@ -94,11 +94,11 @@ nsMenuItemX::~nsMenuItemX()
|
|||
|
||||
NS_METHOD nsMenuItemX::Create ( nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
|
||||
EMenuItemType aItemType, PRBool aEnabled,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode )
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode )
|
||||
{
|
||||
mContent = aNode; // addref
|
||||
mMenuParent = aParent; // weak
|
||||
mWebShellWeakRef = do_GetWeakReference(aShell);
|
||||
mDocShellWeakRef = do_GetWeakReference(aShell);
|
||||
|
||||
mEnabled = aEnabled;
|
||||
mMenuType = aItemType;
|
||||
|
@ -222,7 +222,7 @@ nsEventStatus nsMenuItemX::MenuConstruct(
|
|||
const nsMenuEvent & aMenuEvent,
|
||||
nsIWidget * aParentWindow,
|
||||
void * menuNode,
|
||||
void * aWebShell)
|
||||
void * aDocShell)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
@ -255,10 +255,10 @@ nsEventStatus nsMenuItemX::SetRebuild(PRBool aNeedsRebuild)
|
|||
NS_METHOD nsMenuItemX::DoCommand()
|
||||
{
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell)
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell)
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext));
|
||||
MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext));
|
||||
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsMouseEvent event(NS_XUL_COMMAND);
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
// nsIMenuItem Methods
|
||||
NS_IMETHOD Create ( nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
|
||||
EMenuItemType aItemType, PRBool aEnabled,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode ) ;
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) ;
|
||||
NS_IMETHOD GetLabel(nsString &aText);
|
||||
NS_IMETHOD SetShortcutChar(const nsString &aText);
|
||||
NS_IMETHOD GetShortcutChar(nsString &aText);
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void * menuNode, void * aWebShell);
|
||||
void * menuNode, void * aDocShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
@ -109,7 +109,7 @@ protected:
|
|||
nsCOMPtr<nsIWidget> mTarget; // never set?
|
||||
nsCOMPtr<nsIMenuListener> mXULCommandListener;
|
||||
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
|
||||
nsCOMPtr<nsIContent> mContent;
|
||||
|
||||
PRUint8 mModifiers;
|
||||
|
|
|
@ -148,9 +148,9 @@ nsMenuX::~nsMenuX()
|
|||
//
|
||||
NS_METHOD
|
||||
nsMenuX::Create(nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode )
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode )
|
||||
{
|
||||
mWebShellWeakRef = do_GetWeakReference(aShell);
|
||||
mDocShellWeakRef = do_GetWeakReference(aShell);
|
||||
mMenuContent = aNode;
|
||||
|
||||
// register this menu to be notified when changes are made to our content object
|
||||
|
@ -504,16 +504,16 @@ nsEventStatus nsMenuX::MenuSelected(const nsMenuEvent & aMenuEvent)
|
|||
if (mNeedsRebuild)
|
||||
RemoveAll();
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_ERROR("No web shell");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_ERROR("No doc shell");
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
if (mIsHelpMenu) {
|
||||
HelpMenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, webShell);
|
||||
HelpMenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, docShell);
|
||||
mConstructed = true;
|
||||
} else {
|
||||
MenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, webShell);
|
||||
MenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, docShell);
|
||||
mConstructed = true;
|
||||
}
|
||||
}
|
||||
|
@ -557,7 +557,7 @@ nsEventStatus nsMenuX::MenuConstruct(
|
|||
const nsMenuEvent & aMenuEvent,
|
||||
nsIWidget * aParentWindow,
|
||||
void * /* menuNode */,
|
||||
void * aWebShell)
|
||||
void * aDocShell)
|
||||
{
|
||||
mConstructed = false;
|
||||
gConstructingMenu = PR_TRUE;
|
||||
|
@ -602,7 +602,7 @@ nsEventStatus nsMenuX::HelpMenuConstruct(
|
|||
const nsMenuEvent & aMenuEvent,
|
||||
nsIWidget * aParentWindow,
|
||||
void * /* menuNode */,
|
||||
void * aWebShell)
|
||||
void * aDocShell)
|
||||
{
|
||||
//printf("nsMenuX::MenuConstruct called for %s = %d \n", NS_LossyConvertUCS2toASCII(mLabel).get(), mMacMenuHandle);
|
||||
|
||||
|
@ -844,13 +844,13 @@ void nsMenuX::LoadMenuItem( nsIMenu* inParentMenu, nsIContent* inMenuItemContent
|
|||
else if ( type.EqualsLiteral("radio") )
|
||||
itemType = nsIMenuItem::eRadio;
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell)
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell)
|
||||
return;
|
||||
|
||||
// Create the item.
|
||||
pnsMenuItem->Create(inParentMenu, menuitemName, PR_FALSE, itemType,
|
||||
enabled, mManager, webShell, inMenuItemContent);
|
||||
enabled, mManager, docShell, inMenuItemContent);
|
||||
|
||||
//
|
||||
// Set key shortcut and modifiers
|
||||
|
@ -928,11 +928,11 @@ nsMenuX::LoadSubMenu( nsIMenu * pParentMenu, nsIContent* inMenuItemContent )
|
|||
nsCOMPtr<nsIMenu> pnsMenu ( do_CreateInstance(kMenuCID) );
|
||||
if (pnsMenu) {
|
||||
// Call Create
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell)
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell)
|
||||
return;
|
||||
nsCOMPtr<nsISupports> supports(do_QueryInterface(pParentMenu));
|
||||
pnsMenu->Create(supports, menuName, EmptyString(), mManager, webShell, inMenuItemContent);
|
||||
pnsMenu->Create(supports, menuName, EmptyString(), mManager, docShell, inMenuItemContent);
|
||||
|
||||
// set if it's enabled or disabled
|
||||
nsAutoString disabled;
|
||||
|
@ -978,13 +978,13 @@ nsMenuX::OnCreate()
|
|||
nsCOMPtr<nsIContent> popupContent;
|
||||
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_ERROR("No web shell");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_ERROR("No doc shell");
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext) );
|
||||
MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext) );
|
||||
if ( presContext ) {
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
|
||||
|
@ -1061,13 +1061,13 @@ nsMenuX::OnCreated()
|
|||
nsCOMPtr<nsIContent> popupContent;
|
||||
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_ERROR("No web shell");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_ERROR("No doc shell");
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext) );
|
||||
MenuHelpersX::DocShellToPresContext(DocShell, getter_AddRefs(presContext) );
|
||||
if ( presContext ) {
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
|
||||
|
@ -1094,9 +1094,9 @@ nsMenuX::OnDestroy()
|
|||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsMouseEvent event(NS_XUL_POPUP_HIDING);
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_WARNING("No web shell so can't run the OnDestroy");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_WARNING("No doc shell so can't run the OnDestroy");
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -1104,7 +1104,7 @@ nsMenuX::OnDestroy()
|
|||
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext (webShell, getter_AddRefs(presContext) );
|
||||
MenuHelpersX::DocShellToPresContext (docShell, getter_AddRefs(presContext) );
|
||||
if (presContext ) {
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
|
||||
|
@ -1124,9 +1124,9 @@ nsMenuX::OnDestroyed()
|
|||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsMouseEvent event(NS_XUL_POPUP_HIDDEN);
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_WARNING("No web shell so can't run the OnDestroy");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_WARNING("No doc shell so can't run the OnDestroy");
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -1134,7 +1134,7 @@ nsMenuX::OnDestroyed()
|
|||
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext (webShell, getter_AddRefs(presContext) );
|
||||
MenuHelpersX::DocShellToPresContext (docShell, getter_AddRefs(presContext) );
|
||||
if (presContext ) {
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
|
||||
|
|
|
@ -76,14 +76,14 @@ public:
|
|||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void * menuNode, void * aWebShell);
|
||||
void * menuNode, void * aDocShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
||||
// nsIMenu Methods
|
||||
NS_IMETHOD Create ( nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode ) ;
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) ;
|
||||
NS_IMETHOD GetParent(nsISupports *&aParent);
|
||||
NS_IMETHOD GetLabel(nsString &aText);
|
||||
NS_IMETHOD SetLabel(const nsAString &aText);
|
||||
|
@ -133,7 +133,7 @@ protected:
|
|||
void LoadSeparator ( nsIContent* menuitemContent );
|
||||
|
||||
nsEventStatus HelpMenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow,
|
||||
void* unused, void* aWebShell);
|
||||
void* unused, void* aDocShell);
|
||||
|
||||
MenuHandle NSStringNewMenu(short menuID, nsString& menuTitle);
|
||||
|
||||
|
@ -144,7 +144,7 @@ protected:
|
|||
|
||||
nsISupports* mParent; // weak, my parent owns me
|
||||
nsIChangeManager* mManager; // weak ref, it will outlive us [menubar]
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
|
||||
nsCOMPtr<nsIContent> mMenuContent; // the |menu| tag, strong ref
|
||||
nsCOMPtr<nsIMenuListener> mListener; // strong ref
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,174 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsMenu_h__
|
||||
#define nsMenu_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIMenu.h"
|
||||
#include "nsSupportsArray.h"
|
||||
#include "nsIMenuListener.h"
|
||||
#include "nsIChangeManager.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
#include <Menus.h>
|
||||
#include <UnicodeConverter.h>
|
||||
|
||||
class nsIMenuBar;
|
||||
class nsIMenuListener;
|
||||
|
||||
|
||||
// temporary hack to get apple menu -- sfraser, approved saari
|
||||
#define APPLE_MENU_HACK 1
|
||||
|
||||
#ifdef APPLE_MENU_HACK
|
||||
extern const PRInt16 kMacMenuID;
|
||||
extern const PRInt16 kAppleMenuID;
|
||||
#endif /* APPLE_MENU_HACK */
|
||||
|
||||
//static PRInt16 mMacMenuIDCount; // use GetUniqueMenuID()
|
||||
extern PRInt16 mMacMenuIDCount;// = kMacMenuID;
|
||||
|
||||
|
||||
class nsMenu : public nsIMenu,
|
||||
public nsIMenuListener,
|
||||
public nsIChangeObserver,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
|
||||
public:
|
||||
nsMenu();
|
||||
virtual ~nsMenu();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICHANGEOBSERVER
|
||||
|
||||
// nsIMenuListener methods
|
||||
nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void* unused, void * aWebShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
||||
// nsIMenu Methods
|
||||
NS_IMETHOD Create ( nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode ) ;
|
||||
NS_IMETHOD GetParent(nsISupports *&aParent);
|
||||
NS_IMETHOD GetLabel(nsString &aText);
|
||||
NS_IMETHOD SetLabel(const nsAString &aText);
|
||||
NS_IMETHOD GetAccessKey(nsString &aText);
|
||||
NS_IMETHOD SetAccessKey(const nsAString &aText);
|
||||
NS_IMETHOD AddItem(nsISupports* aText);
|
||||
NS_IMETHOD AddSeparator();
|
||||
NS_IMETHOD GetItemCount(PRUint32 &aCount);
|
||||
NS_IMETHOD GetItemAt(const PRUint32 aPos, nsISupports *& aMenuItem);
|
||||
NS_IMETHOD InsertItemAt(const PRUint32 aPos, nsISupports * aMenuItem);
|
||||
NS_IMETHOD RemoveItem(const PRUint32 aPos);
|
||||
NS_IMETHOD RemoveAll();
|
||||
NS_IMETHOD GetNativeData(void** aData);
|
||||
NS_IMETHOD SetNativeData(void* aData);
|
||||
NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener);
|
||||
NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener);
|
||||
NS_IMETHOD GetMenuContent(nsIContent ** aMenuNode);
|
||||
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
|
||||
NS_IMETHOD GetEnabled(PRBool* aIsEnabled);
|
||||
NS_IMETHOD IsHelpMenu(PRBool* aIsEnabled);
|
||||
|
||||
//
|
||||
NS_IMETHOD AddMenuItem(nsIMenuItem * aMenuItem);
|
||||
NS_IMETHOD AddMenu(nsIMenu * aMenu);
|
||||
|
||||
// MacSpecific
|
||||
static PRInt16 GetUniqueMenuID()
|
||||
{
|
||||
if (mMacMenuIDCount == 32767)
|
||||
mMacMenuIDCount = 256;
|
||||
return mMacMenuIDCount++;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsString mLabel;
|
||||
PRUint32 mNumMenuItems;
|
||||
nsSupportsArray mMenuItemsArray; // array holds refs
|
||||
|
||||
nsISupports* mParent; // weak, my parent owns me
|
||||
nsIChangeManager* mManager; // weak ref, it will outlive us
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsCOMPtr<nsIContent> mMenuContent; // the |menu| tag, strong ref
|
||||
nsCOMPtr<nsIMenuListener> mListener;
|
||||
|
||||
bool mConstructed;
|
||||
// MacSpecific
|
||||
PRInt16 mMacMenuID;
|
||||
MenuHandle mMacMenuHandle;
|
||||
UnicodeToTextRunInfo mUnicodeTextRunConverter;
|
||||
PRInt16 mHelpMenuOSItemsCount;
|
||||
PRPackedBool mIsHelpMenu;
|
||||
PRPackedBool mIsEnabled;
|
||||
PRPackedBool mDestroyHandlerCalled;
|
||||
PRPackedBool mNeedsRebuild;
|
||||
|
||||
nsresult GetNextVisibleMenu(nsIMenu** outNextVisibleMenu);
|
||||
|
||||
// fetch the content node associated with the menupopup item
|
||||
void GetMenuPopupContent ( nsIContent** aResult ) ;
|
||||
|
||||
PRBool IsSpecialHierarchicalMenu ( PRInt32 inMenuId ) ;
|
||||
|
||||
// fire handlers for oncreate/ondestroy
|
||||
PRBool OnDestroy() ;
|
||||
PRBool OnCreate() ;
|
||||
PRBool OnDestroyed() ;
|
||||
PRBool OnCreated() ;
|
||||
|
||||
void LoadMenuItem ( nsIMenu* pParentMenu, nsIContent* menuitemContent);
|
||||
void LoadSubMenu( nsIMenu * pParentMenu, nsIContent* menuitemContent);
|
||||
void LoadSeparator ( nsIContent* menuitemContent );
|
||||
nsEventStatus HelpMenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow,
|
||||
void* unused, void* aWebShell);
|
||||
|
||||
MenuHandle NSStringNewMenu(short menuID, nsString& menuTitle);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // nsMenu_h__
|
|
@ -1,905 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIMenu.h"
|
||||
#include "nsIMenuItem.h"
|
||||
#include "nsIContent.h"
|
||||
|
||||
#include "nsMenuBar.h"
|
||||
#include "nsDynamicMDEF.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
|
||||
#include "nsWidgetAtoms.h"
|
||||
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
#include <Menus.h>
|
||||
#include <TextUtils.h>
|
||||
#include <Balloons.h>
|
||||
#ifndef XP_MACOSX
|
||||
#include <Traps.h>
|
||||
#endif
|
||||
#include <Resources.h>
|
||||
#include <Appearance.h>
|
||||
#include "nsMacResources.h"
|
||||
|
||||
#include "DefProcFakery.h"
|
||||
|
||||
|
||||
Handle gMDEF = nsnull;
|
||||
nsWeakPtr gMacMenubar;
|
||||
nsWeakPtr gOriginalMenuBar;
|
||||
bool gFirstMenuBar = true;
|
||||
|
||||
// The four Golden Hierarchical Child Menus
|
||||
MenuHandle gLevel2HierMenu = nsnull;
|
||||
MenuHandle gLevel3HierMenu = nsnull;
|
||||
MenuHandle gLevel4HierMenu = nsnull;
|
||||
MenuHandle gLevel5HierMenu = nsnull;
|
||||
|
||||
extern nsMenuStack gPreviousMenuStack;
|
||||
extern PRInt16 gCurrentMenuDepth;
|
||||
|
||||
// #if APPLE_MENU_HACK
|
||||
#include "nsMenu.h" // need to get APPLE_MENU_HACK macro
|
||||
// #endif
|
||||
|
||||
// CIDs
|
||||
#include "nsWidgetsCID.h"
|
||||
static NS_DEFINE_CID(kMenuCID, NS_MENU_CID);
|
||||
|
||||
void InstallDefProc( short dpPath, ResType dpType, short dpID, Ptr dpAddr);
|
||||
|
||||
|
||||
PRInt32 gMenuBarCounter = 0;
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS5(nsMenuBar, nsIMenuBar, nsIMenuListener, nsIDocumentObserver, nsIChangeManager, nsISupportsWeakReference)
|
||||
|
||||
//
|
||||
// nsMenuBar constructor
|
||||
//
|
||||
nsMenuBar::nsMenuBar()
|
||||
{
|
||||
gCurrentMenuDepth = 1;
|
||||
|
||||
nsPreviousMenuStackUnwind(nsnull, nsnull);
|
||||
|
||||
mNumMenus = 0;
|
||||
mParent = nsnull;
|
||||
mIsMenuBarAdded = PR_FALSE;
|
||||
mUnicodeTextRunConverter = nsnull;
|
||||
|
||||
mOriginalMacMBarHandle = nsnull;
|
||||
mMacMBarHandle = nsnull;
|
||||
mDocument = nsnull;
|
||||
|
||||
mOriginalMacMBarHandle = ::GetMenuBar();
|
||||
Handle tmp = ::GetMenuBar();
|
||||
::SetMenuBar(tmp);
|
||||
this->SetNativeData((void*)tmp);
|
||||
|
||||
::ClearMenuBar();
|
||||
mRefCnt = 1; // NS_GetWeakReference does an addref then a release, so this +1 is needed
|
||||
gMacMenubar = do_GetWeakReference((nsIMenuBar *)this);
|
||||
mRefCnt = 0;
|
||||
// copy from nsMenu.cpp
|
||||
ScriptCode ps[1];
|
||||
ps[0] = ::GetScriptManagerVariable(smSysScript);
|
||||
|
||||
OSErr err = ::CreateUnicodeToTextRunInfoByScriptCode(0x80000000, ps, &mUnicodeTextRunConverter);
|
||||
NS_ASSERTION(err==noErr,"nsMenu::nsMenu: CreateUnicodeToTextRunInfoByScriptCode failed.");
|
||||
|
||||
++gMenuBarCounter;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// nsMenuBar destructor
|
||||
//
|
||||
nsMenuBar::~nsMenuBar()
|
||||
{
|
||||
mMenusArray.Clear(); // release all menus
|
||||
|
||||
OSErr err = ::DisposeUnicodeToTextRunInfo(&mUnicodeTextRunConverter);
|
||||
NS_ASSERTION(err==noErr,"nsMenu::~nsMenu: DisposeUnicodeToTextRunInfo failed.");
|
||||
|
||||
// make sure we unregister ourselves as a document observer
|
||||
if ( mDocument ) {
|
||||
nsCOMPtr<nsIDocumentObserver> observer ( do_QueryInterface(NS_STATIC_CAST(nsIMenuBar*,this)) );
|
||||
mDocument->RemoveObserver(observer);
|
||||
}
|
||||
|
||||
--gMenuBarCounter;
|
||||
if(gMenuBarCounter == 1) {
|
||||
nsCOMPtr<nsIMenuBar> menubar = do_QueryReferent(gOriginalMenuBar);
|
||||
if(menubar)
|
||||
menubar->Paint();
|
||||
}
|
||||
|
||||
::DisposeHandle(mOriginalMacMBarHandle);
|
||||
::DisposeHandle(mMacMBarHandle);
|
||||
|
||||
}
|
||||
|
||||
|
||||
nsEventStatus
|
||||
nsMenuBar::MenuItemSelected(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
// Dispatch menu event
|
||||
nsEventStatus eventStatus = nsEventStatus_eIgnore;
|
||||
|
||||
PRUint32 numItems;
|
||||
mMenusArray.Count(&numItems);
|
||||
|
||||
for (PRUint32 i = numItems; i > 0; --i)
|
||||
{
|
||||
nsCOMPtr<nsISupports> menuSupports = getter_AddRefs(mMenusArray.ElementAt(i - 1));
|
||||
nsCOMPtr<nsIMenuListener> menuListener = do_QueryInterface(menuSupports);
|
||||
if(menuListener)
|
||||
{
|
||||
eventStatus = menuListener->MenuItemSelected(aMenuEvent);
|
||||
if(nsEventStatus_eIgnore != eventStatus)
|
||||
return eventStatus;
|
||||
}
|
||||
}
|
||||
return eventStatus;
|
||||
}
|
||||
|
||||
|
||||
nsEventStatus
|
||||
nsMenuBar::MenuSelected(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
// Dispatch event
|
||||
nsEventStatus eventStatus = nsEventStatus_eIgnore;
|
||||
|
||||
nsCOMPtr<nsIMenuListener> menuListener;
|
||||
nsCOMPtr<nsIMenu> theMenu;
|
||||
gPreviousMenuStack.GetMenuAt(gPreviousMenuStack.Count() - 1, getter_AddRefs(theMenu));
|
||||
menuListener = do_QueryInterface(theMenu);
|
||||
if (menuListener) {
|
||||
//TODO: MenuSelected is the right thing to call...
|
||||
//eventStatus = menuListener->MenuSelected(aMenuEvent);
|
||||
eventStatus = menuListener->MenuItemSelected(aMenuEvent);
|
||||
if (nsEventStatus_eIgnore != eventStatus)
|
||||
return eventStatus;
|
||||
} else {
|
||||
// If it's the help menu, gPreviousMenuStack won't be accurate so we need to get the listener a different way
|
||||
// We'll do it the old fashioned way of looping through and finding it
|
||||
PRUint32 numItems;
|
||||
mMenusArray.Count(&numItems);
|
||||
for (PRUint32 i = numItems; i > 0; --i)
|
||||
{
|
||||
nsCOMPtr<nsISupports> menuSupports = getter_AddRefs(mMenusArray.ElementAt(i - 1));
|
||||
nsCOMPtr<nsIMenuListener> thisListener = do_QueryInterface(menuSupports);
|
||||
if (thisListener)
|
||||
{
|
||||
//TODO: MenuSelected is the right thing to call...
|
||||
//eventStatus = menuListener->MenuSelected(aMenuEvent);
|
||||
eventStatus = thisListener->MenuItemSelected(aMenuEvent);
|
||||
if(nsEventStatus_eIgnore != eventStatus)
|
||||
return eventStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
return eventStatus;
|
||||
}
|
||||
|
||||
|
||||
nsEventStatus
|
||||
nsMenuBar::MenuDeselected(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
nsEventStatus
|
||||
nsMenuBar::CheckRebuild(PRBool & aNeedsRebuild)
|
||||
{
|
||||
aNeedsRebuild = PR_TRUE;
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
nsEventStatus
|
||||
nsMenuBar::SetRebuild(PRBool aNeedsRebuild)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
void
|
||||
nsMenuBar :: GetDocument ( nsIWebShell* inWebShell, nsIDocument** outDocument )
|
||||
{
|
||||
*outDocument = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell ( do_QueryInterface(inWebShell) );
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
if ( docShell ) {
|
||||
docShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if (cv) {
|
||||
// get the document
|
||||
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
||||
if (!docv)
|
||||
return;
|
||||
docv->GetDocument(outDocument); // addrefs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// RegisterAsDocumentObserver
|
||||
//
|
||||
// Name says it all.
|
||||
//
|
||||
void
|
||||
nsMenuBar :: RegisterAsDocumentObserver ( nsIWebShell* inWebShell )
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
GetDocument(inWebShell, getter_AddRefs(doc));
|
||||
if (!doc)
|
||||
return;
|
||||
|
||||
// register ourselves
|
||||
nsCOMPtr<nsIDocumentObserver> observer ( do_QueryInterface(NS_STATIC_CAST(nsIMenuBar*,this)) );
|
||||
doc->AddObserver(observer);
|
||||
// also get pointer to doc, just in case webshell goes away
|
||||
// we can still remove ourself as doc observer directly from doc
|
||||
mDocument = doc;
|
||||
|
||||
} // RegisterAsDocumentObesrver
|
||||
|
||||
|
||||
nsEventStatus
|
||||
nsMenuBar::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow,
|
||||
void * menubarNode, void * aWebShell )
|
||||
{
|
||||
mWebShellWeakRef = do_GetWeakReference(NS_STATIC_CAST(nsIWebShell*, aWebShell));
|
||||
nsIDOMNode* aDOMNode = NS_STATIC_CAST(nsIDOMNode*, menubarNode);
|
||||
mMenuBarContent = do_QueryInterface(aDOMNode); // strong ref
|
||||
|
||||
if(gFirstMenuBar) {
|
||||
gOriginalMenuBar = do_GetWeakReference((nsIMenuBar *)this);
|
||||
|
||||
gFirstMenuBar = false;
|
||||
// Add the 4 Golden Hierarchical Menus to the MenuList
|
||||
|
||||
MenuHandle macMenuHandle = ::NewMenu(2, "\psubmenu");
|
||||
if(macMenuHandle) {
|
||||
|
||||
// get our fake MDEF ready to be stashed into every menu that comes our way.
|
||||
// if we fail creating it, we're probably so doomed there's no point in going
|
||||
// on.
|
||||
if ( !gMDEF ) {
|
||||
MenuDefUPP mdef = NewMenuDefProc( nsDynamicMDEFMain );
|
||||
Boolean success = DefProcFakery::CreateDefProc( mdef, (**macMenuHandle).menuProc, &gMDEF );
|
||||
if ( !success )
|
||||
::ExitToShell();
|
||||
}
|
||||
|
||||
gLevel2HierMenu = macMenuHandle;
|
||||
(**macMenuHandle).menuProc = gMDEF;
|
||||
(**macMenuHandle).menuWidth = -1;
|
||||
(**macMenuHandle).menuHeight = -1;
|
||||
::InsertMenu(macMenuHandle, hierMenu);
|
||||
}
|
||||
|
||||
macMenuHandle = ::NewMenu(3, "\psubmenu");
|
||||
if(macMenuHandle) {
|
||||
gLevel3HierMenu = macMenuHandle;
|
||||
(**macMenuHandle).menuProc = gMDEF;
|
||||
(**macMenuHandle).menuWidth = -1;
|
||||
(**macMenuHandle).menuHeight = -1;
|
||||
::InsertMenu(macMenuHandle, hierMenu);
|
||||
}
|
||||
|
||||
macMenuHandle = ::NewMenu(4, "\psubmenu");
|
||||
if(macMenuHandle) {
|
||||
gLevel4HierMenu = macMenuHandle;
|
||||
(**macMenuHandle).menuProc = gMDEF;
|
||||
(**macMenuHandle).menuWidth = -1;
|
||||
(**macMenuHandle).menuHeight = -1;
|
||||
::InsertMenu(macMenuHandle, hierMenu);
|
||||
}
|
||||
|
||||
macMenuHandle = ::NewMenu(5, "\psubmenu");
|
||||
if(macMenuHandle) {
|
||||
gLevel5HierMenu = macMenuHandle;
|
||||
(**macMenuHandle).menuProc = gMDEF;
|
||||
(**macMenuHandle).menuWidth = -1;
|
||||
(**macMenuHandle).menuHeight = -1;
|
||||
::InsertMenu(macMenuHandle, hierMenu);
|
||||
}
|
||||
} else {
|
||||
::InsertMenu(gLevel2HierMenu, hierMenu);
|
||||
::InsertMenu(gLevel3HierMenu, hierMenu);
|
||||
::InsertMenu(gLevel4HierMenu, hierMenu);
|
||||
::InsertMenu(gLevel5HierMenu, hierMenu);
|
||||
}
|
||||
|
||||
Create(aParentWindow);
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (webShell)
|
||||
RegisterAsDocumentObserver(webShell);
|
||||
|
||||
// set this as a nsMenuListener on aParentWindow
|
||||
aParentWindow->AddMenuListener((nsIMenuListener *)this);
|
||||
|
||||
PRUint32 count = mMenuBarContent->GetChildCount();
|
||||
for ( PRUint32 i = 0; i < count; ++i ) {
|
||||
nsIContent *menu = mMenuBarContent->GetChildAt(i);
|
||||
if ( menu ) {
|
||||
if (menu->Tag() == nsWidgetAtoms::menu &&
|
||||
menu->IsContentOfType(nsIContent::eXUL)) {
|
||||
nsAutoString menuName;
|
||||
nsAutoString menuAccessKey(NS_LITERAL_STRING(" "));
|
||||
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuName);
|
||||
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::accesskey, menuAccessKey);
|
||||
|
||||
// Don't create the whole menu yet, just add in the top level names
|
||||
|
||||
// Create nsMenu, the menubar will own it
|
||||
nsCOMPtr<nsIMenu> pnsMenu ( do_CreateInstance(kMenuCID) );
|
||||
if ( pnsMenu ) {
|
||||
pnsMenu->Create(NS_STATIC_CAST(nsIMenuBar*, this), menuName, menuAccessKey,
|
||||
NS_STATIC_CAST(nsIChangeManager *, this),
|
||||
NS_REINTERPRET_CAST(nsIWebShell*, aWebShell), menu);
|
||||
|
||||
// Make nsMenu a child of nsMenuBar. nsMenuBar takes ownership
|
||||
AddMenu(pnsMenu);
|
||||
|
||||
nsAutoString menuIDstring;
|
||||
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::id, menuIDstring);
|
||||
if ( menuIDstring.EqualsLiteral("menu_Help") ) {
|
||||
nsMenuEvent event;
|
||||
MenuHandle handle = nsnull;
|
||||
::HMGetHelpMenuHandle(&handle);
|
||||
event.mCommand = (unsigned int) handle;
|
||||
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(pnsMenu));
|
||||
listener->MenuSelected(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // for each menu
|
||||
|
||||
// Give the aParentWindow this nsMenuBar to hold onto.
|
||||
// The parent takes ownership
|
||||
aParentWindow->SetMenuBar(this);
|
||||
|
||||
Handle tempMenuBar = ::GetMenuBar(); // Get a copy of the menu list
|
||||
SetNativeData((void*)tempMenuBar);
|
||||
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
|
||||
nsEventStatus
|
||||
nsMenuBar::MenuDestruct(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Create the proper widget
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::Create(nsIWidget *aParent)
|
||||
{
|
||||
SetParent(aParent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::GetParent(nsIWidget *&aParent)
|
||||
{
|
||||
NS_IF_ADDREF(aParent = mParent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::SetParent(nsIWidget *aParent)
|
||||
{
|
||||
mParent = aParent; // weak ref
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu)
|
||||
{
|
||||
// XXX add to internal data structure
|
||||
nsCOMPtr<nsISupports> supports = do_QueryInterface(aMenu);
|
||||
if(supports)
|
||||
mMenusArray.AppendElement(supports); // owner
|
||||
|
||||
#ifdef APPLE_MENU_HACK
|
||||
if (mNumMenus == 0)
|
||||
{
|
||||
Str32 menuStr = { 1, 0x14 };
|
||||
MenuHandle appleMenu = ::NewMenu(kAppleMenuID, menuStr);
|
||||
|
||||
if (appleMenu)
|
||||
{
|
||||
// this code reads the "label" attribute from the <menuitem/> with
|
||||
// id="aboutName" and puts its label in the Apple Menu
|
||||
nsAutoString label;
|
||||
nsCOMPtr<nsIContent> menu;
|
||||
aMenu->GetMenuContent(getter_AddRefs(menu));
|
||||
if (menu) {
|
||||
nsCOMPtr<nsIDocument> doc = menu->GetDocument();
|
||||
if (doc) {
|
||||
nsCOMPtr<nsIDOMDocument> domdoc ( do_QueryInterface(doc) );
|
||||
if ( domdoc ) {
|
||||
nsCOMPtr<nsIDOMElement> aboutMenuItem;
|
||||
domdoc->GetElementById(NS_LITERAL_STRING("aboutName"), getter_AddRefs(aboutMenuItem));
|
||||
if (aboutMenuItem)
|
||||
aboutMenuItem->GetAttribute(NS_LITERAL_STRING("label"), label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::AppendMenu(appleMenu, "\pa");
|
||||
MenuHelpers::SetMenuItemText(appleMenu, 1, label, mUnicodeTextRunConverter);
|
||||
::AppendMenu(appleMenu, "\p-");
|
||||
::AppendResMenu(appleMenu, 'DRVR');
|
||||
::InsertMenu(appleMenu, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
MenuHandle menuHandle = nsnull;
|
||||
aMenu->GetNativeData((void**)&menuHandle);
|
||||
|
||||
mNumMenus++;
|
||||
PRBool helpMenu;
|
||||
aMenu->IsHelpMenu(&helpMenu);
|
||||
if(!helpMenu) {
|
||||
nsCOMPtr<nsIContent> menu;
|
||||
aMenu->GetMenuContent(getter_AddRefs(menu));
|
||||
nsAutoString menuHidden;
|
||||
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, menuHidden);
|
||||
if( !menuHidden.EqualsLiteral("true"))
|
||||
::InsertMenu(menuHandle, 0);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::GetMenuCount(PRUint32 &aCount)
|
||||
{
|
||||
aCount = mNumMenus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::GetMenuAt(const PRUint32 aCount, nsIMenu *& aMenu)
|
||||
{
|
||||
aMenu = NULL;
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mMenusArray.ElementAt(aCount));
|
||||
if (!supports) return NS_OK;
|
||||
|
||||
return CallQueryInterface(supports, &aMenu); // addref
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::InsertMenuAt(const PRUint32 aCount, nsIMenu *& aMenu)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::RemoveMenu(const PRUint32 aCount)
|
||||
{
|
||||
mMenusArray.RemoveElementAt(aCount);
|
||||
::DrawMenuBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::RemoveAll()
|
||||
{
|
||||
NS_ASSERTION(0, "Not implemented!");
|
||||
// mMenusArray.Clear(); // maybe?
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::GetNativeData(void *& aData)
|
||||
{
|
||||
aData = (void *) mMacMBarHandle;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::SetNativeData(void* aData)
|
||||
{
|
||||
Handle menubarHandle = (Handle)aData;
|
||||
|
||||
if(mMacMBarHandle && mMacMBarHandle != menubarHandle)
|
||||
::DisposeHandle(mMacMBarHandle);
|
||||
|
||||
mMacMBarHandle = menubarHandle;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuBar::Paint()
|
||||
{
|
||||
gMacMenubar = do_GetWeakReference((nsIMenuBar *)this);
|
||||
|
||||
::SetMenuBar(mMacMBarHandle);
|
||||
// Now we have blown away the merged Help menu, so we have to rebuild it
|
||||
PRUint32 numItems;
|
||||
mMenusArray.Count(&numItems);
|
||||
|
||||
for (PRInt32 i = numItems - 1; i >= 0; --i)
|
||||
{
|
||||
nsCOMPtr<nsISupports> thisItem = getter_AddRefs(mMenusArray.ElementAt(i));
|
||||
nsCOMPtr<nsIMenu> menu = do_QueryInterface(thisItem);
|
||||
PRBool isHelpMenu = PR_FALSE;
|
||||
if (menu)
|
||||
menu->IsHelpMenu(&isHelpMenu);
|
||||
if (isHelpMenu)
|
||||
{
|
||||
MenuHandle helpMenuHandle = nil;
|
||||
::HMGetHelpMenuHandle(&helpMenuHandle);
|
||||
menu->SetNativeData((void*)helpMenuHandle);
|
||||
|
||||
nsMenuEvent event;
|
||||
event.mCommand = (unsigned int) helpMenuHandle;
|
||||
nsCOMPtr<nsIMenuListener> listener = do_QueryInterface(menu);
|
||||
listener->MenuSelected(event);
|
||||
}
|
||||
}
|
||||
::DrawMenuBar();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
//
|
||||
// nsIDocumentObserver
|
||||
// this is needed for menubar changes
|
||||
//
|
||||
|
||||
NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(nsMenuBar)
|
||||
NS_IMPL_NSIDOCUMENTOBSERVER_REFLOW_STUB(nsMenuBar)
|
||||
NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(nsMenuBar)
|
||||
NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(nsMenuBar)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar::BeginUpdate( nsIDocument * aDocument, nsUpdateType aUpdateType )
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar::EndUpdate( nsIDocument * aDocument, nsUpdateType aUpdateType )
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar::CharacterDataChanged( nsIDocument * aDocument, nsIContent * aContent, PRBool aAppend)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar::ContentAppended( nsIDocument * aDocument, nsIContent * aContainer,
|
||||
PRInt32 aNewIndexInContainer)
|
||||
{
|
||||
if ( aContainer == mMenuBarContent ) {
|
||||
//Register(aContainer, );
|
||||
//InsertMenu ( aNewIndexInContainer );
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIChangeObserver> obs;
|
||||
Lookup ( aContainer, getter_AddRefs(obs) );
|
||||
if ( obs )
|
||||
obs->ContentInserted ( aDocument, aContainer, aNewIndexInContainer );
|
||||
else {
|
||||
nsCOMPtr<nsIContent> parent = aContainer->GetParent();
|
||||
if(parent) {
|
||||
Lookup ( parent, getter_AddRefs(obs) );
|
||||
if ( obs )
|
||||
obs->ContentInserted ( aDocument, aContainer, aNewIndexInContainer );
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar::DocumentWillBeDestroyed( nsIDocument * aDocument )
|
||||
{
|
||||
mDocument = nsnull; // just for yucks
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar::AttributeChanged( nsIDocument * aDocument, nsIContent * aContent, PRInt32 aNameSpaceID,
|
||||
nsIAtom * aAttribute, PRInt32 aModType )
|
||||
{
|
||||
// lookup and dispatch to registered thang.
|
||||
nsCOMPtr<nsIChangeObserver> obs;
|
||||
Lookup ( aContent, getter_AddRefs(obs) );
|
||||
if ( obs )
|
||||
obs->AttributeChanged ( aDocument, aNameSpaceID, aAttribute );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar::ContentRemoved( nsIDocument * aDocument, nsIContent * aContainer,
|
||||
nsIContent * aChild, PRInt32 aIndexInContainer )
|
||||
{
|
||||
if ( aContainer == mMenuBarContent ) {
|
||||
Unregister(aChild);
|
||||
RemoveMenu ( aIndexInContainer );
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIChangeObserver> obs;
|
||||
Lookup ( aContainer, getter_AddRefs(obs) );
|
||||
if ( obs )
|
||||
obs->ContentRemoved ( aDocument, aChild, aIndexInContainer );
|
||||
else {
|
||||
nsCOMPtr<nsIContent> parent = aContainer->GetParent();
|
||||
if(parent) {
|
||||
Lookup ( parent, getter_AddRefs(obs) );
|
||||
if ( obs )
|
||||
obs->ContentRemoved ( aDocument, aChild, aIndexInContainer );
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar::ContentInserted( nsIDocument * aDocument, nsIContent * aContainer,
|
||||
nsIContent * aChild, PRInt32 aIndexInContainer )
|
||||
{
|
||||
if ( aContainer == mMenuBarContent ) {
|
||||
//Register(aChild, );
|
||||
//InsertMenu ( aIndexInContainer );
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIChangeObserver> obs;
|
||||
Lookup ( aContainer, getter_AddRefs(obs) );
|
||||
if ( obs )
|
||||
obs->ContentInserted ( aDocument, aChild, aIndexInContainer );
|
||||
else {
|
||||
nsCOMPtr<nsIContent> parent = aContainer->GetParent();
|
||||
if(parent) {
|
||||
Lookup ( parent, getter_AddRefs(obs) );
|
||||
if ( obs )
|
||||
obs->ContentInserted ( aDocument, aChild, aIndexInContainer );
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
//
|
||||
// nsIChangeManager
|
||||
//
|
||||
// We don't use a |nsSupportsHashtable| because we know that the lifetime of all these items
|
||||
// is bouded by the lifetime of the menubar. No need to add any more strong refs to the
|
||||
// picture because the containment hierarchy already uses strong refs.
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar :: Register ( nsIContent *aContent, nsIChangeObserver *aMenuObject )
|
||||
{
|
||||
nsVoidKey key ( aContent );
|
||||
mObserverTable.Put ( &key, aMenuObject );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar :: Unregister ( nsIContent *aContent )
|
||||
{
|
||||
nsVoidKey key ( aContent );
|
||||
mObserverTable.Remove ( &key );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBar :: Lookup ( nsIContent *aContent, nsIChangeObserver **_retval )
|
||||
{
|
||||
*_retval = nsnull;
|
||||
|
||||
nsVoidKey key ( aContent );
|
||||
*_retval = NS_REINTERPRET_CAST(nsIChangeObserver*, mObserverTable.Get(&key));
|
||||
NS_IF_ADDREF ( *_retval );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
||||
//
|
||||
// SetMenuItemText
|
||||
//
|
||||
// A utility routine for handling unicode->OS text conversions for setting the item
|
||||
// text in a menu.
|
||||
//
|
||||
void
|
||||
MenuHelpers :: SetMenuItemText ( MenuHandle inMacMenuHandle, short inMenuItem, const nsString& inMenuString,
|
||||
const UnicodeToTextRunInfo inConverter )
|
||||
{
|
||||
// ::TruncString() doesn't take the number of characters to truncate to, it takes a pixel with
|
||||
// to fit the string in. Ugh. I talked it over with sfraser and we couldn't come up with an
|
||||
// easy way to compute what this should be given the system font, etc, so we're just going
|
||||
// to hard code it to something reasonable and bigger fonts will just have to deal.
|
||||
const short kMaxItemPixelWidth = 300;
|
||||
|
||||
short themeFontID;
|
||||
SInt16 themeFontSize;
|
||||
Style themeFontStyle;
|
||||
char* scriptRunText = ConvertToScriptRun ( inMenuString, inConverter, &themeFontID,
|
||||
&themeFontSize, &themeFontStyle );
|
||||
if ( scriptRunText ) {
|
||||
// convert it to a pascal string
|
||||
Str255 menuTitle;
|
||||
short scriptRunTextLength = strlen(scriptRunText);
|
||||
if (scriptRunTextLength > 255)
|
||||
scriptRunTextLength = 255;
|
||||
BlockMoveData(scriptRunText, &menuTitle[1], scriptRunTextLength);
|
||||
menuTitle[0] = scriptRunTextLength;
|
||||
|
||||
// if the item text is too long, truncate it.
|
||||
::TruncString ( kMaxItemPixelWidth, menuTitle, truncMiddle );
|
||||
::SetMenuItemText(inMacMenuHandle, inMenuItem, menuTitle);
|
||||
OSErr err = ::SetMenuItemFontID(inMacMenuHandle, inMenuItem, themeFontID);
|
||||
|
||||
nsMemory::Free(scriptRunText);
|
||||
}
|
||||
|
||||
} // SetMenuItemText
|
||||
|
||||
|
||||
//
|
||||
// ConvertToScriptRun
|
||||
//
|
||||
// Converts unicode to a single script run and extract the relevant font information. The
|
||||
// caller is responsible for deleting the memory allocated by this call with |nsMemory::Free()|.
|
||||
// Returns |nsnull| if an error occurred.
|
||||
//
|
||||
char*
|
||||
MenuHelpers :: ConvertToScriptRun ( const nsString & inStr, const UnicodeToTextRunInfo inConverter,
|
||||
short* outFontID, SInt16* outFontSize, Style* outFontStyle )
|
||||
{
|
||||
//
|
||||
// extract the Unicode text from the nsString and convert it into a single script run
|
||||
//
|
||||
const PRUnichar* unicodeText = inStr.get();
|
||||
size_t unicodeTextLengthInBytes = inStr.Length() * sizeof(PRUnichar);
|
||||
size_t scriptRunTextSizeInBytes = unicodeTextLengthInBytes * 2;
|
||||
char* scriptRunText = NS_REINTERPRET_CAST(char*, nsMemory::Alloc(scriptRunTextSizeInBytes + sizeof(char)));
|
||||
if ( !scriptRunText )
|
||||
return nsnull;
|
||||
|
||||
ScriptCodeRun convertedTextScript;
|
||||
size_t unicdeTextReadInBytes, scriptRunTextLengthInBytes, scriptCodeRunListLength;
|
||||
OSErr err = ::ConvertFromUnicodeToScriptCodeRun(inConverter, unicodeTextLengthInBytes,
|
||||
NS_REINTERPRET_CAST(const PRUint16*, unicodeText),
|
||||
0, /* no flags*/
|
||||
0,NULL,NULL,NULL, /* no offset arrays */
|
||||
scriptRunTextSizeInBytes,&unicdeTextReadInBytes,&scriptRunTextLengthInBytes,
|
||||
scriptRunText,
|
||||
1 /* count of script runs*/,&scriptCodeRunListLength,&convertedTextScript);
|
||||
NS_ASSERTION(err==noErr,"nsMenu::NSStringSetMenuItemText: ConvertFromUnicodeToScriptCodeRun failed.");
|
||||
if ( err ) { nsMemory::Free(scriptRunText); return nsnull; }
|
||||
scriptRunText[scriptRunTextLengthInBytes] = '\0'; // null terminate
|
||||
|
||||
//
|
||||
// get a font from the script code
|
||||
//
|
||||
Str255 themeFontName;
|
||||
err = ::GetThemeFont(kThemeSystemFont, convertedTextScript.script, themeFontName, outFontSize, outFontStyle);
|
||||
NS_ASSERTION(err==noErr,"nsMenu::NSStringSetMenuItemText: GetThemeFont failed.");
|
||||
if ( err ) { nsMemory::Free(scriptRunText); return nsnull; }
|
||||
::GetFNum(themeFontName, outFontID);
|
||||
|
||||
return scriptRunText;
|
||||
|
||||
} // ConvertToScriptRun
|
||||
|
||||
|
||||
//
|
||||
// WebShellToPresContext
|
||||
//
|
||||
// Helper to dig out a pres context from a webshell. A common thing to do before
|
||||
// sending an event into the dom.
|
||||
//
|
||||
nsresult
|
||||
MenuHelpers :: WebShellToPresContext (nsIWebShell* inWebShell, nsPresContext** outContext )
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outContext);
|
||||
*outContext = nsnull;
|
||||
if (!inWebShell)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsresult retval = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(inWebShell));
|
||||
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
||||
if ( contentViewer ) {
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer ( do_QueryInterface(contentViewer) );
|
||||
if ( docViewer )
|
||||
docViewer->GetPresContext(*outContext); // AddRefs for us
|
||||
else
|
||||
retval = NS_ERROR_FAILURE;
|
||||
}
|
||||
else
|
||||
retval = NS_ERROR_FAILURE;
|
||||
|
||||
return retval;
|
||||
|
||||
} // WebShellToPresContext
|
||||
|
||||
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsMenuBar_h__
|
||||
#define nsMenuBar_h__
|
||||
|
||||
#include "nsIMenuBar.h"
|
||||
#include "nsIMenuListener.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
#include "nsIChangeManager.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsSupportsArray.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
#include <MacTypes.h>
|
||||
#include <UnicodeConverter.h>
|
||||
|
||||
extern nsWeakPtr gMacMenubar;
|
||||
|
||||
class nsIWidget;
|
||||
class nsIDocument;
|
||||
|
||||
|
||||
namespace MenuHelpers
|
||||
{
|
||||
// utility routine for getting a PresContext out of a webShell
|
||||
nsresult WebShellToPresContext ( nsIWebShell* inWebShell, nsPresContext** outContext ) ;
|
||||
|
||||
// utility routine for handling unicode->OS text conversions for setting the item
|
||||
// text in a menu.
|
||||
void SetMenuItemText ( MenuHandle macMenuHandle, short menuItem, const nsString& text,
|
||||
const UnicodeToTextRunInfo converter ) ;
|
||||
|
||||
// Converts unicode to a single script run and extract the relevant font information. The
|
||||
// caller is responsible for deleting the memory allocated by this call with |nsMemory::Free()|.
|
||||
// Returns |nsnull| if an error occurred.
|
||||
char* ConvertToScriptRun ( const nsString & inStr, const UnicodeToTextRunInfo inConverter,
|
||||
short* outFontID, SInt16* outFontSize, Style* outFontStyle ) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Native Mac MenuBar wrapper
|
||||
*/
|
||||
|
||||
class nsMenuBar : public nsIMenuBar,
|
||||
public nsIMenuListener,
|
||||
public nsIDocumentObserver,
|
||||
public nsIChangeManager,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
|
||||
nsMenuBar();
|
||||
virtual ~nsMenuBar();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICHANGEMANAGER
|
||||
|
||||
// nsIMenuListener interface
|
||||
nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void* aDOMNode, void * aWebShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
||||
// nsIDocumentObserver
|
||||
NS_DECL_NSIDOCUMENTOBSERVER
|
||||
|
||||
NS_IMETHOD Create(nsIWidget * aParent);
|
||||
|
||||
// nsIMenuBar Methods
|
||||
NS_IMETHOD GetParent(nsIWidget *&aParent);
|
||||
NS_IMETHOD SetParent(nsIWidget * aParent);
|
||||
NS_IMETHOD AddMenu(nsIMenu * aMenu);
|
||||
NS_IMETHOD GetMenuCount(PRUint32 &aCount);
|
||||
NS_IMETHOD GetMenuAt(const PRUint32 aCount, nsIMenu *& aMenu);
|
||||
NS_IMETHOD InsertMenuAt(const PRUint32 aCount, nsIMenu *& aMenu);
|
||||
NS_IMETHOD RemoveMenu(const PRUint32 aCount);
|
||||
NS_IMETHOD RemoveAll();
|
||||
NS_IMETHOD GetNativeData(void*& aData);
|
||||
NS_IMETHOD Paint();
|
||||
NS_IMETHOD SetNativeData(void* aData);
|
||||
|
||||
protected:
|
||||
|
||||
void GetDocument ( nsIWebShell* inWebShell, nsIDocument** outDocument ) ;
|
||||
void RegisterAsDocumentObserver ( nsIWebShell* inWebShell ) ;
|
||||
|
||||
nsHashtable mObserverTable; // stores observers for content change notification
|
||||
|
||||
PRUint32 mNumMenus;
|
||||
nsSupportsArray mMenusArray; // holds refs
|
||||
nsCOMPtr<nsIContent> mMenuBarContent; // menubar content node, strong ref
|
||||
nsIWidget * mParent; // weak ref
|
||||
|
||||
PRBool mIsMenuBarAdded;
|
||||
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsIDocument * mDocument; // pointer to doc
|
||||
|
||||
// Mac Specific
|
||||
Handle mMacMBarHandle;
|
||||
Handle mOriginalMacMBarHandle;
|
||||
UnicodeToTextRunInfo mUnicodeTextRunConverter;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsMenuBar_h__
|
||||
|
|
@ -202,14 +202,13 @@ nsMenuBarX::SetRebuild(PRBool aNeedsRebuild)
|
|||
}
|
||||
|
||||
void
|
||||
nsMenuBarX :: GetDocument ( nsIWebShell* inWebShell, nsIDocument** outDocument )
|
||||
nsMenuBarX :: GetDocument ( nsIDocShell* inDocShell, nsIDocument** outDocument )
|
||||
{
|
||||
*outDocument = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell ( do_QueryInterface(inWebShell) );
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
if ( docShell ) {
|
||||
docShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if ( inDocShell ) {
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
inDocShell->GetContentViewer(getter_AddRefs(cv));
|
||||
if (cv) {
|
||||
// get the document
|
||||
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
|
||||
|
@ -227,17 +226,17 @@ nsMenuBarX :: GetDocument ( nsIWebShell* inWebShell, nsIDocument** outDocument )
|
|||
// Name says it all.
|
||||
//
|
||||
void
|
||||
nsMenuBarX :: RegisterAsDocumentObserver ( nsIWebShell* inWebShell )
|
||||
nsMenuBarX :: RegisterAsDocumentObserver ( nsIDocShell* inDocShell )
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
GetDocument(inWebShell, getter_AddRefs(doc));
|
||||
GetDocument(inDocShell, getter_AddRefs(doc));
|
||||
if (!doc)
|
||||
return;
|
||||
|
||||
// register ourselves
|
||||
nsCOMPtr<nsIDocumentObserver> observer ( do_QueryInterface(NS_STATIC_CAST(nsIMenuBar*,this)) );
|
||||
doc->AddObserver(observer);
|
||||
// also get pointer to doc, just in case webshell goes away
|
||||
// also get pointer to doc, just in case docshell goes away
|
||||
// we can still remove ourself as doc observer directly from doc
|
||||
mDocument = doc;
|
||||
} // RegisterAsDocumentObesrver
|
||||
|
@ -415,7 +414,7 @@ nsMenuBarX :: ExecuteCommand ( nsIContent* inDispatchTo )
|
|||
if (!inDispatchTo)
|
||||
return nsEventStatus_eIgnore;
|
||||
|
||||
return MenuHelpersX::DispatchCommandTo(mWebShellWeakRef, inDispatchTo);
|
||||
return MenuHelpersX::DispatchCommandTo(mDocShellWeakRef, inDispatchTo);
|
||||
} // ExecuteCommand
|
||||
|
||||
|
||||
|
@ -445,9 +444,9 @@ nsMenuBarX :: HideItem ( nsIDOMDocument* inDoc, const nsAString & inID, nsIConte
|
|||
|
||||
nsEventStatus
|
||||
nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow,
|
||||
void * menubarNode, void * aWebShell )
|
||||
void * menubarNode, void * aDocShell )
|
||||
{
|
||||
mWebShellWeakRef = do_GetWeakReference(NS_STATIC_CAST(nsIWebShell*, aWebShell));
|
||||
mDocShellWeakRef = do_GetWeakReference(NS_STATIC_CAST(nsIDocShell*, aDocShell));
|
||||
nsIDOMNode* aDOMNode = NS_STATIC_CAST(nsIDOMNode*, menubarNode);
|
||||
mMenuBarContent = do_QueryInterface(aDOMNode); // strong ref
|
||||
NS_ASSERTION ( mMenuBarContent, "No content specified for this menubar" );
|
||||
|
@ -466,8 +465,8 @@ nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWin
|
|||
if ( err )
|
||||
return nsEventStatus_eIgnore;
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (webShell) RegisterAsDocumentObserver(webShell);
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (docShell) RegisterAsDocumentObserver(docShell);
|
||||
|
||||
// set this as a nsMenuListener on aParentWindow
|
||||
aParentWindow->AddMenuListener((nsIMenuListener *)this);
|
||||
|
@ -490,7 +489,7 @@ nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWin
|
|||
if ( pnsMenu ) {
|
||||
pnsMenu->Create(NS_STATIC_CAST(nsIMenuBar*, this), menuName, menuAccessKey,
|
||||
NS_STATIC_CAST(nsIChangeManager *, this),
|
||||
NS_REINTERPRET_CAST(nsIWebShell*, aWebShell), menu);
|
||||
NS_REINTERPRET_CAST(nsIDocShell*, aDocShell), menu);
|
||||
|
||||
// Make nsMenu a child of nsMenuBar. nsMenuBar takes ownership
|
||||
AddMenu(pnsMenu);
|
||||
|
@ -935,25 +934,23 @@ nsMenuBarX :: Unregister ( PRUint32 inCommandID )
|
|||
|
||||
|
||||
//
|
||||
// WebShellToPresContext
|
||||
// DocShellToPresContext
|
||||
//
|
||||
// Helper to dig out a pres context from a webshell. A common thing to do before
|
||||
// Helper to dig out a pres context from a docshell. A common thing to do before
|
||||
// sending an event into the dom.
|
||||
//
|
||||
nsresult
|
||||
MenuHelpersX::WebShellToPresContext (nsIWebShell* inWebShell, nsPresContext** outContext )
|
||||
MenuHelpersX::DocShellToPresContext (nsIDocShell* inDocShell, nsPresContext** outContext )
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outContext);
|
||||
*outContext = nsnull;
|
||||
if (!inWebShell)
|
||||
if (!inDocShell)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsresult retval = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(inWebShell));
|
||||
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
||||
inDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
||||
if ( contentViewer ) {
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer ( do_QueryInterface(contentViewer) );
|
||||
if ( docViewer )
|
||||
|
@ -966,19 +963,19 @@ MenuHelpersX::WebShellToPresContext (nsIWebShell* inWebShell, nsPresContext** ou
|
|||
|
||||
return retval;
|
||||
|
||||
} // WebShellToPresContext
|
||||
} // DocShellToPresContext
|
||||
|
||||
nsEventStatus
|
||||
MenuHelpersX::DispatchCommandTo(nsIWeakReference* aWebShellWeakRef,
|
||||
MenuHelpersX::DispatchCommandTo(nsIWeakReference* aDocShellWeakRef,
|
||||
nsIContent* aTargetContent)
|
||||
{
|
||||
NS_PRECONDITION(aTargetContent, "null ptr");
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(aWebShellWeakRef);
|
||||
if (!webShell)
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(aDocShellWeakRef);
|
||||
if (!docShell)
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext));
|
||||
MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext));
|
||||
|
||||
nsEventStatus status = nsEventStatus_eConsumeNoDefault;
|
||||
nsMouseEvent event(NS_XUL_COMMAND);
|
||||
|
|
|
@ -63,9 +63,9 @@ class nsIDOMNode;
|
|||
|
||||
namespace MenuHelpersX
|
||||
{
|
||||
// utility routine for getting a PresContext out of a webShell
|
||||
nsresult WebShellToPresContext ( nsIWebShell* inWebShell, nsPresContext** outContext ) ;
|
||||
nsEventStatus DispatchCommandTo(nsIWeakReference* aWebShellWeakRef,
|
||||
// utility routine for getting a PresContext out of a docShell
|
||||
nsresult DocShellToPresContext ( nsIDocShell* inDocShell, nsPresContext** outContext ) ;
|
||||
nsEventStatus DispatchCommandTo(nsIWeakReference* aDocShellWeakRef,
|
||||
nsIContent* aTargetContent);
|
||||
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public:
|
|||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void * menuNode, void * aWebShell);
|
||||
void * menuNode, void * aDocShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
@ -122,8 +122,8 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
void GetDocument ( nsIWebShell* inWebShell, nsIDocument** outDocument ) ;
|
||||
void RegisterAsDocumentObserver ( nsIWebShell* inWebShell ) ;
|
||||
void GetDocument ( nsIDocShell* inDocShell, nsIDocument** outDocument ) ;
|
||||
void RegisterAsDocumentObserver ( nsIDocShell* inDocShell ) ;
|
||||
|
||||
// Make our menubar conform to Aqua UI guidelines
|
||||
void AquifyMenuBar ( ) ;
|
||||
|
@ -152,7 +152,7 @@ protected:
|
|||
PRUint32 mCurrentCommandID; // unique command id (per menu-bar) to give to next item that asks
|
||||
|
||||
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
|
||||
nsIDocument* mDocument; // pointer to document
|
||||
|
||||
MenuRef mRootMenu; // root menu, representing entire menu bar.
|
||||
|
|
|
@ -1,435 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsPresContext.h"
|
||||
|
||||
#include "nsMenuBar.h" // for MenuHelpers namespace
|
||||
#include "nsMenuItem.h"
|
||||
#include "nsIMenu.h"
|
||||
#include "nsIMenuBar.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIMenuListener.h"
|
||||
#include "nsDynamicMDEF.h"
|
||||
#include "nsGUIEvent.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsWidgetAtoms.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
|
||||
|
||||
#if DEBUG
|
||||
nsInstanceCounter gMenuItemCounter("nsMenuItem");
|
||||
#endif
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS4(nsMenuItem, nsIMenuItem, nsIMenuListener, nsIChangeObserver, nsISupportsWeakReference)
|
||||
|
||||
//
|
||||
// nsMenuItem constructor
|
||||
//
|
||||
nsMenuItem::nsMenuItem()
|
||||
{
|
||||
mMenuParent = nsnull;
|
||||
mIsSeparator = PR_FALSE;
|
||||
mKeyEquivalent.AssignLiteral(" ");
|
||||
mEnabled = PR_TRUE;
|
||||
mIsChecked = PR_FALSE;
|
||||
mMenuType = eRegular;
|
||||
|
||||
#if DEBUG
|
||||
++gMenuItemCounter;
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// nsMenuItem destructor
|
||||
//
|
||||
nsMenuItem::~nsMenuItem()
|
||||
{
|
||||
mManager->Unregister(mContent);
|
||||
|
||||
#if DEBUG
|
||||
--gMenuItemCounter;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD nsMenuItem::Create ( nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
|
||||
EMenuItemType aItemType, PRBool aEnabled,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode )
|
||||
{
|
||||
mContent = aNode; // addref
|
||||
mMenuParent = aParent; // weak
|
||||
mWebShellWeakRef = do_GetWeakReference(aShell);
|
||||
|
||||
mEnabled = aEnabled;
|
||||
mMenuType = aItemType;
|
||||
|
||||
// register for AttributeChanged messages
|
||||
mManager = aManager;
|
||||
nsCOMPtr<nsIChangeObserver> obs = do_QueryInterface(NS_STATIC_CAST(nsIChangeObserver*,this));
|
||||
mManager->Register(mContent, obs); // does not addref this
|
||||
|
||||
mIsSeparator = aIsSeparator;
|
||||
mLabel = aLabel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsMenuItem::GetLabel(nsString &aText)
|
||||
{
|
||||
aText = mLabel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD
|
||||
nsMenuItem::GetEnabled(PRBool *aIsEnabled)
|
||||
{
|
||||
*aIsEnabled = mEnabled;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD nsMenuItem::SetChecked(PRBool aIsEnabled)
|
||||
{
|
||||
mIsChecked = aIsEnabled;
|
||||
|
||||
// update the content model. This will also handle unchecking our siblings
|
||||
// if we are a radiomenu
|
||||
mContent->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked,
|
||||
mIsChecked ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"), PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetChecked(PRBool *aIsEnabled)
|
||||
{
|
||||
*aIsEnabled = mIsChecked;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetMenuItemType(EMenuItemType *aType)
|
||||
{
|
||||
*aType = mMenuType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetTarget(nsIWidget *& aTarget)
|
||||
{
|
||||
NS_IF_ADDREF(aTarget = mTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetNativeData(void *& aData)
|
||||
{
|
||||
//aData = (void *)mMenu;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::AddMenuListener(nsIMenuListener * aMenuListener)
|
||||
{
|
||||
mXULCommandListener = aMenuListener; // addref
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::RemoveMenuListener(nsIMenuListener * aMenuListener)
|
||||
{
|
||||
if (mXULCommandListener.get() == aMenuListener)
|
||||
mXULCommandListener = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::IsSeparator(PRBool & aIsSep)
|
||||
{
|
||||
aIsSep = mIsSeparator;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// nsIMenuListener interface
|
||||
//-------------------------------------------------------------------------
|
||||
nsEventStatus nsMenuItem::MenuItemSelected(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
switch ( mMenuType ) {
|
||||
case eCheckbox:
|
||||
SetChecked(!mIsChecked);
|
||||
break;
|
||||
|
||||
case eRadio:
|
||||
{
|
||||
// we only want to muck with things if we were selected and we're not
|
||||
// already checked.
|
||||
if ( mIsChecked )
|
||||
break;
|
||||
SetChecked(PR_TRUE);
|
||||
break;
|
||||
}
|
||||
|
||||
case eRegular:
|
||||
break; // do nothing special
|
||||
|
||||
} // which menu type
|
||||
|
||||
DoCommand();
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
nsEventStatus nsMenuItem::MenuSelected(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
//if(mXULCommandListener)
|
||||
// return mXULCommandListener->MenuSelected(aMenuEvent);
|
||||
|
||||
DoCommand();
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// nsIMenuListener interface
|
||||
//-------------------------------------------------------------------------
|
||||
nsEventStatus nsMenuItem::MenuDeselected(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
nsEventStatus nsMenuItem::MenuConstruct(
|
||||
const nsMenuEvent & aMenuEvent,
|
||||
nsIWidget * aParentWindow,
|
||||
void * menuNode,
|
||||
void * aWebShell)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
nsEventStatus nsMenuItem::MenuDestruct(const nsMenuEvent & aMenuEvent)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
nsEventStatus nsMenuItem::CheckRebuild(PRBool & aNeedsRebuild)
|
||||
{
|
||||
aNeedsRebuild = PR_TRUE;
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
nsEventStatus nsMenuItem::SetRebuild(PRBool aNeedsRebuild)
|
||||
{
|
||||
//mNeedsRebuild = aNeedsRebuild;
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
/**
|
||||
* Executes the "cached" JavaScript Command
|
||||
* @return NS_OK if the command was executed properly, otherwise an error code
|
||||
*/
|
||||
NS_METHOD nsMenuItem::DoCommand()
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell)
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
MenuHelpers::WebShellToPresContext(webShell, getter_AddRefs(presContext));
|
||||
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsMouseEvent event;
|
||||
event.eventStructType = NS_MOUSE_EVENT;
|
||||
event.message = NS_XUL_COMMAND;
|
||||
|
||||
// See if we have a command element. If so, we execute on the command instead
|
||||
// of on our content element.
|
||||
nsAutoString command;
|
||||
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, command);
|
||||
if (!command.IsEmpty()) {
|
||||
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mContent->GetDocument()));
|
||||
nsCOMPtr<nsIDOMElement> commandElt;
|
||||
domDoc->GetElementById(command, getter_AddRefs(commandElt));
|
||||
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
|
||||
if (commandContent)
|
||||
commandContent->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
||||
}
|
||||
else
|
||||
mContent->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
||||
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetModifiers(PRUint8 * aModifiers)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
*aModifiers = mModifiers;
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::SetModifiers(PRUint8 aModifiers)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
mModifiers = aModifiers;
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::SetShortcutChar(const nsString &aText)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
mKeyEquivalent = aText;
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetShortcutChar(nsString &aText)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
aText = mKeyEquivalent;
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// UncheckRadioSiblings
|
||||
//
|
||||
// walk the sibling list looking for nodes with the same name and
|
||||
// uncheck them all.
|
||||
//
|
||||
void
|
||||
nsMenuItem :: UncheckRadioSiblings ( nsIContent* inCheckedContent )
|
||||
{
|
||||
nsAutoString myGroupName;
|
||||
inCheckedContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::name, myGroupName);
|
||||
if ( ! myGroupName.Length() ) // no groupname, nothing to do
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIContent> parent;
|
||||
inCheckedContent->GetParent(getter_AddRefs(parent));
|
||||
if ( !parent )
|
||||
return;
|
||||
|
||||
// loop over siblings
|
||||
PRUint32 count = parent->GetChildCount();
|
||||
for ( PRUint32 i = 0; i < count; ++i ) {
|
||||
nsIContent *sibling = parent->GetChildAt(i);
|
||||
if ( sibling ) {
|
||||
if ( sibling != inCheckedContent ) { // skip this node
|
||||
// if the current sibling is in the same group, clear it
|
||||
nsAutoString currGroupName;
|
||||
sibling->GetAttr(kNameSpaceID_None, nsWidgetAtoms::name, currGroupName);
|
||||
if ( currGroupName == myGroupName )
|
||||
sibling->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, NS_LITERAL_STRING("false"), PR_TRUE);
|
||||
}
|
||||
}
|
||||
} // for each sibling
|
||||
|
||||
} // UncheckRadioSiblings
|
||||
|
||||
#pragma mark -
|
||||
|
||||
//
|
||||
// nsIChangeObserver
|
||||
//
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuItem :: AttributeChanged ( nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIAtom *aAttribute )
|
||||
{
|
||||
if (aAttribute == nsWidgetAtoms::checked) {
|
||||
// if we're a radio menu, uncheck our sibling radio items. No need to
|
||||
// do any of this if we're just a normal check menu.
|
||||
if ( mMenuType == eRadio ) {
|
||||
nsAutoString checked;
|
||||
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, checked);
|
||||
if (checked.EqualsLiteral("true") )
|
||||
UncheckRadioSiblings(mContent);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMenuListener> listener = do_QueryInterface(mMenuParent);
|
||||
listener->SetRebuild(PR_TRUE);
|
||||
|
||||
}
|
||||
else if (aAttribute == nsWidgetAtoms::disabled || aAttribute == nsWidgetAtoms::hidden ||
|
||||
aAttribute == nsWidgetAtoms::collapsed || aAttribute == nsWidgetAtoms::label ) {
|
||||
nsCOMPtr<nsIMenuListener> listener = do_QueryInterface(mMenuParent);
|
||||
listener->SetRebuild(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
} // AttributeChanged
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuItem :: ContentRemoved(nsIDocument *aDocument, nsIContent *aChild, PRInt32 aIndexInContainer)
|
||||
{
|
||||
nsCOMPtr<nsIMenuListener> listener = do_QueryInterface(mMenuParent);
|
||||
listener->SetRebuild(PR_TRUE);
|
||||
return NS_OK;
|
||||
|
||||
} // ContentRemoved
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuItem :: ContentInserted(nsIDocument *aDocument, nsIContent *aChild, PRInt32 aIndexInContainer)
|
||||
{
|
||||
nsCOMPtr<nsIMenuListener> listener = do_QueryInterface(mMenuParent);
|
||||
listener->SetRebuild(PR_TRUE);
|
||||
return NS_OK;
|
||||
|
||||
} // ContentInserted
|
|
@ -1,123 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsMenuItem_h__
|
||||
#define nsMenuItem_h__
|
||||
|
||||
|
||||
#include "nsIMenuItem.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIMenuListener.h"
|
||||
#include "nsIChangeManager.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
|
||||
class nsIMenu;
|
||||
class nsIWidget;
|
||||
|
||||
/**
|
||||
* Native Motif MenuItem wrapper
|
||||
*/
|
||||
|
||||
class nsMenuItem : public nsIMenuItem,
|
||||
public nsIMenuListener,
|
||||
public nsIChangeObserver,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
public:
|
||||
nsMenuItem();
|
||||
virtual ~nsMenuItem();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICHANGEOBSERVER
|
||||
|
||||
// nsIMenuItem Methods
|
||||
NS_IMETHOD Create ( nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
|
||||
EMenuItemType aItemType, PRBool aEnabled,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode ) ;
|
||||
NS_IMETHOD GetLabel(nsString &aText);
|
||||
NS_IMETHOD SetShortcutChar(const nsString &aText);
|
||||
NS_IMETHOD GetShortcutChar(nsString &aText);
|
||||
NS_IMETHOD GetEnabled(PRBool *aIsEnabled);
|
||||
NS_IMETHOD SetChecked(PRBool aIsEnabled);
|
||||
NS_IMETHOD GetChecked(PRBool *aIsEnabled);
|
||||
NS_IMETHOD GetMenuItemType(EMenuItemType *aIsCheckbox);
|
||||
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
|
||||
NS_IMETHOD GetNativeData(void*& aData);
|
||||
NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener);
|
||||
NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener);
|
||||
NS_IMETHOD IsSeparator(PRBool & aIsSep);
|
||||
|
||||
NS_IMETHOD DoCommand();
|
||||
NS_IMETHOD SetModifiers(PRUint8 aModifiers);
|
||||
NS_IMETHOD GetModifiers(PRUint8 * aModifiers);
|
||||
|
||||
// nsIMenuListener interface
|
||||
nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void * menuNode, void * aWebShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
||||
protected:
|
||||
|
||||
void UncheckRadioSiblings ( nsIContent* inCheckedElement ) ;
|
||||
|
||||
nsString mLabel;
|
||||
nsString mKeyEquivalent;
|
||||
|
||||
nsIMenu* mMenuParent; // weak, parent owns us
|
||||
nsIChangeManager* mManager; // weak
|
||||
|
||||
nsCOMPtr<nsIWidget> mTarget; // never set?
|
||||
nsCOMPtr<nsIMenuListener> mXULCommandListener;
|
||||
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsCOMPtr<nsIContent> mContent;
|
||||
|
||||
PRUint8 mModifiers;
|
||||
PRPackedBool mIsSeparator;
|
||||
PRPackedBool mEnabled;
|
||||
PRPackedBool mIsChecked;
|
||||
EMenuItemType mMenuType;
|
||||
};
|
||||
|
||||
#endif // nsMenuItem_h__
|
|
@ -95,11 +95,11 @@ nsMenuItemX::~nsMenuItemX()
|
|||
|
||||
NS_METHOD nsMenuItemX::Create ( nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
|
||||
EMenuItemType aItemType, PRBool aEnabled,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode )
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode )
|
||||
{
|
||||
mContent = aNode; // addref
|
||||
mMenuParent = aParent; // weak
|
||||
mWebShellWeakRef = do_GetWeakReference(aShell);
|
||||
mDocShellWeakRef = do_GetWeakReference(aShell);
|
||||
|
||||
mEnabled = aEnabled;
|
||||
mMenuType = aItemType;
|
||||
|
@ -226,7 +226,7 @@ nsEventStatus nsMenuItemX::MenuConstruct(
|
|||
const nsMenuEvent & aMenuEvent,
|
||||
nsIWidget * aParentWindow,
|
||||
void * menuNode,
|
||||
void * aWebShell)
|
||||
void * aDocShell)
|
||||
{
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ NS_METHOD nsMenuItemX::DoCommand()
|
|||
/* the AttributeChanged code will update all the internal state */
|
||||
}
|
||||
|
||||
return MenuHelpersX::DispatchCommandTo(mWebShellWeakRef, mContent);
|
||||
return MenuHelpersX::DispatchCommandTo(mDocShellWeakRef, mContent);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
// nsIMenuItem Methods
|
||||
NS_IMETHOD Create ( nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
|
||||
EMenuItemType aItemType, PRBool aEnabled,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode ) ;
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) ;
|
||||
NS_IMETHOD GetLabel(nsString &aText);
|
||||
NS_IMETHOD SetShortcutChar(const nsString &aText);
|
||||
NS_IMETHOD GetShortcutChar(nsString &aText);
|
||||
|
@ -91,7 +91,7 @@ public:
|
|||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void * menuNode, void * aWebShell);
|
||||
void * menuNode, void * aDocShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
@ -109,7 +109,7 @@ protected:
|
|||
nsCOMPtr<nsIWidget> mTarget; // never set?
|
||||
nsCOMPtr<nsIMenuListener> mXULCommandListener;
|
||||
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
|
||||
nsCOMPtr<nsIContent> mContent;
|
||||
|
||||
PRUint8 mModifiers;
|
||||
|
|
|
@ -154,9 +154,9 @@ nsMenuX::~nsMenuX()
|
|||
//
|
||||
NS_METHOD
|
||||
nsMenuX::Create(nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode )
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode )
|
||||
{
|
||||
mWebShellWeakRef = do_GetWeakReference(aShell);
|
||||
mDocShellWeakRef = do_GetWeakReference(aShell);
|
||||
mMenuContent = aNode;
|
||||
|
||||
// register this menu to be notified when changes are made to our content object
|
||||
|
@ -510,16 +510,16 @@ nsEventStatus nsMenuX::MenuSelected(const nsMenuEvent & aMenuEvent)
|
|||
if (mNeedsRebuild)
|
||||
RemoveAll();
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_ERROR("No web shell");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_ERROR("No doc shell");
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
if (mIsHelpMenu) {
|
||||
HelpMenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, webShell);
|
||||
HelpMenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, docShell);
|
||||
mConstructed = true;
|
||||
} else {
|
||||
MenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, webShell);
|
||||
MenuConstruct(aMenuEvent, nsnull /* mParentWindow */, nsnull, docShell);
|
||||
mConstructed = true;
|
||||
}
|
||||
}
|
||||
|
@ -563,7 +563,7 @@ nsEventStatus nsMenuX::MenuConstruct(
|
|||
const nsMenuEvent & aMenuEvent,
|
||||
nsIWidget * aParentWindow,
|
||||
void * /* menuNode */,
|
||||
void * aWebShell)
|
||||
void * aDocShell)
|
||||
{
|
||||
mConstructed = false;
|
||||
gConstructingMenu = PR_TRUE;
|
||||
|
@ -608,7 +608,7 @@ nsEventStatus nsMenuX::HelpMenuConstruct(
|
|||
const nsMenuEvent & aMenuEvent,
|
||||
nsIWidget * aParentWindow,
|
||||
void * /* menuNode */,
|
||||
void * aWebShell)
|
||||
void * aDocShell)
|
||||
{
|
||||
//printf("nsMenuX::MenuConstruct called for %s = %d \n", NS_LossyConvertUCS2toASCII(mLabel).get(), mMacMenuHandle);
|
||||
|
||||
|
@ -856,13 +856,13 @@ void nsMenuX::LoadMenuItem( nsIMenu* inParentMenu, nsIContent* inMenuItemContent
|
|||
else if ( type.EqualsLiteral("radio") )
|
||||
itemType = nsIMenuItem::eRadio;
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell)
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell)
|
||||
return;
|
||||
|
||||
// Create the item.
|
||||
pnsMenuItem->Create(inParentMenu, menuitemName, PR_FALSE, itemType,
|
||||
enabled, mManager, webShell, inMenuItemContent);
|
||||
enabled, mManager, docShell, inMenuItemContent);
|
||||
|
||||
//
|
||||
// Set key shortcut and modifiers
|
||||
|
@ -940,11 +940,11 @@ nsMenuX::LoadSubMenu( nsIMenu * pParentMenu, nsIContent* inMenuItemContent )
|
|||
nsCOMPtr<nsIMenu> pnsMenu ( do_CreateInstance(kMenuCID) );
|
||||
if (pnsMenu) {
|
||||
// Call Create
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell)
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell)
|
||||
return;
|
||||
nsCOMPtr<nsISupports> supports(do_QueryInterface(pParentMenu));
|
||||
pnsMenu->Create(supports, menuName, EmptyString(), mManager, webShell, inMenuItemContent);
|
||||
pnsMenu->Create(supports, menuName, EmptyString(), mManager, docShell, inMenuItemContent);
|
||||
|
||||
// set if it's enabled or disabled
|
||||
nsAutoString disabled;
|
||||
|
@ -990,13 +990,13 @@ nsMenuX::OnCreate()
|
|||
nsCOMPtr<nsIContent> popupContent;
|
||||
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_ERROR("No web shell");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_ERROR("No doc shell");
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext) );
|
||||
MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext) );
|
||||
if ( presContext ) {
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
|
||||
|
@ -1072,13 +1072,13 @@ nsMenuX::OnCreated()
|
|||
nsCOMPtr<nsIContent> popupContent;
|
||||
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_ERROR("No web shell");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_ERROR("No doc shell");
|
||||
return PR_FALSE;
|
||||
}
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext) );
|
||||
MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext) );
|
||||
if ( presContext ) {
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
|
||||
|
@ -1105,9 +1105,9 @@ nsMenuX::OnDestroy()
|
|||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsMouseEvent event(NS_XUL_POPUP_HIDING);
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_WARNING("No web shell so can't run the OnDestroy");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_WARNING("No doc shell so can't run the OnDestroy");
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -1115,7 +1115,7 @@ nsMenuX::OnDestroy()
|
|||
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext (webShell, getter_AddRefs(presContext) );
|
||||
MenuHelpersX::DocShellToPresContext (docShell, getter_AddRefs(presContext) );
|
||||
if (presContext ) {
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
|
||||
|
@ -1135,9 +1135,9 @@ nsMenuX::OnDestroyed()
|
|||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsMouseEvent event(NS_XUL_POPUP_HIDDEN);
|
||||
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryReferent(mWebShellWeakRef);
|
||||
if (!webShell) {
|
||||
NS_WARNING("No web shell so can't run the OnDestroy");
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
|
||||
if (!docShell) {
|
||||
NS_WARNING("No doc shell so can't run the OnDestroy");
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -1145,7 +1145,7 @@ nsMenuX::OnDestroyed()
|
|||
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||
|
||||
nsCOMPtr<nsPresContext> presContext;
|
||||
MenuHelpersX::WebShellToPresContext (webShell, getter_AddRefs(presContext) );
|
||||
MenuHelpersX::DocShellToPresContext (docShell, getter_AddRefs(presContext) );
|
||||
if (presContext ) {
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* dispatchTo = popupContent ? popupContent : mMenuContent;
|
||||
|
|
|
@ -76,14 +76,14 @@ public:
|
|||
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget * aParentWindow,
|
||||
void * menuNode, void * aWebShell);
|
||||
void * menuNode, void * aDocShell);
|
||||
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||
nsEventStatus CheckRebuild(PRBool & aMenuEvent);
|
||||
nsEventStatus SetRebuild(PRBool aMenuEvent);
|
||||
|
||||
// nsIMenu Methods
|
||||
NS_IMETHOD Create ( nsISupports * aParent, const nsAString &aLabel, const nsAString &aAccessKey,
|
||||
nsIChangeManager* aManager, nsIWebShell* aShell, nsIContent* aNode ) ;
|
||||
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) ;
|
||||
NS_IMETHOD GetParent(nsISupports *&aParent);
|
||||
NS_IMETHOD GetLabel(nsString &aText);
|
||||
NS_IMETHOD SetLabel(const nsAString &aText);
|
||||
|
@ -133,7 +133,7 @@ protected:
|
|||
void LoadSeparator ( nsIContent* menuitemContent );
|
||||
|
||||
nsEventStatus HelpMenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWindow,
|
||||
void* unused, void* aWebShell);
|
||||
void* unused, void* aDocShell);
|
||||
|
||||
MenuHandle NSStringNewMenu(short menuID, nsString& menuTitle);
|
||||
|
||||
|
@ -144,7 +144,7 @@ protected:
|
|||
|
||||
nsISupports* mParent; // weak, my parent owns me
|
||||
nsIChangeManager* mManager; // weak ref, it will outlive us [menubar]
|
||||
nsWeakPtr mWebShellWeakRef; // weak ref to webshell
|
||||
nsWeakPtr mDocShellWeakRef; // weak ref to docshell
|
||||
nsCOMPtr<nsIContent> mMenuContent; // the |menu| tag, strong ref
|
||||
nsCOMPtr<nsIMenuListener> mListener; // strong ref
|
||||
|
||||
|
|
|
@ -2,14 +2,11 @@
|
|||
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
NS_DEF_PTR(nsIScriptGlobalObject);
|
||||
NS_DEF_PTR(nsIWebShell);
|
||||
NS_DEF_PTR(nsIWebShellContainer);
|
||||
NS_DEF_PTR(nsIWebShellWindow);
|
||||
|
||||
/*
|
||||
|
@ -48,23 +45,8 @@ Test06_raw(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebShellWindow
|
|||
nsIDocShell* docShell = 0;
|
||||
if (scriptGlobalObject)
|
||||
scriptGlobalObject->GetDocShell(&docShell);
|
||||
nsIWebShell* webShell = 0;
|
||||
if (docShell)
|
||||
status=docShell->QueryInterface(NS_GET_IID(nsIWebShell), (void**)&webShell);
|
||||
nsIWebShell* rootWebShell = 0;
|
||||
if (webShell)
|
||||
//status = webShell->GetRootWebShellEvenIfChrome(rootWebShell);
|
||||
{}
|
||||
nsIWebShellContainer* webShellContainer = 0;
|
||||
if (rootWebShell)
|
||||
status = rootWebShell->GetContainer(webShellContainer);
|
||||
if (webShellContainer)
|
||||
status = webShellContainer->QueryInterface(NS_GET_IID(nsIWebShellWindow), (void**)aWebShellWindow);
|
||||
else
|
||||
(*aWebShellWindow) = 0;
|
||||
NS_IF_RELEASE(webShellContainer);
|
||||
NS_IF_RELEASE(rootWebShell);
|
||||
NS_IF_RELEASE(webShell);
|
||||
NS_IF_RELEASE(docShell);
|
||||
NS_IF_RELEASE(scriptGlobalObject);
|
||||
// return status;
|
||||
|
@ -83,22 +65,6 @@ Test06_raw_optimized(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebS
|
|||
nsIDocShell* docShell = 0;
|
||||
scriptGlobalObject->GetDocShell(&docShell);
|
||||
if (docShell) {
|
||||
nsIWebShell* webShell = 0;
|
||||
docShell->QueryInterface(NS_GET_IID(nsIWebShell), (void**)webShell);
|
||||
if (webShell) {
|
||||
nsIWebShell* rootWebShell;
|
||||
// status = webShell->GetRootWebShellEvenIfChrome(rootWebShell);
|
||||
if (NS_SUCCEEDED(status)) {
|
||||
nsIWebShellContainer* webShellContainer;
|
||||
status = rootWebShell->GetContainer(webShellContainer);
|
||||
if (NS_SUCCEEDED(status)) {
|
||||
status = webShellContainer->QueryInterface(NS_GET_IID(nsIWebShellWindow), (void**)aWebShellWindow);
|
||||
NS_RELEASE(webShellContainer);
|
||||
}
|
||||
NS_RELEASE(rootWebShell);
|
||||
}
|
||||
NS_RELEASE(webShell);
|
||||
}
|
||||
NS_RELEASE(docShell);
|
||||
}
|
||||
NS_RELEASE(scriptGlobalObject);
|
||||
|
@ -116,17 +82,6 @@ Test06_nsCOMPtr_as_found(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr<nsIWebShellW
|
|||
nsCOMPtr<nsIDocShell> docShell;
|
||||
if (scriptGlobalObject)
|
||||
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
if (docShell)
|
||||
webShell = do_QueryInterface(docShell);
|
||||
nsCOMPtr<nsIWebShell> rootWebShell;
|
||||
if (webShell)
|
||||
//webShell->GetRootWebShellEvenIfChrome(*getter_AddRefs(rootWebShell));
|
||||
{}
|
||||
nsCOMPtr<nsIWebShellContainer> webShellContainer;
|
||||
if (rootWebShell)
|
||||
rootWebShell->GetContainer(*getter_AddRefs(webShellContainer));
|
||||
(*aWebShellWindow) = do_QueryInterface(webShellContainer);
|
||||
}
|
||||
|
||||
void // nsresult
|
||||
|
@ -141,17 +96,7 @@ Test06_nsCOMPtr00(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebShel
|
|||
if (scriptGlobalObject)
|
||||
scriptGlobalObject->GetDocShell(&temp0);
|
||||
nsCOMPtr<nsIDocShell> docShell = dont_AddRef(temp0);
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
if (docShell)
|
||||
webShell=do_QueryInterface(docShell, &status);
|
||||
nsIWebShellContainer* temp2 = 0;
|
||||
if (webShell)
|
||||
status = webShell->GetContainer(temp2);
|
||||
nsCOMPtr<nsIWebShellContainer> webShellContainer = dont_AddRef(temp2);
|
||||
if (webShellContainer)
|
||||
status = webShellContainer->QueryInterface(NS_GET_IID(nsIWebShellWindow), (void**)aWebShellWindow);
|
||||
else
|
||||
(*aWebShellWindow) = 0;
|
||||
(*aWebShellWindow) = 0;
|
||||
// return status;
|
||||
}
|
||||
|
||||
|
@ -166,17 +111,7 @@ Test06_nsCOMPtr_optimized(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr<nsIWebShell
|
|||
nsIDocShell* temp0 = 0;
|
||||
if (scriptGlobalObject)
|
||||
scriptGlobalObject->GetDocShell(&temp0);
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryInterface(temp0, &status);
|
||||
nsIWebShell* temp2 = 0;
|
||||
if (webShell)
|
||||
// status = webShell->GetRootWebShellEvenIfChrome(temp2);
|
||||
{}
|
||||
nsCOMPtr<nsIWebShell> rootWebShell = dont_AddRef(temp2);
|
||||
nsIWebShellContainer* temp3 = 0;
|
||||
if (rootWebShell)
|
||||
status = rootWebShell->GetContainer(temp3);
|
||||
nsCOMPtr<nsIWebShellContainer> webShellContainer = dont_AddRef(temp3);
|
||||
(*aWebShellWindow) = do_QueryInterface(webShellContainer, &status);
|
||||
(*aWebShellWindow) = do_QueryInterface(nsnull, &status);
|
||||
// return status;
|
||||
}
|
||||
|
||||
|
@ -192,14 +127,6 @@ Test06_nsCOMPtr02(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebShel
|
|||
if (scriptGlobalObject) {
|
||||
nsIDocShell* temp0;
|
||||
scriptGlobalObject->GetDocShell(&temp0);
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryInterface(temp0);
|
||||
if (webShell) {
|
||||
nsIWebShellContainer* temp2;
|
||||
status = webShell->GetContainer(temp2);
|
||||
nsCOMPtr<nsIWebShellContainer> webShellContainer = dont_AddRef(temp2);
|
||||
if (webShellContainer)
|
||||
status = webShellContainer->QueryInterface(NS_GET_IID(nsIWebShellWindow), (void**)aWebShellWindow);
|
||||
}
|
||||
}
|
||||
// return status;
|
||||
}
|
||||
|
@ -218,13 +145,6 @@ Test06_nsCOMPtr03(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr<nsIWebShellWindow>*
|
|||
scriptGlobalObject->GetDocShell(&temp0);
|
||||
nsCOMPtr<nsIDocShell> docShell = dont_AddRef(temp0);
|
||||
if (docShell) {
|
||||
nsCOMPtr<nsIWebShell> webShell = do_QueryInterface(docShell, &status);
|
||||
if (webShell) {
|
||||
nsIWebShellContainer* temp2;
|
||||
status = webShell->GetContainer(temp2);
|
||||
nsCOMPtr<nsIWebShellContainer> webShellContainer = dont_AddRef(temp2);
|
||||
(*aWebShellWindow) = do_QueryInterface(webShellContainer, &status);
|
||||
}
|
||||
}
|
||||
}
|
||||
// return status;
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsIWebShellWindow_h__
|
||||
#define nsIWebShellWindow_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
/* Forward declarations.... */
|
||||
class nsIWebShell;
|
||||
class nsIWidget;
|
||||
class nsString;
|
||||
class nsIDOMWindowInternal;
|
||||
|
||||
// Interface ID for nsIWebShellWindow
|
||||
#define NS_IWEBSHELL_WINDOW_IID \
|
||||
{ 0x28dce479, 0xbf73, 0x11d2, { 0x96, 0xc8, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56}}
|
||||
|
||||
class nsIWebShellWindow : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWEBSHELL_WINDOW_IID)
|
||||
|
||||
NS_IMETHOD Show(PRBool aShow) = 0;
|
||||
NS_IMETHOD ShowModal() = 0;
|
||||
NS_IMETHOD Toolbar() = 0;
|
||||
NS_IMETHOD Close() = 0;
|
||||
NS_IMETHOD GetWebShell(nsIWebShell *& aWebShell) = 0;
|
||||
NS_IMETHOD GetContentWebShell(nsIWebShell **aResult) = 0;
|
||||
NS_IMETHOD GetWidget(nsIWidget *& aWidget) = 0;
|
||||
NS_IMETHOD GetDOMWindow(nsIDOMWindowInternal** aDOMWindow) = 0;
|
||||
NS_IMETHOD ConvertWebShellToDOMWindow(nsIWebShell* aShell, nsIDOMWindowInternal** aDOMWindow) = 0;
|
||||
NS_IMETHOD LockUntilChromeLoad() = 0;
|
||||
NS_IMETHOD GetLockedState(PRBool& aResult) = 0;
|
||||
|
||||
/**
|
||||
* Useful only during window initialization, this method knows whether
|
||||
* the window should try to load a default page, or just wait for
|
||||
* further instructions.
|
||||
* @param aYes returns PR_TRUE iff a default page should be loaded.
|
||||
* @return always NS_OK
|
||||
*/
|
||||
NS_IMETHOD ShouldLoadDefaultPage(PRBool *aYes) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsIWebShellWindow_h__ */
|
|
@ -141,7 +141,6 @@
|
|||
|
||||
/* Define Class IDs */
|
||||
static NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID);
|
||||
static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID);
|
||||
|
||||
#include "nsWidgetsCID.h"
|
||||
static NS_DEFINE_CID(kMenuBarCID, NS_MENUBAR_CID);
|
||||
|
@ -153,8 +152,6 @@ static NS_DEFINE_CID(kMenuItemCID, NS_MENUITEM_CID);
|
|||
#define DEBUG_MENUSDEL 1
|
||||
#endif
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
|
||||
#define SIZE_PERSISTENCE_TIMEOUT 500 // msec
|
||||
|
||||
struct ThreadedWindowEvent {
|
||||
|
@ -162,30 +159,8 @@ struct ThreadedWindowEvent {
|
|||
nsWebShellWindow *window;
|
||||
};
|
||||
|
||||
// The web shell info object is used to hold information about content areas that will
|
||||
// subsequently be filled in when we receive a webshell added notification.
|
||||
struct nsWebShellInfo {
|
||||
nsString id; // The identifier of the iframe or frame node in the XUL tree.
|
||||
PRBool primary; // whether it's considered a/the primary content
|
||||
nsIWebShell* child; // The child web shell that will end up being used for the content area.
|
||||
|
||||
nsWebShellInfo(const nsString& anID, PRBool aPrimary, nsIWebShell* aChildShell)
|
||||
{
|
||||
id = anID;
|
||||
primary = aPrimary;
|
||||
child = aChildShell;
|
||||
NS_IF_ADDREF(aChildShell);
|
||||
}
|
||||
|
||||
~nsWebShellInfo()
|
||||
{
|
||||
NS_IF_RELEASE(child);
|
||||
}
|
||||
};
|
||||
|
||||
nsWebShellWindow::nsWebShellWindow() : nsXULWindow()
|
||||
{
|
||||
mWebShell = nsnull;
|
||||
mWindow = nsnull;
|
||||
mLockedUntilChromeLoad = PR_FALSE;
|
||||
mIntrinsicallySized = PR_FALSE;
|
||||
|
@ -197,12 +172,6 @@ nsWebShellWindow::nsWebShellWindow() : nsXULWindow()
|
|||
|
||||
nsWebShellWindow::~nsWebShellWindow()
|
||||
{
|
||||
if (nsnull != mWebShell) {
|
||||
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mWebShell));
|
||||
shellAsWin->Destroy();
|
||||
NS_RELEASE(mWebShell);
|
||||
}
|
||||
|
||||
if (mWindow)
|
||||
mWindow->SetClientData(0);
|
||||
mWindow = nsnull; // Force release here.
|
||||
|
@ -216,19 +185,14 @@ nsWebShellWindow::~nsWebShellWindow()
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsWebShellWindow)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsWebShellWindow)
|
||||
NS_IMPL_ADDREF_INHERITED(nsWebShellWindow, nsXULWindow)
|
||||
NS_IMPL_RELEASE_INHERITED(nsWebShellWindow, nsXULWindow)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsWebShellWindow)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebShellContainer)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebShellWindow)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebShellContainer)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIXULWindow)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
NS_INTERFACE_MAP_END
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsXULWindow)
|
||||
|
||||
nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
|
||||
nsIAppShell* aShell, nsIURI* aUrl,
|
||||
|
@ -284,17 +248,14 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
|
|||
mWindow->SetBackgroundColor(NS_RGB(192,192,192));
|
||||
|
||||
// Create web shell
|
||||
mDocShell = do_CreateInstance(kWebShellCID);
|
||||
mDocShell = do_CreateInstance("@mozilla.org/webshell;1");
|
||||
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
||||
CallQueryInterface(mDocShell, &mWebShell);
|
||||
NS_ENSURE_TRUE(mWebShell, NS_ERROR_FAILURE);
|
||||
|
||||
r.x = r.y = 0;
|
||||
nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(mDocShell));
|
||||
NS_ENSURE_SUCCESS(docShellAsWin->InitWindow(nsnull, mWindow,
|
||||
r.x, r.y, r.width, r.height), NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(docShellAsWin->Create(), NS_ERROR_FAILURE);
|
||||
mWebShell->SetContainer(this);
|
||||
|
||||
// Attach a WebProgress listener.during initialization...
|
||||
nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(mDocShell, &rv));
|
||||
|
@ -380,7 +341,7 @@ nsEventStatus PR_CALLBACK
|
|||
nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
||||
{
|
||||
nsEventStatus result = nsEventStatus_eIgnore;
|
||||
nsIWebShell* webShell = nsnull;
|
||||
nsIDocShell* docShell = nsnull;
|
||||
nsWebShellWindow *eventWindow = nsnull;
|
||||
|
||||
// Get the WebShell instance...
|
||||
|
@ -390,14 +351,14 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
|||
aEvent->widget->GetClientData(data);
|
||||
if (data != nsnull) {
|
||||
eventWindow = NS_REINTERPRET_CAST(nsWebShellWindow *, data);
|
||||
webShell = eventWindow->mWebShell;
|
||||
docShell = eventWindow->mDocShell;
|
||||
}
|
||||
}
|
||||
|
||||
if (nsnull != webShell) {
|
||||
if (docShell) {
|
||||
switch(aEvent->message) {
|
||||
/*
|
||||
* For size events, the WebShell must be resized to fill the entire
|
||||
* For size events, the DocShell must be resized to fill the entire
|
||||
* client area of the window...
|
||||
*/
|
||||
case NS_MOVE: {
|
||||
|
@ -409,7 +370,7 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
|||
case NS_SIZE: {
|
||||
PRBool chromeLock = PR_FALSE;
|
||||
nsSizeEvent* sizeEvent = (nsSizeEvent*)aEvent;
|
||||
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(webShell));
|
||||
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(docShell));
|
||||
shellAsWin->SetPositionAndSize(0, 0, sizeEvent->windowSize->width,
|
||||
sizeEvent->windowSize->height, PR_FALSE);
|
||||
// persist size, but not immediately, in case this OS is firing
|
||||
|
@ -453,7 +414,7 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
|||
// the deactivation. Bug #82534
|
||||
if(modeEvent->mSizeMode == nsSizeMode_Minimized) {
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
eventWindow->ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow));
|
||||
eventWindow->ConvertDocShellToDOMWindow(docShell, getter_AddRefs(domWindow));
|
||||
if (domWindow) {
|
||||
nsCOMPtr<nsPIDOMWindow> privateDOMWindow = do_QueryInterface(domWindow);
|
||||
if(privateDOMWindow) {
|
||||
|
@ -508,14 +469,14 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
|||
printf("nsWebShellWindow::NS_ACTIVATE\n");
|
||||
#endif
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
eventWindow->ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow));
|
||||
eventWindow->ConvertDocShellToDOMWindow(docShell, getter_AddRefs(domWindow));
|
||||
/*
|
||||
nsCOMPtr<nsIWebShell> contentShell;
|
||||
eventWindow->GetContentWebShell(getter_AddRefs(contentShell));
|
||||
nsCOMPtr<nsIDocShell> contentShell;
|
||||
eventWindow->GetContentDocShell(getter_AddRefs(contentShell));
|
||||
if (contentShell) {
|
||||
|
||||
if (NS_SUCCEEDED(eventWindow->
|
||||
ConvertWebShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) {
|
||||
ConvertDocShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) {
|
||||
if(domWindow){
|
||||
nsCOMPtr<nsPIDOMWindow> privateDOMWindow = do_QueryInterface(domWindow);
|
||||
if(privateDOMWindow)
|
||||
|
@ -539,14 +500,14 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
|||
#endif
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
eventWindow->ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow));
|
||||
eventWindow->ConvertDocShellToDOMWindow(docShell, getter_AddRefs(domWindow));
|
||||
/*
|
||||
nsCOMPtr<nsIWebShell> contentShell;
|
||||
eventWindow->GetContentWebShell(getter_AddRefs(contentShell));
|
||||
nsCOMPtr<nsIDocShell> contentShell;
|
||||
eventWindow->GetContentDocShell(getter_AddRefs(contentShell));
|
||||
if (contentShell) {
|
||||
|
||||
if (NS_SUCCEEDED(eventWindow->
|
||||
ConvertWebShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) {
|
||||
ConvertDocShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) {
|
||||
if(domWindow){
|
||||
nsCOMPtr<nsPIDOMWindow> privateDOMWindow = do_QueryInterface(domWindow);
|
||||
if(privateDOMWindow)
|
||||
|
@ -574,7 +535,7 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
|
|||
#endif
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
eventWindow->ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow));
|
||||
eventWindow->ConvertDocShellToDOMWindow(docShell, getter_AddRefs(domWindow));
|
||||
nsCOMPtr<nsPIDOMWindow> piWin(do_QueryInterface(domWindow));
|
||||
if (!domWindow) {
|
||||
break;
|
||||
|
@ -944,7 +905,7 @@ void nsWebShellWindow::DynamicLoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aP
|
|||
|
||||
//fake event
|
||||
nsMenuEvent fake;
|
||||
menuListener->MenuConstruct(fake, aParentWindow, menubarNode, mWebShell);
|
||||
menuListener->MenuConstruct(fake, aParentWindow, menubarNode, mDocShell);
|
||||
|
||||
// Parent should own menubar now
|
||||
NS_RELEASE(pnsMenuBar);
|
||||
|
@ -1069,7 +1030,7 @@ void nsWebShellWindow::LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWi
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsWebShellWindow::ConvertWebShellToDOMWindow(nsIWebShell* aShell, nsIDOMWindowInternal** aDOMWindow)
|
||||
nsWebShellWindow::ConvertDocShellToDOMWindow(nsIDocShell* aShell, nsIDOMWindowInternal** aDOMWindow)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObjectOwner> globalObjectOwner(do_QueryInterface(aShell));
|
||||
NS_ENSURE_TRUE(globalObjectOwner, NS_ERROR_FAILURE);
|
||||
|
@ -1102,10 +1063,9 @@ nsWebShellWindow::ShowModal()
|
|||
|
||||
/* return the main, outermost webshell in this window */
|
||||
NS_IMETHODIMP
|
||||
nsWebShellWindow::GetWebShell(nsIWebShell *& aWebShell)
|
||||
nsWebShellWindow::GetDocShell(nsIDocShell *& aDocShell)
|
||||
{
|
||||
aWebShell = mWebShell;
|
||||
NS_ADDREF(mWebShell);
|
||||
NS_ADDREF(aDocShell = mDocShell);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1120,7 +1080,7 @@ nsWebShellWindow::GetWebShell(nsIWebShell *& aWebShell)
|
|||
nondeterministic, and it seems dangerous to set a precedent like that.
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsWebShellWindow::GetContentWebShell(nsIWebShell **aResult)
|
||||
nsWebShellWindow::GetContentDocShell(nsIDocShell **aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
nsCOMPtr<nsIDocShellTreeItem> content;
|
||||
|
@ -1144,7 +1104,7 @@ nsWebShellWindow::GetWidget(nsIWidget *& aWidget)
|
|||
NS_IMETHODIMP
|
||||
nsWebShellWindow::GetDOMWindow(nsIDOMWindowInternal** aDOMWindow)
|
||||
{
|
||||
return ConvertWebShellToDOMWindow(mWebShell, aDOMWindow);
|
||||
return ConvertDocShellToDOMWindow(mDocShell, aDOMWindow);
|
||||
}
|
||||
|
||||
void *
|
||||
|
@ -1357,18 +1317,18 @@ nsCOMPtr<nsIDOMNode> nsWebShellWindow::FindNamedDOMNode(const nsAString &aName,
|
|||
} // nsWebShellWindow::FindNamedDOMNode
|
||||
|
||||
//----------------------------------------
|
||||
nsCOMPtr<nsIDOMDocument> nsWebShellWindow::GetNamedDOMDoc(const nsAString & aWebShellName)
|
||||
nsCOMPtr<nsIDOMDocument> nsWebShellWindow::GetNamedDOMDoc(const nsAString & aDocShellName)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> domDoc; // result == nsnull;
|
||||
|
||||
// first get the toolbar child docShell
|
||||
nsCOMPtr<nsIDocShell> childDocShell;
|
||||
if (aWebShellName.EqualsLiteral("this")) { // XXX small kludge for code reused
|
||||
if (aDocShellName.EqualsLiteral("this")) { // XXX small kludge for code reused
|
||||
childDocShell = mDocShell;
|
||||
} else {
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem;
|
||||
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode(do_QueryInterface(mDocShell));
|
||||
docShellAsNode->FindChildWithName(PromiseFlatString(aWebShellName).get(),
|
||||
docShellAsNode->FindChildWithName(PromiseFlatString(aDocShellName).get(),
|
||||
PR_TRUE, PR_FALSE, nsnull, getter_AddRefs(docShellAsItem));
|
||||
childDocShell = do_QueryInterface(docShellAsItem);
|
||||
if (!childDocShell)
|
||||
|
@ -1446,7 +1406,7 @@ void nsWebShellWindow::LoadContentAreas() {
|
|||
searchSpec.Mid(contentURL, eqPos+1, endPos-eqPos-1);
|
||||
endPos++;
|
||||
|
||||
// see if we have a webshell with a matching contentAreaID
|
||||
// see if we have a docshell with a matching contentAreaID
|
||||
nsCOMPtr<nsIDocShellTreeItem> content;
|
||||
rv = GetContentShellById(contentAreaID.get(), getter_AddRefs(content));
|
||||
if (NS_SUCCEEDED(rv) && content) {
|
||||
|
@ -1482,7 +1442,7 @@ PRBool nsWebShellWindow::ExecuteCloseHandler()
|
|||
than it otherwise would.) */
|
||||
nsCOMPtr<nsIWebShellWindow> kungFuDeathGrip(this);
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(mWebShell));
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(mDocShell));
|
||||
|
||||
if (globalObject) {
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
@ -74,7 +73,6 @@ class nsVoidArray;
|
|||
|
||||
class nsWebShellWindow : public nsXULWindow,
|
||||
public nsIWebShellWindow,
|
||||
public nsIWebShellContainer,
|
||||
public nsIWebProgressListener,
|
||||
public nsIDocumentObserver
|
||||
|
||||
|
@ -83,7 +81,7 @@ public:
|
|||
nsWebShellWindow();
|
||||
|
||||
// nsISupports interface...
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_IMETHOD LockUntilChromeLoad() { mLockedUntilChromeLoad = PR_TRUE; return NS_OK; }
|
||||
NS_IMETHOD GetLockedState(PRBool& aResult) { aResult = mLockedUntilChromeLoad; return NS_OK; }
|
||||
|
@ -96,11 +94,11 @@ public:
|
|||
NS_IMETHOD ShowModal();
|
||||
NS_IMETHOD Toolbar();
|
||||
NS_IMETHOD Close();
|
||||
NS_IMETHOD GetWebShell(nsIWebShell *& aWebShell);
|
||||
NS_IMETHOD GetContentWebShell(nsIWebShell **aResult);
|
||||
NS_IMETHOD GetDocShell(nsIDocShell *& aWebShell);
|
||||
NS_IMETHOD GetContentDocShell(nsIDocShell **aResult);
|
||||
NS_IMETHOD GetWidget(nsIWidget *& aWidget);
|
||||
NS_IMETHOD GetDOMWindow(nsIDOMWindowInternal** aDOMWindow);
|
||||
NS_IMETHOD ConvertWebShellToDOMWindow(nsIWebShell* aShell, nsIDOMWindowInternal** aDOMWindow);
|
||||
NS_IMETHOD ConvertDocShellToDOMWindow(nsIDocShell* aShell, nsIDOMWindowInternal** aDOMWindow);
|
||||
// nsWebShellWindow methods...
|
||||
nsresult Initialize(nsIXULWindow * aParent, nsIAppShell* aShell, nsIURI* aUrl,
|
||||
PRBool aCreatedVisible, PRBool aLoadDefaultPage,
|
||||
|
@ -130,7 +128,7 @@ protected:
|
|||
NS_IMETHOD LoadMenuItem(nsIMenu * pParentMenu, nsIDOMElement * menuitemElement, nsIDOMNode * menuitemNode);
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIDOMNode> GetDOMNodeFromWebShell(nsIWebShell *aShell);
|
||||
nsCOMPtr<nsIDOMNode> GetDOMNodeFromDocShell(nsIDocShell *aShell);
|
||||
void ExecuteStartupCode();
|
||||
void LoadContentAreas();
|
||||
PRBool ExecuteCloseHandler();
|
||||
|
@ -139,7 +137,6 @@ protected:
|
|||
|
||||
static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent);
|
||||
|
||||
nsIWebShell* mWebShell;
|
||||
PRBool mLockedUntilChromeLoad;
|
||||
PRBool mLoadDefaultPage;
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
#include "nsIDOMDocument.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsAppShellWindowEnumerator.h"
|
||||
#include "nsWindowMediator.h"
|
||||
#include "nsIWindowMediatorListener.h"
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIContentViewerEdit.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
|
|
|
@ -54,7 +54,6 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче