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:
@@ -7452,12 +7452,38 @@ nsresult HTMLEditor::SplitParagraph(Element& aParentDivOrP,
|
|||||||
// it'll be exposed as <br> with Element.innerHTML. Therefore, we can use
|
// it'll be exposed as <br> with Element.innerHTML. Therefore, we can use
|
||||||
// normal <br> elements for placeholder in this case. Note that Chromium
|
// normal <br> elements for placeholder in this case. Note that Chromium
|
||||||
// also behaves so.
|
// 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
|
// MOZ_KnownLive(leftDivOrParagraphElement) because it's grabbed by
|
||||||
// splitDivOrResult.
|
// splitDivOrResult.
|
||||||
rv = InsertBRElementIfEmptyBlockElement(
|
rv = InsertBRElementIfEmptyBlockElement(
|
||||||
MOZ_KnownLive(*leftDivOrParagraphElement));
|
MOZ_KnownLive(*leftDivOrParagraphElement));
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING("HTMLEditor::InsertBRElementIfEmptyBlockElement() failed");
|
NS_WARNING(
|
||||||
|
"InsertBRElementIfEmptyBlockElement(leftDivOrParagraphElement) failed");
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
// MOZ_KnownLive(rightDivOrParagraphElement) because it's grabbed by
|
// MOZ_KnownLive(rightDivOrParagraphElement) because it's grabbed by
|
||||||
@@ -7465,7 +7491,9 @@ nsresult HTMLEditor::SplitParagraph(Element& aParentDivOrP,
|
|||||||
rv = InsertBRElementIfEmptyBlockElement(
|
rv = InsertBRElementIfEmptyBlockElement(
|
||||||
MOZ_KnownLive(*rightDivOrParagraphElement));
|
MOZ_KnownLive(*rightDivOrParagraphElement));
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING("HTMLEditor::InsertBRElementIfEmptyBlockElement() failed");
|
NS_WARNING(
|
||||||
|
"InsertBRElementIfEmptyBlockElement(rightDivOrParagraphElement) "
|
||||||
|
"failed");
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9558,40 +9586,6 @@ nsresult HTMLEditor::InsertPaddingBRElementForEmptyLastLineIfNeeded(
|
|||||||
return NS_OK;
|
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,
|
nsresult HTMLEditor::RemoveAlignFromDescendants(Element& aElement,
|
||||||
const nsAString& aAlignType,
|
const nsAString& aAlignType,
|
||||||
EditTarget aEditTarget) {
|
EditTarget aEditTarget) {
|
||||||
|
|||||||
@@ -1458,12 +1458,6 @@ class HTMLEditor final : public EditorBase,
|
|||||||
InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary(
|
InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary(
|
||||||
const EditorDOMPoint& aPointToInsert);
|
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
|
* Insert padding `<br>` element for empty last line into aElement if
|
||||||
* aElement is a block element and empty.
|
* aElement is a block element and empty.
|
||||||
|
|||||||
Reference in New Issue
Block a user