diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index b140c2ebd62..725b8d5eaf1 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -80,6 +80,12 @@ public: }; #endif +// The base value for the content ID counter. +// This counter is used by the document to +// assign a monotonically increasing ID to each content +// object it creates +#define NS_CONTENT_ID_COUNTER_BASE 10000 + //---------------------------------------------------------------------- // Document interface @@ -311,9 +317,9 @@ public: PRUint32 aFlags, nsEventStatus* aEventStatus) = 0; - NS_IMETHOD FlushPendingNotifications() = 0; + NS_IMETHOD GetAndIncrementContentID(PRInt32* aID) = 0; }; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 7f821ca6f67..b569bc7a22f 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -591,6 +591,7 @@ nsDocument::nsDocument() mModCount = 0; mFileSpec = nsnull; mPrincipal = nsnull; + mNextContentID = NS_CONTENT_ID_COUNTER_BASE; Init();/* XXX */ } @@ -3056,6 +3057,14 @@ nsDocument::FlushPendingNotifications() return NS_OK; } +NS_IMETHODIMP +nsDocument::GetAndIncrementContentID(PRInt32* aID) +{ + *aID = mNextContentID++; + return NS_OK; +} + + NS_IMETHODIMP nsDocument::GetModCount(PRInt32 *outModCount) { diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 2ea591ee5a7..12fb1bc31ff 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -318,6 +318,7 @@ public: virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); NS_IMETHOD FlushPendingNotifications(); + NS_IMETHOD GetAndIncrementContentID(PRInt32* aID); public: @@ -489,7 +490,10 @@ protected: nsVoidArray *mEpilog; nsDocumentChildNodes* mChildNodes; nsIWordBreaker* mWordBreaker; - + // A content ID counter used to give a monotonically increasing ID to the content + // objects in the document's content model + PRInt32 mNextContentID; + // disk file members nsFileSpec* mFileSpec; PRInt32 mModCount; diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index ee638e3d5a4..d89916bd47e 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -299,6 +299,13 @@ nsGenericHTMLElement::CopyInnerTo(nsIContent* aSrcContent, result = mAttributes->Clone(&(aDst->mAttributes)); } + PRInt32 id; + if (mDocument) { + mDocument->GetAndIncrementContentID(&id); + } + if (aDst && aDst->mContent) { + aDst->mContent->SetContentID(id); + } return result; } diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index bbfb7475c67..8855ee4793a 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -334,7 +334,6 @@ public: nsString mPreferredStyle; PRInt32 mStyleSheetCount; nsICSSLoader* mCSSLoader; - PRUint32 mContentIDCounter; PRInt32 mInsideNoXXXTag; PRInt32 mInMonolithicContainer; @@ -970,6 +969,10 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, } rv = MakeContentObject(aNodeType, atom, aForm, aWebShell, aResult, &content); + + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + (*aResult)->SetContentID(id); NS_RELEASE(atom); } @@ -1261,7 +1264,6 @@ SinkContext::OpenContainer(const nsIParserNode& aNode) if (NS_OK != rv) { return rv; } - content->SetContentID(mSink->mContentIDCounter++); nsresult srv; nsCOMPtr select = do_QueryInterface(content, &srv); @@ -1617,8 +1619,7 @@ SinkContext::AddLeaf(const nsIParserNode& aNode) &content); if (NS_OK != rv) { return rv; - } - content->SetContentID(mSink->mContentIDCounter++); + } // Set the content's document content->SetDocument(mSink->mDocument, PR_FALSE); @@ -2070,8 +2071,7 @@ HTMLContentSink::HTMLContentSink() { gSinkLogModuleInfo = PR_NewLogModule("htmlcontentsink"); } #endif - mNotAtRef = PR_TRUE; - mContentIDCounter = NS_CONTENT_ID_COUNTER_BASE; + mNotAtRef = PR_TRUE; mInScript = 0; mInNotification = 0; mInMonolithicContainer = 0; @@ -3202,8 +3202,7 @@ HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode) rv = CreateContentObject(aNode, nodeType, nsnull, nsnull, &area); if (NS_FAILED(rv)) { return rv; - } - area->SetContentID(mContentIDCounter++); + } // Set the content's document and attributes area->SetDocument(mDocument, PR_FALSE); @@ -3279,7 +3278,9 @@ HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode) nsCOMPtr element; result = NS_CreateHTMLElement(getter_AddRefs(element), tag); if (NS_SUCCEEDED(result)) { - element->SetContentID(mContentIDCounter++); + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + element->SetContentID(id); // Add in the attributes and add the style content object to the // head container. @@ -3619,7 +3620,9 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) nsIHTMLContent* element = nsnull; result = NS_CreateHTMLElement(&element, tag); if (NS_SUCCEEDED(result)) { - element->SetContentID(mContentIDCounter++); + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + element->SetContentID(id); // Add in the attributes and add the style content object to the // head container. @@ -4245,7 +4248,9 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) nsIHTMLContent* element = nsnull; rv = NS_CreateHTMLElement(&element, tag); if (NS_SUCCEEDED(rv)) { - element->SetContentID(mContentIDCounter++); + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + element->SetContentID(id); // Add in the attributes and add the style content object to the // head container. @@ -4373,7 +4378,9 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) nsIHTMLContent* element = nsnull; rv = NS_CreateHTMLElement(&element, tag); if (NS_SUCCEEDED(rv)) { - element->SetContentID(mContentIDCounter++); + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + element->SetContentID(id); // Add in the attributes and add the style content object to the // head container. diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 020f430d628..97f55f0ae7e 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1213,6 +1213,7 @@ nsHTMLDocument::CreateElement(const nsString& aTagName, nsCOMPtr content; nsresult rv = NS_CreateHTMLElement(getter_AddRefs(content), aTagName); if (NS_SUCCEEDED(rv)) { + content->SetContentID(mNextContentID++); rv = content->QueryInterface(kIDOMElementIID, (void**)aReturn); } return rv; diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index 3c0f5e04c79..73e32252ec3 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -736,6 +736,9 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode) } if (NS_OK == result) { + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + content->SetContentID(id); content->SetDocument(mDocument, PR_FALSE); // Set the attributes on the new content element diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 108ff15c6ea..2ffde668ce9 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -690,6 +690,7 @@ nsXMLDocument::CreateElementWithNameSpace(const nsString& aTagName, if (NS_OK != rv) { return rv; } + content->SetContentID(mNextContentID++); rv = content->QueryInterface(kIDOMElementIID, (void**)aReturn); return rv; diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 4f9d87f4ee3..eeb4728ca65 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -1755,6 +1755,13 @@ nsXULDocument::FlushPendingNotifications() return NS_OK; } +NS_IMETHODIMP +nsXULDocument::GetAndIncrementContentID(PRInt32* aID) +{ + *aID = mNextContentID++; + return NS_OK; +} + void nsXULDocument::BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) { diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 4472d1e0e36..d7f898b525d 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -248,6 +248,8 @@ public: NS_IMETHOD FlushPendingNotifications(); + NS_IMETHOD GetAndIncrementContentID(PRInt32* aID); + virtual void BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); virtual void ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); diff --git a/layout/base/public/nsIDocument.h b/layout/base/public/nsIDocument.h index b140c2ebd62..725b8d5eaf1 100644 --- a/layout/base/public/nsIDocument.h +++ b/layout/base/public/nsIDocument.h @@ -80,6 +80,12 @@ public: }; #endif +// The base value for the content ID counter. +// This counter is used by the document to +// assign a monotonically increasing ID to each content +// object it creates +#define NS_CONTENT_ID_COUNTER_BASE 10000 + //---------------------------------------------------------------------- // Document interface @@ -311,9 +317,9 @@ public: PRUint32 aFlags, nsEventStatus* aEventStatus) = 0; - NS_IMETHOD FlushPendingNotifications() = 0; + NS_IMETHOD GetAndIncrementContentID(PRInt32* aID) = 0; }; diff --git a/layout/base/src/nsDocument.cpp b/layout/base/src/nsDocument.cpp index 7f821ca6f67..b569bc7a22f 100644 --- a/layout/base/src/nsDocument.cpp +++ b/layout/base/src/nsDocument.cpp @@ -591,6 +591,7 @@ nsDocument::nsDocument() mModCount = 0; mFileSpec = nsnull; mPrincipal = nsnull; + mNextContentID = NS_CONTENT_ID_COUNTER_BASE; Init();/* XXX */ } @@ -3056,6 +3057,14 @@ nsDocument::FlushPendingNotifications() return NS_OK; } +NS_IMETHODIMP +nsDocument::GetAndIncrementContentID(PRInt32* aID) +{ + *aID = mNextContentID++; + return NS_OK; +} + + NS_IMETHODIMP nsDocument::GetModCount(PRInt32 *outModCount) { diff --git a/layout/base/src/nsDocument.h b/layout/base/src/nsDocument.h index 2ea591ee5a7..12fb1bc31ff 100644 --- a/layout/base/src/nsDocument.h +++ b/layout/base/src/nsDocument.h @@ -318,6 +318,7 @@ public: virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); NS_IMETHOD FlushPendingNotifications(); + NS_IMETHOD GetAndIncrementContentID(PRInt32* aID); public: @@ -489,7 +490,10 @@ protected: nsVoidArray *mEpilog; nsDocumentChildNodes* mChildNodes; nsIWordBreaker* mWordBreaker; - + // A content ID counter used to give a monotonically increasing ID to the content + // objects in the document's content model + PRInt32 mNextContentID; + // disk file members nsFileSpec* mFileSpec; PRInt32 mModCount; diff --git a/layout/html/content/src/nsGenericHTMLElement.cpp b/layout/html/content/src/nsGenericHTMLElement.cpp index ee638e3d5a4..d89916bd47e 100644 --- a/layout/html/content/src/nsGenericHTMLElement.cpp +++ b/layout/html/content/src/nsGenericHTMLElement.cpp @@ -299,6 +299,13 @@ nsGenericHTMLElement::CopyInnerTo(nsIContent* aSrcContent, result = mAttributes->Clone(&(aDst->mAttributes)); } + PRInt32 id; + if (mDocument) { + mDocument->GetAndIncrementContentID(&id); + } + if (aDst && aDst->mContent) { + aDst->mContent->SetContentID(id); + } return result; } diff --git a/layout/html/document/src/nsHTMLContentSink.cpp b/layout/html/document/src/nsHTMLContentSink.cpp index bbfb7475c67..8855ee4793a 100644 --- a/layout/html/document/src/nsHTMLContentSink.cpp +++ b/layout/html/document/src/nsHTMLContentSink.cpp @@ -334,7 +334,6 @@ public: nsString mPreferredStyle; PRInt32 mStyleSheetCount; nsICSSLoader* mCSSLoader; - PRUint32 mContentIDCounter; PRInt32 mInsideNoXXXTag; PRInt32 mInMonolithicContainer; @@ -970,6 +969,10 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, } rv = MakeContentObject(aNodeType, atom, aForm, aWebShell, aResult, &content); + + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + (*aResult)->SetContentID(id); NS_RELEASE(atom); } @@ -1261,7 +1264,6 @@ SinkContext::OpenContainer(const nsIParserNode& aNode) if (NS_OK != rv) { return rv; } - content->SetContentID(mSink->mContentIDCounter++); nsresult srv; nsCOMPtr select = do_QueryInterface(content, &srv); @@ -1617,8 +1619,7 @@ SinkContext::AddLeaf(const nsIParserNode& aNode) &content); if (NS_OK != rv) { return rv; - } - content->SetContentID(mSink->mContentIDCounter++); + } // Set the content's document content->SetDocument(mSink->mDocument, PR_FALSE); @@ -2070,8 +2071,7 @@ HTMLContentSink::HTMLContentSink() { gSinkLogModuleInfo = PR_NewLogModule("htmlcontentsink"); } #endif - mNotAtRef = PR_TRUE; - mContentIDCounter = NS_CONTENT_ID_COUNTER_BASE; + mNotAtRef = PR_TRUE; mInScript = 0; mInNotification = 0; mInMonolithicContainer = 0; @@ -3202,8 +3202,7 @@ HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode) rv = CreateContentObject(aNode, nodeType, nsnull, nsnull, &area); if (NS_FAILED(rv)) { return rv; - } - area->SetContentID(mContentIDCounter++); + } // Set the content's document and attributes area->SetDocument(mDocument, PR_FALSE); @@ -3279,7 +3278,9 @@ HTMLContentSink::ProcessBASETag(const nsIParserNode& aNode) nsCOMPtr element; result = NS_CreateHTMLElement(getter_AddRefs(element), tag); if (NS_SUCCEEDED(result)) { - element->SetContentID(mContentIDCounter++); + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + element->SetContentID(id); // Add in the attributes and add the style content object to the // head container. @@ -3619,7 +3620,9 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) nsIHTMLContent* element = nsnull; result = NS_CreateHTMLElement(&element, tag); if (NS_SUCCEEDED(result)) { - element->SetContentID(mContentIDCounter++); + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + element->SetContentID(id); // Add in the attributes and add the style content object to the // head container. @@ -4245,7 +4248,9 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) nsIHTMLContent* element = nsnull; rv = NS_CreateHTMLElement(&element, tag); if (NS_SUCCEEDED(rv)) { - element->SetContentID(mContentIDCounter++); + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + element->SetContentID(id); // Add in the attributes and add the style content object to the // head container. @@ -4373,7 +4378,9 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) nsIHTMLContent* element = nsnull; rv = NS_CreateHTMLElement(&element, tag); if (NS_SUCCEEDED(rv)) { - element->SetContentID(mContentIDCounter++); + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + element->SetContentID(id); // Add in the attributes and add the style content object to the // head container. diff --git a/layout/html/document/src/nsHTMLDocument.cpp b/layout/html/document/src/nsHTMLDocument.cpp index 020f430d628..97f55f0ae7e 100644 --- a/layout/html/document/src/nsHTMLDocument.cpp +++ b/layout/html/document/src/nsHTMLDocument.cpp @@ -1213,6 +1213,7 @@ nsHTMLDocument::CreateElement(const nsString& aTagName, nsCOMPtr content; nsresult rv = NS_CreateHTMLElement(getter_AddRefs(content), aTagName); if (NS_SUCCEEDED(rv)) { + content->SetContentID(mNextContentID++); rv = content->QueryInterface(kIDOMElementIID, (void**)aReturn); } return rv; diff --git a/layout/xml/document/src/nsXMLContentSink.cpp b/layout/xml/document/src/nsXMLContentSink.cpp index 3c0f5e04c79..73e32252ec3 100644 --- a/layout/xml/document/src/nsXMLContentSink.cpp +++ b/layout/xml/document/src/nsXMLContentSink.cpp @@ -736,6 +736,9 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode) } if (NS_OK == result) { + PRInt32 id; + mDocument->GetAndIncrementContentID(&id); + content->SetContentID(id); content->SetDocument(mDocument, PR_FALSE); // Set the attributes on the new content element diff --git a/layout/xml/document/src/nsXMLDocument.cpp b/layout/xml/document/src/nsXMLDocument.cpp index 108ff15c6ea..2ffde668ce9 100644 --- a/layout/xml/document/src/nsXMLDocument.cpp +++ b/layout/xml/document/src/nsXMLDocument.cpp @@ -690,6 +690,7 @@ nsXMLDocument::CreateElementWithNameSpace(const nsString& aTagName, if (NS_OK != rv) { return rv; } + content->SetContentID(mNextContentID++); rv = content->QueryInterface(kIDOMElementIID, (void**)aReturn); return rv; diff --git a/rdf/content/src/nsXULDocument.cpp b/rdf/content/src/nsXULDocument.cpp index 4f9d87f4ee3..eeb4728ca65 100644 --- a/rdf/content/src/nsXULDocument.cpp +++ b/rdf/content/src/nsXULDocument.cpp @@ -1755,6 +1755,13 @@ nsXULDocument::FlushPendingNotifications() return NS_OK; } +NS_IMETHODIMP +nsXULDocument::GetAndIncrementContentID(PRInt32* aID) +{ + *aID = mNextContentID++; + return NS_OK; +} + void nsXULDocument::BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) { diff --git a/rdf/content/src/nsXULDocument.h b/rdf/content/src/nsXULDocument.h index 4472d1e0e36..d7f898b525d 100644 --- a/rdf/content/src/nsXULDocument.h +++ b/rdf/content/src/nsXULDocument.h @@ -248,6 +248,8 @@ public: NS_IMETHOD FlushPendingNotifications(); + NS_IMETHOD GetAndIncrementContentID(PRInt32* aID); + virtual void BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); virtual void ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);