Bug 1906727 - Make HTMLEditor::SplitAncestorStyledInlineElementsAt check attr value type first r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D215990
This commit is contained in:
Masayuki Nakano
2024-07-25 00:41:49 +00:00
parent 44aae6e962
commit ea3e323dff
3 changed files with 13 additions and 14 deletions

View File

@@ -1828,10 +1828,10 @@ bool nsAttrValue::ParsePositiveIntValue(const nsAString& aString) {
return true;
}
void nsAttrValue::SetColorValue(nscolor aColor, const nsAString& aString) {
bool nsAttrValue::SetColorValue(nscolor aColor, const nsAString& aString) {
mozilla::StringBuffer* buf = GetStringBuffer(aString).take();
if (!buf) {
return;
return false;
}
MiscContainer* cont = EnsureEmptyMiscContainer();
@@ -1840,6 +1840,7 @@ void nsAttrValue::SetColorValue(nscolor aColor, const nsAString& aString) {
// Save the literal string we were passed for round-tripping.
cont->SetStringBitsMainThread(reinterpret_cast<uintptr_t>(buf) | eStringBase);
return true;
}
bool nsAttrValue::ParseColor(const nsAString& aString) {
@@ -1861,17 +1862,14 @@ bool nsAttrValue::ParseColor(const nsAString& aString) {
if (colorStr.First() == '#') {
nsDependentString withoutHash(colorStr.get() + 1, colorStr.Length() - 1);
if (NS_HexToRGBA(withoutHash, nsHexColorType::NoAlpha, &color)) {
SetColorValue(color, aString);
return true;
return SetColorValue(color, aString);
}
} else if (colorStr.LowerCaseEqualsLiteral("transparent")) {
SetColorValue(NS_RGBA(0, 0, 0, 0), aString);
return true;
return SetColorValue(NS_RGBA(0, 0, 0, 0), aString);
} else {
const NS_ConvertUTF16toUTF8 colorNameU8(colorStr);
if (Servo_ColorNameToRgb(&colorNameU8, &color)) {
SetColorValue(color, aString);
return true;
return SetColorValue(color, aString);
}
}
@@ -1882,8 +1880,7 @@ bool nsAttrValue::ParseColor(const nsAString& aString) {
// Use NS_LooseHexToRGB as a fallback if nothing above worked.
if (NS_LooseHexToRGB(colorStr, &color)) {
SetColorValue(color, aString);
return true;
return SetColorValue(color, aString);
}
return false;

View File

@@ -515,7 +515,7 @@ class nsAttrValue {
// aType can be ePercent or eDoubleValue.
void SetDoubleValueAndType(double aValue, ValueType aType,
const nsAString* aStringValue);
void SetColorValue(nscolor aColor, const nsAString& aString);
bool SetColorValue(nscolor aColor, const nsAString& aString);
void SetMiscAtomOrString(const nsAString* aValue);
void ResetMiscAtomOrString();
void SetSVGType(ValueType aType, const void* aValue,

View File

@@ -2218,15 +2218,17 @@ HTMLEditor::SplitAncestorStyledInlineElementsAt(
element->GetParsedAttr(aStyle.mAttribute);
if (attrValue) {
if (aStyle.mAttribute == nsGkAtoms::size) {
if (nsContentUtils::ParseLegacyFontSize(
if (attrValue->Type() == nsAttrValue::eInteger &&
nsContentUtils::ParseLegacyFontSize(
aStyle.AsInlineStyleAndValue().mAttributeValue) ==
attrValue->GetIntegerValue()) {
attrValue->GetIntegerValue()) {
continue;
}
} else if (aStyle.mAttribute == nsGkAtoms::color) {
nsAttrValue newValue;
nscolor oldColor, newColor;
if (attrValue->GetColorValue(oldColor) &&
if (attrValue->Type() == nsAttrValue::eColor &&
attrValue->GetColorValue(oldColor) &&
newValue.ParseColor(
aStyle.AsInlineStyleAndValue().mAttributeValue) &&
newValue.GetColorValue(newColor) && oldColor == newColor) {