diff --git a/mozilla/content/base/public/nsINodeInfo.h b/mozilla/content/base/public/nsINodeInfo.h index ee2cf983072..497f8014a3b 100644 --- a/mozilla/content/base/public/nsINodeInfo.h +++ b/mozilla/content/base/public/nsINodeInfo.h @@ -223,6 +223,12 @@ public: mInner.mNamespaceID); } + PRBool NameAndNamespaceEquals(nsINodeInfo *aNodeInfo) const + { + return aNodeInfo == this || aNodeInfo->Equals(mInner.mName, + mInner.mNamespaceID); + } + PRBool Equals(nsIAtom *aNameAtom) const { return mInner.mName == aNameAtom; diff --git a/mozilla/content/base/src/nsXMLContentSerializer.cpp b/mozilla/content/base/src/nsXMLContentSerializer.cpp index 0f84d2b842b..7e3e276c84b 100644 --- a/mozilla/content/base/src/nsXMLContentSerializer.cpp +++ b/mozilla/content/base/src/nsXMLContentSerializer.cpp @@ -421,10 +421,7 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, aElement->GetLocalName(tagLocalName); aElement->GetNamespaceURI(tagNamespaceURI); - PRInt32 namespaceID, elementNamespaceID; - content->GetNameSpaceID(elementNamespaceID); - if (elementNamespaceID == kNameSpaceID_HTML) - ToLowerCase(tagLocalName); // XXX We shouldn't need this hack + PRInt32 namespaceID; PRInt32 index, count; nsAutoString nameStr, prefixStr, uriStr, valueStr; @@ -440,26 +437,15 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, *getter_AddRefs(attrName), *getter_AddRefs(attrPrefix)); - if (namespaceID == kNameSpaceID_XMLNS || - elementNamespaceID == kNameSpaceID_HTML /*XXX Hack*/) { + if (namespaceID == kNameSpaceID_XMLNS) { PRBool hasPrefix = attrPrefix ? PR_TRUE : PR_FALSE; content->GetAttr(namespaceID, attrName, uriStr); - attrName->ToString(nameStr); - // XXX We shouldn't need this hack - if (elementNamespaceID == kNameSpaceID_HTML) { - if (Substring(nameStr, 0, 6).Equals(NS_LITERAL_STRING("xmlns:"))) { - nameStr.Cut(0,6); - hasPrefix = PR_TRUE; - } else if (!nameStr.Equals(kXMLNS)) { - continue; - } - } - - if (!hasPrefix) { + if (!attrPrefix) { // Default NS attribute does not have prefix (and the name is "xmlns") PushNameSpaceDecl(nsString(), uriStr, aElement); } else { + attrName->ToString(nameStr); PushNameSpaceDecl(nameStr, uriStr, aElement); } } @@ -470,8 +456,7 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, addNSAttr = ConfirmPrefix(tagPrefix, tagNamespaceURI); // Serialize the qualified name of the element AppendToString(NS_LITERAL_STRING("<"), aStr); - if (!tagPrefix.IsEmpty() && - !(elementNamespaceID == kNameSpaceID_HTML && tagPrefix.Equals(kXMLNS) /*XXX Hack*/)) { + if (!tagPrefix.IsEmpty()) { AppendToString(tagPrefix, aStr); AppendToString(NS_LITERAL_STRING(":"), aStr); } @@ -515,8 +500,6 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, content->GetAttr(namespaceID, attrName, valueStr); attrName->ToString(nameStr); - if (elementNamespaceID == kNameSpaceID_HTML && nameStr.Equals(NS_LITERAL_STRING("xmlns:xmlns"))) - nameStr.Assign(kXMLNS); // XXX Shouldn't need this hack, breaks case where there really is xmlns:xmlns SerializeAttr(prefixStr, nameStr, valueStr, aStr, PR_TRUE); if (addNSAttr) { @@ -559,16 +542,10 @@ nsXMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement, aElement->GetLocalName(tagLocalName); aElement->GetNamespaceURI(tagNamespaceURI); - PRInt32 namespaceID; - content->GetNameSpaceID(namespaceID); - if (namespaceID == kNameSpaceID_HTML) - ToLowerCase(tagLocalName); // XXX We shouldn't need this hack - ConfirmPrefix(tagPrefix, tagNamespaceURI); AppendToString(NS_LITERAL_STRING("ReleaseContentRef(); - NS_RELEASE(aAttributes); -} - class nsGenericHTMLElementTearoff : public nsIDOMNSHTMLElement, public nsIDOMElementCSSInlineStyle { @@ -270,9 +249,7 @@ nsGenericHTMLElement::nsGenericHTMLElement() nsGenericHTMLElement::~nsGenericHTMLElement() { - if (nsnull != mAttributes) { - ReleaseAttributes(mAttributes); - } + delete mAttributes; } NS_IMETHODIMP @@ -1601,7 +1578,16 @@ nsGenericHTMLElement::SetAttr(PRInt32 aNameSpaceID, if ((kNameSpaceID_HTML != aNameSpaceID) && (kNameSpaceID_None != aNameSpaceID) && (kNameSpaceID_Unknown != aNameSpaceID)) { - return NS_ERROR_ILLEGAL_VALUE; + nsCOMPtr nimgr; + result = mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_SUCCESS(result, result); + + nsCOMPtr ni; + result = nimgr->GetNodeInfo(aAttribute, nsnull, kNameSpaceID_None, + *getter_AddRefs(ni)); + NS_ENSURE_SUCCESS(result, result); + + return SetAttr(ni, aValue, aNotify); } if (nsHTMLAtoms::style == aAttribute) { @@ -1664,23 +1650,13 @@ nsGenericHTMLElement::SetAttr(PRInt32 aNameSpaceID, GetMappedAttributeImpact(aAttribute, modHint, impact); nsCOMPtr sheet(dont_AddRef(GetAttrStyleSheet(mDocument))); - if (sheet) { // set attr via style sheet - result = sheet->SetAttributeFor(aAttribute, aValue, - (NS_STYLE_HINT_CONTENT < impact), - this, mAttributes); - } - else { // manage this ourselves and re-sync when we connect to doc - result = EnsureWritableAttributes(this, mAttributes, PR_TRUE); - if (mAttributes) { - PRInt32 count; - result = mAttributes->SetAttributeFor(aAttribute, aValue, - (NS_STYLE_HINT_CONTENT < impact), - this, nsnull, count); - if (0 == count) { - ReleaseAttributes(mAttributes); - } - } + if (!mAttributes) { + result = NS_NewHTMLAttributes(&mAttributes); + NS_ENSURE_SUCCESS(result, result); } + result = mAttributes->SetAttributeFor(aAttribute, aValue, + (NS_STYLE_HINT_CONTENT < impact), + this, sheet); } if (mDocument) { @@ -1737,15 +1713,89 @@ nsGenericHTMLElement::SetAttr(nsINodeInfo* aNodeInfo, { NS_ENSURE_ARG_POINTER(aNodeInfo); - nsCOMPtr atom; - PRInt32 nsid; + nsresult rv; + nsCOMPtr localName; + PRInt32 namespaceID; - aNodeInfo->GetNameAtom(*getter_AddRefs(atom)); - aNodeInfo->GetNamespaceID(nsid); + aNodeInfo->GetNameAtom(*getter_AddRefs(localName)); + aNodeInfo->GetNamespaceID(namespaceID); - // We still rely on the old way of setting the attribute. + if (namespaceID == kNameSpaceID_HTML || + namespaceID == kNameSpaceID_None || + namespaceID == kNameSpaceID_Unknown) + return SetAttr(namespaceID, localName, aValue, aNotify); + + // This code is copied from SetAttr(PRInt32, nsIAtom* ,... + // It sux that we have it duplicated, but we'll have to live with it + // until we have better SetAttr signatures in nsIContent - return SetAttr(nsid, atom, aValue, aNotify); + nsAutoString strValue; + + // don't do any update if old == new + rv = GetAttr(namespaceID, localName, strValue); + if (rv != NS_CONTENT_ATTR_NOT_THERE && aValue.Equals(strValue)) + return NS_OK; + + PRBool modification = (rv != NS_CONTENT_ATTR_NOT_THERE); + + if (aNotify && mDocument) { + mDocument->BeginUpdate(); + mDocument->AttributeWillChange(this, namespaceID, localName); + } + + if (!mAttributes) { + rv = NS_NewHTMLAttributes(&mAttributes); + NS_ENSURE_SUCCESS(rv, rv); + } + rv = mAttributes->SetAttributeFor(aNodeInfo, aValue); + NS_ENSURE_SUCCESS(rv, rv); + + if (mDocument) { + nsCOMPtr bindingManager; + mDocument->GetBindingManager(getter_AddRefs(bindingManager)); + nsCOMPtr binding; + bindingManager->GetBinding(this, getter_AddRefs(binding)); + if (binding) + binding->AttributeChanged(localName, namespaceID, PR_FALSE); + + if (nsGenericElement::HasMutationListeners(this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED)) { + nsCOMPtr node(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); + nsMutationEvent mutation; + mutation.eventStructType = NS_MUTATION_EVENT; + mutation.message = NS_MUTATION_ATTRMODIFIED; + mutation.mTarget = node; + + nsAutoString attrLocalName, attrNamespace; + localName->ToString(attrLocalName); + aNodeInfo->GetNamespaceURI(attrNamespace); + nsCOMPtr attrNode; + GetAttributeNodeNS(attrNamespace, attrLocalName, getter_AddRefs(attrNode)); + mutation.mRelatedNode = attrNode; + + mutation.mAttrName = localName; + if (!strValue.IsEmpty()) + mutation.mPrevAttrValue = getter_AddRefs(NS_NewAtom(strValue)); + if (!aValue.IsEmpty()) + mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(aValue)); + if (modification) + mutation.mAttrChange = nsIDOMMutationEvent::MODIFICATION; + else + mutation.mAttrChange = nsIDOMMutationEvent::ADDITION; + nsEventStatus status = nsEventStatus_eIgnore; + HandleDOMEvent(nsnull, &mutation, nsnull, + NS_EVENT_FLAG_INIT, &status); + } + + if (aNotify) { + PRInt32 modHint = modification ? PRInt32(nsIDOMMutationEvent::MODIFICATION) + : PRInt32(nsIDOMMutationEvent::ADDITION); + mDocument->AttributeChanged(this, namespaceID, localName, modHint, + NS_STYLE_HINT_UNKNOWN); + mDocument->EndUpdate(); + } + } + + return NS_OK; } PRBool nsGenericHTMLElement::IsEventName(nsIAtom* aName) @@ -1861,10 +1911,19 @@ nsGenericHTMLElement::SetHTMLAttribute(nsIAtom* aAttribute, } } sheet = dont_AddRef(GetAttrStyleSheet(mDocument)); - if (sheet) { // set attr via style sheet - result = sheet->SetAttributeFor(aAttribute, aValue, - (NS_STYLE_HINT_CONTENT < impact), - this, mAttributes); + if (sheet) { + if (!mAttributes) { + nsresult rv = NS_NewHTMLAttributes(&mAttributes); + NS_ENSURE_SUCCESS(rv, rv); + } + PRInt32 count; + result = mAttributes->SetAttributeFor(aAttribute, aValue, + (NS_STYLE_HINT_CONTENT < impact), + this, sheet, count); + if (0 == count) { + delete mAttributes; + mAttributes = nsnull; + } } nsCOMPtr bindingManager; @@ -1909,15 +1968,17 @@ nsGenericHTMLElement::SetHTMLAttribute(nsIAtom* aAttribute, } } if (!sheet) { // manage this ourselves and re-sync when we connect to doc - result = EnsureWritableAttributes(this, mAttributes, PR_TRUE); - if (mAttributes) { - PRInt32 count; - result = mAttributes->SetAttributeFor(aAttribute, aValue, - (NS_STYLE_HINT_CONTENT < impact), - this, nsnull, count); - if (0 == count) { - ReleaseAttributes(mAttributes); - } + if (!mAttributes) { + nsresult rv = NS_NewHTMLAttributes(&mAttributes); + NS_ENSURE_SUCCESS(rv, rv); + } + PRInt32 count; + result = mAttributes->SetAttributeFor(aAttribute, aValue, + (NS_STYLE_HINT_CONTENT < impact), + this, sheet, count); + if (0 == count) { + delete mAttributes; + mAttributes = nsnull; } } @@ -1929,19 +1990,15 @@ nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBoo { nsresult result = NS_OK; - NS_ASSERTION((kNameSpaceID_HTML == aNameSpaceID) || - (kNameSpaceID_None == aNameSpaceID) || - (kNameSpaceID_Unknown == aNameSpaceID), - "html content only holds HTML attributes"); - - if ((kNameSpaceID_HTML != aNameSpaceID) && - (kNameSpaceID_None != aNameSpaceID) && - (kNameSpaceID_Unknown != aNameSpaceID)) { - return NS_ERROR_ILLEGAL_VALUE; + if (aNameSpaceID == kNameSpaceID_HTML || + aNameSpaceID == kNameSpaceID_Unknown) { + aNameSpaceID = kNameSpaceID_None; } + // Check for event handlers - if (IsEventName(aAttribute)) { + if (aNameSpaceID == kNameSpaceID_None && + IsEventName(aAttribute)) { nsCOMPtr manager; GetListenerManager(getter_AddRefs(manager)); @@ -1951,14 +2008,15 @@ nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBoo } nsCOMPtr sheet; + PRInt32 impact = NS_STYLE_HINT_UNKNOWN; if (mDocument) { - PRInt32 impact = NS_STYLE_HINT_UNKNOWN; if (aNotify) { mDocument->BeginUpdate(); mDocument->AttributeWillChange(this, aNameSpaceID, aAttribute); - if (nsHTMLAtoms::style == aAttribute) { + if (aNameSpaceID == kNameSpaceID_None && + aAttribute == nsHTMLAtoms::style) { nsHTMLValue oldValue; if (NS_CONTENT_ATTR_NOT_THERE != GetHTMLAttribute(aAttribute, oldValue)) { @@ -1995,12 +2053,20 @@ nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBoo HandleDOMEvent(nsnull, &mutation, nsnull, NS_EVENT_FLAG_INIT, &status); } + } - sheet = dont_AddRef(GetAttrStyleSheet(mDocument)); - if (sheet) { // set attr via style sheet - result = sheet->UnsetAttributeFor(aAttribute, this, mAttributes); + sheet = dont_AddRef(GetAttrStyleSheet(mDocument)); + if (sheet && mAttributes) { + PRInt32 count; + result = mAttributes->UnsetAttributeFor(aAttribute, aNameSpaceID, this, + sheet, count); + if (0 == count) { + delete mAttributes; + mAttributes = nsnull; } + } + if (mDocument) { nsCOMPtr bindingManager; mDocument->GetBindingManager(getter_AddRefs(bindingManager)); nsCOMPtr binding; @@ -2013,57 +2079,48 @@ nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBoo mDocument->EndUpdate(); } } - if (!sheet) { // manage this ourselves and re-sync when we connect to doc - result = EnsureWritableAttributes(this, mAttributes, PR_FALSE); - if (mAttributes) { - PRInt32 count; - result = mAttributes->UnsetAttributeFor(aAttribute, this, nsnull, count); - if (0 == count) { - ReleaseAttributes(mAttributes); - } - } - } return result; } nsresult nsGenericHTMLElement::GetAttr(PRInt32 aNameSpaceID, nsIAtom *aAttribute, - nsIAtom*& aPrefix, nsAString& aResult) const + nsAString& aResult) const { - aPrefix = nsnull; - - return GetAttr(aNameSpaceID, aAttribute, aResult); + nsCOMPtr prefix; + return GetAttr(aNameSpaceID, aAttribute, *getter_AddRefs(prefix), aResult); } nsresult nsGenericHTMLElement::GetAttr(PRInt32 aNameSpaceID, nsIAtom *aAttribute, - nsAString& aResult) const + nsIAtom*& aPrefix, nsAString& aResult) const { - aResult.SetLength(0); - -#if 0 - NS_ASSERTION((kNameSpaceID_HTML == aNameSpaceID) || - (kNameSpaceID_None == aNameSpaceID) || - (kNameSpaceID_Unknown == aNameSpaceID), - "html content only holds HTML attributes"); -#endif + nsresult rv; + aResult.Truncate(); + aPrefix = nsnull; + const nsHTMLValue* value; if ((kNameSpaceID_HTML != aNameSpaceID) && (kNameSpaceID_None != aNameSpaceID) && (kNameSpaceID_Unknown != aNameSpaceID)) { - return NS_CONTENT_ATTR_NOT_THERE; + rv = mAttributes ? mAttributes->GetAttribute(aAttribute, aNameSpaceID, + aPrefix, + &value) : + NS_CONTENT_ATTR_NOT_THERE; + } + else { + aNameSpaceID = kNameSpaceID_None; + rv = mAttributes ? mAttributes->GetAttribute(aAttribute, &value) : + NS_CONTENT_ATTR_NOT_THERE; } - const nsHTMLValue* value; - nsresult result = mAttributes ? mAttributes->GetAttribute(aAttribute, &value) : - NS_CONTENT_ATTR_NOT_THERE; - - if (NS_CONTENT_ATTR_HAS_VALUE == result) { + aResult.Truncate(); + if (rv == NS_CONTENT_ATTR_HAS_VALUE) { // Try subclass conversion routine first - if (NS_CONTENT_ATTR_HAS_VALUE == - AttributeToString(aAttribute, *value, aResult)) { - return result; + if (aNameSpaceID == kNameSpaceID_None && + AttributeToString(aAttribute, *value, aResult) == + NS_CONTENT_ATTR_HAS_VALUE) { + return rv; } nscolor color; @@ -2119,18 +2176,21 @@ nsGenericHTMLElement::GetAttr(PRInt32 aNameSpaceID, nsIAtom *aAttribute, default: case eHTMLUnit_Enumerated: NS_NOTREACHED("no default enumerated value to string conversion"); - result = NS_CONTENT_ATTR_NOT_THERE; + rv = NS_CONTENT_ATTR_NOT_THERE; break; } } - return result; + return rv; } NS_IMETHODIMP_(PRBool) nsGenericHTMLElement::HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const { - return mAttributes ? mAttributes->HasAttribute(aName) : PR_FALSE; + if (aNameSpaceID == kNameSpaceID_HTML || + aNameSpaceID == kNameSpaceID_Unknown) + aNameSpaceID = kNameSpaceID_None; + return mAttributes && mAttributes->HasAttribute(aName, aNameSpaceID); } nsresult @@ -2150,12 +2210,13 @@ nsGenericHTMLElement::GetAttrNameAt(PRInt32 aIndex, nsIAtom*& aName, nsIAtom*& aPrefix) const { - aNameSpaceID = kNameSpaceID_None; - aPrefix = nsnull; if (nsnull != mAttributes) { - return mAttributes->GetAttributeNameAt(aIndex, aName); + return mAttributes->GetAttributeNameAt(aIndex, aNameSpaceID, aName, + aPrefix); } + aNameSpaceID = kNameSpaceID_None; aName = nsnull; + aPrefix = nsnull; return NS_ERROR_ILLEGAL_VALUE; } diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.h b/mozilla/content/html/content/src/nsGenericHTMLElement.h index 9525729c7a3..ba70ef0e87f 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.h +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.h @@ -55,7 +55,7 @@ class nsIDOMEventListener; class nsIDOMNodeList; class nsIEventListenerManager; class nsIFrame; -class nsIHTMLAttributes; +class nsHTMLAttributes; class nsIHTMLMappedAttributes; class nsIHTMLContent; class nsIStyleRule; @@ -380,7 +380,7 @@ public: const nsAString& aValue, PRBool aNotify); - nsIHTMLAttributes* mAttributes; + nsHTMLAttributes* mAttributes; // Helper functions for and static nsresult SetProtocolInHrefString(const nsAString &aHref, diff --git a/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp b/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp index eafce6dcb7b..99a3285fe75 100644 --- a/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLAnchorElement.cpp @@ -67,7 +67,7 @@ #include "nsIFrameManager.h" #include "nsIPresShell.h" #include "nsIDocument.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult); diff --git a/mozilla/content/html/content/src/nsHTMLBRElement.cpp b/mozilla/content/html/content/src/nsHTMLBRElement.cpp index eda2ce79044..a3e75174094 100644 --- a/mozilla/content/html/content/src/nsHTMLBRElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLBRElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" class nsHTMLBRElement : public nsGenericHTMLLeafElement, diff --git a/mozilla/content/html/content/src/nsHTMLBodyElement.cpp b/mozilla/content/html/content/src/nsHTMLBodyElement.cpp index 66d9080b29d..c955071e0e8 100644 --- a/mozilla/content/html/content/src/nsHTMLBodyElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLBodyElement.cpp @@ -57,7 +57,7 @@ #include "nsIWebShell.h" #include "nsIContentViewer.h" #include "nsIMarkupDocumentViewer.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsIHTMLContentContainer.h" #include "nsISupportsArray.h" #include "nsIFrame.h" diff --git a/mozilla/content/html/content/src/nsHTMLDListElement.cpp b/mozilla/content/html/content/src/nsHTMLDListElement.cpp index 1be4a3be97e..c50aa439b04 100644 --- a/mozilla/content/html/content/src/nsHTMLDListElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLDListElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" class nsHTMLDListElement : public nsGenericHTMLContainerElement, diff --git a/mozilla/content/html/content/src/nsHTMLDirectoryElement.cpp b/mozilla/content/html/content/src/nsHTMLDirectoryElement.cpp index e2fcb42bcac..06534ba8ddb 100644 --- a/mozilla/content/html/content/src/nsHTMLDirectoryElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLDirectoryElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" // XXX nav4 has type= start= (same as OL/UL) diff --git a/mozilla/content/html/content/src/nsHTMLDivElement.cpp b/mozilla/content/html/content/src/nsHTMLDivElement.cpp index 30d675cfe3c..ea707cdf9f0 100644 --- a/mozilla/content/html/content/src/nsHTMLDivElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLDivElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" // XXX support missing nav attributes? gutter, cols, width diff --git a/mozilla/content/html/content/src/nsHTMLFontElement.cpp b/mozilla/content/html/content/src/nsHTMLFontElement.cpp index 7edaafe807a..290bf732a8f 100644 --- a/mozilla/content/html/content/src/nsHTMLFontElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLFontElement.cpp @@ -47,7 +47,7 @@ #include "nsStyleConsts.h" #include "nsStyleUtil.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsCSSDeclaration.h" #include "nsRuleNode.h" diff --git a/mozilla/content/html/content/src/nsHTMLHRElement.cpp b/mozilla/content/html/content/src/nsHTMLHRElement.cpp index d94551ec927..1ff3f7649f7 100644 --- a/mozilla/content/html/content/src/nsHTMLHRElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLHRElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" class nsHTMLHRElement : public nsGenericHTMLLeafElement, diff --git a/mozilla/content/html/content/src/nsHTMLHeadingElement.cpp b/mozilla/content/html/content/src/nsHTMLHeadingElement.cpp index 95763344673..f7b1f746ab4 100644 --- a/mozilla/content/html/content/src/nsHTMLHeadingElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLHeadingElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" class nsHTMLHeadingElement : public nsGenericHTMLContainerElement, diff --git a/mozilla/content/html/content/src/nsHTMLIFrameElement.cpp b/mozilla/content/html/content/src/nsHTMLIFrameElement.cpp index 84cc0c4942f..161391af067 100644 --- a/mozilla/content/html/content/src/nsHTMLIFrameElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLIFrameElement.cpp @@ -50,7 +50,7 @@ #include "nsIDocument.h" #include "nsIDOMDocument.h" #include "nsIWebNavigation.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsIChromeEventHandler.h" #include "nsDOMError.h" #include "nsRuleNode.h" diff --git a/mozilla/content/html/content/src/nsHTMLImageElement.cpp b/mozilla/content/html/content/src/nsHTMLImageElement.cpp index 41778eadffd..30cfce016c1 100644 --- a/mozilla/content/html/content/src/nsHTMLImageElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLImageElement.cpp @@ -46,7 +46,7 @@ #include "nsStyleConsts.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsIJSNativeInitializer.h" #include "nsSize.h" #include "nsIDocument.h" diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 2af39bcc30b..bb30e5eb5d5 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -59,7 +59,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsIFormControl.h" #include "nsIForm.h" #include "nsIFormSubmission.h" diff --git a/mozilla/content/html/content/src/nsHTMLLIElement.cpp b/mozilla/content/html/content/src/nsHTMLLIElement.cpp index 195d672ed28..aad13793c0d 100644 --- a/mozilla/content/html/content/src/nsHTMLLIElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLLIElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" class nsHTMLLIElement : public nsGenericHTMLContainerElement, diff --git a/mozilla/content/html/content/src/nsHTMLMenuElement.cpp b/mozilla/content/html/content/src/nsHTMLMenuElement.cpp index b60a69636d8..7d227f810e7 100644 --- a/mozilla/content/html/content/src/nsHTMLMenuElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLMenuElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" // XXX nav4 has type= start= (same as OL/UL) diff --git a/mozilla/content/html/content/src/nsHTMLOListElement.cpp b/mozilla/content/html/content/src/nsHTMLOListElement.cpp index 0c0168978eb..412017239a6 100644 --- a/mozilla/content/html/content/src/nsHTMLOListElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLOListElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" class nsHTMLOListElement : public nsGenericHTMLContainerElement, diff --git a/mozilla/content/html/content/src/nsHTMLParagraphElement.cpp b/mozilla/content/html/content/src/nsHTMLParagraphElement.cpp index a2c18f65034..07daf66ce86 100644 --- a/mozilla/content/html/content/src/nsHTMLParagraphElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLParagraphElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" // XXX missing nav attributes diff --git a/mozilla/content/html/content/src/nsHTMLPreElement.cpp b/mozilla/content/html/content/src/nsHTMLPreElement.cpp index aa076351fad..692996da2f6 100644 --- a/mozilla/content/html/content/src/nsHTMLPreElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLPreElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" #include "nsCSSDeclaration.h" diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp index 69ce18e180e..13c5b8fe2e7 100644 --- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp @@ -50,7 +50,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsIForm.h" #include "nsIFormSubmission.h" #include "nsIDOMHTMLCollection.h" diff --git a/mozilla/content/html/content/src/nsHTMLSharedElement.cpp b/mozilla/content/html/content/src/nsHTMLSharedElement.cpp index 5cd9b9ce3f6..5e141734ad8 100644 --- a/mozilla/content/html/content/src/nsHTMLSharedElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSharedElement.cpp @@ -48,7 +48,7 @@ #include "nsStyleConsts.h" #include "nsIPresContext.h" #include "nsRuleNode.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" class nsHTMLSharedLeafElement : public nsGenericHTMLLeafElement, diff --git a/mozilla/content/html/content/src/nsHTMLSharedLeafElement.cpp b/mozilla/content/html/content/src/nsHTMLSharedLeafElement.cpp index 5cd9b9ce3f6..5e141734ad8 100644 --- a/mozilla/content/html/content/src/nsHTMLSharedLeafElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSharedLeafElement.cpp @@ -48,7 +48,7 @@ #include "nsStyleConsts.h" #include "nsIPresContext.h" #include "nsRuleNode.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" class nsHTMLSharedLeafElement : public nsGenericHTMLLeafElement, diff --git a/mozilla/content/html/content/src/nsHTMLTableCaptionElement.cpp b/mozilla/content/html/content/src/nsHTMLTableCaptionElement.cpp index 9788d49b186..60143c4f0a5 100644 --- a/mozilla/content/html/content/src/nsHTMLTableCaptionElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableCaptionElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" class nsHTMLTableCaptionElement : public nsGenericHTMLContainerElement, diff --git a/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp b/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp index 681915923d3..45c72c94261 100644 --- a/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp @@ -41,7 +41,7 @@ #include "nsIDOMHTMLCollection.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" diff --git a/mozilla/content/html/content/src/nsHTMLTableColElement.cpp b/mozilla/content/html/content/src/nsHTMLTableColElement.cpp index 6b46133f76f..d7544add78b 100644 --- a/mozilla/content/html/content/src/nsHTMLTableColElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableColElement.cpp @@ -39,7 +39,7 @@ #include "nsIHTMLTableColElement.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" diff --git a/mozilla/content/html/content/src/nsHTMLTableElement.cpp b/mozilla/content/html/content/src/nsHTMLTableElement.cpp index 319e5c6a6da..19289cf4e45 100644 --- a/mozilla/content/html/content/src/nsHTMLTableElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableElement.cpp @@ -43,7 +43,7 @@ #include "nsDOMError.h" #include "GenericElementCollection.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" diff --git a/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp b/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp index 2d8241a519d..7cf676c3739 100644 --- a/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp @@ -42,7 +42,7 @@ #include "nsIDOMEventReceiver.h" #include "nsDOMError.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "GenericElementCollection.h" #include "nsHTMLAtoms.h" diff --git a/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp b/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp index f3a035c997d..35c732843ad 100644 --- a/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp @@ -38,7 +38,7 @@ #include "nsIDOMHTMLTableSectionElem.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp index 126cadac6bd..6c7cd29cb96 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -56,7 +56,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsIFormControlFrame.h" #include "nsIGfxTextControlFrame.h" #include "nsIEventStateManager.h" diff --git a/mozilla/content/html/content/src/nsHTMLUListElement.cpp b/mozilla/content/html/content/src/nsHTMLUListElement.cpp index a2dc1ac6723..211581edf8c 100644 --- a/mozilla/content/html/content/src/nsHTMLUListElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLUListElement.cpp @@ -44,7 +44,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsRuleNode.h" extern nsGenericHTMLElement::EnumTable kListTypeTable[]; diff --git a/mozilla/content/html/content/src/nsHTMLUnknownElement.cpp b/mozilla/content/html/content/src/nsHTMLUnknownElement.cpp index 43e62e19e3c..30c60b1a88b 100644 --- a/mozilla/content/html/content/src/nsHTMLUnknownElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLUnknownElement.cpp @@ -50,7 +50,7 @@ #include "nsIDocument.h" #include "nsIHTMLStyleSheet.h" #include "nsIHTMLContentContainer.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsIDOMMutationEvent.h" class nsHTMLUnknownElement : public nsGenericHTMLContainerElement, @@ -167,27 +167,6 @@ static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument) return sheet; } -static nsresult -EnsureWritableAttributes(nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes, PRBool aCreate) -{ - nsresult result = NS_OK; - - if (!aAttributes) { - if (PR_TRUE == aCreate) { - result = NS_NewHTMLAttributes(&aAttributes); - } - } - - return result; -} - -static void ReleaseAttributes(nsIHTMLAttributes*& aAttributes) -{ -// aAttributes->ReleaseContentRef(); - NS_RELEASE(aAttributes); -} - NS_IMETHODIMP nsHTMLUnknownElement::SetAttribute(PRInt32 aNameSpaceID, @@ -276,24 +255,13 @@ nsHTMLUnknownElement::SetAttribute(PRInt32 aNameSpaceID, GetMappedAttributeImpact(aAttribute, nsIDOMMutationEvent::MODIFICATION, impact); nsCOMPtr sheet(dont_AddRef(GetAttrStyleSheet(mDocument))); - if (sheet) { // set attr via style sheet - result = sheet->SetAttributeFor(aAttribute, aValue, - (NS_STYLE_HINT_CONTENT < impact), - this, mAttributes); - } - else { // manage this ourselves and re-sync when we connect to doc - result = EnsureWritableAttributes(this, mAttributes, PR_TRUE); - - if (mAttributes) { - PRInt32 count; - result = mAttributes->SetAttributeFor(aAttribute, aValue, - (NS_STYLE_HINT_CONTENT < impact), - this, nsnull, count); - if (0 == count) { - ReleaseAttributes(mAttributes); - } - } + if (!mAttributes) { + result = NS_NewHTMLAttributes(&mAttributes); + NS_ENSURE_SUCCESS(result, result); } + result = mAttributes->SetAttributeFor(aAttribute, aValue, + (NS_STYLE_HINT_CONTENT < impact), + this, sheet); } if (aNotify && (mDocument)) { diff --git a/mozilla/content/html/style/src/MANIFEST b/mozilla/content/html/style/src/MANIFEST index 909ca3d68f8..0ba407843db 100644 --- a/mozilla/content/html/style/src/MANIFEST +++ b/mozilla/content/html/style/src/MANIFEST @@ -14,5 +14,4 @@ nsICSSRule.h nsICSSStyleRule.h nsICSSStyleRuleProcessor.h nsIHTMLCSSStyleSheet.h -nsIHTMLAttributes.h nsIInspectorCSSUtils.h diff --git a/mozilla/content/html/style/src/Makefile.in b/mozilla/content/html/style/src/Makefile.in index 23edbcab8e5..8343e0588cf 100644 --- a/mozilla/content/html/style/src/Makefile.in +++ b/mozilla/content/html/style/src/Makefile.in @@ -85,7 +85,6 @@ EXPORTS = \ nsCSSDeclaration.h \ nsICSSOMFactory.h \ nsIHTMLCSSStyleSheet.h \ - nsIHTMLAttributes.h \ nsIInspectorCSSUtils.h \ $(NULL) diff --git a/mozilla/content/html/style/src/makefile.win b/mozilla/content/html/style/src/makefile.win index 488329bc527..36f9093bd92 100644 --- a/mozilla/content/html/style/src/makefile.win +++ b/mozilla/content/html/style/src/makefile.win @@ -58,7 +58,6 @@ EXPORTS = \ nsICSSOMFactory.h \ nsIHTMLCSSStyleSheet.h \ nsDOMCSSDeclaration.h \ - nsIHTMLAttributes.h \ nsIInspectorCSSUtils.h \ $(NULL) diff --git a/mozilla/content/html/style/src/nsHTMLAttributes.cpp b/mozilla/content/html/style/src/nsHTMLAttributes.cpp index 9a6b4adf496..07d7b61baa2 100644 --- a/mozilla/content/html/style/src/nsHTMLAttributes.cpp +++ b/mozilla/content/html/style/src/nsHTMLAttributes.cpp @@ -38,7 +38,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nscore.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsIHTMLStyleSheet.h" #include "nsIPresContext.h" #include "nsIDocument.h" @@ -63,11 +63,11 @@ MOZ_DECL_CTOR_COUNTER(HTMLAttribute) struct HTMLAttribute { HTMLAttribute(void) - : mAttribute(nsnull), - mValue(), + : mValue(), mNext(nsnull) { MOZ_COUNT_CTOR(HTMLAttribute); + mAttribute.mAtom = nsnull; } HTMLAttribute(nsIAtom* aAttribute, const nsAString& aValue) @@ -76,16 +76,16 @@ struct HTMLAttribute { mNext(nsnull) { MOZ_COUNT_CTOR(HTMLAttribute); - NS_IF_ADDREF(mAttribute); + mAttribute.Addref(); } - HTMLAttribute(nsIAtom* aAttribute, const nsHTMLValue& aValue) + HTMLAttribute(nsHTMLAttrName aAttribute, const nsHTMLValue& aValue) : mAttribute(aAttribute), mValue(aValue), mNext(nsnull) { MOZ_COUNT_CTOR(HTMLAttribute); - NS_IF_ADDREF(mAttribute); + mAttribute.Addref(); } HTMLAttribute(const HTMLAttribute& aCopy) @@ -94,63 +94,74 @@ struct HTMLAttribute { mNext(nsnull) { MOZ_COUNT_CTOR(HTMLAttribute); - NS_IF_ADDREF(mAttribute); + mAttribute.Addref(); } ~HTMLAttribute(void) { MOZ_COUNT_DTOR(HTMLAttribute); - NS_IF_RELEASE(mAttribute); + mAttribute.Release(); } HTMLAttribute& operator=(const HTMLAttribute& aCopy) { - NS_IF_RELEASE(mAttribute); + mAttribute.Release(); mAttribute = aCopy.mAttribute; - NS_IF_ADDREF(mAttribute); + mAttribute.Addref(); mValue = aCopy.mValue; return *this; } PRBool operator==(const HTMLAttribute& aOther) const { - return PRBool((mAttribute == aOther.mAttribute) && + return PRBool((mAttribute.mBits == aOther.mAttribute.mBits) && (mValue == aOther.mValue)); } PRUint32 HashValue(void) const { - return NS_PTR_TO_INT32(mAttribute) ^ mValue.HashValue(); + return mAttribute.mBits ^ mValue.HashValue(); } void Reset(void) { - NS_IF_RELEASE(mAttribute); + mAttribute.Release(); mValue.Reset(); } void Set(nsIAtom* aAttribute, const nsHTMLValue& aValue) { - NS_IF_RELEASE(mAttribute); - mAttribute = aAttribute; - NS_IF_ADDREF(mAttribute); + mAttribute.Release(); + mAttribute.mAtom = aAttribute; + mAttribute.Addref(); mValue = aValue; } void Set(nsIAtom* aAttribute, const nsAString& aValue) { - NS_IF_RELEASE(mAttribute); - mAttribute = aAttribute; - NS_IF_ADDREF(mAttribute); + mAttribute.Release(); + mAttribute.mAtom = aAttribute; + mAttribute.Addref(); + mValue.SetStringValue(aValue); + } + + void Set(nsINodeInfo* aAttribute, const nsAString& aValue) + { + mAttribute.Release(); + mAttribute.SetNodeInfo(aAttribute); + mAttribute.Addref(); mValue.SetStringValue(aValue); } #ifdef DEBUG void AppendToString(nsString& aBuffer) const { - if (nsnull != mAttribute) { + if (mAttribute.mBits) { nsAutoString temp; - mAttribute->ToString(temp); + if (mAttribute.IsAtom()) + mAttribute.mAtom->ToString(temp); + else + mAttribute.GetNodeInfo()->GetQualifiedName(temp); aBuffer.Append(temp); if (eHTMLUnit_Null != mValue.GetUnit()) { aBuffer.Append(NS_LITERAL_STRING(" = ")); @@ -164,8 +175,11 @@ struct HTMLAttribute { void ToString(nsString& aBuffer) const { - if (nsnull != mAttribute) { - mAttribute->ToString(aBuffer); + if (mAttribute.mBits) { + if (mAttribute.IsAtom()) + mAttribute.mAtom->ToString(aBuffer); + else + mAttribute.GetNodeInfo()->GetQualifiedName(aBuffer); if (eHTMLUnit_Null != mValue.GetUnit()) { aBuffer.Append(NS_LITERAL_STRING(" = ")); mValue.AppendToString(aBuffer); @@ -204,7 +218,7 @@ struct HTMLAttribute { FindHTMLAttribute(nsIAtom* aAttrName, HTMLAttribute* aAttr) { while (aAttr) { - if (aAttrName == aAttr->mAttribute) { + if (aAttrName == aAttr->mAttribute.mAtom) { return aAttr; } aAttr = aAttr->mNext; @@ -216,7 +230,25 @@ struct HTMLAttribute { FindHTMLAttribute(nsIAtom* aAttrName, const HTMLAttribute* aAttr) { while (aAttr) { - if (aAttrName == aAttr->mAttribute) { + if (aAttrName == aAttr->mAttribute.mAtom) { + return aAttr; + } + aAttr = aAttr->mNext; + } + return nsnull; + } + + static HTMLAttribute* + FindHTMLAttribute(nsIAtom* aAttrName, PRInt32 aNamespaceID, + HTMLAttribute* aAttr) + { + // Just a precaution + if (aNamespaceID == kNameSpaceID_None) + return FindHTMLAttribute(aAttrName, aAttr); + + while (aAttr) { + if (!aAttr->mAttribute.IsAtom() && + aAttr->mAttribute.GetNodeInfo()->Equals(aAttrName, aNamespaceID)) { return aAttr; } aAttr = aAttr->mNext; @@ -228,7 +260,28 @@ struct HTMLAttribute { RemoveHTMLAttribute(nsIAtom* aAttrName, HTMLAttribute** aAttr) { while (*aAttr) { - if ((*aAttr)->mAttribute == aAttrName) { + if ((*aAttr)->mAttribute.mAtom == aAttrName) { + HTMLAttribute* attr = *aAttr; + *aAttr = (*aAttr)->mNext; + delete attr; + return PR_TRUE; + } + aAttr = &((*aAttr)->mNext); + } + return PR_FALSE; + } + + static PRBool + RemoveHTMLAttribute(nsIAtom* aAttrName, PRInt32 aNamespaceID, + HTMLAttribute** aAttr) + { + if (aNamespaceID == kNameSpaceID_None) + return RemoveHTMLAttribute(aAttrName, aAttr); + + while (*aAttr) { + if (!(*aAttr)->mAttribute.IsAtom() && + (*aAttr)->mAttribute.GetNodeInfo()->Equals(aAttrName, + aNamespaceID)) { HTMLAttribute* attr = *aAttr; *aAttr = (*aAttr)->mNext; delete attr; @@ -249,52 +302,14 @@ struct HTMLAttribute { } #endif - nsIAtom* mAttribute; + nsHTMLAttrName mAttribute; nsHTMLValue mValue; HTMLAttribute* mNext; }; // ---------------- -MOZ_DECL_CTOR_COUNTER(nsClassList) - -struct nsClassList { - nsClassList(nsIAtom* aAtom) - : mAtom(aAtom), // take ref - mNext(nsnull) - { - MOZ_COUNT_CTOR(nsClassList); - } - - nsClassList(const nsClassList& aCopy) - : mAtom(aCopy.mAtom), - mNext(nsnull) - { - MOZ_COUNT_CTOR(nsClassList); - NS_IF_ADDREF(mAtom); - if (aCopy.mNext) { - mNext = new nsClassList(*(aCopy.mNext)); - } - } - - ~nsClassList(void) - { - MOZ_COUNT_DTOR(nsClassList); - Reset(); - } - - void Reset(void) - { - NS_IF_RELEASE(mAtom); - if (mNext) { - delete mNext; - mNext = nsnull; - } - } - - nsIAtom* mAtom; - nsClassList* mNext; -}; +MOZ_DECL_CTOR_COUNTER(nsHTMLClassList) // ---------------- @@ -468,7 +483,7 @@ nsHTMLMappedAttributes::SetAttribute(nsIAtom* aAttrName, const nsAString& aValue return NS_ERROR_NULL_POINTER; } - if (mFirst.mAttribute) { // do we already have any? + if (mFirst.mAttribute.mBits) { // do we already have any? HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(aAttrName, &mFirst); if (attr) { attr->mValue.SetStringValue(aValue); @@ -476,7 +491,7 @@ nsHTMLMappedAttributes::SetAttribute(nsIAtom* aAttrName, const nsAString& aValue else { // add new attribute // keep these arbitrarily sorted so they'll equal regardless of set order - if (aAttrName < mFirst.mAttribute) { // before first, move first down one + if (aAttrName < mFirst.mAttribute.mAtom) { // before first, move first down one attr = new HTMLAttribute(mFirst); if (attr) { attr->mNext = mFirst.mNext; @@ -491,7 +506,7 @@ nsHTMLMappedAttributes::SetAttribute(nsIAtom* aAttrName, const nsAString& aValue attr = new HTMLAttribute(aAttrName, aValue); if (attr) { HTMLAttribute* prev = &mFirst; - while (prev->mNext && (prev->mNext->mAttribute < aAttrName)) { + while (prev->mNext && (prev->mNext->mAttribute.mAtom < aAttrName)) { prev = prev->mNext; } attr->mNext = prev->mNext; @@ -518,7 +533,7 @@ nsHTMLMappedAttributes::SetAttribute(nsIAtom* aAttrName, const nsHTMLValue& aVal return NS_ERROR_NULL_POINTER; } - if (mFirst.mAttribute) { // do we already have any? + if (mFirst.mAttribute.mBits) { // do we already have any? HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(aAttrName, &mFirst); if (attr) { attr->mValue = aValue; @@ -526,7 +541,7 @@ nsHTMLMappedAttributes::SetAttribute(nsIAtom* aAttrName, const nsHTMLValue& aVal else { // add new attribute // keep these arbitrarily sorted so they'll hash regardless of set order - if (aAttrName < mFirst.mAttribute) { // before first, move first down one + if (aAttrName < mFirst.mAttribute.mAtom) { // before first, move first down one attr = new HTMLAttribute(mFirst); if (attr) { attr->mNext = mFirst.mNext; @@ -541,7 +556,7 @@ nsHTMLMappedAttributes::SetAttribute(nsIAtom* aAttrName, const nsHTMLValue& aVal attr = new HTMLAttribute(aAttrName, aValue); if (attr) { HTMLAttribute* prev = &mFirst; - while (prev->mNext && (prev->mNext->mAttribute < aAttrName)) { + while (prev->mNext && (prev->mNext->mAttribute.mAtom < aAttrName)) { prev = prev->mNext; } attr->mNext = prev->mNext; @@ -568,7 +583,7 @@ nsHTMLMappedAttributes::UnsetAttribute(nsIAtom* aAttrName, PRInt32& aAttrCount) return NS_ERROR_NULL_POINTER; } - if (aAttrName == mFirst.mAttribute) { + if (aAttrName == mFirst.mAttribute.mAtom) { if (mFirst.mNext) { HTMLAttribute* attr = mFirst.mNext; mFirst = *attr; @@ -680,7 +695,7 @@ nsHTMLMappedAttributes::HashValue(PRUint32& aValue) const const HTMLAttribute* attr = &mFirst; while (nsnull != attr) { - if (nsnull != attr->mAttribute) { + if (attr->mAttribute.mAtom) { aValue = aValue ^ attr->HashValue(); } attr = attr->mNext; @@ -821,160 +836,29 @@ void nsHTMLMappedAttributes::SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult) //-------------------- -const PRInt32 kNameBufferSize = 4; - -class HTMLAttributesImpl: public nsIHTMLAttributes { -public: - void* operator new(size_t size); - void* operator new(size_t size, nsIArena* aArena); - void operator delete(void* ptr); - - HTMLAttributesImpl(void); - HTMLAttributesImpl(const HTMLAttributesImpl& aCopy); - virtual ~HTMLAttributesImpl(void); - - NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - // nsIHTMLAttributes - NS_IMETHOD SetAttributeFor(nsIAtom* aAttrName, const nsHTMLValue& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet, - PRInt32& aAttrCount); - NS_IMETHOD SetAttributeFor(nsIAtom* aAttrName, const nsAString& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet); - NS_IMETHOD UnsetAttributeFor(nsIAtom* aAttrName, - nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet, - PRInt32& aAttrCount); - - NS_IMETHOD GetAttribute(nsIAtom* aAttrName, - nsHTMLValue& aValue) const; - NS_IMETHOD GetAttribute(nsIAtom* aAttribute, - const nsHTMLValue** aValue) const; - - NS_IMETHOD_(PRBool) HasAttribute(nsIAtom* aAttrName) const; - - NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, - nsIAtom*& aName) const; - - NS_IMETHOD GetAttributeCount(PRInt32& aCount) const; - - NS_IMETHOD GetID(nsIAtom*& aResult) const; - NS_IMETHOD GetClasses(nsVoidArray& aArray) const; - NS_IMETHOD HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const; - - NS_IMETHOD Clone(nsIHTMLAttributes** aInstancePtrResult) const; - - NS_IMETHOD SetStyleSheet(nsIHTMLStyleSheet* aSheet); - - NS_IMETHOD WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker) const; - -#ifdef UNIQUE_ATTR_SUPPORT - NS_IMETHOD AddContentRef(void); - NS_IMETHOD ReleaseContentRef(void); - NS_IMETHOD GetContentRefCount(PRInt32& aCount) const; -#endif - NS_IMETHOD Reset(void); - -#ifdef DEBUG - NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const; - - void SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult); -#endif - -protected: - virtual nsresult SetAttributeName(nsIAtom* aAttrName, PRBool& aFound); - virtual nsresult UnsetAttributeName(nsIAtom* aAttrName, PRBool& aFound); - virtual nsresult EnsureSingleMappedFor(nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet, - PRBool aCreate); - virtual nsresult UniqueMapped(nsIHTMLStyleSheet* aSheet); - -private: - HTMLAttributesImpl& operator=(const HTMLAttributesImpl& aCopy); - PRBool operator==(const HTMLAttributesImpl& aCopy) const; - -protected: - PRUint32 mInHeap : 1; - PRUint32 mRefCnt : 31; - NS_DECL_OWNINGTHREAD // for thread-safety checking - - nsIAtom** mAttrNames; - PRInt32 mAttrCount; - PRInt32 mAttrSize; - HTMLAttribute* mFirstUnmapped; - nsHTMLMappedAttributes* mMapped; - nsIAtom* mID; - nsClassList mFirstClass; - - nsIAtom* mNameBuffer[kNameBufferSize]; -}; - -void* HTMLAttributesImpl::operator new(size_t size) -{ - HTMLAttributesImpl* rv = (HTMLAttributesImpl*) ::operator new(size); -#ifdef NS_DEBUG - if (nsnull != rv) { - memset(rv, 0xEE, size); - } -#endif - rv->mInHeap = 1; - return (void*) rv; -} - -void* HTMLAttributesImpl::operator new(size_t size, nsIArena* aArena) -{ - HTMLAttributesImpl* rv = (HTMLAttributesImpl*) aArena->Alloc(PRInt32(size)); -#ifdef NS_DEBUG - if (nsnull != rv) { - memset(rv, 0xEE, size); - } -#endif - rv->mInHeap = 0; - return (void*) rv; -} - -void HTMLAttributesImpl::operator delete(void* ptr) -{ - HTMLAttributesImpl* attr = (HTMLAttributesImpl*) ptr; - if (nsnull != attr) { - if (attr->mInHeap) { - ::operator delete(ptr); - } - } -} - -HTMLAttributesImpl::HTMLAttributesImpl(void) +nsHTMLAttributes::nsHTMLAttributes(void) : mAttrNames(mNameBuffer), mAttrCount(0), - mAttrSize(kNameBufferSize), + mAttrSize(kHTMLAttrNameBufferSize), mFirstUnmapped(nsnull), mMapped(nsnull), mID(nsnull), mFirstClass(nsnull) { - NS_INIT_REFCNT(); } -HTMLAttributesImpl::HTMLAttributesImpl(const HTMLAttributesImpl& aCopy) +nsHTMLAttributes::nsHTMLAttributes(const nsHTMLAttributes& aCopy) : mAttrNames(mNameBuffer), mAttrCount(aCopy.mAttrCount), - mAttrSize(kNameBufferSize), + mAttrSize(kHTMLAttrNameBufferSize), mFirstUnmapped(nsnull), mMapped(aCopy.mMapped), mID(aCopy.mID), mFirstClass(aCopy.mFirstClass) { - NS_INIT_REFCNT(); - if (mAttrCount) { if (mAttrSize < mAttrCount) { - mAttrNames = new nsIAtom*[mAttrCount]; + mAttrNames = new nsHTMLAttrName[mAttrCount]; if (mAttrNames) { mAttrSize = mAttrCount; } @@ -986,7 +870,7 @@ HTMLAttributesImpl::HTMLAttributesImpl(const HTMLAttributesImpl& aCopy) PRInt32 index = mAttrCount; while (0 < index--) { mAttrNames[index] = aCopy.mAttrNames[index]; - NS_ADDREF(mAttrNames[index]); + mAttrNames[index].Addref(); } } @@ -999,16 +883,14 @@ HTMLAttributesImpl::HTMLAttributesImpl(const HTMLAttributesImpl& aCopy) NS_IF_ADDREF(mID); } -HTMLAttributesImpl::~HTMLAttributesImpl(void) +nsHTMLAttributes::~nsHTMLAttributes(void) { Reset(); } -NS_IMPL_ISUPPORTS1(HTMLAttributesImpl, nsIHTMLAttributes) - const PRUnichar kNullCh = PRUnichar('\0'); -static void ParseClasses(const nsAString& aClassString, nsClassList& aClassList) +static void ParseClasses(const nsAString& aClassString, nsHTMLClassList& aClassList) { nsAutoString classStr(aClassString); // copy to work buffer classStr.Append(kNullCh); // put an extra null at the end @@ -1016,7 +898,7 @@ static void ParseClasses(const nsAString& aClassString, nsClassList& aClassList) PRUnichar* start = (PRUnichar*)(const PRUnichar*)classStr.get(); PRUnichar* end = start; - nsClassList* list = &aClassList; + nsHTMLClassList* list = &aClassList; while (list && (kNullCh != *start)) { while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space start++; @@ -1033,7 +915,7 @@ static void ParseClasses(const nsAString& aClassString, nsClassList& aClassList) list->mAtom = NS_NewAtom(start); } else { - list->mNext = new nsClassList(NS_NewAtom(start)); + list->mNext = new nsHTMLClassList(NS_NewAtom(start)); list = list->mNext; } } @@ -1043,20 +925,32 @@ static void ParseClasses(const nsAString& aClassString, nsClassList& aClassList) } nsresult -HTMLAttributesImpl::SetAttributeName(nsIAtom* aAttrName, PRBool& aFound) +nsHTMLAttributes::SetAttributeName(nsHTMLAttrName aAttrName, PRBool& aFound) { PRInt32 index = mAttrCount; - while (0 < index--) { - if (mAttrNames[index] == aAttrName) { - aFound = PR_TRUE; - return NS_OK; + if (aAttrName.IsAtom()) { + while (0 < index--) { + if (mAttrNames[index].mAtom == aAttrName.mAtom) { + aFound = PR_TRUE; + return NS_OK; + } + } + } + else { + nsINodeInfo* ni = aAttrName.GetNodeInfo(); + while (0 < index--) { + if (!mAttrNames[index].IsAtom() && + ni->NameAndNamespaceEquals(mAttrNames[index].GetNodeInfo())) { + aFound = PR_TRUE; + return NS_OK; + } } } aFound = PR_FALSE; if (mAttrCount == mAttrSize) { // no more room, grow buffer - nsIAtom** buffer = new nsIAtom*[mAttrSize + 4]; + nsHTMLAttrName* buffer = new nsHTMLAttrName[mAttrSize + 4]; if (buffer) { - memcpy(buffer, mAttrNames, sizeof(nsIAtom*) * mAttrCount); + memcpy(buffer, mAttrNames, sizeof(nsHTMLAttrName) * mAttrCount); mAttrSize += 4; if (mAttrNames != mNameBuffer) { delete [] mAttrNames; @@ -1067,19 +961,20 @@ HTMLAttributesImpl::SetAttributeName(nsIAtom* aAttrName, PRBool& aFound) return NS_ERROR_OUT_OF_MEMORY; } } - mAttrNames[mAttrCount++] = aAttrName; - NS_ADDREF(aAttrName); + mAttrNames[mAttrCount] = aAttrName; + mAttrNames[mAttrCount++].Addref(); return NS_OK; } nsresult -HTMLAttributesImpl::UnsetAttributeName(nsIAtom* aAttrName, PRBool& aFound) +nsHTMLAttributes::UnsetAttributeName(nsIAtom* aAttrName, PRBool& aFound) { PRInt32 index = mAttrCount; while (0 < index--) { - if (mAttrNames[index] == aAttrName) { + if (mAttrNames[index].mAtom == aAttrName) { mAttrCount--; - if ((mAttrNames != mNameBuffer) && (mAttrCount <= (kNameBufferSize / 2))) { + if (mAttrNames != mNameBuffer && + mAttrCount <= (kHTMLAttrNameBufferSize / 2)) { // go back to using internal buffer if (0 < index) { memcpy(mNameBuffer, mAttrNames, index * sizeof(nsIAtom*)); @@ -1090,7 +985,7 @@ HTMLAttributesImpl::UnsetAttributeName(nsIAtom* aAttrName, PRBool& aFound) } delete [] mAttrNames; mAttrNames = mNameBuffer; - mAttrSize = kNameBufferSize; + mAttrSize = kHTMLAttrNameBufferSize; } else { if (index < mAttrCount) { @@ -1108,9 +1003,49 @@ HTMLAttributesImpl::UnsetAttributeName(nsIAtom* aAttrName, PRBool& aFound) } nsresult -HTMLAttributesImpl::EnsureSingleMappedFor(nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet, - PRBool aCreate) +nsHTMLAttributes::UnsetAttributeName(nsIAtom* aAttrName, PRInt32 aNamespaceID, + PRBool& aFound) +{ + NS_ASSERTION(aNamespaceID != kNameSpaceID_None, + "namespaced UnsetAttributeName called with null namespace"); + PRInt32 index = mAttrCount; + while (0 < index--) { + if (!mAttrNames[index].IsAtom() && + mAttrNames[index].GetNodeInfo()->Equals(aAttrName, aNamespaceID)) { + mAttrNames[index].Release(); + mAttrCount--; + if (mAttrNames != mNameBuffer && + mAttrCount <= (kHTMLAttrNameBufferSize / 2)) { + // go back to using internal buffer + if (0 < index) { + memcpy(mNameBuffer, mAttrNames, index * sizeof(nsIAtom*)); + } + if (index < mAttrCount) { + memcpy(&mNameBuffer[index], &mAttrNames[index + 1], + (mAttrCount - index) * sizeof(nsIAtom*)); + } + delete [] mAttrNames; + mAttrNames = mNameBuffer; + mAttrSize = kHTMLAttrNameBufferSize; + } + else { + if (index < mAttrCount) { + memmove(&(mAttrNames[index]), &(mAttrNames[index + 1]), + (mAttrCount - index) * sizeof(nsIAtom*)); + } + } + aFound = PR_TRUE; + return NS_OK; + } + } + aFound = PR_FALSE; + return NS_OK; +} + +nsresult +nsHTMLAttributes::EnsureSingleMappedFor(nsIHTMLContent* aContent, + nsIHTMLStyleSheet* aSheet, + PRBool aCreate) { nsresult result = NS_OK; if (mMapped) { @@ -1142,7 +1077,7 @@ HTMLAttributesImpl::EnsureSingleMappedFor(nsIHTMLContent* aContent, } nsresult -HTMLAttributesImpl::UniqueMapped(nsIHTMLStyleSheet* aSheet) +nsHTMLAttributes::UniqueMapped(nsIHTMLStyleSheet* aSheet) { nsresult result = NS_OK; @@ -1165,9 +1100,9 @@ HTMLAttributesImpl::UniqueMapped(nsIHTMLStyleSheet* aSheet) } NS_IMETHODIMP -HTMLAttributesImpl::SetAttributeFor(nsIAtom* aAttrName, const nsAString& aValue, - PRBool aMappedToStyle, nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet) +nsHTMLAttributes::SetAttributeFor(nsIAtom* aAttrName, const nsAString& aValue, + PRBool aMappedToStyle, nsIHTMLContent* aContent, + nsIHTMLStyleSheet* aSheet) { nsresult result = NS_OK; @@ -1215,17 +1150,18 @@ HTMLAttributesImpl::SetAttributeFor(nsIAtom* aAttrName, const nsAString& aValue, } NS_IMETHODIMP -HTMLAttributesImpl::SetAttributeFor(nsIAtom* aAttrName, - const nsHTMLValue& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet, - PRInt32& aCount) +nsHTMLAttributes::SetAttributeFor(nsIAtom* aAttrName, + const nsHTMLValue& aValue, + PRBool aMappedToStyle, + nsIHTMLContent* aContent, + nsIHTMLStyleSheet* aSheet, + PRInt32& aCount) { nsresult result = NS_OK; if (eHTMLUnit_Null == aValue.GetUnit()) { - return UnsetAttributeFor(aAttrName, aContent, aSheet, aCount); + return UnsetAttributeFor(aAttrName, kNameSpaceID_None, aContent, + aSheet, aCount); } if (nsHTMLAtoms::id == aAttrName) { @@ -1280,23 +1216,32 @@ HTMLAttributesImpl::SetAttributeFor(nsIAtom* aAttrName, } NS_IMETHODIMP -HTMLAttributesImpl::UnsetAttributeFor(nsIAtom* aAttrName, - nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet, - PRInt32& aCount) +nsHTMLAttributes::UnsetAttributeFor(nsIAtom* aAttrName, + PRInt32 aNamespaceID, + nsIHTMLContent* aContent, + nsIHTMLStyleSheet* aSheet, + PRInt32& aCount) { nsresult result = NS_OK; - if (nsHTMLAtoms::id == aAttrName) { - NS_IF_RELEASE(mID); + PRBool haveAttr; + + if (aNamespaceID == kNameSpaceID_None) { + if (nsHTMLAtoms::id == aAttrName) { + NS_IF_RELEASE(mID); + } + else if (nsHTMLAtoms::kClass == aAttrName) { + mFirstClass.Reset(); + } + result = UnsetAttributeName(aAttrName, haveAttr); } - else if (nsHTMLAtoms::kClass == aAttrName) { - mFirstClass.Reset(); + else { + result = UnsetAttributeName(aAttrName, aNamespaceID, haveAttr); } - PRBool haveAttr; - result = UnsetAttributeName(aAttrName, haveAttr); if (NS_SUCCEEDED(result) && haveAttr) { - if (! HTMLAttribute::RemoveHTMLAttribute(aAttrName, &mFirstUnmapped)) { + if (!HTMLAttribute::RemoveHTMLAttribute(aAttrName, aNamespaceID, + &mFirstUnmapped) && + aNamespaceID == kNameSpaceID_None) { // must be mapped if (mMapped) { EnsureSingleMappedFor(aContent, aSheet, PR_FALSE); @@ -1318,8 +1263,8 @@ HTMLAttributesImpl::UnsetAttributeFor(nsIAtom* aAttrName, } NS_IMETHODIMP -HTMLAttributesImpl::GetAttribute(nsIAtom* aAttrName, - nsHTMLValue& aValue) const +nsHTMLAttributes::GetAttribute(nsIAtom* aAttrName, + nsHTMLValue& aValue) const { nsresult result = NS_CONTENT_ATTR_NOT_THERE; @@ -1345,8 +1290,8 @@ HTMLAttributesImpl::GetAttribute(nsIAtom* aAttrName, } NS_IMETHODIMP -HTMLAttributesImpl::GetAttribute(nsIAtom* aAttrName, - const nsHTMLValue** aValue) const +nsHTMLAttributes::GetAttribute(nsIAtom* aAttrName, + const nsHTMLValue** aValue) const { nsresult result = NS_CONTENT_ATTR_NOT_THERE; @@ -1372,40 +1317,113 @@ HTMLAttributesImpl::GetAttribute(nsIAtom* aAttrName, } NS_IMETHODIMP_(PRBool) -HTMLAttributesImpl::HasAttribute(nsIAtom* aAttrName) const +nsHTMLAttributes::HasAttribute(nsIAtom* aAttrName, PRInt32 aNamespaceID) const { - if (mMapped && mMapped->HasAttribute(aAttrName)) + if (mMapped && aNamespaceID == kNameSpaceID_None && + mMapped->HasAttribute(aAttrName)) return PR_TRUE; - const HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(aAttrName, mFirstUnmapped); - return attr != nsnull; + return (PRBool)HTMLAttribute::FindHTMLAttribute(aAttrName, aNamespaceID, mFirstUnmapped); +} + +NS_IMETHODIMP +nsHTMLAttributes::SetAttributeFor(nsINodeInfo* aAttrName, + const nsAString& aValue) +{ + NS_ENSURE_ARG_POINTER(aAttrName); + nsresult rv; +#ifdef DEBUG + { + PRInt32 namespaceID; + aAttrName->GetNamespaceID(namespaceID); + NS_ASSERTION(namespaceID != kNameSpaceID_None, "namespace is null in SetAttributeFor"); + } +#endif + + PRBool haveAttr; + rv = SetAttributeName(aAttrName, haveAttr); + NS_ENSURE_SUCCESS(rv, rv); + if (haveAttr) { + PRInt32 namespaceID; + nsCOMPtr localName; + aAttrName->GetNamespaceID(namespaceID); + aAttrName->GetNameAtom(*getter_AddRefs(localName)); + HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(localName, + namespaceID, + mFirstUnmapped); + NS_ASSERTION(attr, "failed to find attribute"); + if (!attr) + return NS_ERROR_FAILURE; + attr->mValue.SetStringValue(aValue); + } + else { + HTMLAttribute* attr = new HTMLAttribute(aAttrName, aValue); + NS_ENSURE_TRUE(attr, NS_ERROR_OUT_OF_MEMORY); + attr->mNext = mFirstUnmapped; + mFirstUnmapped = attr; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLAttributes::GetAttribute(nsIAtom* aAttrName, PRInt32 aNamespaceID, + nsIAtom*& aPrefix, + const nsHTMLValue** aValue) const +{ + NS_ASSERTION(aNamespaceID != kNameSpaceID_None, "namespace is null in UnsetAttributeFor"); + + const HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(aAttrName, + aNamespaceID, + mFirstUnmapped); + if (!attr) { + *aValue = nsnull; + return NS_CONTENT_ATTR_NOT_THERE; + } + + *aValue = &attr->mValue; + attr->mAttribute.GetNodeInfo()->GetPrefixAtom(aPrefix); + return attr->mValue.GetUnit() == eHTMLUnit_Null ? + NS_CONTENT_ATTR_NO_VALUE : + NS_CONTENT_ATTR_HAS_VALUE; } - NS_IMETHODIMP -HTMLAttributesImpl::GetAttributeNameAt(PRInt32 aIndex, - nsIAtom*& aName) const +nsHTMLAttributes::GetAttributeNameAt(PRInt32 aIndex, + PRInt32& aNamespaceID, + nsIAtom*& aName, + nsIAtom*& aPrefix) const { nsresult result = NS_ERROR_ILLEGAL_VALUE; if ((0 <= aIndex) && (aIndex < mAttrCount)) { - aName = mAttrNames[aIndex]; - NS_ADDREF(aName); + if (mAttrNames[aIndex].IsAtom()) { + aNamespaceID = kNameSpaceID_None; + aName = mAttrNames[aIndex].mAtom; + NS_ADDREF(aName); + aPrefix = nsnull; + } + else { + nsINodeInfo* ni = mAttrNames[aIndex].GetNodeInfo(); + ni->GetNamespaceID(aNamespaceID); + ni->GetNameAtom(aName); + ni->GetPrefixAtom(aPrefix); + } result = NS_OK; } return result; } NS_IMETHODIMP -HTMLAttributesImpl::GetAttributeCount(PRInt32& aCount) const +nsHTMLAttributes::GetAttributeCount(PRInt32& aCount) const { aCount = mAttrCount; return NS_OK; } NS_IMETHODIMP -HTMLAttributesImpl::GetID(nsIAtom*& aResult) const +nsHTMLAttributes::GetID(nsIAtom*& aResult) const { aResult = mID; NS_IF_ADDREF(aResult); @@ -1413,10 +1431,10 @@ HTMLAttributesImpl::GetID(nsIAtom*& aResult) const } NS_IMETHODIMP -HTMLAttributesImpl::GetClasses(nsVoidArray& aArray) const +nsHTMLAttributes::GetClasses(nsVoidArray& aArray) const { aArray.Clear(); - const nsClassList* classList = &mFirstClass; + const nsHTMLClassList* classList = &mFirstClass; while (classList && classList->mAtom) { aArray.AppendElement(classList->mAtom); // NOTE atom is not addrefed classList = classList->mNext; @@ -1425,11 +1443,11 @@ HTMLAttributesImpl::GetClasses(nsVoidArray& aArray) const } NS_IMETHODIMP -HTMLAttributesImpl::HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const +nsHTMLAttributes::HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const { NS_PRECONDITION(aClass, "unexpected null pointer"); if (mFirstClass.mAtom) { - const nsClassList* classList = &mFirstClass; + const nsHTMLClassList* classList = &mFirstClass; if (aCaseSensitive) { do { if (classList->mAtom == aClass) @@ -1458,21 +1476,21 @@ HTMLAttributesImpl::HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const #ifdef UNIQUE_ATTR_SUPPORT NS_IMETHODIMP -HTMLAttributesImpl::AddContentRef(void) +nsHTMLAttributes::AddContentRef(void) { ++mContentRefCount; return NS_OK; } NS_IMETHODIMP -HTMLAttributesImpl::ReleaseContentRef(void) +nsHTMLAttributes::ReleaseContentRef(void) { --mContentRefCount; return NS_OK; } NS_IMETHODIMP -HTMLAttributesImpl::GetContentRefCount(PRInt32& aCount) const +nsHTMLAttributes::GetContentRefCount(PRInt32& aCount) const { aCount = mContentRefCount; return NS_OK; @@ -1480,23 +1498,24 @@ HTMLAttributesImpl::GetContentRefCount(PRInt32& aCount) const #endif NS_IMETHODIMP -HTMLAttributesImpl::Clone(nsIHTMLAttributes** aInstancePtrResult) const +nsHTMLAttributes::Clone(nsHTMLAttributes** aInstancePtrResult) const { if (aInstancePtrResult == nsnull) { return NS_ERROR_NULL_POINTER; } - HTMLAttributesImpl* clone = new HTMLAttributesImpl(*this); + nsHTMLAttributes* clone = new nsHTMLAttributes(*this); if (nsnull == clone) { return NS_ERROR_OUT_OF_MEMORY; } - return clone->QueryInterface(NS_GET_IID(nsIHTMLAttributes), (void **) aInstancePtrResult); + *aInstancePtrResult = clone; + return NS_OK; } NS_IMETHODIMP -HTMLAttributesImpl::SetStyleSheet(nsIHTMLStyleSheet* aSheet) +nsHTMLAttributes::SetStyleSheet(nsIHTMLStyleSheet* aSheet) { if (mMapped && (aSheet != mMapped->mSheet)) { mMapped->SetStyleSheet(aSheet); @@ -1506,7 +1525,7 @@ HTMLAttributesImpl::SetStyleSheet(nsIHTMLStyleSheet* aSheet) } NS_IMETHODIMP -HTMLAttributesImpl::WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker) const +nsHTMLAttributes::WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker) const { if (aRuleWalker && mMapped) aRuleWalker->Forward((nsIStyleRule*)mMapped); @@ -1514,17 +1533,17 @@ HTMLAttributesImpl::WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker) con } NS_IMETHODIMP -HTMLAttributesImpl::Reset(void) +nsHTMLAttributes::Reset(void) { // Release atoms first, then the table if it was malloc'd PRInt32 i, n = mAttrCount; for (i = 0; i < n; i++) { - NS_IF_RELEASE(mAttrNames[i]); + mAttrNames[i].Release(); } if (mAttrNames != mNameBuffer) { delete [] mAttrNames; mAttrNames = mNameBuffer; - mAttrSize = kNameBufferSize; + mAttrSize = kHTMLAttrNameBufferSize; } mAttrCount = 0; @@ -1544,7 +1563,7 @@ HTMLAttributesImpl::Reset(void) #ifdef DEBUG NS_IMETHODIMP -HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const +nsHTMLAttributes::List(FILE* out, PRInt32 aIndent) const { PRInt32 index = 0; while (index < mAttrCount) { @@ -1552,9 +1571,22 @@ HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const for (indent = aIndent; --indent >= 0; ) fputs(" ", out); nsHTMLValue value; - GetAttribute(mAttrNames[index], value); nsAutoString buffer; - mAttrNames[index]->ToString(buffer); + if (mAttrNames[index].IsAtom()) { + GetAttribute(mAttrNames[index].mAtom, value); + mAttrNames[index].mAtom->ToString(buffer); + } + else { + nsINodeInfo* ni = mAttrNames[index].GetNodeInfo(); + PRInt32 namespaceID; + nsCOMPtr localName, prefix; + ni->GetNameAtom(*getter_AddRefs(localName)); + ni->GetNamespaceID(namespaceID); + const nsHTMLValue *tmp; + GetAttribute(localName, namespaceID, *getter_AddRefs(prefix), &tmp); + value = *tmp; + ni->GetQualifiedName(buffer); + } if (eHTMLUnit_Null != value.GetUnit()) { buffer.Append(NS_LITERAL_STRING(" = ")); value.AppendToString(buffer); @@ -1564,7 +1596,7 @@ HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const return NS_OK; } -void HTMLAttributesImpl::SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult) +void nsHTMLAttributes::SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult) { PRUint32 sum = 0; @@ -1602,19 +1634,17 @@ void HTMLAttributesImpl::SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult) aResult = sum; nsCOMPtr tag; - tag = getter_AddRefs(NS_NewAtom("HTMLAttributesImpl")); + tag = getter_AddRefs(NS_NewAtom("nsHTMLAttributes")); aSizer->AddSize(tag, aResult); } #endif nsresult -NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult) +NS_NewHTMLAttributes(nsHTMLAttributes** aInstancePtrResult) { - *aInstancePtrResult = new HTMLAttributesImpl(); + *aInstancePtrResult = new nsHTMLAttributes(); NS_ENSURE_TRUE(*aInstancePtrResult, NS_ERROR_OUT_OF_MEMORY); - NS_ADDREF(*aInstancePtrResult); - return NS_OK; } diff --git a/mozilla/content/html/style/src/nsHTMLAttributes.h b/mozilla/content/html/style/src/nsHTMLAttributes.h new file mode 100644 index 00000000000..907bc8ca28b --- /dev/null +++ b/mozilla/content/html/style/src/nsHTMLAttributes.h @@ -0,0 +1,285 @@ +/* -*- Mode: C++; tab-width: 2; 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.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 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 ***** */ +#ifndef nsIHTMLAttributes_h___ +#define nsIHTMLAttributes_h___ + +#include "nsISupports.h" +#include "nsHTMLValue.h" +#include "nsIHTMLContent.h" +#include "nsINodeInfo.h" +class nsIAtom; +class nsISupportsArray; +class nsIHTMLStyleSheet; +class nsRuleWalker; +struct HTMLAttribute; +class nsHTMLMappedAttributes; + +// IID for the nsIHTMLMappedAttributes interface {0fdd27a0-2e7b-11d3-8060-006008159b5a} +#define NS_IHTML_MAPPED_ATTRIBUTES_IID \ +{0x0fdd27a0, 0x2e7b, 0x11d3, \ + {0x80, 0x60, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}} + +class nsIHTMLMappedAttributes : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTML_MAPPED_ATTRIBUTES_IID); + + NS_IMETHOD GetAttribute(nsIAtom* aAttrName, nsHTMLValue& aValue) const = 0; + NS_IMETHOD GetAttribute(nsIAtom* aAttrName, const nsHTMLValue** aValue) const = 0; + NS_IMETHOD GetAttributeCount(PRInt32& aCount) const = 0; + + NS_IMETHOD Equals(const nsIHTMLMappedAttributes* aAttributes, PRBool& aResult) const = 0; + NS_IMETHOD HashValue(PRUint32& aValue) const = 0; + + // Sheet accessors for unique table management + NS_IMETHOD SetUniqued(PRBool aUniqued) = 0; + NS_IMETHOD GetUniqued(PRBool& aUniqued) = 0; + NS_IMETHOD DropStyleSheetReference(void) = 0; + +#ifdef DEBUG + virtual void SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult) = 0; +#endif +}; + + +const PRInt32 kHTMLAttrNameBufferSize = 4; + +struct nsHTMLClassList { + nsHTMLClassList(nsIAtom* aAtom) + : mAtom(aAtom), // take ref + mNext(nsnull) + { + MOZ_COUNT_CTOR(nsHTMLClassList); + } + + nsHTMLClassList(const nsHTMLClassList& aCopy) + : mAtom(aCopy.mAtom), + mNext(nsnull) + { + MOZ_COUNT_CTOR(nsHTMLClassList); + NS_IF_ADDREF(mAtom); + if (aCopy.mNext) { + mNext = new nsHTMLClassList(*(aCopy.mNext)); + } + } + + ~nsHTMLClassList(void) + { + MOZ_COUNT_DTOR(nsHTMLClassList); + Reset(); + } + + void Reset(void) + { + NS_IF_RELEASE(mAtom); + if (mNext) { + delete mNext; + mNext = nsnull; + } + } + + nsIAtom* mAtom; + nsHTMLClassList* mNext; +}; + +/* + * union that represents an atom or a nsINodeInfo. It is used to save cycles + * for the common case when an attribute is not in a namespace, and therefore + * can't have a prefix. In that case we only store the attribute name and + * don't spend cycles looking up the right nsINodeInfo in the nodeinfo-hash. + * The union handles NO refcounting automatically, the client has to call + * Addref and Release manually. + */ +#define NS_ATTRNAME_NODEINFO_BIT 0x01 +union nsHTMLAttrName { + nsHTMLAttrName() + { + } + + nsHTMLAttrName(nsIAtom* aAtom) : mAtom(aAtom) + { + NS_ASSERTION(aAtom, "null atom-name in nsHTMLAttrName"); + } + + nsHTMLAttrName(nsINodeInfo* aNodeInfo) : mNodeInfo(aNodeInfo) + { + NS_ASSERTION(aNodeInfo, "null nodeinfo-name in nsHTMLAttrName"); + mBits |= NS_ATTRNAME_NODEINFO_BIT; + } + + PRBool IsAtom() const + { + return !(mBits & NS_ATTRNAME_NODEINFO_BIT); + } + + nsINodeInfo* GetNodeInfo() const + { + NS_ASSERTION(!IsAtom(), "getting NodeInfo-value of atom-name"); + return (nsINodeInfo*)(mBits & ~NS_ATTRNAME_NODEINFO_BIT); + } + + void SetNodeInfo(nsINodeInfo* aNodeInfo) + { + NS_ASSERTION(aNodeInfo, "null nodeinfo-name in nsHTMLAttrName"); + mNodeInfo = aNodeInfo; + mBits |= NS_ATTRNAME_NODEINFO_BIT; + } + + void Addref() + { + // Since both nsINodeInfo and nsIAtom inherits nsISupports as it's first + // interface we can safly assume that it's first in the vtable + nsISupports* name = NS_REINTERPRET_CAST(nsISupports *, + mBits & ~NS_ATTRNAME_NODEINFO_BIT); + + NS_IF_ADDREF(name); + } + + void Release() + { + // Since both nsINodeInfo and nsIAtom inherits nsISupports as it's first + // interface we can safly assume that it's first in the vtable + nsISupports* name = NS_REINTERPRET_CAST(nsISupports *, + mBits & ~NS_ATTRNAME_NODEINFO_BIT); + + NS_IF_RELEASE(name); + mBits = 0; + } + nsIAtom* mAtom; // Used if !(mBits & NS_ATTRNAME_NODEINFO_BIT) + nsINodeInfo* mNodeInfo; // Used if (mBits & NS_ATTRNAME_NODEINFO_BIT) + PRWord mBits; +}; + +class nsHTMLAttributes { +public: + nsHTMLAttributes(void); + nsHTMLAttributes(const nsHTMLAttributes& aCopy); + ~nsHTMLAttributes(void); + + NS_METHOD SetAttributeFor(nsIAtom* aAttrName, const nsHTMLValue& aValue, + PRBool aMappedToStyle, + nsIHTMLContent* aContent, + nsIHTMLStyleSheet* aSheet, + PRInt32& aAttrCount); + NS_METHOD SetAttributeFor(nsIAtom* aAttrName, const nsAString& aValue, + PRBool aMappedToStyle, + nsIHTMLContent* aContent, + nsIHTMLStyleSheet* aSheet); + NS_METHOD UnsetAttributeFor(nsIAtom* aAttrName, + PRInt32 aNamespaceID, + nsIHTMLContent* aContent, + nsIHTMLStyleSheet* aSheet, + PRInt32& aAttrCount); + + NS_METHOD GetAttribute(nsIAtom* aAttrName, + nsHTMLValue& aValue) const; + NS_METHOD GetAttribute(nsIAtom* aAttribute, + const nsHTMLValue** aValue) const; + + NS_METHOD_(PRBool) HasAttribute(nsIAtom* aAttrName, + PRInt32 aNamespaceID) const; + + // Namespace-able methods. The namespace must NOT be null + NS_METHOD SetAttributeFor(nsINodeInfo* aAttrName, + const nsAString& aValue); + NS_METHOD GetAttribute(nsIAtom* aAttrName, PRInt32 aNamespaceID, + nsIAtom*& aPrefix, + const nsHTMLValue** aValue) const; + + + NS_METHOD GetAttributeNameAt(PRInt32 aIndex, + PRInt32& aNamespaceID, + nsIAtom*& aName, + nsIAtom*& aPrefix) const; + + NS_METHOD GetAttributeCount(PRInt32& aCount) const; + + NS_METHOD GetID(nsIAtom*& aResult) const; + NS_METHOD GetClasses(nsVoidArray& aArray) const; + NS_METHOD HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const; + + NS_METHOD Clone(nsHTMLAttributes** aInstancePtrResult) const; + + NS_METHOD SetStyleSheet(nsIHTMLStyleSheet* aSheet); + + NS_METHOD WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker) const; + +#ifdef UNIQUE_ATTR_SUPPORT + NS_METHOD AddContentRef(void); + NS_METHOD ReleaseContentRef(void); + NS_METHOD GetContentRefCount(PRInt32& aCount) const; +#endif + NS_METHOD Reset(void); + +#ifdef DEBUG + NS_METHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const; + + void SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult); +#endif + +protected: + nsresult SetAttributeName(nsHTMLAttrName aAttrName, PRBool& aFound); + nsresult UnsetAttributeName(nsIAtom* aAttrName, PRBool& aFound); + nsresult UnsetAttributeName(nsIAtom* aAttrName, PRInt32 aNamespaceID, + PRBool& aFound); + nsresult EnsureSingleMappedFor(nsIHTMLContent* aContent, + nsIHTMLStyleSheet* aSheet, + PRBool aCreate); + nsresult UniqueMapped(nsIHTMLStyleSheet* aSheet); + +private: + nsHTMLAttributes& operator=(const nsHTMLAttributes& aCopy); + PRBool operator==(const nsHTMLAttributes& aCopy) const; + +protected: + + nsHTMLAttrName* mAttrNames; + PRInt32 mAttrCount; + PRInt32 mAttrSize; + HTMLAttribute* mFirstUnmapped; + nsHTMLMappedAttributes* mMapped; + nsIAtom* mID; + nsHTMLClassList mFirstClass; + + nsHTMLAttrName mNameBuffer[kHTMLAttrNameBufferSize]; +}; + +nsresult +NS_NewHTMLAttributes(nsHTMLAttributes** aInstancePtrResult); + +#endif /* nsIHTMLAttributes_h___ */ diff --git a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp index ee033162a5e..55687c54587 100644 --- a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp @@ -37,7 +37,7 @@ #include "nsISupportsArray.h" #include "nsHashtable.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsILink.h" #include "nsStyleUtil.h" #include "nsIStyleRuleProcessor.h" @@ -852,21 +852,6 @@ public: NS_IMETHOD SetActiveLinkColor(nscolor aColor); NS_IMETHOD SetVisitedLinkColor(nscolor aColor); - // Attribute management methods, aAttributes is an in/out param - NS_IMETHOD SetAttributesFor(nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes); - NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, - const nsAString& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes); - NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, const nsHTMLValue& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes); - NS_IMETHOD UnsetAttributeFor(nsIAtom* aAttribute, nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes); - // Mapped Attribute management methods NS_IMETHOD UniqueMappedAttributes(nsIHTMLMappedAttributes* aMapped, nsIHTMLMappedAttributes*& aUniqueMapped); @@ -1406,75 +1391,6 @@ HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor) return NS_OK; } -NS_IMETHODIMP -HTMLStyleSheetImpl::SetAttributesFor(nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) -{ - if (aAttributes) { - aAttributes->SetStyleSheet(this); - } - return NS_OK; -} - -NS_IMETHODIMP -HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute, - const nsAString& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) -{ - if (!aAttributes) { - nsresult rv = NS_NewHTMLAttributes(&aAttributes); - NS_ENSURE_SUCCESS(rv, rv); - } - - return aAttributes->SetAttributeFor(aAttribute, aValue, aMappedToStyle, - aContent, this); -} - -NS_IMETHODIMP -HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) -{ - nsresult rv = NS_OK; - - if ((!aAttributes) && (eHTMLUnit_Null != aValue.GetUnit())) { - rv = NS_NewHTMLAttributes(&aAttributes); - NS_ENSURE_SUCCESS(rv, rv); - } - - PRInt32 count; - rv = aAttributes->SetAttributeFor(aAttribute, aValue, aMappedToStyle, - aContent, this, count); - if (count == 0) { - NS_RELEASE(aAttributes); - } - - return rv; -} - -NS_IMETHODIMP -HTMLStyleSheetImpl::UnsetAttributeFor(nsIAtom* aAttribute, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) -{ - nsresult result = NS_OK; - - if (aAttributes) { - PRInt32 count; - result = aAttributes->UnsetAttributeFor(aAttribute, aContent, this, count); - if (0 == count) { - NS_RELEASE(aAttributes); - } - } - - return result; - -} - NS_IMETHODIMP HTMLStyleSheetImpl::UniqueMappedAttributes(nsIHTMLMappedAttributes* aMapped, nsIHTMLMappedAttributes*& aUniqueMapped) diff --git a/mozilla/content/html/style/src/nsIHTMLAttributes.h b/mozilla/content/html/style/src/nsIHTMLAttributes.h deleted file mode 100644 index 2dd59f70df5..00000000000 --- a/mozilla/content/html/style/src/nsIHTMLAttributes.h +++ /dev/null @@ -1,146 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; 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.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 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 ***** */ -#ifndef nsIHTMLAttributes_h___ -#define nsIHTMLAttributes_h___ - -#include "nsISupports.h" -#include "nsHTMLValue.h" -#include "nsIHTMLContent.h" -class nsIAtom; -class nsISupportsArray; -class nsIHTMLStyleSheet; -class nsRuleWalker; - -// IID for the nsIHTMLAttributes interface {a18f85f0-c058-11d1-8031-006008159b5a} -#define NS_IHTML_ATTRIBUTES_IID \ -{0xa18f85f0, 0xc058, 0x11d1, \ - {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}} - -// IID for the nsIHTMLMappedAttributes interface {0fdd27a0-2e7b-11d3-8060-006008159b5a} -#define NS_IHTML_MAPPED_ATTRIBUTES_IID \ -{0x0fdd27a0, 0x2e7b, 0x11d3, \ - {0x80, 0x60, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}} - -class nsIHTMLAttributes : public nsISupports -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTML_ATTRIBUTES_IID); - - NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, const nsHTMLValue& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet, - PRInt32& aAttrCount) = 0; - // this string value version lets you avoid an extra string copy, - // the value is still stored in a nsHTMLValue - NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, const nsAString& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet) = 0; - NS_IMETHOD UnsetAttributeFor(nsIAtom* aAttribute, - nsIHTMLContent* aContent, - nsIHTMLStyleSheet* aSheet, - PRInt32& aAttrCount) = 0; - - NS_IMETHOD GetAttribute(nsIAtom* aAttribute, - nsHTMLValue& aValue) const = 0; - NS_IMETHOD GetAttribute(nsIAtom* aAttribute, - const nsHTMLValue** aValue) const = 0; - - NS_IMETHOD_(PRBool) HasAttribute(nsIAtom* aAttrName) const = 0; - - NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, - nsIAtom*& aName) const = 0; - - NS_IMETHOD GetAttributeCount(PRInt32& aAttrCount) const = 0; - - NS_IMETHOD GetID(nsIAtom*& aResult) const = 0; - NS_IMETHOD GetClasses(nsVoidArray& aArray) const = 0; - NS_IMETHOD HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const = 0; - - NS_IMETHOD Clone(nsIHTMLAttributes** aInstancePtrResult) const = 0; - - NS_IMETHOD SetStyleSheet(nsIHTMLStyleSheet* aSheet) = 0; - - NS_IMETHOD WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker) const = 0; - -#ifdef UNIQUE_ATTR_SUPPORT - NS_IMETHOD Equals(const nsIHTMLAttributes* aAttributes, PRBool& aResult) const = 0; - NS_IMETHOD HashValue(PRUint32& aValue) const = 0; - - NS_IMETHOD AddContentRef(void) = 0; - NS_IMETHOD ReleaseContentRef(void) = 0; - NS_IMETHOD GetContentRefCount(PRInt32& aCount) const = 0; - - NS_IMETHOD Reset(void) = 0; -#endif - -#ifdef DEBUG - NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0; - - virtual void SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult) = 0; -#endif -}; - -class nsIHTMLMappedAttributes : public nsISupports -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTML_MAPPED_ATTRIBUTES_IID); - - NS_IMETHOD GetAttribute(nsIAtom* aAttrName, nsHTMLValue& aValue) const = 0; - NS_IMETHOD GetAttribute(nsIAtom* aAttrName, const nsHTMLValue** aValue) const = 0; - NS_IMETHOD GetAttributeCount(PRInt32& aCount) const = 0; - - NS_IMETHOD Equals(const nsIHTMLMappedAttributes* aAttributes, PRBool& aResult) const = 0; - NS_IMETHOD HashValue(PRUint32& aValue) const = 0; - - // Sheet accessors for unique table management - NS_IMETHOD SetUniqued(PRBool aUniqued) = 0; - NS_IMETHOD GetUniqued(PRBool& aUniqued) = 0; - NS_IMETHOD DropStyleSheetReference(void) = 0; - -#ifdef DEBUG - virtual void SizeOf(nsISizeOfHandler* aSizer, PRUint32 &aResult) = 0; -#endif -}; - -nsresult -NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult); - -#endif /* nsIHTMLAttributes_h___ */ - diff --git a/mozilla/content/xml/content/src/nsXMLElement.h b/mozilla/content/xml/content/src/nsXMLElement.h index b60a5317f61..6b498c52cc4 100644 --- a/mozilla/content/xml/content/src/nsXMLElement.h +++ b/mozilla/content/xml/content/src/nsXMLElement.h @@ -48,7 +48,6 @@ #include "nsIStyledContent.h" class nsIEventListenerManager; -class nsIHTMLAttributes; class nsIURI; class nsIWebShell; diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index d77ec88926a..f10b8b1ddd2 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -1762,12 +1762,6 @@ nsXMLContentSink::AddAttributes(const PRUnichar** aAtts, nameSpaceID = kNameSpaceID_None; nameAtom = dont_AddRef(NS_NewAtom(key)); nameSpacePrefix = nsnull; - } else if ((kNameSpaceID_XMLNS == nameSpaceID) && aIsHTML) { - // Ooh, what a nice little hack we have here :-) - nsAutoString name; - nameAtom->ToString(name); - nameAtom = dont_AddRef(NS_NewAtom(NS_LITERAL_STRING("xmlns:") + name)); - nameSpaceID = kNameSpaceID_HTML; // XXX this is wrong, but necessary until HTML can store other namespaces for attrs } nsCOMPtr ni; diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 2e7751db444..91c09b7fee8 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -45,7 +45,6 @@ #include "nsISupportsArray.h" #include "nsHashtable.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" #include "nsIStyleRule.h" #include "nsIFrame.h" #include "nsHTMLAtoms.h" diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index 62d792410f1..bc5e504a3dd 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -57,7 +57,7 @@ #include "nsIImage.h" #include "nsStyleUtil.h" #include "nsStyleConsts.h" -#include "nsIHTMLAttributes.h" +#include "nsIHTMLContent.h" #include "nsIWidget.h" #include "nsIComponentManager.h" #include "nsIView.h" diff --git a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp index 62d792410f1..bc5e504a3dd 100644 --- a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp @@ -57,7 +57,7 @@ #include "nsIImage.h" #include "nsStyleUtil.h" #include "nsStyleConsts.h" -#include "nsIHTMLAttributes.h" +#include "nsIHTMLContent.h" #include "nsIWidget.h" #include "nsIComponentManager.h" #include "nsIView.h" diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index 2e7751db444..91c09b7fee8 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -45,7 +45,6 @@ #include "nsISupportsArray.h" #include "nsHashtable.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" #include "nsIStyleRule.h" #include "nsIFrame.h" #include "nsHTMLAtoms.h" diff --git a/mozilla/layout/html/style/src/nsIHTMLStyleSheet.h b/mozilla/layout/html/style/src/nsIHTMLStyleSheet.h index fc9f8951f5b..aba3e8f5463 100644 --- a/mozilla/layout/html/style/src/nsIHTMLStyleSheet.h +++ b/mozilla/layout/html/style/src/nsIHTMLStyleSheet.h @@ -43,7 +43,6 @@ class nsIAtom; class nsString; class nsHTMLValue; -class nsIHTMLAttributes; class nsIHTMLMappedAttributes; class nsIHTMLContent; class nsIDocument; @@ -65,21 +64,6 @@ public: NS_IMETHOD GetVisitedLinkColor(nscolor& aColor) = 0; NS_IMETHOD SetVisitedLinkColor(nscolor aColor) = 0; - // Attribute management methods - NS_IMETHOD SetAttributesFor(nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) = 0; - NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, - const nsAString& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) = 0; - NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, const nsHTMLValue& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) = 0; - NS_IMETHOD UnsetAttributeFor(nsIAtom* aAttribute, nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) = 0; - // Mapped Attribute management methods NS_IMETHOD UniqueMappedAttributes(nsIHTMLMappedAttributes* aMapped, nsIHTMLMappedAttributes*& aUniqueMapped) = 0; diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.cpp b/mozilla/layout/html/table/src/nsTableRowFrame.cpp index ad71532667a..d81b50d1a33 100644 --- a/mozilla/layout/html/table/src/nsTableRowFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowFrame.cpp @@ -41,7 +41,7 @@ #include "nsIPresContext.h" #include "nsIStyleContext.h" #include "nsStyleConsts.h" -#include "nsIHTMLAttributes.h" +#include "nsIHTMLContent.h" #include "nsHTMLAtoms.h" #include "nsIContent.h" #include "nsTableFrame.h" diff --git a/mozilla/layout/html/tests/TestAttributes.cpp b/mozilla/layout/html/tests/TestAttributes.cpp index 5da5d161b06..a7fb3e9ed36 100644 --- a/mozilla/layout/html/tests/TestAttributes.cpp +++ b/mozilla/layout/html/tests/TestAttributes.cpp @@ -40,7 +40,6 @@ #include "nsCRT.h" #include "nsHTMLParts.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" #include "nsITextContent.h" #include "nsString.h" #include "nsIDocument.h" diff --git a/mozilla/layout/style/nsHTMLStyleSheet.cpp b/mozilla/layout/style/nsHTMLStyleSheet.cpp index ee033162a5e..55687c54587 100644 --- a/mozilla/layout/style/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/style/nsHTMLStyleSheet.cpp @@ -37,7 +37,7 @@ #include "nsISupportsArray.h" #include "nsHashtable.h" #include "nsIHTMLContent.h" -#include "nsIHTMLAttributes.h" +#include "nsHTMLAttributes.h" #include "nsILink.h" #include "nsStyleUtil.h" #include "nsIStyleRuleProcessor.h" @@ -852,21 +852,6 @@ public: NS_IMETHOD SetActiveLinkColor(nscolor aColor); NS_IMETHOD SetVisitedLinkColor(nscolor aColor); - // Attribute management methods, aAttributes is an in/out param - NS_IMETHOD SetAttributesFor(nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes); - NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, - const nsAString& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes); - NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, const nsHTMLValue& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes); - NS_IMETHOD UnsetAttributeFor(nsIAtom* aAttribute, nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes); - // Mapped Attribute management methods NS_IMETHOD UniqueMappedAttributes(nsIHTMLMappedAttributes* aMapped, nsIHTMLMappedAttributes*& aUniqueMapped); @@ -1406,75 +1391,6 @@ HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor) return NS_OK; } -NS_IMETHODIMP -HTMLStyleSheetImpl::SetAttributesFor(nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) -{ - if (aAttributes) { - aAttributes->SetStyleSheet(this); - } - return NS_OK; -} - -NS_IMETHODIMP -HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute, - const nsAString& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) -{ - if (!aAttributes) { - nsresult rv = NS_NewHTMLAttributes(&aAttributes); - NS_ENSURE_SUCCESS(rv, rv); - } - - return aAttributes->SetAttributeFor(aAttribute, aValue, aMappedToStyle, - aContent, this); -} - -NS_IMETHODIMP -HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - PRBool aMappedToStyle, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) -{ - nsresult rv = NS_OK; - - if ((!aAttributes) && (eHTMLUnit_Null != aValue.GetUnit())) { - rv = NS_NewHTMLAttributes(&aAttributes); - NS_ENSURE_SUCCESS(rv, rv); - } - - PRInt32 count; - rv = aAttributes->SetAttributeFor(aAttribute, aValue, aMappedToStyle, - aContent, this, count); - if (count == 0) { - NS_RELEASE(aAttributes); - } - - return rv; -} - -NS_IMETHODIMP -HTMLStyleSheetImpl::UnsetAttributeFor(nsIAtom* aAttribute, - nsIHTMLContent* aContent, - nsIHTMLAttributes*& aAttributes) -{ - nsresult result = NS_OK; - - if (aAttributes) { - PRInt32 count; - result = aAttributes->UnsetAttributeFor(aAttribute, aContent, this, count); - if (0 == count) { - NS_RELEASE(aAttributes); - } - } - - return result; - -} - NS_IMETHODIMP HTMLStyleSheetImpl::UniqueMappedAttributes(nsIHTMLMappedAttributes* aMapped, nsIHTMLMappedAttributes*& aUniqueMapped) diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp index ad71532667a..d81b50d1a33 100644 --- a/mozilla/layout/tables/nsTableRowFrame.cpp +++ b/mozilla/layout/tables/nsTableRowFrame.cpp @@ -41,7 +41,7 @@ #include "nsIPresContext.h" #include "nsIStyleContext.h" #include "nsStyleConsts.h" -#include "nsIHTMLAttributes.h" +#include "nsIHTMLContent.h" #include "nsHTMLAtoms.h" #include "nsIContent.h" #include "nsTableFrame.h" diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp index d4a1218747f..b624e327ddf 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp @@ -64,7 +64,7 @@ #include "nsIImage.h" #include "nsIWidget.h" #include "nsHTMLAtoms.h" -#include "nsIHTMLAttributes.h" +#include "nsIHTMLContent.h" #include "nsIDocument.h" #include "nsIHTMLDocument.h" #include "nsIStyleContext.h"