Bug 1156062 part 1a - New nsEditor::SplitNodeDeep variant; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Wed, 05 Aug 2015 17:54:36 +0300
changeset 287973 d52990c9dea8ca4f85249e2fc9baa900218146e9
parent 287972 8a866b4de644140d10238d87ff8581a5646a3c23
child 287974 712501bf9b886066f5f8c2ce6ff3e7b3c5ad3000
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1156062
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1156062 part 1a - New nsEditor::SplitNodeDeep variant; r=ehsan
editor/libeditor/nsEditor.cpp
editor/libeditor/nsEditor.h
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -3826,16 +3826,43 @@ nsEditor::IsPreformatted(nsIDOMNode *aNo
 //                appropriate.  The place to split is represented by
 //                a dom point at {splitPointParent, splitPointOffset}.
 //                That dom point must be inside aNode, which is the node to
 //                split.  outOffset is set to the offset in the parent of aNode where
 //                the split terminates - where you would want to insert
 //                a new element, for instance, if that's why you were splitting
 //                the node.
 //
+int32_t
+nsEditor::SplitNodeDeep(nsIContent& aNode, nsIContent& aSplitPointParent,
+                        int32_t aSplitPointOffset,
+                        EmptyContainers aEmptyContainers,
+                        nsIContent** outLeftNode,
+                        nsIContent** outRightNode)
+{
+  int32_t offset;
+  nsCOMPtr<nsIDOMNode> leftNodeDOM, rightNodeDOM;
+  nsresult res = SplitNodeDeep(aNode.AsDOMNode(),
+      aSplitPointParent.AsDOMNode(), aSplitPointOffset, &offset,
+      aEmptyContainers == EmptyContainers::no, address_of(leftNodeDOM),
+      address_of(rightNodeDOM));
+  NS_ENSURE_SUCCESS(res, -1);
+  if (outLeftNode) {
+    nsCOMPtr<nsIContent> leftNode = do_QueryInterface(leftNodeDOM);
+    MOZ_ASSERT(!leftNodeDOM || leftNode);
+    leftNode.forget(outLeftNode);
+  }
+  if (outRightNode) {
+    nsCOMPtr<nsIContent> rightNode = do_QueryInterface(rightNodeDOM);
+    MOZ_ASSERT(!rightNodeDOM || rightNode);
+    rightNode.forget(outRightNode);
+  }
+  return offset;
+}
+
 nsresult
 nsEditor::SplitNodeDeep(nsIDOMNode *aNode,
                         nsIDOMNode *aSplitPointParent,
                         int32_t aSplitPointOffset,
                         int32_t *outOffset,
                         bool    aNoEmptyContainers,
                         nsCOMPtr<nsIDOMNode> *outLeftNode,
                         nsCOMPtr<nsIDOMNode> *outRightNode)
--- a/editor/libeditor/nsEditor.h
+++ b/editor/libeditor/nsEditor.h
@@ -633,23 +633,27 @@ public:
 
   // Creates a range with just the supplied node and appends that to the selection
   nsresult AppendNodeToSelectionAsRange(nsIDOMNode *aNode);
   // When you are using AppendNodeToSelectionAsRange, call this first to start a new selection
   nsresult ClearSelection();
 
   nsresult IsPreformatted(nsIDOMNode *aNode, bool *aResult);
 
-  nsresult SplitNodeDeep(nsIDOMNode *aNode,
-                         nsIDOMNode *aSplitPointParent,
-                         int32_t aSplitPointOffset,
-                         int32_t *outOffset,
-                         bool    aNoEmptyContainers = false,
-                         nsCOMPtr<nsIDOMNode> *outLeftNode = 0,
-                         nsCOMPtr<nsIDOMNode> *outRightNode = 0);
+  enum class EmptyContainers { no, yes };
+  int32_t SplitNodeDeep(nsIContent& aNode, nsIContent& aSplitPointParent,
+                        int32_t aSplitPointOffset,
+                        EmptyContainers aEmptyContainers =
+                          EmptyContainers::yes,
+                        nsIContent** outLeftNode = nullptr,
+                        nsIContent** outRightNode = nullptr);
+  nsresult SplitNodeDeep(nsIDOMNode* aNode, nsIDOMNode* aSplitPointParent,
+      int32_t aSplitPointOffset, int32_t* outOffset, bool aNoEmptyContainers =
+      false, nsCOMPtr<nsIDOMNode>* outLeftNode = nullptr, nsCOMPtr<nsIDOMNode>*
+      outRightNode = nullptr);
   ::DOMPoint JoinNodeDeep(nsIContent& aLeftNode, nsIContent& aRightNode);
 
   nsresult GetString(const nsAString& name, nsAString& value);
 
   void BeginUpdateViewBatch(void);
   virtual nsresult EndUpdateViewBatch(void);
 
   bool GetShouldTxnSetSelection();