Bug 1574852 - part 44: Move HTMLEditRules::IsEmptyBlockElement() to HTMLEditor r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D44181

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-09-02 06:37:43 +00:00
parent fc08e740d8
commit 7c64e596da
3 changed files with 21 additions and 21 deletions

View File

@ -1928,7 +1928,8 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
// 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(*blockParent, IgnoreSingleBR::eNo)) {
if (HTMLEditorRef().IsEmptyBlockElement(*blockParent,
HTMLEditor::IgnoreSingleBR::No)) {
AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
EditorDOMPoint endOfBlockParent;
endOfBlockParent.SetToEndOf(blockParent);
@ -6086,20 +6087,16 @@ nsresult HTMLEditor::CreateStyleForInsertText(AbstractRange& aAbstractRange) {
return rv;
}
bool HTMLEditRules::IsEmptyBlockElement(Element& aElement,
IgnoreSingleBR aIgnoreSingleBR) {
MOZ_ASSERT(IsEditorDataAvailable());
if (NS_WARN_IF(!HTMLEditor::NodeIsBlockStatic(aElement))) {
bool HTMLEditor::IsEmptyBlockElement(Element& aElement,
IgnoreSingleBR aIgnoreSingleBR) const {
if (!HTMLEditor::NodeIsBlockStatic(aElement)) {
return false;
}
bool isEmpty = true;
nsresult rv = HTMLEditorRef().IsEmptyNode(
&aElement, &isEmpty, aIgnoreSingleBR == IgnoreSingleBR::eYes);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
return isEmpty;
nsresult rv =
IsEmptyNode(&aElement, &isEmpty, aIgnoreSingleBR == IgnoreSingleBR::Yes);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "IsEmptyNode() failed");
return NS_SUCCEEDED(rv) && isEmpty;
}
nsresult HTMLEditRules::WillAlign(const nsAString& aAlignType, bool* aCancel,
@ -8034,7 +8031,8 @@ nsresult HTMLEditRules::ReturnInHeader(Element& aHeader, nsINode& aNode,
}
// If the new (righthand) header node is empty, delete it
if (IsEmptyBlockElement(aHeader, IgnoreSingleBR::eYes)) {
if (HTMLEditorRef().IsEmptyBlockElement(aHeader,
HTMLEditor::IgnoreSingleBR::Yes)) {
rv = MOZ_KnownLive(HTMLEditorRef()).DeleteNodeWithTransaction(aHeader);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
@ -8433,7 +8431,8 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
// only if prefs say it's okay and if the parent isn't the active editing
// host.
if (host != aListItem.GetParentElement() &&
IsEmptyBlockElement(aListItem, IgnoreSingleBR::eYes)) {
HTMLEditorRef().IsEmptyBlockElement(aListItem,
HTMLEditor::IgnoreSingleBR::Yes)) {
nsCOMPtr<nsIContent> leftListNode = aListItem.GetParent();
// Are we the last list item in the list?
if (!HTMLEditorRef().IsLastEditableChild(&aListItem)) {

View File

@ -618,13 +618,6 @@ class HTMLEditRules : public TextEditRules {
nsAtom& aListType,
nsAtom& aItemType);
/**
* IsEmptyBlockElement() returns true if aElement is a block level element
* and it doesn't have any visible content.
*/
enum class IgnoreSingleBR { eYes, eNo };
bool IsEmptyBlockElement(Element& aElement, IgnoreSingleBR aIgnoreSingleBR);
/**
* MaybeDeleteTopMostEmptyAncestor() looks for top most empty block ancestor
* of aStartNode in aEditingHostElement.

View File

@ -1755,6 +1755,14 @@ class HTMLEditor final : public TextEditor,
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE 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;
protected: // Called by helper classes.
virtual void OnStartToHandleTopLevelEditSubAction(
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;