Bug 1627175 - part 58: Move `HTMLEditor::IsEmptyBlockElement()` to `HTMLEditUtils` r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D115167
This commit is contained in:
Masayuki Nakano 2021-05-17 21:50:39 +00:00
Родитель e412a4f3bf
Коммит e0baad182c
4 изменённых файлов: 15 добавлений и 24 удалений

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

@ -1388,7 +1388,8 @@ EditActionResult HTMLEditor::InsertParagraphSeparatorAsSubAction() {
// contains the word "text". The user selects "text" and types return.
// "Text" is deleted leaving an empty block. We want to put in one br to
// make block have a line. Then code further below will put in a second br.)
if (IsEmptyBlockElement(*blockElement, IgnoreSingleBR::No)) {
if (HTMLEditUtils::IsEmptyBlockElement(
*blockElement, {EmptyCheckOption::TreatSingleBRElementAsVisible})) {
AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
EditorDOMPoint endOfBlockParent;
endOfBlockParent.SetToEndOf(blockElement);
@ -4714,18 +4715,6 @@ nsresult HTMLEditor::CreateStyleForInsertText(
return rv;
}
bool HTMLEditor::IsEmptyBlockElement(Element& aElement,
IgnoreSingleBR aIgnoreSingleBR) const {
if (!HTMLEditUtils::IsBlockElement(aElement)) {
return false;
}
HTMLEditUtils::EmptyCheckOptions options;
if (aIgnoreSingleBR != IgnoreSingleBR::Yes) {
options += EmptyCheckOption::TreatSingleBRElementAsVisible;
}
return HTMLEditUtils::IsEmptyNode(aElement, options);
}
EditActionResult HTMLEditor::AlignAsSubAction(const nsAString& aAlignType) {
MOZ_ASSERT(IsEditActionDataAvailable());
@ -6496,7 +6485,7 @@ nsresult HTMLEditor::HandleInsertParagraphInHeadingElement(Element& aHeader,
}
// If the new (righthand) header node is empty, delete it
if (IsEmptyBlockElement(aHeader, IgnoreSingleBR::Yes)) {
if (HTMLEditUtils::IsEmptyBlockElement(aHeader, {})) {
nsresult rv = DeleteNodeWithTransaction(aHeader);
if (NS_WARN_IF(Destroyed())) {
return NS_ERROR_EDITOR_DESTROYED;
@ -6896,7 +6885,7 @@ nsresult HTMLEditor::HandleInsertParagraphInListItemElement(Element& aListItem,
// only if prefs say it's okay and if the parent isn't the active editing
// host.
if (editingHost != aListItem.GetParentElement() &&
IsEmptyBlockElement(aListItem, IgnoreSingleBR::Yes)) {
HTMLEditUtils::IsEmptyBlockElement(aListItem, {})) {
nsCOMPtr<nsIContent> leftListNode = aListItem.GetParent();
// Are we the last list item in the list?
if (!HTMLEditUtils::IsLastChild(aListItem,

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

@ -395,7 +395,7 @@ bool HTMLEditUtils::IsVisibleTextNode(
}
WSScanResult nextWSScanResult =
WSRunScanner::ScanNextVisibleNodeOrBlockBoundary(
aEditingHost, EditorRawDOMPoint(&aText, 0));
const_cast<Element*>(aEditingHost), EditorRawDOMPoint(&aText, 0));
return nextWSScanResult.InNormalWhiteSpacesOrText() &&
nextWSScanResult.TextPtr() == &aText;
}

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

@ -319,6 +319,16 @@ class HTMLEditUtils final {
aContent, {EmptyCheckOption::TreatSingleBRElementAsVisible});
}
/**
* IsEmptyBlockElement() returns true if aElement is a block level element
* and it doesn't have any visible content.
*/
static bool IsEmptyBlockElement(const Element& aElement,
const EmptyCheckOptions& aOptions) {
return HTMLEditUtils::IsBlockElement(aElement) &&
HTMLEditUtils::IsEmptyNode(aElement, aOptions);
}
/**
* IsEmptyOneHardLine() returns true if aArrayOfContents does not represent
* 2 or more lines and have meaningful content.

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

@ -1591,14 +1591,6 @@ class HTMLEditor final : public TextEditor,
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
/**
* IsEmptyBlockElement() returns true if aElement is a block level element
* and it doesn't have any visible content.
*/
enum class IgnoreSingleBR { Yes, No };
bool IsEmptyBlockElement(Element& aElement,
IgnoreSingleBR aIgnoreSingleBR) const;
/**
* SplitParagraph() splits the parent block, aParentDivOrP, at
* aStartOfRightNode.