Bug 750079 - Part a: Add IsOnlyAttribute(nsIContent*, const nsAString&); r=ehsan

This commit is contained in:
Ms2ger 2012-05-05 11:00:06 +02:00
parent f051ed6486
commit 3296a0d96c
2 changed files with 18 additions and 6 deletions

View File

@ -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);

View File

@ -762,20 +762,31 @@ bool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode,
const nsAString *aAttribute)
{
NS_ENSURE_TRUE(aNode && aAttribute, false); // ooops
nsCOMPtr<nsIContent> 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;
}