Bug 1153629 part 7 - Clean up nsHTMLEditRules::RemoveBlockStyle, RemovePartOfBlock; r=ehsan
☠☠ backed out by 329dd852c06b ☠ ☠
authorAryeh Gregor <ayg@aryeh.name>
Wed, 22 Apr 2015 14:26:58 +0300
changeset 240511 b0b609c3da83bb914977feb5d19dbcade419253f
parent 240510 9a62d4ec4542221646cafaa2c4cd102b84f9dabf
child 240512 42f5d3fc71b32ea48dcad7914797a6dd7efb2693
push id28636
push userkwierso@gmail.com
push dateThu, 23 Apr 2015 00:16:12 +0000
treeherdermozilla-central@a5af73b32ac8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1153629
milestone40.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 1153629 part 7 - Clean up nsHTMLEditRules::RemoveBlockStyle, RemovePartOfBlock; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -3531,27 +3531,27 @@ nsHTMLEditRules::WillMakeBasicBlock(Sele
     }
     return res;    
   }
   else
   {
     // Ok, now go through all the nodes and make the right kind of blocks, 
     // or whatever is approriate.  Wohoo! 
     // Note: blockquote is handled a little differently
-    nsCOMArray<nsIDOMNode> arrayOfDOMNodes;
-    for (auto& node : arrayOfNodes) {
-      arrayOfDOMNodes.AppendObject(GetAsDOMNode(node));
-    }
-    if (tString.EqualsLiteral("blockquote"))
+    if (tString.EqualsLiteral("blockquote")) {
       res = MakeBlockquote(arrayOfNodes);
-    else if (tString.EqualsLiteral("normal") ||
-             tString.IsEmpty() )
-      res = RemoveBlockStyle(arrayOfDOMNodes);
-    else
+    } else if (tString.EqualsLiteral("normal") || tString.IsEmpty()) {
+      res = RemoveBlockStyle(arrayOfNodes);
+    } else {
+      nsCOMArray<nsIDOMNode> arrayOfDOMNodes;
+      for (auto& node : arrayOfNodes) {
+        arrayOfDOMNodes.AppendObject(GetAsDOMNode(node));
+      }
       res = ApplyBlockStyle(arrayOfDOMNodes, aBlockType);
+    }
     return res;
   }
   return res;
 }
 
 nsresult 
 nsHTMLEditRules::DidMakeBasicBlock(Selection* aSelection,
                                    nsRulesInfo *aInfo, nsresult aResult)
@@ -4303,38 +4303,31 @@ nsHTMLEditRules::WillOutdent(Selection* 
       }
     }
     return NS_OK;
   }
   return res;
 }
 
 
-///////////////////////////////////////////////////////////////////////////
-// RemovePartOfBlock:  split aBlock and move aStartChild to aEndChild out
-//                     of aBlock.  return left side of block (if any) in
-//                     aLeftNode.  return right side of block (if any) in
-//                     aRightNode.  
-//                  
-nsresult 
-nsHTMLEditRules::RemovePartOfBlock(nsIDOMNode *aBlock, 
-                                   nsIDOMNode *aStartChild, 
-                                   nsIDOMNode *aEndChild,
-                                   nsCOMPtr<nsIDOMNode> *aLeftNode,
-                                   nsCOMPtr<nsIDOMNode> *aRightNode)
-{
-  nsCOMPtr<nsIDOMNode> middleNode;
-  nsresult res = SplitBlock(aBlock, aStartChild, aEndChild,
-                            aLeftNode, aRightNode,
-                            address_of(middleNode));
-  NS_ENSURE_SUCCESS(res, res);
-  // get rid of part of blockquote we are outdenting
+///////////////////////////////////////////////////////////////////////////////
+// RemovePartOfBlock: Split aBlock and move aStartChild to aEndChild out of
+//                    aBlock.
+nsresult
+nsHTMLEditRules::RemovePartOfBlock(Element& aBlock,
+                                   nsIContent& aStartChild,
+                                   nsIContent& aEndChild)
+{
+  nsresult res = SplitBlock(aBlock.AsDOMNode(), aStartChild.AsDOMNode(),
+                            aEndChild.AsDOMNode());
+  NS_ENSURE_SUCCESS(res, res);
+  // Get rid of part of blockquote we are outdenting
 
   NS_ENSURE_STATE(mHTMLEditor);
-  return mHTMLEditor->RemoveBlockContainer(aBlock);
+  return mHTMLEditor->RemoveBlockContainer(aBlock.AsDOMNode());
 }
 
 nsresult 
 nsHTMLEditRules::SplitBlock(nsIDOMNode *aBlock, 
                             nsIDOMNode *aStartChild, 
                             nsIDOMNode *aEndChild,
                             nsCOMPtr<nsIDOMNode> *aLeftNode,
                             nsCOMPtr<nsIDOMNode> *aRightNode,
@@ -6862,124 +6855,101 @@ nsHTMLEditRules::MakeBlockquote(nsTArray
     NS_ENSURE_STATE(mHTMLEditor);
     res = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
     NS_ENSURE_SUCCESS(res, res);
   }
   return NS_OK;
 }
 
 
-///////////////////////////////////////////////////////////////////////////
-// RemoveBlockStyle:  make the nodes have no special block type.  
-//                       
-nsresult 
-nsHTMLEditRules::RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes)
-{
-  // intent of this routine is to be used for converting to/from
-  // headers, paragraphs, pre, and address.  Those blocks
-  // that pretty much just contain inline things...
-  
-  nsresult res = NS_OK;
-  
-  nsCOMPtr<nsIDOMNode> curBlock, firstNode, lastNode;
-  int32_t listCount = arrayOfNodes.Count();
-  for (int32_t i = 0; i < listCount; ++i) {
-    // get the node to act on, and its location
-    nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[i];
-
-    nsCOMPtr<dom::Element> curElement = do_QueryInterface(curNode);
-
-    // if curNode is a address, p, header, address, or pre, remove it 
-    if (curElement && nsHTMLEditUtils::IsFormatNode(curElement)) {
-      // process any partial progress saved
-      if (curBlock)
-      {
-        res = RemovePartOfBlock(curBlock, firstNode, lastNode);
+///////////////////////////////////////////////////////////////////////////////
+// RemoveBlockStyle: Make the nodes have no special block type.
+nsresult
+nsHTMLEditRules::RemoveBlockStyle(nsTArray<nsCOMPtr<nsINode>>& aNodeArray)
+{
+  NS_ENSURE_STATE(mHTMLEditor);
+  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+
+  // Intent of this routine is to be used for converting to/from headers,
+  // paragraphs, pre, and address.  Those blocks that pretty much just contain
+  // inline things...
+  nsresult res;
+
+  nsCOMPtr<Element> curBlock;
+  nsCOMPtr<nsIContent> firstNode, lastNode;
+  for (auto& curNode : aNodeArray) {
+    // If curNode is a address, p, header, address, or pre, remove it
+    if (nsHTMLEditUtils::IsFormatNode(curNode)) {
+      // Process any partial progress saved
+      if (curBlock) {
+        res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
         NS_ENSURE_SUCCESS(res, res);
-        curBlock = 0;  firstNode = 0;  lastNode = 0;
-      }
-      // remove curent block
-      NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->RemoveBlockContainer(curNode); 
+        firstNode = lastNode = curBlock = nullptr;
+      }
+      // Remove current block
+      res = mHTMLEditor->RemoveBlockContainer(curNode->AsDOMNode());
       NS_ENSURE_SUCCESS(res, res);
-    } else if (curElement &&
-               (curElement->IsAnyOfHTMLElements(nsGkAtoms::table,
-                                                nsGkAtoms::tr,
-                                                nsGkAtoms::tbody,
-                                                nsGkAtoms::td,
-                                                nsGkAtoms::li,
-                                                nsGkAtoms::blockquote,
-                                                nsGkAtoms::div) ||
-                nsHTMLEditUtils::IsList(curElement))) {
-      // process any partial progress saved
-      if (curBlock)
-      {
-        res = RemovePartOfBlock(curBlock, firstNode, lastNode);
+    } else if (curNode->IsAnyOfHTMLElements(nsGkAtoms::table,
+                                            nsGkAtoms::tr,
+                                            nsGkAtoms::tbody,
+                                            nsGkAtoms::td,
+                                            nsGkAtoms::li,
+                                            nsGkAtoms::blockquote,
+                                            nsGkAtoms::div) ||
+                nsHTMLEditUtils::IsList(curNode)) {
+      // Process any partial progress saved
+      if (curBlock) {
+        res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
         NS_ENSURE_SUCCESS(res, res);
-        curBlock = 0;  firstNode = 0;  lastNode = 0;
-      }
-      // recursion time
+        firstNode = lastNode = curBlock = nullptr;
+      }
+      // Recursion time
       nsTArray<nsCOMPtr<nsINode>> childArray;
-      GetChildNodesForOperation(*curElement, childArray);
-      nsCOMArray<nsIDOMNode> childArrayDOM;
-      for (auto& child : childArray) {
-        childArrayDOM.AppendObject(GetAsDOMNode(child));
-      }
-      res = RemoveBlockStyle(childArrayDOM);
+      GetChildNodesForOperation(*curNode, childArray);
+      res = RemoveBlockStyle(childArray);
       NS_ENSURE_SUCCESS(res, res);
-    }
-    else if (IsInlineNode(curNode))
-    {
-      if (curBlock)
-      {
-        // if so, is this node a descendant?
-        if (nsEditorUtils::IsDescendantOf(curNode, curBlock))
-        {
-          lastNode = curNode;
-          continue;  // then we don't need to do anything different for this node
+    } else if (IsInlineNode(GetAsDOMNode(curNode))) {
+      if (curBlock) {
+        // If so, is this node a descendant?
+        if (nsEditorUtils::IsDescendantOf(curNode, curBlock)) {
+          // Then we don't need to do anything different for this node
+          lastNode = curNode->AsContent();
+          continue;
+        } else {
+          // Otherwise, we have progressed beyond end of curBlock, so let's
+          // handle it now.  We need to remove the portion of curBlock that
+          // contains [firstNode - lastNode].
+          res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
+          NS_ENSURE_SUCCESS(res, res);
+          firstNode = lastNode = curBlock = nullptr;
+          // Fall out and handle curNode
         }
-        else
-        {
-          // otherwise, we have progressed beyond end of curBlock,
-          // so lets handle it now.  We need to remove the portion of 
-          // curBlock that contains [firstNode - lastNode].
-          res = RemovePartOfBlock(curBlock, firstNode, lastNode);
-          NS_ENSURE_SUCCESS(res, res);
-          curBlock = 0;  firstNode = 0;  lastNode = 0;
-          // fall out and handle curNode
-        }
-      }
-      NS_ENSURE_STATE(mHTMLEditor);
+      }
       curBlock = mHTMLEditor->GetBlockNodeParent(curNode);
       if (curBlock && nsHTMLEditUtils::IsFormatNode(curBlock)) {
-        firstNode = curNode;  
-        lastNode = curNode;
-      }
-      else
-        curBlock = 0;  // not a block kind that we care about.
-    }
-    else
-    { // some node that is already sans block style.  skip over it and
-      // process any partial progress saved
-      if (curBlock)
-      {
-        res = RemovePartOfBlock(curBlock, firstNode, lastNode);
-        NS_ENSURE_SUCCESS(res, res);
-        curBlock = 0;  firstNode = 0;  lastNode = 0;
-      }
-    }
-  }
-  // process any partial progress saved
-  if (curBlock)
-  {
-    res = RemovePartOfBlock(curBlock, firstNode, lastNode);
+        firstNode = lastNode = curNode->AsContent();
+      } else {
+        // Not a block kind that we care about.
+        curBlock = nullptr;
+      }
+    } else if (curBlock) {
+      // Some node that is already sans block style.  Skip over it and process
+      // any partial progress saved.
+      res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
+      NS_ENSURE_SUCCESS(res, res);
+      firstNode = lastNode = curBlock = nullptr;
+    }
+  }
+  // Process any partial progress saved
+  if (curBlock) {
+    res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
     NS_ENSURE_SUCCESS(res, res);
-    curBlock = 0;  firstNode = 0;  lastNode = 0;
-  }
-  return res;
+    firstNode = lastNode = curBlock = nullptr;
+  }
+  return NS_OK;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////
 // ApplyBlockStyle:  do whatever it takes to make the list of nodes into 
 //                   one or more blocks of type blockTag.  
 //                       
 nsresult 
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -215,21 +215,19 @@ protected:
                           mozilla::dom::Selection* aSelection,
                           nsCOMPtr<nsIDOMNode> *aSelNode, 
                           int32_t *aOffset);
   nsresult ReturnInListItem(mozilla::dom::Selection* aSelection,
                             nsIDOMNode* aHeader, nsIDOMNode* aTextNode,
                             int32_t aOffset);
   nsresult AfterEditInner(EditAction action,
                           nsIEditor::EDirection aDirection);
-  nsresult RemovePartOfBlock(nsIDOMNode *aBlock, 
-                             nsIDOMNode *aStartChild, 
-                             nsIDOMNode *aEndChild,
-                             nsCOMPtr<nsIDOMNode> *aLeftNode = 0,
-                             nsCOMPtr<nsIDOMNode> *aRightNode = 0);
+  nsresult RemovePartOfBlock(mozilla::dom::Element& aBlock,
+                             nsIContent& aStartChild,
+                             nsIContent& aEndChild);
   nsresult SplitBlock(nsIDOMNode *aBlock, 
                       nsIDOMNode *aStartChild, 
                       nsIDOMNode *aEndChild,
                       nsCOMPtr<nsIDOMNode> *aLeftNode = 0,
                       nsCOMPtr<nsIDOMNode> *aRightNode = 0,
                       nsCOMPtr<nsIDOMNode> *aMiddleNode = 0);
   nsresult OutdentPartOfBlock(nsIDOMNode *aBlock, 
                               nsIDOMNode *aStartChild, 
@@ -295,17 +293,17 @@ protected:
       TouchContent aTouchContent = TouchContent::yes);
   void LookInsideDivBQandList(nsTArray<nsCOMPtr<nsINode>>& aNodeArray);
   nsresult BustUpInlinesAtRangeEndpoints(nsRangeStore &inRange);
   nsresult BustUpInlinesAtBRs(nsINode& aNode,
                               nsTArray<nsCOMPtr<nsINode>>& aOutArrayOfNodes);
   nsCOMPtr<nsIDOMNode> GetHighestInlineParent(nsIDOMNode* aNode);
   nsresult MakeTransitionList(nsCOMArray<nsIDOMNode>& inArrayOfNodes, 
                               nsTArray<bool> &inTransitionArray);
-  nsresult RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes);
+  nsresult RemoveBlockStyle(nsTArray<nsCOMPtr<nsINode>>& aNodeArray);
   nsresult ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsAString *aBlockTag);
   nsresult MakeBlockquote(nsTArray<nsCOMPtr<nsINode>>& aNodeArray);
   nsresult SplitAsNeeded(nsIAtom& aTag, nsCOMPtr<nsINode>& inOutParent,
                          int32_t& inOutOffset);
   nsresult AddTerminatingBR(nsIDOMNode *aBlock);
   ::DOMPoint JoinNodesSmart(nsIContent& aNodeLeft, nsIContent& aNodeRight);
   mozilla::dom::Element* GetTopEnclosingMailCite(nsINode& aNode);
   nsresult PopListItem(nsIDOMNode *aListItem, bool *aOutOfList);