Bug 480647 part 1 - Clean up nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-04-17 20:50:19 +03:00
parent 4f420966ed
commit 01b6da4885

View File

@ -1048,17 +1048,16 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
return NS_OK; return NS_OK;
} }
// Does the node aNode (or his parent if it is not an element node) carries // Does the node aNode (or its parent, if it's not an element node) have a CSS
// the CSS equivalent styles to the HTML style aHTMLProperty/aAttribute/ // style equivalent to the HTML style aHTMLProperty/aHTMLAttribute/valueString?
// aValueString for this node ? // The value of aStyleType controls the styles we retrieve: specified or
// The value of aStyleType controls the styles we retrieve : specified or // computed. The return value aIsSet is true if the CSS styles are set.
// computed. The return value aIsSet is true is the CSS styles are set.
nsresult nsresult
nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode *aNode,
nsIAtom *aHTMLProperty, nsIAtom *aHTMLProperty,
const nsAString * aHTMLAttribute, const nsAString *aHTMLAttribute,
bool & aIsSet, bool& aIsSet,
nsAString & valueString, nsAString& valueString,
PRUint8 aStyleType) PRUint8 aStyleType)
{ {
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
@ -1066,7 +1065,6 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
nsAutoString htmlValueString(valueString); nsAutoString htmlValueString(valueString);
aIsSet = false; aIsSet = false;
nsCOMPtr<nsINode> node = do_QueryInterface(aNode); nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_NAMED_LITERAL_STRING(boldStr, "bold");
do { do {
valueString.Assign(htmlValueString); valueString.Assign(htmlValueString);
// get the value of the CSS equivalent styles // get the value of the CSS equivalent styles
@ -1075,64 +1073,54 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
// early way out if we can // early way out if we can
if (valueString.IsEmpty()) return NS_OK; if (valueString.IsEmpty()) {
return NS_OK;
}
if (nsEditProperty::b == aHTMLProperty) { if (nsEditProperty::b == aHTMLProperty) {
if (valueString.Equals(boldStr)) { if (valueString.EqualsLiteral("bold")) {
aIsSet = true; aIsSet = true;
} } else if (valueString.EqualsLiteral("normal")) {
else if (valueString.EqualsLiteral("normal")) {
aIsSet = false; aIsSet = false;
} } else if (valueString.EqualsLiteral("bolder")) {
else if (valueString.EqualsLiteral("bolder")) {
aIsSet = true; aIsSet = true;
valueString.Assign(boldStr); valueString.AssignLiteral("bold");
} } else {
else {
PRInt32 weight = 0; PRInt32 weight = 0;
PRInt32 errorCode; PRInt32 errorCode;
nsAutoString value(valueString); nsAutoString value(valueString);
weight = value.ToInteger(&errorCode, 10); weight = value.ToInteger(&errorCode, 10);
if (400 < weight) { if (400 < weight) {
aIsSet = true; aIsSet = true;
valueString.Assign(boldStr); valueString.AssignLiteral("bold");
} } else {
else {
aIsSet = false; aIsSet = false;
valueString.AssignLiteral("normal"); valueString.AssignLiteral("normal");
} }
} }
} } else if (nsEditProperty::i == aHTMLProperty) {
else if (nsEditProperty::i == aHTMLProperty) {
if (valueString.EqualsLiteral("italic") || if (valueString.EqualsLiteral("italic") ||
valueString.EqualsLiteral("oblique")) { valueString.EqualsLiteral("oblique")) {
aIsSet= true; aIsSet = true;
} }
} } else if (nsEditProperty::u == aHTMLProperty) {
else if (nsEditProperty::u == aHTMLProperty) {
nsAutoString val; nsAutoString val;
val.AssignLiteral("underline"); val.AssignLiteral("underline");
aIsSet = bool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, false)); aIsSet = bool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, false));
} } else if (nsEditProperty::strike == aHTMLProperty) {
else if (nsEditProperty::strike == aHTMLProperty) {
nsAutoString val; nsAutoString val;
val.AssignLiteral("line-through"); val.AssignLiteral("line-through");
aIsSet = bool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, false)); aIsSet = bool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, false));
} } else if (aHTMLAttribute &&
((nsEditProperty::font == aHTMLProperty &&
else if (aHTMLAttribute && aHTMLAttribute->EqualsLiteral("color")) ||
( (nsEditProperty::font == aHTMLProperty && aHTMLAttribute->EqualsLiteral("bgcolor"))) {
aHTMLAttribute->EqualsLiteral("color")) || if (htmlValueString.IsEmpty()) {
aHTMLAttribute->EqualsLiteral("bgcolor"))) {
if (htmlValueString.IsEmpty())
aIsSet = true; aIsSet = true;
else { } else {
nscolor rgba; nscolor rgba;
nsAutoString subStr; nsAutoString subStr;
htmlValueString.Right(subStr, htmlValueString.Length()-1); htmlValueString.Right(subStr, htmlValueString.Length() - 1);
if (NS_ColorNameToRGB(htmlValueString, &rgba) || if (NS_ColorNameToRGB(htmlValueString, &rgba) ||
NS_HexToRGB(subStr, &rgba)) { NS_HexToRGB(subStr, &rgba)) {
nsAutoString htmlColor, tmpStr; nsAutoString htmlColor, tmpStr;
@ -1154,19 +1142,15 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
htmlColor.Append(PRUnichar(')')); htmlColor.Append(PRUnichar(')'));
aIsSet = htmlColor.Equals(valueString, aIsSet = htmlColor.Equals(valueString,
nsCaseInsensitiveStringComparator()); nsCaseInsensitiveStringComparator());
} } else {
else
aIsSet = htmlValueString.Equals(valueString, aIsSet = htmlValueString.Equals(valueString,
nsCaseInsensitiveStringComparator()); nsCaseInsensitiveStringComparator());
}
} }
} } else if (nsEditProperty::tt == aHTMLProperty) {
else if (nsEditProperty::tt == aHTMLProperty) {
aIsSet = StringBeginsWith(valueString, NS_LITERAL_STRING("monospace")); aIsSet = StringBeginsWith(valueString, NS_LITERAL_STRING("monospace"));
} } else if (nsEditProperty::font == aHTMLProperty && aHTMLAttribute &&
aHTMLAttribute->EqualsLiteral("face")) {
else if ((nsEditProperty::font == aHTMLProperty) && aHTMLAttribute
&& aHTMLAttribute->EqualsLiteral("face")) {
if (!htmlValueString.IsEmpty()) { if (!htmlValueString.IsEmpty()) {
const PRUnichar commaSpace[] = { PRUnichar(','), PRUnichar(' '), 0 }; const PRUnichar commaSpace[] = { PRUnichar(','), PRUnichar(' '), 0 };
const PRUnichar comma[] = { PRUnichar(','), 0 }; const PRUnichar comma[] = { PRUnichar(','), 0 };
@ -1175,8 +1159,7 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
valueStringNorm.ReplaceSubstring(commaSpace, comma); valueStringNorm.ReplaceSubstring(commaSpace, comma);
aIsSet = htmlValueString.Equals(valueStringNorm, aIsSet = htmlValueString.Equals(valueStringNorm,
nsCaseInsensitiveStringComparator()); nsCaseInsensitiveStringComparator());
} } else {
else {
// ignore this, it's TT or our default // ignore this, it's TT or our default
nsAutoString valueStringLower; nsAutoString valueStringLower;
ToLowerCase(valueString, valueStringLower); ToLowerCase(valueString, valueStringLower);
@ -1184,21 +1167,17 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
!valueStringLower.EqualsLiteral("serif"); !valueStringLower.EqualsLiteral("serif");
} }
return NS_OK; return NS_OK;
} } else if (aHTMLAttribute && aHTMLAttribute->EqualsLiteral("align")) {
else if (aHTMLAttribute
&& aHTMLAttribute->EqualsLiteral("align")) {
aIsSet = true; aIsSet = true;
} } else {
else {
aIsSet = false; aIsSet = false;
return NS_OK; return NS_OK;
} }
if (!htmlValueString.IsEmpty()) { if (!htmlValueString.IsEmpty() &&
if (htmlValueString.Equals(valueString, htmlValueString.Equals(valueString,
nsCaseInsensitiveStringComparator())) { nsCaseInsensitiveStringComparator())) {
aIsSet = true; aIsSet = true;
}
} }
if (nsEditProperty::u == aHTMLProperty || nsEditProperty::strike == aHTMLProperty) { if (nsEditProperty::u == aHTMLProperty || nsEditProperty::strike == aHTMLProperty) {