diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index ca2aecb060c..58fbc1d0bdb 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -91,8 +91,8 @@ class nsIDocumentObserver; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ -{ 0x3b3cb52f, 0xf604, 0x48d5, \ - { 0xb5, 0x70, 0xf3, 0x25, 0xbb, 0x0a, 0x7a, 0x22 } } +{ 0x726ce58e, 0x13ab, 0x4c91, \ + { 0x80, 0x45, 0xa8, 0x7b, 0xfe, 0xd5, 0xfe, 0xcd } } // Flag for AddStyleSheet(). @@ -899,6 +899,13 @@ public: virtual void CopyUserData(const nsINode *aObject, nsIDocument *aDestination) = 0; + /** + * Resets and removes a box object from the document's box object cache + * + * @param aElement canonical nsIContent pointer of the box object's element + */ + virtual void ClearBoxObjectFor(nsIContent *aContent) = 0; + protected: ~nsIDocument() { diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 506587b0dd1..375a6cfcfb9 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -106,8 +106,6 @@ #include "nsPIDOMWindow.h" #include "nsIDOMElement.h" -#include "nsIBoxObject.h" -#include "nsPIBoxObject.h" #include "nsXULAtoms.h" // for radio group stuff @@ -3228,21 +3226,18 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) NS_ENSURE_TRUE(content->GetCurrentDoc() == this, NS_ERROR_DOM_WRONG_DOCUMENT_ERR); - nsresult rv; - *aResult = nsnull; if (!mBoxObjectTable) { - mBoxObjectTable = new nsSupportsHashtable; + mBoxObjectTable = new nsInterfaceHashtable; + if (mBoxObjectTable) { + mBoxObjectTable->Init(12); + } } else { - nsISupportsKey key(aElement); - nsCOMPtr supports = dont_AddRef(mBoxObjectTable->Get(&key)); - - nsCOMPtr boxObject(do_QueryInterface(supports)); - if (boxObject) { - *aResult = boxObject; + // Want to use Get(content, aResult); but it's the wrong type + *aResult = mBoxObjectTable->GetWeak(content); + if (*aResult) { NS_ADDREF(*aResult); - return NS_OK; } } @@ -3276,14 +3271,15 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) } contractID += ";1"; - nsCOMPtr boxObject(do_CreateInstance(contractID.get())); + nsCOMPtr boxObject(do_CreateInstance(contractID.get())); if (!boxObject) return NS_ERROR_FAILURE; - nsCOMPtr privateBox(do_QueryInterface(boxObject)); - privateBox->Init(content); + boxObject->Init(content); - SetBoxObjectFor(aElement, boxObject); + if (mBoxObjectTable) { + mBoxObjectTable->Put(content, boxObject.get()); + } *aResult = boxObject; NS_ADDREF(*aResult); @@ -3291,29 +3287,16 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) return NS_OK; } -NS_IMETHODIMP -nsDocument::SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject) +void +nsDocument::ClearBoxObjectFor(nsIContent* aContent) { - if (!mBoxObjectTable) { - if (!aBoxObject) - return NS_OK; - mBoxObjectTable = new nsSupportsHashtable(12); - } - - nsISupportsKey key(aElement); - - if (aBoxObject) { - mBoxObjectTable->Put(&key, aBoxObject); - } else { - nsCOMPtr supp; - mBoxObjectTable->Remove(&key, getter_AddRefs(supp)); - nsCOMPtr boxObject(do_QueryInterface(supp)); + if (mBoxObjectTable) { + nsPIBoxObject *boxObject = mBoxObjectTable->GetWeak(aContent); if (boxObject) { boxObject->Clear(); + mBoxObjectTable->Remove(aContent); } } - - return NS_OK; } struct DirTable { diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 7a946f97d6c..82d894dffb0 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -77,6 +77,9 @@ #include "nsIDOM3DocumentEvent.h" #include "nsCOMArray.h" #include "nsHashtable.h" +#include "nsInterfaceHashtable.h" +#include "nsIBoxObject.h" +#include "nsPIBoxObject.h" #include "nsIScriptObjectPrincipal.h" #include "nsIURI.h" #include "nsScriptLoader.h" @@ -673,6 +676,7 @@ public: nsIDOMNode *aDest); NS_HIDDEN_(void) CopyUserData(const nsINode *aObject, nsIDocument *aDestination); + NS_HIDDEN_(void) ClearBoxObjectFor(nsIContent* aContent); protected: @@ -784,7 +788,7 @@ protected: PRUint8 mDefaultElementType; - nsSupportsHashtable* mBoxObjectTable; + nsInterfaceHashtable *mBoxObjectTable; // The channel that got passed to StartDocumentLoad(), if any nsCOMPtr mChannel; diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 1f46be2a2dc..93e46d72e29 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -1850,12 +1850,7 @@ nsGenericElement::UnbindFromTree(PRBool aDeep, PRBool aNullParent) document->ForgetLink(this); } - nsCOMPtr domElement = do_QueryInterface(this); - - if (domElement) { - nsCOMPtr nsDoc = do_QueryInterface(document); - nsDoc->SetBoxObjectFor(domElement, nsnull); - } + document->ClearBoxObjectFor(this); } // Unset things in the reverse order from how we set them in BindToTree diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 77d0b3de0ee..a2d57a727a2 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -937,8 +937,7 @@ nsXULElement::UnbindFromTree(PRBool aDeep, PRBool aNullParent) // anonymous content that the document is changing. document->BindingManager()->ChangeDocumentFor(this, document, nsnull); - nsCOMPtr nsDoc(do_QueryInterface(document)); - nsDoc->SetBoxObjectFor(this, nsnull); + document->ClearBoxObjectFor(this); } // mControllers can own objects that are implemented diff --git a/dom/public/idl/core/nsIDOMNSDocument.idl b/dom/public/idl/core/nsIDOMNSDocument.idl index 28d6222b31d..b26c5acdef0 100644 --- a/dom/public/idl/core/nsIDOMNSDocument.idl +++ b/dom/public/idl/core/nsIDOMNSDocument.idl @@ -43,7 +43,7 @@ interface nsIBoxObject; interface nsIDOMLocation; -[scriptable, uuid(a6cf90cd-15b3-11d2-932e-00805f8add32)] +[scriptable, uuid(170763c7-c94e-4db9-98be-e69ac3a02a41)] interface nsIDOMNSDocument : nsISupports { readonly attribute DOMString characterSet; @@ -58,6 +58,4 @@ interface nsIDOMNSDocument : nsISupports readonly attribute DOMString referrer; nsIBoxObject getBoxObjectFor(in nsIDOMElement elt); - void setBoxObjectFor(in nsIDOMElement elt, - in nsIBoxObject boxObject); };