Bug 1770877 - part 26: Make `HTMLEditor::InsertBRElementIfEmptyBlockElement` a lambda since it's used only by one method r=m_kato

And its selection update are not used except the legacy mutation event
listeners so that we can drop them.

Differential Revision: https://phabricator.services.mozilla.com/D149090
This commit is contained in:
Masayuki Nakano 2022-06-21 08:19:37 +00:00
Родитель 232e442ab2
Коммит 6f93e32018
2 изменённых файлов: 30 добавлений и 42 удалений

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

@ -7452,12 +7452,38 @@ nsresult HTMLEditor::SplitParagraph(Element& aParentDivOrP,
// it'll be exposed as <br> with Element.innerHTML. Therefore, we can use
// normal <br> elements for placeholder in this case. Note that Chromium
// also behaves so.
auto InsertBRElementIfEmptyBlockElement =
[&](Element& aElement) MOZ_CAN_RUN_SCRIPT {
if (!HTMLEditUtils::IsBlockElement(aElement)) {
return NS_OK;
}
if (!HTMLEditUtils::IsEmptyNode(
aElement, {EmptyCheckOption::TreatSingleBRElementAsVisible})) {
return NS_OK;
}
CreateElementResult insertBRElementResult = InsertBRElement(
WithTransaction::Yes, EditorDOMPoint(&aElement, 0u));
if (insertBRElementResult.isErr()) {
NS_WARNING(
"HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
return insertBRElementResult.unwrapErr();
}
// After this is called twice, selection will be updated by
// SplitParagraph itself. Therefore, we don't need to update selection
// here.
insertBRElementResult.IgnoreCaretPointSuggestion();
return NS_OK;
};
// MOZ_KnownLive(leftDivOrParagraphElement) because it's grabbed by
// splitDivOrResult.
rv = InsertBRElementIfEmptyBlockElement(
MOZ_KnownLive(*leftDivOrParagraphElement));
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::InsertBRElementIfEmptyBlockElement() failed");
NS_WARNING(
"InsertBRElementIfEmptyBlockElement(leftDivOrParagraphElement) failed");
return rv;
}
// MOZ_KnownLive(rightDivOrParagraphElement) because it's grabbed by
@ -7465,7 +7491,9 @@ nsresult HTMLEditor::SplitParagraph(Element& aParentDivOrP,
rv = InsertBRElementIfEmptyBlockElement(
MOZ_KnownLive(*rightDivOrParagraphElement));
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::InsertBRElementIfEmptyBlockElement() failed");
NS_WARNING(
"InsertBRElementIfEmptyBlockElement(rightDivOrParagraphElement) "
"failed");
return rv;
}
@ -9558,40 +9586,6 @@ nsresult HTMLEditor::InsertPaddingBRElementForEmptyLastLineIfNeeded(
return NS_OK;
}
nsresult HTMLEditor::InsertBRElementIfEmptyBlockElement(Element& aElement) {
MOZ_ASSERT(IsEditActionDataAvailable());
if (!HTMLEditUtils::IsBlockElement(aElement)) {
return NS_OK;
}
if (!HTMLEditUtils::IsEmptyNode(
aElement, {EmptyCheckOption::TreatSingleBRElementAsVisible})) {
return NS_OK;
}
CreateElementResult insertBRElementResult =
InsertBRElement(WithTransaction::Yes, EditorDOMPoint(&aElement, 0u));
if (insertBRElementResult.isErr()) {
NS_WARNING("HTMLEditor::InsertBRElement(WithTransaction::Yes) failed");
return insertBRElementResult.unwrapErr();
}
// XXX Is this intentional selection change?
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
if (NS_FAILED(rv)) {
NS_WARNING("CreateElementResult::SuggestCaretPointTo() failed");
return rv;
}
NS_WARNING_ASSERTION(
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
"CreateElementResult::SuggestCaretPointTo() failed, but ignored");
MOZ_ASSERT(insertBRElementResult.GetNewNode());
return NS_OK;
}
nsresult HTMLEditor::RemoveAlignFromDescendants(Element& aElement,
const nsAString& aAlignType,
EditTarget aEditTarget) {

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

@ -1458,12 +1458,6 @@ class HTMLEditor final : public EditorBase,
InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary(
const EditorDOMPoint& aPointToInsert);
/**
* Insert a `<br>` element if aElement is a block element and empty.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
InsertBRElementIfEmptyBlockElement(Element& aElement);
/**
* Insert padding `<br>` element for empty last line into aElement if
* aElement is a block element and empty.