diff --git a/editor/libeditor/html/nsHTMLCSSUtils.cpp b/editor/libeditor/html/nsHTMLCSSUtils.cpp index 1abc01efa174..2e08940b4668 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.cpp +++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp @@ -1300,36 +1300,35 @@ nsHTMLCSSUtils::IsCSSPrefChecked() // specified CSS declarations in the STYLE attribute // The answer is always negative if at least one of them carries an ID or a class bool -nsHTMLCSSUtils::ElementsSameStyle(dom::Element* aFirstNode, - dom::Element* aSecondNode) +nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode) { - MOZ_ASSERT(aFirstNode && aSecondNode); - return ElementsSameStyle(aFirstNode->AsDOMNode(), aSecondNode->AsDOMNode()); + nsCOMPtr firstElement = do_QueryInterface(aFirstNode); + nsCOMPtr secondElement = do_QueryInterface(aSecondNode); + + NS_ASSERTION((firstElement && secondElement), "Non element nodes passed to ElementsSameStyle."); + NS_ENSURE_TRUE(firstElement, false); + NS_ENSURE_TRUE(secondElement, false); + + return ElementsSameStyle(firstElement, secondElement); } bool -nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode) +nsHTMLCSSUtils::ElementsSameStyle(dom::Element* aFirstElement, + dom::Element* aSecondElement) { - nsresult res; - nsCOMPtr firstElement = do_QueryInterface(aFirstNode); - nsCOMPtr secondElement = do_QueryInterface(aSecondNode); + MOZ_ASSERT(aFirstElement); + MOZ_ASSERT(aSecondElement); - NS_ASSERTION((firstElement && secondElement), "Non element nodes passed to ElementsSameStyle."); - - nsAutoString firstID, secondID; - bool isFirstIDSet, isSecondIDSet; - res = mHTMLEditor->GetAttributeValue(firstElement, NS_LITERAL_STRING("id"), firstID, &isFirstIDSet); - res = mHTMLEditor->GetAttributeValue(secondElement, NS_LITERAL_STRING("id"), secondID, &isSecondIDSet); - if (isFirstIDSet || isSecondIDSet) { + if (aFirstElement->HasAttr(kNameSpaceID_None, nsGkAtoms::id) || + aSecondElement->HasAttr(kNameSpaceID_None, nsGkAtoms::id)) { // at least one of the spans carries an ID ; suspect a CSS rule applies to it and // refuse to merge the nodes return false; } nsAutoString firstClass, secondClass; - bool isFirstClassSet, isSecondClassSet; - res = mHTMLEditor->GetAttributeValue(firstElement, NS_LITERAL_STRING("class"), firstClass, &isFirstClassSet); - res = mHTMLEditor->GetAttributeValue(secondElement, NS_LITERAL_STRING("class"), secondClass, &isSecondClassSet); + bool isFirstClassSet = aFirstElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, firstClass); + bool isSecondClassSet = aSecondElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, secondClass); if (isFirstClassSet && isSecondClassSet) { // both spans carry a class, let's compare them if (!firstClass.Equals(secondClass)) { @@ -1341,32 +1340,35 @@ nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNod // need to discuss this issue before any modification. return false; } - } - else if (isFirstClassSet || isSecondClassSet) { + } else if (isFirstClassSet || isSecondClassSet) { // one span only carries a class, early way out return false; } nsCOMPtr firstCSSDecl, secondCSSDecl; uint32_t firstLength, secondLength; - res = GetInlineStyles(firstElement, getter_AddRefs(firstCSSDecl), &firstLength); - if (NS_FAILED(res) || !firstCSSDecl) return false; - res = GetInlineStyles(secondElement, getter_AddRefs(secondCSSDecl), &secondLength); - if (NS_FAILED(res) || !secondCSSDecl) return false; + nsresult rv = GetInlineStyles(aFirstElement, getter_AddRefs(firstCSSDecl), &firstLength); + if (NS_FAILED(rv) || !firstCSSDecl) { + return false; + } + rv = GetInlineStyles(aSecondElement, getter_AddRefs(secondCSSDecl), &secondLength); + if (NS_FAILED(rv) || !secondCSSDecl) { + return false; + } if (firstLength != secondLength) { // early way out if we can return false; } - else if (0 == firstLength) { + + if (!firstLength) { // no inline style ! return true; } - uint32_t i; nsAutoString propertyNameString; nsAutoString firstValue, secondValue; - for (i=0; iItem(i, propertyNameString); firstCSSDecl->GetPropertyValue(propertyNameString, firstValue); secondCSSDecl->GetPropertyValue(propertyNameString, secondValue); @@ -1374,7 +1376,7 @@ nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNod return false; } } - for (i=0; iItem(i, propertyNameString); secondCSSDecl->GetPropertyValue(propertyNameString, secondValue); firstCSSDecl->GetPropertyValue(propertyNameString, firstValue); @@ -1387,7 +1389,23 @@ nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNod } nsresult -nsHTMLCSSUtils::GetInlineStyles(nsIDOMElement *aElement, +nsHTMLCSSUtils::GetInlineStyles(dom::Element* aElement, + nsIDOMCSSStyleDeclaration** aCssDecl, + uint32_t* aLength) +{ + return GetInlineStyles(static_cast(aElement), aCssDecl, aLength); +} + +nsresult +nsHTMLCSSUtils::GetInlineStyles(nsIDOMElement* aElement, + nsIDOMCSSStyleDeclaration** aCssDecl, + uint32_t* aLength) +{ + return GetInlineStyles(static_cast(aElement), aCssDecl, aLength); +} + +nsresult +nsHTMLCSSUtils::GetInlineStyles(nsISupports *aElement, nsIDOMCSSStyleDeclaration **aCssDecl, uint32_t *aLength) { @@ -1395,8 +1413,11 @@ nsHTMLCSSUtils::GetInlineStyles(nsIDOMElement *aElement, *aLength = 0; nsCOMPtr inlineStyles = do_QueryInterface(aElement); NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER); + nsresult res = inlineStyles->GetStyle(aCssDecl); - if (NS_FAILED(res) || !aCssDecl) return NS_ERROR_NULL_POINTER; + NS_ENSURE_SUCCESS(res, NS_ERROR_NULL_POINTER); + MOZ_ASSERT(*aCssDecl); + (*aCssDecl)->GetLength(aLength); return NS_OK; } diff --git a/editor/libeditor/html/nsHTMLCSSUtils.h b/editor/libeditor/html/nsHTMLCSSUtils.h index 0d456b571e43..a391d8b149a1 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.h +++ b/editor/libeditor/html/nsHTMLCSSUtils.h @@ -291,9 +291,18 @@ public: * @param aCssDecl [OUT] the CSS declaration corresponding to the style attr * @param aLength [OUT] the number of declarations in aCssDecl */ - nsresult GetInlineStyles(nsIDOMElement * aElement, nsIDOMCSSStyleDeclaration ** aCssDecl, - uint32_t * aLength); + nsresult GetInlineStyles(mozilla::dom::Element* aElement, + nsIDOMCSSStyleDeclaration** aCssDecl, + uint32_t* aLength); + nsresult GetInlineStyles(nsIDOMElement* aElement, + nsIDOMCSSStyleDeclaration** aCssDecl, + uint32_t* aLength); +private: + nsresult GetInlineStyles(nsISupports* aElement, + nsIDOMCSSStyleDeclaration** aCssDecl, + uint32_t* aLength); +public: /** returns aNode itself if it is an element node, or the first ancestors being an element * node if aNode is not one itself *