From ee3a61b53fe348e4997f1337794417a2c2ed1732 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 23 Nov 2004 17:21:37 +0000 Subject: [PATCH] deCOMify nsIStyledContent::GetID (make it return we a weak pointer to the ID atom). Bug 244249, patch by jpl24 , r=sicking, sr=bzbarsky --- content/base/public/nsIStyleRuleProcessor.h | 205 ------------------ content/base/public/nsIStyledContent.h | 2 +- content/base/src/nsGenericElement.cpp | 46 +++- content/base/src/nsGenericElement.h | 2 +- content/events/src/nsXMLEventsManager.cpp | 6 +- .../html/content/src/nsGenericHTMLElement.cpp | 18 -- .../html/content/src/nsGenericHTMLElement.h | 1 - content/html/style/src/nsCSSStyleSheet.cpp | 3 +- content/svg/content/src/nsSVGElement.cpp | 20 +- content/svg/content/src/nsSVGElement.h | 3 - content/xml/content/src/nsXMLElement.cpp | 19 -- content/xml/content/src/nsXMLElement.h | 3 - content/xml/document/src/nsXMLContentSink.cpp | 20 +- content/xml/document/src/nsXMLDocument.cpp | 5 +- content/xul/content/src/nsXULElement.cpp | 11 +- content/xul/content/src/nsXULElement.h | 2 +- layout/style/nsCSSStyleSheet.cpp | 3 +- layout/style/nsIStyleRuleProcessor.h | 2 +- 18 files changed, 67 insertions(+), 304 deletions(-) diff --git a/content/base/public/nsIStyleRuleProcessor.h b/content/base/public/nsIStyleRuleProcessor.h index 4e229c7437d..e69de29bb2d 100644 --- a/content/base/public/nsIStyleRuleProcessor.h +++ b/content/base/public/nsIStyleRuleProcessor.h @@ -1,205 +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 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 nsIStyleRuleProcessor_h___ -#define nsIStyleRuleProcessor_h___ - -#include - -#include "nsISupports.h" -#include "nsPresContext.h" // for nsCompatability -#include "nsILinkHandler.h" -#include "nsString.h" -#include "nsChangeHint.h" - -class nsIStyleSheet; -class nsPresContext; -class nsIContent; -class nsIStyledContent; -class nsISupportsArray; -class nsIAtom; -class nsICSSPseudoComparator; -class nsRuleWalker; - -// The implementation of the constructor and destructor are currently in -// nsCSSStyleSheet.cpp. - -struct RuleProcessorData { - RuleProcessorData(nsPresContext* aPresContext, - nsIContent* aContent, - nsRuleWalker* aRuleWalker, - nsCompatibility* aCompat = nsnull); - - // NOTE: not |virtual| - ~RuleProcessorData(); - - void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW { - return aContext->AllocateFromShell(sz); - } - void Destroy(nsPresContext* aContext) { - this->~RuleProcessorData(); - aContext->FreeToShell(sizeof(RuleProcessorData), this); - }; - - const nsString* GetLang(); - - nsPresContext* mPresContext; - nsIContent* mContent; // weak ref - nsIContent* mParentContent; // if content, content->GetParent(); weak ref - nsRuleWalker* mRuleWalker; // Used to add rules to our results. - nsIContent* mScopedRoot; // Root of scoped stylesheet (set and unset by the supplier of the scoped stylesheet - - nsIAtom* mContentTag; // if content, then content->GetTag() - nsIAtom* mContentID; // if styled content, then styledcontent->GetID() - nsIStyledContent* mStyledContent; // if content, content->QI(nsIStyledContent) - PRPackedBool mIsHTMLContent; // if content, then does QI on HTMLContent, true or false - PRPackedBool mIsHTMLLink; // if content, calls nsStyleUtil::IsHTMLLink - PRPackedBool mIsSimpleXLink; // if content, calls nsStyleUtil::IsSimpleXLink - nsCompatibility mCompatMode; // Possibly remove use of this in SelectorMatches? - PRPackedBool mHasAttributes; // if content, content->GetAttrCount() > 0 - PRPackedBool mIsChecked; // checked/selected attribute for option and select elements - nsLinkState mLinkState; // if a link, this is the state, otherwise unknown - PRInt32 mEventState; // if content, eventStateMgr->GetContentState() - PRInt32 mNameSpaceID; // if content, content->GetNameSapce() - RuleProcessorData* mPreviousSiblingData; - RuleProcessorData* mParentData; - -protected: - nsAutoString *mLanguage; // NULL means we haven't found out the language yet -}; - -struct ElementRuleProcessorData : public RuleProcessorData { - ElementRuleProcessorData(nsPresContext* aPresContext, - nsIContent* aContent, - nsRuleWalker* aRuleWalker) - : RuleProcessorData(aPresContext,aContent,aRuleWalker) - { - NS_PRECONDITION(aContent, "null pointer"); - NS_PRECONDITION(aRuleWalker, "null pointer"); - } -}; - -struct PseudoRuleProcessorData : public RuleProcessorData { - PseudoRuleProcessorData(nsPresContext* aPresContext, - nsIContent* aParentContent, - nsIAtom* aPseudoTag, - nsICSSPseudoComparator* aComparator, - nsRuleWalker* aRuleWalker) - : RuleProcessorData(aPresContext, aParentContent, aRuleWalker) - { - NS_PRECONDITION(aPseudoTag, "null pointer"); - NS_PRECONDITION(aRuleWalker, "null pointer"); - mPseudoTag = aPseudoTag; - mComparator = aComparator; - } - - nsIAtom* mPseudoTag; - nsICSSPseudoComparator* mComparator; -}; - -struct StateRuleProcessorData : public RuleProcessorData { - StateRuleProcessorData(nsPresContext* aPresContext, - nsIContent* aContent, - PRInt32 aStateMask) - : RuleProcessorData(aPresContext, aContent, nsnull), - mStateMask(aStateMask) - { - NS_PRECONDITION(aContent, "null pointer"); - } - const PRInt32 mStateMask; // |HasStateDependentStyle| for which state(s)? - // Constants defined in nsIEventStateManager.h . -}; - -struct AttributeRuleProcessorData : public RuleProcessorData { - AttributeRuleProcessorData(nsPresContext* aPresContext, - nsIContent* aContent, - nsIAtom* aAttribute, - PRInt32 aModType) - : RuleProcessorData(aPresContext, aContent, nsnull), - mAttribute(aAttribute), - mModType(aModType) - { - NS_PRECONDITION(aContent, "null pointer"); - } - nsIAtom* mAttribute; // |HasAttributeDependentStyle| for which attribute? - PRInt32 mModType; // The type of modification (see nsIDOMMutationEvent). -}; - - -// IID for the nsIStyleRuleProcessor interface {015575fe-7b6c-11d3-ba05-001083023c2b} -#define NS_ISTYLE_RULE_PROCESSOR_IID \ -{0x015575fe, 0x7b6c, 0x11d3, {0xba, 0x05, 0x00, 0x10, 0x83, 0x02, 0x3c, 0x2b}} - -/* The style rule processor interface is a mechanism to separate the matching - * of style rules from style sheet instances. - * Simple style sheets can and will act as their own processor. - * Sheets where rule ordering interlaces between multiple sheets, will need to - * share a single rule processor between them (CSS sheets do this for cascading order) - */ -class nsIStyleRuleProcessor : public nsISupports { -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_PROCESSOR_IID) - - // Shorthand for: - // nsCOMArray::nsCOMArrayEnumFunc - typedef PRBool (* PR_CALLBACK EnumFunc)(nsIStyleRuleProcessor*, void*); - - // populate rule node tree with nsIStyleRule* - // rules are ordered, those with higher precedence are farthest from the root of the tree - NS_IMETHOD RulesMatching(ElementRuleProcessorData* aData) = 0; - - NS_IMETHOD RulesMatching(PseudoRuleProcessorData* aData) = 0; - - /** - * Test whether style is dependent on content state. This test is - * used for optimization only, and may err on the side of reporting - * more dependencies than really exist. - * - * Event states are defined in nsIEventStateManager.h. - */ - NS_IMETHOD HasStateDependentStyle(StateRuleProcessorData* aData, - nsReStyleHint* aResult) = 0; - - /** - * Test whether style is dependent the presence or value of an - * attribute. This test is used for optimization only, and may err on - * the side of reporting more dependencies than really exist. - */ - NS_IMETHOD HasAttributeDependentStyle(AttributeRuleProcessorData* aData, - nsReStyleHint* aResult) = 0; -}; - -#endif /* nsIStyleRuleProcessor_h___ */ diff --git a/content/base/public/nsIStyledContent.h b/content/base/public/nsIStyledContent.h index 543beb16360..5fbd4a274b4 100644 --- a/content/base/public/nsIStyledContent.h +++ b/content/base/public/nsIStyledContent.h @@ -60,7 +60,7 @@ public: // corresponds to the attribute nsHTMLAtoms::id and that the Class // corresponds to the attribute nsHTMLAtoms::kClass. If this becomes // incorrect, then new methods need to be added here. - NS_IMETHOD GetID(nsIAtom** aResult) const = 0; + virtual nsIAtom* GetID() const = 0; virtual const nsAttrValue* GetClasses() const = 0; NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const = 0; diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 357900afb0c..032f8b7af89 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -2114,12 +2114,32 @@ nsGenericElement::MaybeTriggerAutoLink(nsIDocShell *aShell) return NS_OK; } -NS_IMETHODIMP -nsGenericElement::GetID(nsIAtom** aResult) const +nsIAtom* +nsGenericElement::GetID() const { - *aResult = nsnull; + nsIAtom* IDName = GetIDAttributeName(); + if (IDName) { + const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(IDName); + if (attrVal){ + if (attrVal->Type() == nsAttrValue::eAtom) { + return attrVal->GetAtomValue(); + } + if(attrVal->IsEmptyString()){ + return nsnull; + } + // Check if the ID has been stored as a string. + // This would occur if the ID attribute name changed after + // the ID was parsed. + if (attrVal->Type() == nsAttrValue::eString) { + nsAutoString idVal(attrVal->GetStringValue()); - return NS_OK; + // Create an atom from the value and set it into the attribute list. + NS_CONST_CAST(nsAttrValue*, attrVal)->ParseAtom(idVal); + return attrVal->GetAtomValue(); + } + } + } + return nsnull; } const nsAttrValue* @@ -3370,8 +3390,18 @@ nsGenericElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, nsresult rv; if (aNamespaceID == kNameSpaceID_None) { - rv = mAttrsAndChildren.SetAttr(aName, aValue); - NS_ENSURE_SUCCESS(rv, rv); + if (aName == GetIDAttributeName() && !aValue.IsEmpty()) { + // Store id as atom. id="" means that the element has no id, not that it has + // an emptystring as the id. + nsAttrValue attrValue; + attrValue.ParseAtom(aValue); + rv = mAttrsAndChildren.SetAndTakeAttr(aName, attrValue); + NS_ENSURE_SUCCESS(rv, rv); + } + else { + rv = mAttrsAndChildren.SetAttr(aName, aValue); + NS_ENSURE_SUCCESS(rv, rv); + } } else { nsCOMPtr ni; @@ -3564,7 +3594,7 @@ nsGenericElement::List(FILE* out, PRInt32 aIndent) const { NS_PRECONDITION(IsInDoc(), "bad content"); - PRInt32 index; + PRUint32 index; for (index = aIndent; --index >= 0; ) fputs(" ", out); nsAutoString buf; @@ -3593,7 +3623,7 @@ nsGenericElement::List(FILE* out, PRInt32 aIndent) const fprintf(out, " refcount=%d<", mRefCnt.get()); fputs("\n", out); - PRInt32 kids = GetChildCount(); + PRUint32 kids = GetChildCount(); for (index = 0; index < kids; index++) { nsIContent *kid = GetChildAt(index); diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index 0a47fe343c1..7f4830023b2 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -429,7 +429,7 @@ public: #endif // nsIStyledContent interface methods - NS_IMETHOD GetID(nsIAtom** aResult) const; + virtual nsIAtom* GetID() const; virtual const nsAttrValue* GetClasses() const; NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const; NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker); diff --git a/content/events/src/nsXMLEventsManager.cpp b/content/events/src/nsXMLEventsManager.cpp index edea504610c..dda55a6621c 100644 --- a/content/events/src/nsXMLEventsManager.cpp +++ b/content/events/src/nsXMLEventsManager.cpp @@ -233,12 +233,8 @@ nsXMLEventsListener::HandleEvent(nsIDOMEvent* aEvent) nsCOMPtr target; aEvent->GetTarget(getter_AddRefs(target)); nsCOMPtr targetEl(do_QueryInterface(target)); - if (targetEl) { - nsCOMPtr id; - targetEl->GetID(getter_AddRefs(id)); - if (id == mTarget) + if (targetEl && targetEl->GetID() == mTarget) targetMatched = PR_TRUE; - } } if (!targetMatched) return NS_OK; diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 83f25e2cbd2..8d39ded25d0 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -1882,24 +1882,6 @@ nsGenericHTMLElement::GetHTMLAttribute(nsIAtom* aAttribute, return NS_CONTENT_ATTR_HAS_VALUE; } -nsresult -nsGenericHTMLElement::GetID(nsIAtom** aResult) const -{ - *aResult = nsnull; - - const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(nsHTMLAtoms::id); - NS_ASSERTION(!attrVal || - attrVal->Type() == nsAttrValue::eAtom || - (attrVal->Type() == nsAttrValue::eString && - attrVal->GetStringValue().IsEmpty()), - "unexpected attribute type"); - if (attrVal && attrVal->Type() == nsAttrValue::eAtom) { - NS_ADDREF(*aResult = attrVal->GetAtomValue()); - } - - return NS_OK; -} - const nsAttrValue* nsGenericHTMLElement::GetClasses() const { diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 3559f0c5168..acb9fff1a54 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -211,7 +211,6 @@ public: // Implementation for nsIHTMLContent NS_IMETHOD GetHTMLAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const; - NS_IMETHOD GetID(nsIAtom** aResult) const; virtual const nsAttrValue* GetClasses() const; virtual nsIAtom *GetIDAttributeName() const; virtual nsIAtom *GetClassAttributeName() const; diff --git a/content/html/style/src/nsCSSStyleSheet.cpp b/content/html/style/src/nsCSSStyleSheet.cpp index 9afe2506a46..682b22fdb5a 100644 --- a/content/html/style/src/nsCSSStyleSheet.cpp +++ b/content/html/style/src/nsCSSStyleSheet.cpp @@ -2859,7 +2859,7 @@ RuleProcessorData::RuleProcessorData(nsPresContext* aPresContext, // get the styledcontent interface and the ID if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIStyledContent), (void**)&mStyledContent))) { NS_ASSERTION(mStyledContent, "Succeeded but returned null"); - mStyledContent->GetID(&mContentID); + mContentID = mStyledContent->GetID(); } // see if there are attributes for the content @@ -2910,7 +2910,6 @@ RuleProcessorData::~RuleProcessorData() if (mParentData) mParentData->Destroy(mPresContext); - NS_IF_RELEASE(mContentID); NS_IF_RELEASE(mStyledContent); delete mLanguage; diff --git a/content/svg/content/src/nsSVGElement.cpp b/content/svg/content/src/nsSVGElement.cpp index 9bc38b4fcb0..aa0f229ca8e 100644 --- a/content/svg/content/src/nsSVGElement.cpp +++ b/content/svg/content/src/nsSVGElement.cpp @@ -202,8 +202,11 @@ nsSVGElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, nsIAtom* aPrefix, else if (aName == nsSVGAtoms::style && aNamespaceID == kNameSpaceID_None) { nsGenericHTMLElement::ParseStyleAttribute(this, PR_TRUE, aValue, attrValue); } + // We don't have an nsISVGValue attribute. + else if (aName == nsSVGAtoms::id && aNamespaceID == kNameSpaceID_None){ + attrValue.ParseAtom(aValue); + } else { - // We don't have an nsISVGValue attribute. attrValue.SetTo(aValue); } @@ -278,21 +281,6 @@ nsSVGElement::IsContentOfType(PRUint32 aFlags) const //---------------------------------------------------------------------- // nsIStyledContent methods -NS_IMETHODIMP -nsSVGElement::GetID(nsIAtom** aId)const -{ - nsAutoString value; - - nsresult rv = NS_CONST_CAST(nsSVGElement*,this)-> - GetAttribute(NS_LITERAL_STRING("id"), value); - if (NS_SUCCEEDED(rv)) - *aId = NS_NewAtom(value); - else - *aId = nsnull; - - return rv; -} - NS_IMETHODIMP nsSVGElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker) { diff --git a/content/svg/content/src/nsSVGElement.h b/content/svg/content/src/nsSVGElement.h index 3941adaf9da..9dee051ff1d 100644 --- a/content/svg/content/src/nsSVGElement.h +++ b/content/svg/content/src/nsSVGElement.h @@ -85,9 +85,6 @@ public: virtual nsresult SetBindingParent(nsIContent* aParent); virtual PRBool IsContentOfType(PRUint32 aFlags) const; - - // nsIStyledContent - NS_IMETHOD GetID(nsIAtom** aResult) const; NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker); NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify); diff --git a/content/xml/content/src/nsXMLElement.cpp b/content/xml/content/src/nsXMLElement.cpp index 8820b36531c..a725c57c172 100644 --- a/content/xml/content/src/nsXMLElement.cpp +++ b/content/xml/content/src/nsXMLElement.cpp @@ -437,22 +437,3 @@ nsXMLElement::IsFocusable(PRInt32 *aTabIndex) NS_IMPL_DOM_CLONENODE(nsXMLElement) -// nsIStyledContent implementation - -NS_IMETHODIMP -nsXMLElement::GetID(nsIAtom** aResult) const -{ - nsIAtom* atom = GetIDAttributeName(); - - *aResult = nsnull; - nsresult rv = NS_OK; - if (atom) { - nsAutoString value; - rv = nsGenericElement::GetAttr(kNameSpaceID_None, atom, value); - if (NS_SUCCEEDED(rv)) { - *aResult = NS_NewAtom(value); - } - } - - return rv; -} diff --git a/content/xml/content/src/nsXMLElement.h b/content/xml/content/src/nsXMLElement.h index 400b114bff7..b36e48457ff 100644 --- a/content/xml/content/src/nsXMLElement.h +++ b/content/xml/content/src/nsXMLElement.h @@ -69,9 +69,6 @@ public: // nsIXMLContent NS_IMETHOD MaybeTriggerAutoLink(nsIDocShell *aShell); - // nsIStyledContent - NS_IMETHOD GetID(nsIAtom** aResult) const; - // nsIContent nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, const nsAString& aValue, PRBool aNotify) diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index c95a8fa2b5c..52c0ad72262 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -1039,6 +1039,17 @@ nsXMLContentSink::HandleStartElement(const PRUnichar *aName, } content->SetDocument(mDocument, PR_FALSE, PR_TRUE); + // Set the ID attribute atom on the node info object for this node + // This must occur before the attributes are added so the name + // of the id attribute is known. + if (aIndex != -1 && NS_SUCCEEDED(result)) { + nsCOMPtr IDAttr = do_GetAtom(aAtts[aIndex]); + + if (IDAttr) { + nodeInfo->SetIDAttributeAtom(IDAttr); + } + } + // Set the attributes on the new content element result = AddAttributes(aAtts, content); @@ -1054,15 +1065,6 @@ nsXMLContentSink::HandleStartElement(const PRUnichar *aName, PushContent(content); } - // Set the ID attribute atom on the node info object for this node - if (aIndex != -1 && NS_SUCCEEDED(result)) { - nsCOMPtr IDAttr = do_GetAtom(aAtts[aIndex]); - - if (IDAttr) { - nodeInfo->SetIDAttributeAtom(IDAttr); - } - } - #ifdef MOZ_XTF if (nameSpaceID > kNameSpaceID_LastBuiltin) content->BeginAddingChildren(); diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 0ffda938211..c74a1476955 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -735,9 +735,8 @@ MatchElementId(nsIContent *aContent, const nsACString& aUTF8Id, const nsAString& nsCOMPtr xmlContent = do_QueryInterface(aContent); if (xmlContent) { - nsCOMPtr value; - if (NS_SUCCEEDED(xmlContent->GetID(getter_AddRefs(value))) && - value && value->EqualsUTF8(aUTF8Id)) { + nsIAtom* value = xmlContent->GetID(); + if (value && value->EqualsUTF8(aUTF8Id)) { return aContent; } } diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index be4597f6d1f..06d393089c8 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -3083,10 +3083,10 @@ nsXULElement::EnsureContentsGenerated(void) const } // nsIStyledContent Implementation -NS_IMETHODIMP -nsXULElement::GetID(nsIAtom** aResult) const +/// XXX GetID must be defined here because nsXUL element does not inherit from nsGenericElement. +nsIAtom* +nsXULElement::GetID() const { - *aResult = nsnull; const nsAttrValue* attrVal = FindLocalOrProtoAttr(kNameSpaceID_None, nsXULAtoms::id); NS_ASSERTION(!attrVal || @@ -3096,10 +3096,9 @@ nsXULElement::GetID(nsIAtom** aResult) const "unexpected attribute type"); if (attrVal && attrVal->Type() == nsAttrValue::eAtom) { - NS_ADDREF(*aResult = attrVal->GetAtomValue()); + return attrVal->GetAtomValue(); } - - return NS_OK; + return nsnull; } const nsAttrValue* diff --git a/content/xul/content/src/nsXULElement.h b/content/xul/content/src/nsXULElement.h index 66f044163c0..f8215d6997c 100644 --- a/content/xul/content/src/nsXULElement.h +++ b/content/xul/content/src/nsXULElement.h @@ -519,7 +519,7 @@ public: NS_IMETHOD MaybeTriggerAutoLink(nsIDocShell *aShell); // nsIStyledContent - NS_IMETHOD GetID(nsIAtom** aResult) const; + virtual nsIAtom* GetID() const; virtual const nsAttrValue* GetClasses() const; NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const; diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index 9afe2506a46..682b22fdb5a 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -2859,7 +2859,7 @@ RuleProcessorData::RuleProcessorData(nsPresContext* aPresContext, // get the styledcontent interface and the ID if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIStyledContent), (void**)&mStyledContent))) { NS_ASSERTION(mStyledContent, "Succeeded but returned null"); - mStyledContent->GetID(&mContentID); + mContentID = mStyledContent->GetID(); } // see if there are attributes for the content @@ -2910,7 +2910,6 @@ RuleProcessorData::~RuleProcessorData() if (mParentData) mParentData->Destroy(mPresContext); - NS_IF_RELEASE(mContentID); NS_IF_RELEASE(mStyledContent); delete mLanguage; diff --git a/layout/style/nsIStyleRuleProcessor.h b/layout/style/nsIStyleRuleProcessor.h index 4e229c7437d..e5880c5b731 100644 --- a/layout/style/nsIStyleRuleProcessor.h +++ b/layout/style/nsIStyleRuleProcessor.h @@ -83,7 +83,7 @@ struct RuleProcessorData { nsIContent* mScopedRoot; // Root of scoped stylesheet (set and unset by the supplier of the scoped stylesheet nsIAtom* mContentTag; // if content, then content->GetTag() - nsIAtom* mContentID; // if styled content, then styledcontent->GetID() + nsIAtom* mContentID; // if styled content, then weak reference to styledcontent->GetID() nsIStyledContent* mStyledContent; // if content, content->QI(nsIStyledContent) PRPackedBool mIsHTMLContent; // if content, then does QI on HTMLContent, true or false PRPackedBool mIsHTMLLink; // if content, calls nsStyleUtil::IsHTMLLink