Bug 1574852 - part 36: Move HTMLEditRules::RemvoeBlockStyle() to HTMLEditor r=m_kato

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-08-26 04:00:15 +00:00
parent 72ea02b6a7
commit 364649f84e
3 changed files with 34 additions and 39 deletions

View File

@ -4725,7 +4725,8 @@ nsresult HTMLEditRules::MakeBasicBlock(nsAtom& blockType) {
} }
} else if (&blockType == nsGkAtoms::normal || } else if (&blockType == nsGkAtoms::normal ||
&blockType == nsGkAtoms::_empty) { &blockType == nsGkAtoms::_empty) {
rv = RemoveBlockStyle(arrayOfNodes); rv = MOZ_KnownLive(HTMLEditorRef())
.RemoveBlockContainerElements(arrayOfNodes);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -8773,9 +8774,9 @@ nsresult HTMLEditor::MoveNodesIntoNewBlockquoteElement(
return NS_OK; return NS_OK;
} }
nsresult HTMLEditRules::RemoveBlockStyle( nsresult HTMLEditor::RemoveBlockContainerElements(
nsTArray<OwningNonNull<nsINode>>& aNodeArray) { nsTArray<OwningNonNull<nsINode>>& aNodeArray) {
MOZ_ASSERT(IsEditorDataAvailable()); MOZ_ASSERT(IsEditActionDataAvailable());
// Intent of this routine is to be used for converting to/from headers, // Intent of this routine is to be used for converting to/from headers,
// paragraphs, pre, and address. Those blocks that pretty much just contain // paragraphs, pre, and address. Those blocks that pretty much just contain
@ -8788,22 +8789,20 @@ nsresult HTMLEditRules::RemoveBlockStyle(
// Process any partial progress saved // Process any partial progress saved
if (curBlock) { if (curBlock) {
SplitRangeOffFromNodeResult removeMiddleContainerResult = SplitRangeOffFromNodeResult removeMiddleContainerResult =
MOZ_KnownLive(HTMLEditorRef()) SplitRangeOffFromBlockAndRemoveMiddleContainer(
.SplitRangeOffFromBlockAndRemoveMiddleContainer( *curBlock, *firstNode, *lastNode);
*curBlock, *firstNode, *lastNode);
if (NS_WARN_IF(removeMiddleContainerResult.Failed())) { if (NS_WARN_IF(removeMiddleContainerResult.Failed())) {
return removeMiddleContainerResult.Rv(); return removeMiddleContainerResult.Rv();
} }
firstNode = lastNode = curBlock = nullptr; firstNode = lastNode = curBlock = nullptr;
} }
if (!HTMLEditorRef().IsEditable(curNode)) { if (!IsEditable(curNode)) {
continue; continue;
} }
// Remove current block // Remove current block
nsresult rv = MOZ_KnownLive(HTMLEditorRef()) nsresult rv = RemoveBlockContainerWithTransaction(
.RemoveBlockContainerWithTransaction( MOZ_KnownLive(*curNode->AsElement()));
MOZ_KnownLive(*curNode->AsElement())); if (NS_WARN_IF(Destroyed())) {
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED; return NS_ERROR_EDITOR_DESTROYED;
} }
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
@ -8820,21 +8819,20 @@ nsresult HTMLEditRules::RemoveBlockStyle(
// Process any partial progress saved // Process any partial progress saved
if (curBlock) { if (curBlock) {
SplitRangeOffFromNodeResult removeMiddleContainerResult = SplitRangeOffFromNodeResult removeMiddleContainerResult =
MOZ_KnownLive(HTMLEditorRef()) SplitRangeOffFromBlockAndRemoveMiddleContainer(
.SplitRangeOffFromBlockAndRemoveMiddleContainer( *curBlock, *firstNode, *lastNode);
*curBlock, *firstNode, *lastNode);
if (NS_WARN_IF(removeMiddleContainerResult.Failed())) { if (NS_WARN_IF(removeMiddleContainerResult.Failed())) {
return removeMiddleContainerResult.Rv(); return removeMiddleContainerResult.Rv();
} }
firstNode = lastNode = curBlock = nullptr; firstNode = lastNode = curBlock = nullptr;
} }
if (!HTMLEditorRef().IsEditable(curNode)) { if (!IsEditable(curNode)) {
continue; continue;
} }
// Recursion time // Recursion time
AutoTArray<OwningNonNull<nsINode>, 24> childNodes; AutoTArray<OwningNonNull<nsINode>, 24> childNodes;
HTMLEditor::GetChildNodesOf(*curNode, childNodes); HTMLEditor::GetChildNodesOf(*curNode, childNodes);
nsresult rv = RemoveBlockStyle(childNodes); nsresult rv = RemoveBlockContainerElements(childNodes);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }
@ -8853,18 +8851,17 @@ nsresult HTMLEditRules::RemoveBlockStyle(
// handle it now. We need to remove the portion of curBlock that // handle it now. We need to remove the portion of curBlock that
// contains [firstNode - lastNode]. // contains [firstNode - lastNode].
SplitRangeOffFromNodeResult removeMiddleContainerResult = SplitRangeOffFromNodeResult removeMiddleContainerResult =
MOZ_KnownLive(HTMLEditorRef()) SplitRangeOffFromBlockAndRemoveMiddleContainer(
.SplitRangeOffFromBlockAndRemoveMiddleContainer( *curBlock, *firstNode, *lastNode);
*curBlock, *firstNode, *lastNode);
if (NS_WARN_IF(removeMiddleContainerResult.Failed())) { if (NS_WARN_IF(removeMiddleContainerResult.Failed())) {
return removeMiddleContainerResult.Rv(); return removeMiddleContainerResult.Rv();
} }
firstNode = lastNode = curBlock = nullptr; firstNode = lastNode = curBlock = nullptr;
// Fall out and handle curNode // Fall out and handle curNode
} }
curBlock = HTMLEditorRef().GetBlockNodeParent(curNode); curBlock = GetBlockNodeParent(curNode);
if (!curBlock || !HTMLEditUtils::IsFormatNode(curBlock) || if (!curBlock || !HTMLEditUtils::IsFormatNode(curBlock) ||
!HTMLEditorRef().IsEditable(curBlock)) { !IsEditable(curBlock)) {
// Not a block kind that we care about. // Not a block kind that we care about.
curBlock = nullptr; curBlock = nullptr;
} else { } else {
@ -8877,9 +8874,8 @@ nsresult HTMLEditRules::RemoveBlockStyle(
// Some node that is already sans block style. Skip over it and process // Some node that is already sans block style. Skip over it and process
// any partial progress saved. // any partial progress saved.
SplitRangeOffFromNodeResult removeMiddleContainerResult = SplitRangeOffFromNodeResult removeMiddleContainerResult =
MOZ_KnownLive(HTMLEditorRef()) SplitRangeOffFromBlockAndRemoveMiddleContainer(*curBlock, *firstNode,
.SplitRangeOffFromBlockAndRemoveMiddleContainer( *lastNode);
*curBlock, *firstNode, *lastNode);
if (NS_WARN_IF(removeMiddleContainerResult.Failed())) { if (NS_WARN_IF(removeMiddleContainerResult.Failed())) {
return removeMiddleContainerResult.Rv(); return removeMiddleContainerResult.Rv();
} }
@ -8890,9 +8886,8 @@ nsresult HTMLEditRules::RemoveBlockStyle(
// Process any partial progress saved // Process any partial progress saved
if (curBlock) { if (curBlock) {
SplitRangeOffFromNodeResult removeMiddleContainerResult = SplitRangeOffFromNodeResult removeMiddleContainerResult =
MOZ_KnownLive(HTMLEditorRef()) SplitRangeOffFromBlockAndRemoveMiddleContainer(*curBlock, *firstNode,
.SplitRangeOffFromBlockAndRemoveMiddleContainer( *lastNode);
*curBlock, *firstNode, *lastNode);
if (NS_WARN_IF(removeMiddleContainerResult.Failed())) { if (NS_WARN_IF(removeMiddleContainerResult.Failed())) {
return removeMiddleContainerResult.Rv(); return removeMiddleContainerResult.Rv();
} }

View File

@ -425,7 +425,7 @@ class HTMLEditRules : public TextEditRules {
* *
* @param aBlockType New block tag name. * @param aBlockType New block tag name.
* If nsGkAtoms::normal or nsGkAtoms::_empty, * If nsGkAtoms::normal or nsGkAtoms::_empty,
* RemoveBlockStyle() will be called. * RemoveBlockContainerElements() will be called.
* If nsGkAtoms::blockquote, * If nsGkAtoms::blockquote,
* MoveNodesIntoNewBlockquoteElement() will be * MoveNodesIntoNewBlockquoteElement() will be
* called. Otherwise, ApplyBlockStyle() will * called. Otherwise, ApplyBlockStyle() will
@ -755,17 +755,6 @@ class HTMLEditRules : public TextEditRules {
void MakeTransitionList(nsTArray<OwningNonNull<nsINode>>& aNodeArray, void MakeTransitionList(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
nsTArray<bool>& aTransitionArray); nsTArray<bool>& aTransitionArray);
/**
* RemoveBlockStyle() removes all format blocks, table related element,
* etc in aNodeArray.
* If aNodeArray has a format node, it will be removed and its contents
* will be moved to where it was.
* If aNodeArray has a table related element, <li>, <blockquote> or <div>,
* it will removed and its contents will be moved to where it was.
*/
MOZ_CAN_RUN_SCRIPT
nsresult RemoveBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
/** /**
* ApplyBlockStyle() formats all nodes in aNodeArray with block elements * ApplyBlockStyle() formats all nodes in aNodeArray with block elements
* whose name is aBlockTag. * whose name is aBlockTag.

View File

@ -1665,6 +1665,17 @@ class HTMLEditor final : public TextEditor,
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult MoveNodesIntoNewBlockquoteElement( MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult MoveNodesIntoNewBlockquoteElement(
nsTArray<OwningNonNull<nsINode>>& aNodeArray); nsTArray<OwningNonNull<nsINode>>& aNodeArray);
/**
* RemoveBlockContainerElements() removes all format blocks, table related
* element, etc in aNodeArray from the DOM tree.
* If aNodeArray has a format node, it will be removed and its contents
* will be moved to where it was.
* If aNodeArray has a table related element, <li>, <blockquote> or <div>,
* it will be removed and its contents will be moved to where it was.
*/
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
RemoveBlockContainerElements(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
protected: // Called by helper classes. protected: // Called by helper classes.
virtual void OnStartToHandleTopLevelEditSubAction( virtual void OnStartToHandleTopLevelEditSubAction(
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override; EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;