зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1801028 - part 4: Make `HTMLEditor::ClearStyleAt` take `EditorInlineStyle` r=m_kato
Depends on D162503 Differential Revision: https://phabricator.services.mozilla.com/D162504
This commit is contained in:
Родитель
ced1d68660
Коммит
9e35e5429b
|
@ -6075,8 +6075,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::CreateStyleForInsertText(
|
|||
// MOZ_KnownLive because we own pendingStyle which guarantees the lifetime
|
||||
// of its members.
|
||||
Result<EditorDOMPoint, nsresult> pointToPutCaretOrError =
|
||||
ClearStyleAt(pointToPutCaret, MOZ_KnownLive(pendingStyle->GetTag()),
|
||||
MOZ_KnownLive(pendingStyle->GetAttribute()),
|
||||
ClearStyleAt(pointToPutCaret, pendingStyle->ToInlineStyle(),
|
||||
pendingStyle->GetSpecifiedStyle());
|
||||
if (MOZ_UNLIKELY(pointToPutCaretOrError.isErr())) {
|
||||
NS_WARNING("HTMLEditor::ClearStyleAt() failed");
|
||||
|
|
|
@ -928,10 +928,7 @@ class HTMLEditor final : public EditorBase,
|
|||
* from the point and returns DOM point to put caret.
|
||||
*
|
||||
* @param aPoint The point to clear style at.
|
||||
* @param aProperty An HTML tag name which represents a style.
|
||||
* Set nullptr if you want to clear all styles.
|
||||
* @param aAttribute Attribute name if aProperty has some styles like
|
||||
* nsGkAtoms::font.
|
||||
* @param aStyleToRemove The style which you want to clear.
|
||||
* @param aSpecifiedStyle Whether the class and style attributes should
|
||||
* be preserved or discarded.
|
||||
* @return A candidate position to put caret. If there is
|
||||
|
@ -939,8 +936,9 @@ class HTMLEditor final : public EditorBase,
|
|||
* suggesting caret point only in some cases.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditorDOMPoint, nsresult>
|
||||
ClearStyleAt(const EditorDOMPoint& aPoint, nsAtom* aProperty,
|
||||
nsAtom* aAttribute, SpecifiedStyle aSpecifiedStyle);
|
||||
ClearStyleAt(const EditorDOMPoint& aPoint,
|
||||
const EditorInlineStyle& aStyleToRemove,
|
||||
SpecifiedStyle aSpecifiedStyle);
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT nsresult SetPositionToAbsolute(Element& aElement);
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
||||
|
|
|
@ -670,8 +670,8 @@ Result<EditActionResult, nsresult> HTMLEditor::HTMLWithContextInserter::Run(
|
|||
// pasting does not inherit local inline styles
|
||||
Result<EditorDOMPoint, nsresult> pointToPutCaretOrError =
|
||||
mHTMLEditor.ClearStyleAt(
|
||||
EditorDOMPoint(mHTMLEditor.SelectionRef().AnchorRef()), nullptr,
|
||||
nullptr, SpecifiedStyle::Preserve);
|
||||
EditorDOMPoint(mHTMLEditor.SelectionRef().AnchorRef()),
|
||||
EditorInlineStyle::RemoveAllStyles(), SpecifiedStyle::Preserve);
|
||||
if (MOZ_UNLIKELY(pointToPutCaretOrError.isErr())) {
|
||||
NS_WARNING("HTMLEditor::ClearStyleAt() failed");
|
||||
return pointToPutCaretOrError.propagateErr();
|
||||
|
|
|
@ -1146,7 +1146,7 @@ HTMLEditor::SplitAncestorStyledInlineElementsAt(
|
|||
}
|
||||
|
||||
Result<EditorDOMPoint, nsresult> HTMLEditor::ClearStyleAt(
|
||||
const EditorDOMPoint& aPoint, nsAtom* aProperty, nsAtom* aAttribute,
|
||||
const EditorDOMPoint& aPoint, const EditorInlineStyle& aStyleToRemove,
|
||||
SpecifiedStyle aSpecifiedStyle) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
|
@ -1160,12 +1160,13 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::ClearStyleAt(
|
|||
// DOM tree from point of view of users.
|
||||
|
||||
// First, split inline elements at the point.
|
||||
// E.g., if aProperty is nsGkAtoms::b and `<p><b><i>a[]bc</i></b></p>`,
|
||||
// we want to make it as `<p><b><i>a</i></b><b><i>bc</i></b></p>`.
|
||||
// E.g., if aStyleToRemove.mHTMLProperty is nsGkAtoms::b and
|
||||
// `<p><b><i>a[]bc</i></b></p>`, we want to make it as
|
||||
// `<p><b><i>a</i></b><b><i>bc</i></b></p>`.
|
||||
EditorDOMPoint pointToPutCaret(aPoint);
|
||||
Result<SplitNodeResult, nsresult> splitNodeResult =
|
||||
SplitAncestorStyledInlineElementsAt(
|
||||
aPoint, aProperty, aAttribute,
|
||||
aPoint, aStyleToRemove.mHTMLProperty, aStyleToRemove.mAttribute,
|
||||
SplitAtEdges::eAllowToCreateEmptyContainer);
|
||||
if (MOZ_UNLIKELY(splitNodeResult.isErr())) {
|
||||
NS_WARNING("HTMLEditor::SplitAncestorStyledInlineElementsAt() failed");
|
||||
|
@ -1177,8 +1178,8 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::ClearStyleAt(
|
|||
{SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
|
||||
|
||||
// If there is no styled inline elements of aProperty/aAttribute, we just
|
||||
// return the given point.
|
||||
// If there is no styled inline elements of aStyleToRemove, we just return the
|
||||
// given point.
|
||||
// E.g., `<p><i>a[]bc</i></p>` for nsGkAtoms::b.
|
||||
if (!unwrappedSplitNodeResult.Handled()) {
|
||||
return pointToPutCaret;
|
||||
|
@ -1245,7 +1246,8 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::ClearStyleAt(
|
|||
}
|
||||
Result<SplitNodeResult, nsresult> splitResultAtStartOfNextNode =
|
||||
SplitAncestorStyledInlineElementsAt(
|
||||
atStartOfNextNode, aProperty, aAttribute,
|
||||
atStartOfNextNode, aStyleToRemove.mHTMLProperty,
|
||||
aStyleToRemove.mAttribute,
|
||||
SplitAtEdges::eAllowToCreateEmptyContainer);
|
||||
if (MOZ_UNLIKELY(splitResultAtStartOfNextNode.isErr())) {
|
||||
NS_WARNING("HTMLEditor::SplitAncestorStyledInlineElementsAt() failed");
|
||||
|
@ -1412,7 +1414,8 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::ClearStyleAt(
|
|||
// It's grabbed by unwrappedSplitResultAtStartOfNextNode.
|
||||
Result<EditorDOMPoint, nsresult> removeStyleResult =
|
||||
RemoveStyleInside(MOZ_KnownLive(*previousElementOfSplitPoint),
|
||||
aProperty, aAttribute, aSpecifiedStyle);
|
||||
aStyleToRemove.mHTMLProperty,
|
||||
aStyleToRemove.mAttribute, aSpecifiedStyle);
|
||||
if (MOZ_UNLIKELY(removeStyleResult.isErr())) {
|
||||
NS_WARNING("HTMLEditor::RemoveStyleInside() failed");
|
||||
return removeStyleResult;
|
||||
|
|
|
@ -32,6 +32,15 @@ namespace mozilla {
|
|||
|
||||
using namespace dom;
|
||||
|
||||
/********************************************************************
|
||||
* mozilla::PendingStyle
|
||||
*******************************************************************/
|
||||
|
||||
EditorInlineStyle PendingStyle::ToInlineStyle() const {
|
||||
return mTag ? EditorInlineStyle(*mTag, mAttribute)
|
||||
: EditorInlineStyle::RemoveAllStyles();
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* mozilla::PendingStyleCache
|
||||
*******************************************************************/
|
||||
|
|
|
@ -53,6 +53,8 @@ class PendingStyle final {
|
|||
}
|
||||
SpecifiedStyle GetSpecifiedStyle() const { return mSpecifiedStyle; }
|
||||
|
||||
EditorInlineStyle ToInlineStyle() const;
|
||||
|
||||
private:
|
||||
MOZ_KNOWN_LIVE nsStaticAtom* const mTag = nullptr;
|
||||
// TODO: Once we stop using `HTMLEditor::SetInlinePropertiesAsSubAction` to
|
||||
|
|
Загрузка…
Ссылка в новой задаче