diff --git a/editor/libeditor/HTMLEditSubActionHandler.cpp b/editor/libeditor/HTMLEditSubActionHandler.cpp
index d18977d52b7b..3c1f538e71c4 100644
--- a/editor/libeditor/HTMLEditSubActionHandler.cpp
+++ b/editor/libeditor/HTMLEditSubActionHandler.cpp
@@ -2354,8 +2354,7 @@ EditorDOMPoint HTMLEditor::GetGoodCaretPointFor(
// If we are going backward, put caret to next node unless aContent is an
// invisible `
` element.
// XXX Shouldn't we put caret to first leaf of the next node?
- if (!aContent.IsHTMLElement(nsGkAtoms::br) ||
- HTMLEditUtils::IsVisibleBRElement(aContent)) {
+ if (!HTMLEditUtils::IsInvisibleBRElement(aContent)) {
EditorDOMPoint ret(EditorDOMPoint::After(aContent));
NS_WARNING_ASSERTION(ret.IsSet(), "Failed to set after aContent");
return ret;
@@ -8203,8 +8202,8 @@ nsresult HTMLEditor::AdjustCaretPositionAndEnsurePaddingBRElement(
previousEditableContent->IsHTMLElement(nsGkAtoms::br)) {
// If it's an invisible `
` element, we need to insert a padding
// `
` element for making empty line have one-line height.
- if (!HTMLEditUtils::IsVisibleBRElement(*previousEditableContent,
- editingHost)) {
+ if (HTMLEditUtils::IsInvisibleBRElement(*previousEditableContent,
+ editingHost)) {
CreateElementResult createPaddingBRResult =
InsertPaddingBRElementForEmptyLastLineWithTransaction(point);
if (createPaddingBRResult.Failed()) {
diff --git a/editor/libeditor/HTMLEditUtils.h b/editor/libeditor/HTMLEditUtils.h
index 1e137b78bd66..728cf6b9ca55 100644
--- a/editor/libeditor/HTMLEditUtils.h
+++ b/editor/libeditor/HTMLEditUtils.h
@@ -263,9 +263,9 @@ class HTMLEditUtils final {
dom::Text& aText);
/**
- * IsVisibleBRElement() returns true if aContent is a visible HTML
- * element, i.e., not a padding
element for making last line in a
- * block element visible.
+ * IsVisibleBRElement() and IsInvisibleBRElement() return true if aContent is
+ * a visible HTML
element, i.e., not a padding
element for making
+ * last line in a block element visible, or an invisible
element.
*
* If aEditingHost is omitted, this computes parent editable block for you.
* But if you call this a lot, please specify proper editing host (or parent
@@ -273,6 +273,11 @@ class HTMLEditUtils final {
*/
static bool IsVisibleBRElement(const nsIContent& aContent,
const Element* aEditingHost = nullptr);
+ static bool IsInvisibleBRElement(const nsIContent& aContent,
+ const Element* aEditingHost = nullptr) {
+ return aContent.IsHTMLElement(nsGkAtoms::br) &&
+ !HTMLEditUtils::IsVisibleBRElement(aContent, aEditingHost);
+ }
/**
* IsEmptyNode() returns false if aNode has some visible content nodes,
diff --git a/editor/libeditor/HTMLEditorDataTransfer.cpp b/editor/libeditor/HTMLEditorDataTransfer.cpp
index 0674374d2648..090b95341c3e 100644
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -340,10 +340,8 @@ HTMLEditor::HTMLWithContextInserter::GetInvisibleBRElementAtPoint(
WSRunScanner wsRunScannerAtInsertionPoint(mHTMLEditor.GetActiveEditingHost(),
aPointToInsert);
if (wsRunScannerAtInsertionPoint.GetEndReasonContent() &&
- wsRunScannerAtInsertionPoint.GetEndReasonContent()->IsHTMLElement(
- nsGkAtoms::br) &&
- !HTMLEditUtils::IsVisibleBRElement(
- *wsRunScannerAtInsertionPoint.EndReasonBRElementPtr(),
+ HTMLEditUtils::IsInvisibleBRElement(
+ *wsRunScannerAtInsertionPoint.GetEndReasonContent(),
wsRunScannerAtInsertionPoint.GetEditingHost())) {
return wsRunScannerAtInsertionPoint.EndReasonBRElementPtr();
}
@@ -406,7 +404,7 @@ HTMLEditor::HTMLWithContextInserter::GetNewCaretPointAfterInsertingHTML(
if (wsRunScannerAtCaret
.ScanPreviousVisibleNodeOrBlockBoundaryFrom(pointToPutCaret)
.ReachedBRElement() &&
- !HTMLEditUtils::IsVisibleBRElement(
+ HTMLEditUtils::IsInvisibleBRElement(
*wsRunScannerAtCaret.GetStartReasonContent(), editingHost)) {
WSRunScanner wsRunScannerAtStartReason(
editingHost,
diff --git a/editor/libeditor/HTMLEditorDeleteHandler.cpp b/editor/libeditor/HTMLEditorDeleteHandler.cpp
index 8354cd1d22c8..1b7e42275003 100644
--- a/editor/libeditor/HTMLEditorDeleteHandler.cpp
+++ b/editor/libeditor/HTMLEditorDeleteHandler.cpp
@@ -1293,7 +1293,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete(
*scanFromCaretPointResult.BRElementPtr(), EditorType::HTML)) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
- if (!HTMLEditUtils::IsVisibleBRElement(
+ if (HTMLEditUtils::IsInvisibleBRElement(
*scanFromCaretPointResult.BRElementPtr(), editingHost)) {
EditorDOMPoint newCaretPosition =
aDirectionAndAmount == nsIEditor::eNext
@@ -1567,7 +1567,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::Run(
*scanFromCaretPointResult.BRElementPtr(), EditorType::HTML)) {
return EditActionCanceled();
}
- if (!HTMLEditUtils::IsVisibleBRElement(
+ if (HTMLEditUtils::IsInvisibleBRElement(
*scanFromCaretPointResult.BRElementPtr(), editingHost)) {
// TODO: We should extend the range to delete again before/after
// the caret point and use `HandleDeleteNonCollapsedRanges()`
@@ -1620,7 +1620,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::Run(
return EditActionResult(NS_ERROR_FAILURE);
}
if (scanFromCaretPointResult.ReachedBRElement() &&
- !HTMLEditUtils::IsVisibleBRElement(
+ HTMLEditUtils::IsInvisibleBRElement(
*scanFromCaretPointResult.BRElementPtr(), editingHost)) {
return EditActionHandled(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
@@ -2387,9 +2387,8 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::HandleDeleteAtomicContent(
const EditorDOMPoint& aCaretPoint,
const WSRunScanner& aWSRunScannerAtCaret) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
- MOZ_ASSERT_IF(aAtomicContent.IsHTMLElement(nsGkAtoms::br),
- HTMLEditUtils::IsVisibleBRElement(
- aAtomicContent, aWSRunScannerAtCaret.GetEditingHost()));
+ MOZ_ASSERT(!HTMLEditUtils::IsInvisibleBRElement(
+ aAtomicContent, aWSRunScannerAtCaret.GetEditingHost()));
MOZ_ASSERT(&aAtomicContent != aWSRunScannerAtCaret.GetEditingHost());
nsresult rv =
@@ -3373,8 +3372,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
{EmptyCheckOption::TreatSingleBRElementAsVisible})) {
continue;
}
- if (!content->IsHTMLElement(nsGkAtoms::br) ||
- HTMLEditUtils::IsVisibleBRElement(*content)) {
+ if (!HTMLEditUtils::IsInvisibleBRElement(*content)) {
return false;
}
}
@@ -4434,8 +4432,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
NS_WARNING_ASSERTION(editingHost, "There was no editing host");
nsIContent* nextContent =
atStart.IsEndOfContainer() && range.StartRef().GetChild() &&
- range.StartRef().GetChild()->IsHTMLElement(nsGkAtoms::br) &&
- !HTMLEditUtils::IsVisibleBRElement(
+ HTMLEditUtils::IsInvisibleBRElement(
*range.StartRef().GetChild(), editingHost)
? HTMLEditUtils::GetNextContent(
*atStart.ContainerAsContent(),