Bug 1801028 - part 11: Make `CSSEditUtils::Is(Computed|Specified)CSSEquivalentToHTMLInlineStyleSet` take `EditorInlineStyle` r=m_kato

Depends on D162510

Differential Revision: https://phabricator.services.mozilla.com/D162511
This commit is contained in:
Masayuki Nakano 2022-11-25 06:43:51 +00:00
Родитель 86439634a2
Коммит 26d6947e93
7 изменённых файлов: 175 добавлений и 175 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include "CSSEditUtils.h"
#include "ChangeStyleTransaction.h"
#include "HTMLEditHelpers.h"
#include "HTMLEditor.h"
#include "HTMLEditUtils.h"
@ -980,13 +981,29 @@ nsresult CSSEditUtils::GetCSSEquivalentToHTMLInlineStyleSetInternal(
// does not modify aValue.
// static
Result<bool, nsresult>
CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal(
const HTMLEditor& aHTMLEditor, nsIContent& aContent, nsAtom* aHTMLProperty,
nsAtom* aAttribute, nsAString& aValue, StyleType aStyleType) {
MOZ_ASSERT(aHTMLProperty || aAttribute);
Result<bool, nsresult> CSSEditUtils::IsComputedCSSEquivalentTo(
const HTMLEditor& aHTMLEditor, nsIContent& aContent,
const EditorInlineStyle& aStyle, nsAString& aInOutValue) {
return IsCSSEquivalentTo(aHTMLEditor, aContent, aStyle, aInOutValue,
StyleType::Computed);
}
nsAutoString htmlValueString(aValue);
// static
Result<bool, nsresult> CSSEditUtils::IsSpecifiedCSSEquivalentTo(
const HTMLEditor& aHTMLEditor, nsIContent& aContent,
const EditorInlineStyle& aStyle, nsAString& aInOutValue) {
return IsCSSEquivalentTo(aHTMLEditor, aContent, aStyle, aInOutValue,
StyleType::Specified);
}
// static
Result<bool, nsresult> CSSEditUtils::IsCSSEquivalentTo(
const HTMLEditor& aHTMLEditor, nsIContent& aContent,
const EditorInlineStyle& aStyle, nsAString& aInOutValue,
StyleType aStyleType) {
MOZ_ASSERT(!aStyle.IsStyleToClearAllInlineStyles());
nsAutoString htmlValueString(aInOutValue);
bool isSet = false;
// FYI: Cannot use InclusiveAncestorsOfType here because
// GetCSSEquivalentToHTMLInlineStyleSetInternal() may flush pending
@ -994,10 +1011,11 @@ CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal(
for (nsCOMPtr<nsIContent> content = &aContent; content;
content = content->GetParentElement()) {
nsCOMPtr<nsINode> parentNode = content->GetParentNode();
aValue.Assign(htmlValueString);
aInOutValue.Assign(htmlValueString);
// get the value of the CSS equivalent styles
nsresult rv = GetCSSEquivalentToHTMLInlineStyleSetInternal(
*content, aHTMLProperty, aAttribute, aValue, aStyleType);
*content, aStyle.mHTMLProperty, aStyle.mAttribute, aInOutValue,
aStyleType);
if (NS_WARN_IF(aHTMLEditor.Destroyed())) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
@ -1012,46 +1030,47 @@ CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal(
}
// early way out if we can
if (aValue.IsEmpty()) {
if (aInOutValue.IsEmpty()) {
return isSet;
}
if (nsGkAtoms::b == aHTMLProperty) {
if (aValue.EqualsLiteral("bold")) {
if (nsGkAtoms::b == aStyle.mHTMLProperty) {
if (aInOutValue.EqualsLiteral("bold")) {
isSet = true;
} else if (aValue.EqualsLiteral("normal")) {
} else if (aInOutValue.EqualsLiteral("normal")) {
isSet = false;
} else if (aValue.EqualsLiteral("bolder")) {
} else if (aInOutValue.EqualsLiteral("bolder")) {
isSet = true;
aValue.AssignLiteral("bold");
aInOutValue.AssignLiteral("bold");
} else {
int32_t weight = 0;
nsresult rvIgnored;
nsAutoString value(aValue);
nsAutoString value(aInOutValue);
weight = value.ToInteger(&rvIgnored);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"nsAString::ToInteger() failed, but ignored");
if (400 < weight) {
isSet = true;
aValue.AssignLiteral("bold");
aInOutValue.AssignLiteral(u"bold");
} else {
isSet = false;
aValue.AssignLiteral("normal");
aInOutValue.AssignLiteral(u"normal");
}
}
} else if (nsGkAtoms::i == aHTMLProperty) {
if (aValue.EqualsLiteral("italic") || aValue.EqualsLiteral("oblique")) {
} else if (nsGkAtoms::i == aStyle.mHTMLProperty) {
if (aInOutValue.EqualsLiteral(u"italic") ||
aInOutValue.EqualsLiteral(u"oblique")) {
isSet = true;
}
} else if (nsGkAtoms::u == aHTMLProperty) {
} else if (nsGkAtoms::u == aStyle.mHTMLProperty) {
isSet = ChangeStyleTransaction::ValueIncludes(
NS_ConvertUTF16toUTF8(aValue), "underline"_ns);
} else if (nsGkAtoms::strike == aHTMLProperty) {
NS_ConvertUTF16toUTF8(aInOutValue), "underline"_ns);
} else if (nsGkAtoms::strike == aStyle.mHTMLProperty) {
isSet = ChangeStyleTransaction::ValueIncludes(
NS_ConvertUTF16toUTF8(aValue), "line-through"_ns);
} else if ((nsGkAtoms::font == aHTMLProperty &&
aAttribute == nsGkAtoms::color) ||
aAttribute == nsGkAtoms::bgcolor) {
NS_ConvertUTF16toUTF8(aInOutValue), "line-through"_ns);
} else if ((nsGkAtoms::font == aStyle.mHTMLProperty &&
aStyle.mAttribute == nsGkAtoms::color) ||
aStyle.mAttribute == nsGkAtoms::bgcolor) {
if (htmlValueString.IsEmpty()) {
isSet = true;
} else {
@ -1067,9 +1086,9 @@ CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal(
// currently serializes to "transparent" (not "rgba(0, 0, 0, 0)").
MOZ_ASSERT(NS_GET_R(rgba) == 0 && NS_GET_G(rgba) == 0 &&
NS_GET_B(rgba) == 0 && NS_GET_A(rgba) == 0);
htmlColor.AppendLiteral("transparent");
htmlColor.AppendLiteral(u"transparent");
} else {
htmlColor.AppendLiteral("rgb(");
htmlColor.AppendLiteral(u"rgb(");
constexpr auto comma = u", "_ns;
@ -1084,24 +1103,25 @@ CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal(
tmpStr.AppendInt(NS_GET_B(rgba), 10);
htmlColor.Append(tmpStr);
htmlColor.Append(char16_t(')'));
htmlColor.AppendLiteral(u")");
}
isSet = htmlColor.Equals(aValue, nsCaseInsensitiveStringComparator);
} else {
isSet =
htmlValueString.Equals(aValue, nsCaseInsensitiveStringComparator);
htmlColor.Equals(aInOutValue, nsCaseInsensitiveStringComparator);
} else {
isSet = htmlValueString.Equals(aInOutValue,
nsCaseInsensitiveStringComparator);
}
}
} else if (nsGkAtoms::tt == aHTMLProperty) {
isSet = StringBeginsWith(aValue, u"monospace"_ns);
} else if (nsGkAtoms::font == aHTMLProperty && aAttribute &&
aAttribute == nsGkAtoms::face) {
} else if (nsGkAtoms::tt == aStyle.mHTMLProperty) {
isSet = StringBeginsWith(aInOutValue, u"monospace"_ns);
} else if (nsGkAtoms::font == aStyle.mHTMLProperty &&
aStyle.mAttribute == nsGkAtoms::face) {
if (!htmlValueString.IsEmpty()) {
const char16_t commaSpace[] = {char16_t(','), HTMLEditUtils::kSpace, 0};
const char16_t comma[] = {char16_t(','), 0};
htmlValueString.ReplaceSubstring(commaSpace, comma);
nsAutoString valueStringNorm(aValue);
nsAutoString valueStringNorm(aInOutValue);
valueStringNorm.ReplaceSubstring(commaSpace, comma);
isSet = htmlValueString.Equals(valueStringNorm,
nsCaseInsensitiveStringComparator);
@ -1109,18 +1129,19 @@ CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal(
isSet = true;
}
return isSet;
} else if (aAttribute == nsGkAtoms::align) {
} else if (aStyle.mAttribute == nsGkAtoms::align) {
isSet = true;
} else {
return false;
}
if (!htmlValueString.IsEmpty() &&
htmlValueString.Equals(aValue, nsCaseInsensitiveStringComparator)) {
htmlValueString.Equals(aInOutValue,
nsCaseInsensitiveStringComparator)) {
isSet = true;
}
if (htmlValueString.EqualsLiteral("-moz-editor-invert-value")) {
if (htmlValueString.EqualsLiteral(u"-moz-editor-invert-value")) {
isSet = !isSet;
}
@ -1128,7 +1149,8 @@ CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal(
return true;
}
if (nsGkAtoms::u != aHTMLProperty && nsGkAtoms::strike != aHTMLProperty) {
if (!aStyle.IsStyleOfTextDecoration(
EditorInlineStyle::IgnoreSElement::Yes)) {
return isSet;
}

Просмотреть файл

@ -192,44 +192,28 @@ class CSSEditUtils final {
*
* @param aHTMLEditor [IN] An HTMLEditor instance
* @param aContent [IN] A DOM node.
* @param aHTMLProperty [IN] An atom containing an HTML property.
* @param aAttribute [IN] A pointer/atom to an attribute name or nullptr
* if irrelevant.
* @param aValueString [IN/OUT] The attribute value (in) the list of CSS
* values (out).
* @param aStyle [IN] The style to check.
* @param aInOutValue [IN/OUT] Input value is used for initial value of the
* result, out value is the list of CSS values.
* @return A boolean being true if the css properties are
* not same as initial value.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<bool, nsresult>
IsComputedCSSEquivalentToHTMLInlineStyleSet(const HTMLEditor& aHTMLEditor,
nsIContent& aContent,
nsAtom* aHTMLProperty,
nsAtom* aAttribute,
nsAString& aValue) {
MOZ_ASSERT(aHTMLProperty || aAttribute);
return IsCSSEquivalentToHTMLInlineStyleSetInternal(
aHTMLEditor, aContent, aHTMLProperty, aAttribute, aValue,
StyleType::Computed);
}
IsComputedCSSEquivalentTo(const HTMLEditor& aHTMLEditor, nsIContent& aContent,
const EditorInlineStyle& aStyle,
nsAString& aInOutValue);
[[nodiscard]] MOZ_CAN_RUN_SCRIPT_BOUNDARY static Result<bool, nsresult>
IsSpecifiedCSSEquivalentToHTMLInlineStyleSet(const HTMLEditor& aHTMLEditor,
nsIContent& aContent,
nsAtom* aHTMLProperty,
nsAtom* aAttribute,
nsAString& aValue) {
MOZ_ASSERT(aHTMLProperty || aAttribute);
return IsCSSEquivalentToHTMLInlineStyleSetInternal(
aHTMLEditor, aContent, aHTMLProperty, aAttribute, aValue,
StyleType::Specified);
}
IsSpecifiedCSSEquivalentTo(const HTMLEditor& aHTMLEditor,
nsIContent& aContent,
const EditorInlineStyle& aStyle,
nsAString& aInOutValue);
/**
* This is a kind of IsCSSEquivalentToHTMLInlineStyleSet.
* IsCSSEquivalentToHTMLInlineStyleSet returns whether the properties
* aren't same as initial value. But this method returns whether the
* properties aren't set.
* This is a kind of Is*CSSEquivalentTo.
* Is*CSSEquivalentTo returns whether the properties aren't same as initial
* value. But this method returns whether the properties aren't set.
* If node is <span style="font-weight: normal"/>,
* - Is(Computed|Specified)CSSEquivalentToHTMLInlineStyleSet returns false.
* - Is(Computed|Specified)CSSEquivalentTo returns false.
* - Have(Computed|Specified)CSSEquivalentStyles returns true.
*
* @param aHTMLEditor [IN] An HTMLEditor instance
@ -425,12 +409,9 @@ class CSSEditUtils final {
nsAString& aValue,
StyleType aStyleType);
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<bool, nsresult>
IsCSSEquivalentToHTMLInlineStyleSetInternal(const HTMLEditor& aHTMLEditor,
nsIContent& aContent,
nsAtom* aHTMLProperty,
nsAtom* aAttribute,
nsAString& aValue,
StyleType aStyleType);
IsCSSEquivalentTo(const HTMLEditor& aHTMLEditor, nsIContent& aContent,
const EditorInlineStyle& aStyle, nsAString& aInOutValue,
StyleType aStyleType);
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<bool, nsresult>
HaveCSSEquivalentStylesInternal(const HTMLEditor& aHTMLEditor,
nsIContent& aContent, nsAtom* aHTMLProperty,

Просмотреть файл

@ -7,6 +7,7 @@
#include "EditorDOMPoint.h"
#include "HTMLEditor.h"
#include "PendingStyles.h"
#include "WSRunObject.h"
#include "mozilla/ContentIterator.h"
@ -85,4 +86,15 @@ nsresult DOMSubtreeIterator::Init(nsRange& aRange) {
return mIter->Init(&aRange);
}
/******************************************************************************
* mozilla::EditorInlineStyle
*****************************************************************************/
PendingStyleCache EditorInlineStyle::ToPendingStyleCache(
nsAString&& aValue) const {
return PendingStyleCache(*mHTMLProperty,
mAttribute ? mAttribute->AsStatic() : nullptr,
std::move(aValue));
}
} // namespace mozilla

Просмотреть файл

@ -924,6 +924,8 @@ struct MOZ_STACK_CLASS EditorInlineStyle {
*/
static EditorInlineStyle RemoveAllStyles() { return EditorInlineStyle(); }
PendingStyleCache ToPendingStyleCache(nsAString&& aValue) const;
bool operator==(const EditorInlineStyle& aOther) const {
return mHTMLProperty == aOther.mHTMLProperty &&
mAttribute == aOther.mAttribute;

Просмотреть файл

@ -9042,18 +9042,15 @@ nsresult HTMLEditor::GetInlineStyles(
nsGkAtoms::backgroundColor,
nsGkAtoms::sub,
nsGkAtoms::sup}) {
nsStaticAtom *tag, *attribute;
if (property == nsGkAtoms::face || property == nsGkAtoms::size ||
property == nsGkAtoms::color) {
tag = nsGkAtoms::font;
attribute = property;
} else {
tag = property;
attribute = nullptr;
}
const EditorInlineStyle style =
property == nsGkAtoms::face || property == nsGkAtoms::size ||
property == nsGkAtoms::color
? EditorInlineStyle(*nsGkAtoms::font, property)
: EditorInlineStyle(*property);
// If type-in state is set, don't intervene
const PendingStyleState styleState =
mPendingStylesToApplyToNewContent->GetStyleState(*tag, attribute);
mPendingStylesToApplyToNewContent->GetStyleState(*style.mHTMLProperty,
style.mAttribute);
if (styleState != PendingStyleState::NotUpdated) {
continue;
}
@ -9063,22 +9060,20 @@ nsresult HTMLEditor::GetInlineStyles(
// Don't use CSS for <font size>, we don't support it usefully (bug 780035)
if (!useCSS || (property == nsGkAtoms::size)) {
isSet = HTMLEditUtils::IsInlineStyleSetByElement(
aContent, *tag, attribute, nullptr, &value);
aContent, *style.mHTMLProperty, style.mAttribute, nullptr, &value);
} else {
Result<bool, nsresult> isComputedCSSEquivalentToHTMLInlineStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet(
*this, aContent, MOZ_KnownLive(tag), MOZ_KnownLive(attribute),
value);
if (isComputedCSSEquivalentToHTMLInlineStyleOrError.isErr()) {
NS_WARNING(
"CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet failed");
return isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrapErr();
Result<bool, nsresult> isComputedCSSEquivalentToStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentTo(*this, aContent, style,
value);
if (MOZ_UNLIKELY(isComputedCSSEquivalentToStyleOrError.isErr())) {
NS_WARNING("CSSEditUtils::IsComputedCSSEquivalentTo() failed");
return isComputedCSSEquivalentToStyleOrError.unwrapErr();
}
isSet = isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrap();
isSet = isComputedCSSEquivalentToStyleOrError.unwrap();
}
if (isSet) {
aPendingStyleCacheArray.AppendElement(
PendingStyleCache(*tag, attribute, value));
style.ToPendingStyleCache(std::move(value)));
}
}
return NS_OK;
@ -9129,18 +9124,15 @@ nsresult HTMLEditor::ReapplyCachedStyles() {
// check computed style first in css case
// MOZ_KnownLive(styleCacheBeforeEdit.*) because they are nsStaticAtom
// and its instances are alive until shutting down.
Result<bool, nsresult> isComputedCSSEquivalentToHTMLInlineStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet(
Result<bool, nsresult> isComputedCSSEquivalentToStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentTo(
*this, *startContainerContent,
MOZ_KnownLive(&styleCacheBeforeEdit.TagRef()),
MOZ_KnownLive(styleCacheBeforeEdit.GetAttribute()), currentValue);
if (isComputedCSSEquivalentToHTMLInlineStyleOrError.isErr()) {
NS_WARNING(
"CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet() "
"failed");
return isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrapErr();
styleCacheBeforeEdit.ToInlineStyle(), currentValue);
if (MOZ_UNLIKELY(isComputedCSSEquivalentToStyleOrError.isErr())) {
NS_WARNING("CSSEditUtils::IsComputedCSSEquivalentTo() failed");
return isComputedCSSEquivalentToStyleOrError.unwrapErr();
}
isAny = isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrap();
isAny = isComputedCSSEquivalentToStyleOrError.unwrap();
}
if (!isAny) {
// then check typeinstate and html style

Просмотреть файл

@ -483,16 +483,14 @@ HTMLEditor::SetInlinePropertyOnTextNode(
// The HTML styles defined by aStyleToSet have a CSS equivalence for node;
// let's check if it carries those CSS styles
nsAutoString value(aStyleToSet.mAttributeValue);
Result<bool, nsresult> isComputedCSSEquivalentToHTMLInlineStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet(
*this, aText, MOZ_KnownLive(&aStyleToSet.HTMLPropertyRef()),
aStyleToSet.mAttribute, value);
if (MOZ_UNLIKELY(isComputedCSSEquivalentToHTMLInlineStyleOrError.isErr())) {
NS_WARNING(
"CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet() failed");
return isComputedCSSEquivalentToHTMLInlineStyleOrError.propagateErr();
Result<bool, nsresult> isComputedCSSEquivalentToStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentTo(*this, aText, aStyleToSet,
value);
if (MOZ_UNLIKELY(isComputedCSSEquivalentToStyleOrError.isErr())) {
NS_WARNING("CSSEditUtils::IsComputedCSSEquivalentTo() failed");
return isComputedCSSEquivalentToStyleOrError.propagateErr();
}
if (isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrap()) {
if (isComputedCSSEquivalentToStyleOrError.unwrap()) {
return SplitRangeOffFromNodeResult(nullptr, &aText, nullptr);
}
} else if (HTMLEditUtils::IsInlineStyleSetByElement(
@ -768,16 +766,14 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SetInlinePropertyOnNodeImpl(
if (CSSEditUtils::IsCSSEditableProperty(
&aContent, &aStyleToSet.HTMLPropertyRef(), aStyleToSet.mAttribute)) {
nsAutoString value(aStyleToSet.mAttributeValue);
Result<bool, nsresult> isComputedCSSEquivalentToHTMLInlineStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet(
*this, aContent, MOZ_KnownLive(&aStyleToSet.HTMLPropertyRef()),
aStyleToSet.mAttribute, value);
if (isComputedCSSEquivalentToHTMLInlineStyleOrError.isErr()) {
NS_WARNING(
"CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet() failed");
return isComputedCSSEquivalentToHTMLInlineStyleOrError.propagateErr();
Result<bool, nsresult> isComputedCSSEquivalentToStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentTo(*this, aContent, aStyleToSet,
value);
if (MOZ_UNLIKELY(isComputedCSSEquivalentToStyleOrError.isErr())) {
NS_WARNING("CSSEditUtils::IsComputedCSSEquivalentTo() failed");
return isComputedCSSEquivalentToStyleOrError.propagateErr();
}
if (isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrap()) {
if (isComputedCSSEquivalentToStyleOrError.unwrap()) {
return EditorDOMPoint();
}
} else if (HTMLEditUtils::IsInlineStyleSetByElement(
@ -1066,14 +1062,11 @@ HTMLEditor::SplitAncestorStyledInlineElementsAt(
// implementation for the node; let's check if it carries those CSS styles
nsAutoString firstValue;
Result<bool, nsresult> isSpecifiedByCSSOrError =
CSSEditUtils::IsSpecifiedCSSEquivalentToHTMLInlineStyleSet(
*this, *content, aStyle.mHTMLProperty, aStyle.mAttribute,
firstValue);
CSSEditUtils::IsSpecifiedCSSEquivalentTo(*this, *content, aStyle,
firstValue);
if (MOZ_UNLIKELY(isSpecifiedByCSSOrError.isErr())) {
result.IgnoreCaretPointSuggestion();
NS_WARNING(
"CSSEditUtils::IsSpecifiedCSSEquivalentToHTMLInlineStyleSet() "
"failed");
NS_WARNING("CSSEditUtils::IsSpecifiedCSSEquivalentTo() failed");
return isSpecifiedByCSSOrError.propagateErr();
}
isSetByCSS = isSpecifiedByCSSOrError.unwrap();
@ -1842,18 +1835,16 @@ nsresult HTMLEditor::GetInlinePropertyBase(const EditorInlineStyle& aStyle,
if (aValue) {
tOutString.Assign(*aValue);
}
Result<bool, nsresult> isComputedCSSEquivalentToHTMLInlineStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet(
*this, MOZ_KnownLive(*collapsedNode->AsContent()),
aStyle.mHTMLProperty, aStyle.mAttribute, tOutString);
if (isComputedCSSEquivalentToHTMLInlineStyleOrError.isErr()) {
NS_WARNING(
"CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet() "
"failed");
return isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrapErr();
Result<bool, nsresult> isComputedCSSEquivalentToStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentTo(
*this, MOZ_KnownLive(*collapsedNode->AsContent()), aStyle,
tOutString);
if (MOZ_UNLIKELY(isComputedCSSEquivalentToStyleOrError.isErr())) {
NS_WARNING("CSSEditUtils::IsComputedCSSEquivalentTo() failed");
return isComputedCSSEquivalentToStyleOrError.unwrapErr();
}
*aFirst = *aAny = *aAll =
isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrap();
isComputedCSSEquivalentToStyleOrError.unwrap();
if (outValue) {
outValue->Assign(tOutString);
}
@ -1920,18 +1911,14 @@ nsresult HTMLEditor::GetInlinePropertyBase(const EditorInlineStyle& aStyle,
if (aValue) {
firstValue.Assign(*aValue);
}
Result<bool, nsresult>
isComputedCSSEquivalentToHTMLInlineStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet(
*this, *content, aStyle.mHTMLProperty, aStyle.mAttribute,
firstValue);
if (isComputedCSSEquivalentToHTMLInlineStyleOrError.isErr()) {
NS_WARNING(
"CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet() "
"failed");
return isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrapErr();
Result<bool, nsresult> isComputedCSSEquivalentToStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentTo(*this, *content, aStyle,
firstValue);
if (MOZ_UNLIKELY(isComputedCSSEquivalentToStyleOrError.isErr())) {
NS_WARNING("CSSEditUtils::IsComputedCSSEquivalentTo() failed");
return isComputedCSSEquivalentToStyleOrError.unwrapErr();
}
isSet = isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrap();
isSet = isComputedCSSEquivalentToStyleOrError.unwrap();
} else {
isSet = HTMLEditUtils::IsInlineStyleSetByElement(
*content, *aStyle.mHTMLProperty, aStyle.mAttribute, aValue,
@ -1951,18 +1938,14 @@ nsresult HTMLEditor::GetInlinePropertyBase(const EditorInlineStyle& aStyle,
if (aValue) {
theValue.Assign(*aValue);
}
Result<bool, nsresult>
isComputedCSSEquivalentToHTMLInlineStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet(
*this, *content, aStyle.mHTMLProperty, aStyle.mAttribute,
theValue);
if (isComputedCSSEquivalentToHTMLInlineStyleOrError.isErr()) {
NS_WARNING(
"CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet() "
"failed");
return isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrapErr();
Result<bool, nsresult> isComputedCSSEquivalentToStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentTo(*this, *content, aStyle,
theValue);
if (MOZ_UNLIKELY(isComputedCSSEquivalentToStyleOrError.isErr())) {
NS_WARNING("CSSEditUtils::IsComputedCSSEquivalentTo() failed");
return isComputedCSSEquivalentToStyleOrError.unwrapErr();
}
isSet = isComputedCSSEquivalentToHTMLInlineStyleOrError.unwrap();
isSet = isComputedCSSEquivalentToStyleOrError.unwrap();
} else {
isSet = HTMLEditUtils::IsInlineStyleSetByElement(
*content, *aStyle.mHTMLProperty, aStyle.mAttribute, aValue,
@ -2595,15 +2578,12 @@ Result<bool, nsresult> HTMLEditor::IsRemovableParentStyleWithNewSpanElement(
// assume it comes from a rule and let's try to insert a span
// "inverting" the style
nsAutoString emptyString;
Result<bool, nsresult> isComputedCSSEquivalentToHTMLInlineStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet(
*this, aContent, aStyle.mHTMLProperty, aStyle.mAttribute,
emptyString);
NS_WARNING_ASSERTION(
isComputedCSSEquivalentToHTMLInlineStyleOrError.isOk(),
"CSSEditUtils::IsComputedCSSEquivalentToHTMLInlineStyleSet() "
"failed");
return isComputedCSSEquivalentToHTMLInlineStyleOrError;
Result<bool, nsresult> isComputedCSSEquivalentToStyleOrError =
CSSEditUtils::IsComputedCSSEquivalentTo(*this, aContent, aStyle,
emptyString);
NS_WARNING_ASSERTION(isComputedCSSEquivalentToStyleOrError.isOk(),
"CSSEditUtils::IsComputedCSSEquivalentTo() failed");
return isComputedCSSEquivalentToStyleOrError;
}
void HTMLEditor::CollectEditableLeafTextNodes(

Просмотреть файл

@ -73,9 +73,20 @@ class PendingStyle final {
class PendingStyleCache final {
public:
PendingStyleCache() = delete;
PendingStyleCache(nsStaticAtom& aTag, nsStaticAtom* aAttribute,
PendingStyleCache(const nsStaticAtom& aTag, const nsStaticAtom* aAttribute,
const nsAString& aValue)
: mTag(aTag), mAttribute(aAttribute), mAttributeValueOrCSSValue(aValue) {}
// Needs const_cast hack here because the this class users may want
// non-const nsStaticAtom reference/pointer due to bug 1794954
: mTag(const_cast<nsStaticAtom&>(aTag)),
mAttribute(const_cast<nsStaticAtom*>(aAttribute)),
mAttributeValueOrCSSValue(aValue) {}
PendingStyleCache(const nsStaticAtom& aTag, const nsStaticAtom* aAttribute,
nsAString&& aValue)
// Needs const_cast hack here because the this class users may want
// non-const nsStaticAtom reference/pointer due to bug 1794954
: mTag(const_cast<nsStaticAtom&>(aTag)),
mAttribute(const_cast<nsStaticAtom*>(aAttribute)),
mAttributeValueOrCSSValue(std::move(aValue)) {}
MOZ_KNOWN_LIVE nsStaticAtom& TagRef() const { return mTag; }
MOZ_KNOWN_LIVE nsStaticAtom* GetAttribute() const { return mAttribute; }