diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index cc70e17ce97..8c363292c97 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -716,6 +716,7 @@ protected: bool IsAtFrontOfNode(nsIDOMNode *aNode, PRInt32 aOffset); bool IsAtEndOfNode(nsIDOMNode *aNode, PRInt32 aOffset); bool IsOnlyAttribute(nsIDOMNode *aElement, const nsAString *aAttribute); + bool IsOnlyAttribute(const nsIContent* aElement, const nsAString& aAttribute); nsresult RemoveBlockContainer(nsIDOMNode *inNode); nsINode* GetPriorHTMLSibling(nsINode* aNode); diff --git a/editor/libeditor/html/nsHTMLEditorStyle.cpp b/editor/libeditor/html/nsHTMLEditorStyle.cpp index f0c8a954028..34b50518b80 100644 --- a/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -762,20 +762,31 @@ bool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode, const nsAString *aAttribute) { NS_ENSURE_TRUE(aNode && aAttribute, false); // ooops + nsCOMPtr content = do_QueryInterface(aNode); NS_ENSURE_TRUE(content, false); // ooops - - PRUint32 i, attrCount = content->GetAttrCount(); - for (i = 0; i < attrCount; ++i) { - nsAutoString attrString; - const nsAttrName* name = content->GetAttrNameAt(i); + + return IsOnlyAttribute(content, *aAttribute); +} + +bool +nsHTMLEditor::IsOnlyAttribute(const nsIContent* aContent, + const nsAString& aAttribute) +{ + MOZ_ASSERT(aContent); + + PRUint32 attrCount = aContent->GetAttrCount(); + for (PRUint32 i = 0; i < attrCount; ++i) { + const nsAttrName* name = aContent->GetAttrNameAt(i); if (!name->NamespaceEquals(kNameSpaceID_None)) { return false; } + + nsAutoString attrString; name->LocalName()->ToString(attrString); // if it's the attribute we know about, or a special _moz attribute, // keep looking - if (!attrString.Equals(*aAttribute, nsCaseInsensitiveStringComparator()) && + if (!attrString.Equals(aAttribute, nsCaseInsensitiveStringComparator()) && !StringBeginsWith(attrString, NS_LITERAL_STRING("_moz"))) { return false; }