Bug 1460509 - part 42: Make HTMLEditRules::BustUpInlinesAtBRs() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato
MozReview-Commit-ID: 5KGPE8mPqge
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -7179,32 +7179,38 @@ HTMLEditRules::BustUpInlinesAtBRs(
EditorRawDOMPoint atBrNode(brNode);
if (NS_WARN_IF(!atBrNode.IsSet())) {
return NS_ERROR_FAILURE;
}
SplitNodeResult splitNodeResult =
HTMLEditorRef().SplitNodeDeepWithTransaction(
*nextNode, atBrNode,
SplitAtEdges::eAllowToCreateEmptyContainer);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
// Put previous node at the split point.
if (splitNodeResult.GetPreviousNode()) {
// Might not be a left node. A break might have been at the very
// beginning of inline container, in which case
// SplitNodeDeepWithTransaction() would not actually split anything.
aOutArrayOfNodes.AppendElement(*splitNodeResult.GetPreviousNode());
}
// Move break outside of container and also put in node list
EditorRawDOMPoint atNextNode(splitNodeResult.GetNextNode());
nsresult rv =
HTMLEditorRef().MoveNodeWithTransaction(*brNode->AsContent(), atNextNode);
+ if (NS_WARN_IF(!CanHandleEditAction())) {
+ return NS_ERROR_EDITOR_DESTROYED;
+ }
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
aOutArrayOfNodes.AppendElement(*brNode);
nextNode = splitNodeResult.GetNextNode();
}
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -499,19 +499,32 @@ protected:
EntireList aEntireList,
TouchContent aTouchContent = TouchContent::yes);
void GetDefinitionListItemTypes(Element* aElement, bool* aDT, bool* aDD);
nsresult GetParagraphFormatNodes(
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
TouchContent aTouchContent = TouchContent::yes);
void LookInsideDivBQandList(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
nsresult BustUpInlinesAtRangeEndpoints(RangeItem& inRange);
- nsresult BustUpInlinesAtBRs(
- nsIContent& aNode,
- nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes);
+
+ /**
+ * BustUpInlinesAtBRs() splits before all <br> elements in aNode. All <br>
+ * nodes will be moved before right node at splitting its parent. Finally,
+ * this returns all <br> elements, every left node and aNode with
+ * aOutArrayNodes.
+ *
+ * @param aNode An inline container element.
+ * @param aOutArrayOfNodes All found <br> elements, left nodes (may not
+ * be set if <br> is at start edge of aNode) and
+ * aNode itself.
+ */
+ MOZ_MUST_USE nsresult
+ BustUpInlinesAtBRs(nsIContent& aNode,
+ nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes);
+
/**
* GetHiestInlineParent() returns the highest inline node parent between
* aNode and the editing host. Even if the editing host is an inline
* element, this method never returns the editing host as the result.
*/
nsIContent* GetHighestInlineParent(nsINode& aNode);
void MakeTransitionList(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
nsTArray<bool>& aTransitionArray);