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
Родитель 72ea02b6a7
Коммит 364649f84e
3 изменённых файлов: 34 добавлений и 39 удалений

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

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

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

@ -425,7 +425,7 @@ class HTMLEditRules : public TextEditRules {
*
* @param aBlockType New block tag name.
* If nsGkAtoms::normal or nsGkAtoms::_empty,
* RemoveBlockStyle() will be called.
* RemoveBlockContainerElements() will be called.
* If nsGkAtoms::blockquote,
* MoveNodesIntoNewBlockquoteElement() will be
* called. Otherwise, ApplyBlockStyle() will
@ -755,17 +755,6 @@ class HTMLEditRules : public TextEditRules {
void MakeTransitionList(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
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
* whose name is aBlockTag.

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

@ -1665,6 +1665,17 @@ class HTMLEditor final : public TextEditor,
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult MoveNodesIntoNewBlockquoteElement(
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.
virtual void OnStartToHandleTopLevelEditSubAction(
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;