Bug 1460509 - part 42: Make HTMLEditRules::BustUpInlinesAtBRs() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 15 May 2018 17:04:28 +0900
changeset 798760 da8dc60eeb184fe4d0abcefafddf748ac525b6b1
parent 798759 188287c29177ed4e25ea5a5cd02348ff85941172
child 798761 29a58365db705ddab2c83c30c9b14b6e771f2377
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
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
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- 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);