diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index cc67568e460..8c1d2453610 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -58,6 +58,7 @@ #include "nsIObserver.h" #include "nsGkAtoms.h" #include "nsAutoPtr.h" +#include "nsPIDOMWindow.h" #ifdef MOZ_SMIL #include "nsSMILAnimationController.h" #endif // MOZ_SMIL @@ -72,7 +73,6 @@ class nsIStyleRule; class nsICSSStyleSheet; class nsIViewManager; class nsIScriptGlobalObject; -class nsPIDOMWindow; class nsIDOMEvent; class nsIDOMEventTarget; class nsIDeviceContext; @@ -115,8 +115,8 @@ class Link; } // namespace mozilla #define NS_IDOCUMENT_IID \ -{ 0x4a0c9bfa, 0xef60, 0x4bb2, \ - { 0x87, 0x5e, 0xac, 0xdb, 0xe8, 0xfe, 0xa1, 0xb5 } } +{ 0x56d981ce, 0x7f03, 0x4d90, \ + { 0xb2, 0x40, 0x72, 0x08, 0xb6, 0x28, 0x73, 0x06 } } // Flag for AddStyleSheet(). #define NS_STYLESHEET_FROM_CATALOG (1 << 0) @@ -633,7 +633,10 @@ public: /** * Return the window containing the document (the outer window). */ - virtual nsPIDOMWindow *GetWindow() = 0; + nsPIDOMWindow *GetWindow() + { + return mWindow ? mWindow->GetOuterWindow() : GetWindowInternal(); + } /** * Return the inner window used as the script compilation scope for @@ -1348,6 +1351,9 @@ protected: nsPropertyTable* GetExtraPropertyTable(PRUint16 aCategory); + // Never ever call this. Only call GetWindow! + virtual nsPIDOMWindow *GetWindowInternal() = 0; + // Never ever call this. Only call GetInnerWindow! virtual nsPIDOMWindow *GetInnerWindowInternal() = 0; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 5b4e0284522..300bb03bf10 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -3817,11 +3817,9 @@ nsDocument::SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject) } nsPIDOMWindow * -nsDocument::GetWindow() +nsDocument::GetWindowInternal() { - if (mWindow) { - return mWindow->GetOuterWindow(); - } + NS_ASSERTION(!mWindow, "This should not be called when mWindow is not null!"); nsCOMPtr win(do_QueryInterface(GetScriptGlobalObject())); diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index c66ff898e87..2c61e03cd17 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -649,11 +649,6 @@ public: virtual nsIScriptGlobalObject* GetScopeObject(); - /** - * Return the window containing the document (the outer window). - */ - virtual nsPIDOMWindow *GetWindow(); - /** * Get the script loader for this document */ @@ -1011,6 +1006,7 @@ protected: const nsAString& aType, PRBool aPersisted); + virtual nsPIDOMWindow *GetWindowInternal(); virtual nsPIDOMWindow *GetInnerWindowInternal(); // nsContentList match functions for GetElementsByClassName diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 923c3ba6fb9..55c25f07e35 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -4282,7 +4282,7 @@ nsEventStateManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent { // inform the focus manager that the content is being removed. If this // content is focused, the focus will be removed without firing events. - nsIFocusManager* fm = nsFocusManager::GetFocusManager(); + nsFocusManager* fm = nsFocusManager::GetFocusManager(); if (fm) fm->ContentRemoved(aDocument, aContent); diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 7e216b7e3db..989c215e014 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -742,7 +742,7 @@ nsFocusManager::WindowLowered(nsIDOMWindow* aWindow) return NS_OK; } -NS_IMETHODIMP +nsresult nsFocusManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent) { NS_ENSURE_ARG(aDocument); @@ -754,7 +754,7 @@ nsFocusManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent) // if the content is currently focused in the window, or is an ancestor // of the currently focused element, reset the focus within that window. - nsCOMPtr content = window->GetFocusedNode(); + nsIContent* content = window->GetFocusedNode(); if (content && nsContentUtils::ContentIsDescendantOf(content, aContent)) { window->SetFocusedNode(nsnull); diff --git a/dom/base/nsFocusManager.h b/dom/base/nsFocusManager.h index 83291afbac2..fa43d4234be 100644 --- a/dom/base/nsFocusManager.h +++ b/dom/base/nsFocusManager.h @@ -83,6 +83,11 @@ public: */ nsIContent* GetFocusedContent() { return mFocusedContent; } + /** + * Called when content has been removed. + */ + nsresult ContentRemoved(nsIDocument* aDocument, nsIContent* aContent); + /** * Returns the content node that would be focused if aWindow was in an * active window. This will traverse down the frame hierarchy, starting at diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index ccef6439f4f..c93a0e0da94 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -610,7 +610,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsTimeout, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsTimeout, Release) - +nsPIDOMWindow::nsPIDOMWindow(nsPIDOMWindow *aOuterWindow) +: mFrameElement(nsnull), mDocShell(nsnull), mModalStateDepth(0), + mRunningTimeout(nsnull), mMutationBits(0), mIsDocumentLoaded(PR_FALSE), + mIsHandlingResizeEvent(PR_FALSE), mIsInnerWindow(aOuterWindow != nsnull), + mMayHavePaintEventListener(PR_FALSE), + mIsModalContentWindow(PR_FALSE), mIsActive(PR_FALSE), + mInnerWindow(nsnull), mOuterWindow(aOuterWindow) {} + +nsPIDOMWindow::~nsPIDOMWindow() {} + //***************************************************************************** //*** nsGlobalWindow: Object Management //***************************************************************************** @@ -6912,14 +6921,6 @@ nsGlobalWindow::SetChromeEventHandler(nsPIDOMEventTarget* aChromeEventHandler) } } -nsIContent* -nsGlobalWindow::GetFocusedNode() -{ - FORWARD_TO_INNER(GetFocusedNode, (), NS_OK); - - return mFocusedNode; -} - void nsGlobalWindow::SetFocusedNode(nsIContent* aNode, PRUint32 aFocusMethod, diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 2fe53116a5e..046dfe2543d 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -660,7 +660,6 @@ protected: nsIntSize DevToCSSIntPixels(nsIntSize px); nsIntSize CSSToDevIntPixels(nsIntSize px); - virtual nsIContent* GetFocusedNode(); virtual void SetFocusedNode(nsIContent* aNode, PRUint32 aFocusMethod = 0, PRBool aNeedsFocus = PR_FALSE); @@ -803,10 +802,6 @@ protected: PRUint32 mTimeoutsSuspendDepth; - // the element within the document that is currently focused when this - // window is active - nsCOMPtr mFocusedNode; - // the method that was used to focus mFocusedNode PRUint32 mFocusMethod; diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 3413724e2a4..1da70c4ad7b 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -78,8 +78,8 @@ class nsIArray; class nsPIWindowRoot; #define NS_PIDOMWINDOW_IID \ -{ 0xC5CB154D, 0x17C0, 0x49E9, \ - { 0x9C, 0x83, 0xFF, 0xC7, 0x2C, 0x93, 0xAF, 0x24 } } +{ 0x7cbe5277, 0x5de8, 0x45e4, \ + { 0x9c, 0x2d, 0x81, 0x37, 0xa9, 0x5b, 0x42, 0xc6 } } class nsPIDOMWindow : public nsIDOMWindowInternal { @@ -432,7 +432,13 @@ public: * DO NOT CALL EITHER OF THESE METHODS DIRECTLY. USE THE FOCUS MANAGER * INSTEAD. */ - virtual nsIContent* GetFocusedNode() = 0; + nsIContent* GetFocusedNode() + { + if (IsOuterWindow()) { + return mInnerWindow ? mInnerWindow->mFocusedNode.get() : nsnull; + } + return mFocusedNode; + } virtual void SetFocusedNode(nsIContent* aNode, PRUint32 aFocusMethod = 0, PRBool aNeedsFocus = PR_FALSE) = 0; @@ -512,15 +518,9 @@ protected: // be null if and only if the created window itself is an outer // window. In all other cases aOuterWindow should be the outer // window for the inner window that is being created. - nsPIDOMWindow(nsPIDOMWindow *aOuterWindow) - : mFrameElement(nsnull), mDocShell(nsnull), mModalStateDepth(0), - mRunningTimeout(nsnull), mMutationBits(0), mIsDocumentLoaded(PR_FALSE), - mIsHandlingResizeEvent(PR_FALSE), mIsInnerWindow(aOuterWindow != nsnull), - mMayHavePaintEventListener(PR_FALSE), - mIsModalContentWindow(PR_FALSE), mIsActive(PR_FALSE), - mInnerWindow(nsnull), mOuterWindow(aOuterWindow) - { - } + nsPIDOMWindow(nsPIDOMWindow *aOuterWindow); + + ~nsPIDOMWindow(); void SetChromeEventHandlerInternal(nsPIDOMEventTarget* aChromeEventHandler) { mChromeEventHandler = aChromeEventHandler; @@ -558,6 +558,10 @@ protected: // And these are the references between inner and outer windows. nsPIDOMWindow *mInnerWindow; nsPIDOMWindow *mOuterWindow; + + // the element within the document that is currently focused when this + // window is active + nsCOMPtr mFocusedNode; }; diff --git a/dom/interfaces/base/nsIFocusManager.idl b/dom/interfaces/base/nsIFocusManager.idl index 912339f00d3..5d2fbf73659 100644 --- a/dom/interfaces/base/nsIFocusManager.idl +++ b/dom/interfaces/base/nsIFocusManager.idl @@ -39,7 +39,7 @@ interface nsIDocument; interface nsIContent; -[scriptable, uuid(39BB7C9F-10FC-4345-B381-5E6B3FF3A277)] +[scriptable, uuid(5cb91200-53f6-4d35-989d-1d28ad80a0d4)] /** * The focus manager deals with all focus related behaviour. Only one element * in the entire application may have the focus at a time; this element @@ -243,12 +243,6 @@ interface nsIFocusManager : nsISupports */ [noscript] void windowLowered(in nsIDOMWindow aWindow); - /** - * Called when content has been removed. - */ - [noscript] void contentRemoved(in nsIDocument aDocument, - in nsIContent aElement); - /** * Called when a new document in a window is shown. *