mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1774704 - part 7-2: Make CSSEditUtils::RemoveCSSInlineStyleWithTransaction
stop touching Selection
directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152975
This commit is contained in:
parent
68caf865dc
commit
efd0248a4c
@ -571,7 +571,8 @@ already_AddRefed<nsComputedDOMStyle> CSSEditUtils::GetComputedStyle(
|
||||
|
||||
// remove the CSS style "aProperty : aPropertyValue" and possibly remove the
|
||||
// whole node if it is a span and if its only attribute is _moz_dirty
|
||||
nsresult CSSEditUtils::RemoveCSSInlineStyleWithTransaction(
|
||||
Result<EditorDOMPoint, nsresult>
|
||||
CSSEditUtils::RemoveCSSInlineStyleWithTransaction(
|
||||
nsStyledElement& aStyledElement, nsAtom* aProperty,
|
||||
const nsAString& aPropertyValue) {
|
||||
// remove the property from the style attribute
|
||||
@ -579,30 +580,20 @@ nsresult CSSEditUtils::RemoveCSSInlineStyleWithTransaction(
|
||||
aPropertyValue);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("CSSEditUtils::RemoveCSSPropertyWithTransaction() failed");
|
||||
return rv;
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
if (!aStyledElement.IsHTMLElement(nsGkAtoms::span) ||
|
||||
HTMLEditor::HasAttributes(&aStyledElement)) {
|
||||
return NS_OK;
|
||||
return EditorDOMPoint();
|
||||
}
|
||||
|
||||
OwningNonNull<HTMLEditor> htmlEditor(*mHTMLEditor);
|
||||
const Result<EditorDOMPoint, nsresult> unwrapStyledElementResult =
|
||||
Result<EditorDOMPoint, nsresult> unwrapStyledElementResult =
|
||||
htmlEditor->RemoveContainerWithTransaction(aStyledElement);
|
||||
if (MOZ_UNLIKELY(unwrapStyledElementResult.isErr())) {
|
||||
NS_WARNING("HTMLEditor::RemoveContainerWithTransaction() failed");
|
||||
return unwrapStyledElementResult.inspectErr();
|
||||
}
|
||||
const EditorDOMPoint& pointToPutCaret = unwrapStyledElementResult.inspect();
|
||||
if (!htmlEditor->AllowsTransactionsToChangeSelection() ||
|
||||
!pointToPutCaret.IsSet()) {
|
||||
return NS_OK;
|
||||
}
|
||||
rv = htmlEditor->CollapseSelectionTo(pointToPutCaret);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"EditorBase::CollapseSelectionTo() failed");
|
||||
return rv;
|
||||
NS_WARNING_ASSERTION(unwrapStyledElementResult.isOk(),
|
||||
"HTMLEditor::RemoveContainerWithTransaction() failed");
|
||||
return unwrapStyledElementResult;
|
||||
}
|
||||
|
||||
// Answers true if the property can be removed by setting a "none" CSS value
|
||||
|
@ -134,10 +134,12 @@ class CSSEditUtils final {
|
||||
* @param aProperty [IN] The CSS property atom to remove.
|
||||
* @param aPropertyValue [IN] The value of the property we have to remove
|
||||
* if the property accepts more than one value.
|
||||
* @return A candidate point to put caret.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveCSSInlineStyleWithTransaction(
|
||||
nsStyledElement& aStyledElement, nsAtom* aProperty,
|
||||
const nsAString& aPropertyValue);
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditorDOMPoint, nsresult>
|
||||
RemoveCSSInlineStyleWithTransaction(nsStyledElement& aStyledElement,
|
||||
nsAtom* aProperty,
|
||||
const nsAString& aPropertyValue);
|
||||
|
||||
/**
|
||||
* Answers true is the property can be removed by setting a "none" CSS value
|
||||
|
@ -9720,14 +9720,23 @@ nsresult HTMLEditor::RemoveAlignFromDescendants(Element& aElement,
|
||||
// MOZ_KnownLive(*styledBlockOrHRElement): It's `blockOrHRElement
|
||||
// which is OwningNonNull.
|
||||
nsAutoString dummyCssValue;
|
||||
nsresult rv = mCSSEditUtils->RemoveCSSInlineStyleWithTransaction(
|
||||
MOZ_KnownLive(*styledBlockOrHRElement), nsGkAtoms::textAlign,
|
||||
dummyCssValue);
|
||||
if (NS_FAILED(rv)) {
|
||||
Result<EditorDOMPoint, nsresult> pointToPutCaretOrError =
|
||||
mCSSEditUtils->RemoveCSSInlineStyleWithTransaction(
|
||||
MOZ_KnownLive(*styledBlockOrHRElement), nsGkAtoms::textAlign,
|
||||
dummyCssValue);
|
||||
if (MOZ_UNLIKELY(pointToPutCaretOrError.isErr())) {
|
||||
NS_WARNING(
|
||||
"CSSEditUtils::RemoveCSSInlineStyleWithTransaction(nsGkAtoms::"
|
||||
"textAlign) failed");
|
||||
return rv;
|
||||
return pointToPutCaretOrError.unwrapErr();
|
||||
}
|
||||
if (AllowsTransactionsToChangeSelection() &&
|
||||
pointToPutCaretOrError.inspect().IsSet()) {
|
||||
nsresult rv = CollapseSelectionTo(pointToPutCaretOrError.inspect());
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user