Bug 1153629 part 6 - Clean up nsHTMLEditRules::MakeBlockquote; r=ehsan
☠☠ backed out by 329dd852c06b ☠ ☠
authorAryeh Gregor <ayg@aryeh.name>
Wed, 22 Apr 2015 14:26:58 +0300
changeset 240510 9a62d4ec4542221646cafaa2c4cd102b84f9dabf
parent 240509 87ff1d4bb056d0bb2878bd32435c5346f079dbfa
child 240511 b0b609c3da83bb914977feb5d19dbcade419253f
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 6 - Clean up nsHTMLEditRules::MakeBlockquote; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -3536,17 +3536,17 @@ nsHTMLEditRules::WillMakeBasicBlock(Sele
     // 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"))
-      res = MakeBlockquote(arrayOfDOMNodes);
+      res = MakeBlockquote(arrayOfNodes);
     else if (tString.EqualsLiteral("normal") ||
              tString.IsEmpty() )
       res = RemoveBlockStyle(arrayOfDOMNodes);
     else
       res = ApplyBlockStyle(arrayOfDOMNodes, aBlockType);
     return res;
   }
   return res;
@@ -6797,104 +6797,79 @@ nsHTMLEditRules::ReturnInListItem(Select
       }
     }
   }
   res = aSelection->Collapse(aListItem,0);
   return res;
 }
 
 
-///////////////////////////////////////////////////////////////////////////
-// MakeBlockquote:  put the list of nodes into one or more blockquotes.  
-//                       
-nsresult 
-nsHTMLEditRules::MakeBlockquote(nsCOMArray<nsIDOMNode>& arrayOfNodes)
-{
-  // the idea here is to put the nodes into a minimal number of 
-  // blockquotes.  When the user blockquotes something, they expect
-  // one blockquote.  That may not be possible (for instance, if they
-  // have two table cells selected, you need two blockquotes inside the cells).
-  
-  nsresult res = NS_OK;
-  
-  nsCOMPtr<nsIDOMNode> curNode, newBlock;
-  nsCOMPtr<nsINode> curParent;
+///////////////////////////////////////////////////////////////////////////////
+// MakeBlockquote: Put the list of nodes into one or more blockquotes.
+//
+nsresult
+nsHTMLEditRules::MakeBlockquote(nsTArray<nsCOMPtr<nsINode>>& aNodeArray)
+{
+  // The idea here is to put the nodes into a minimal number of blockquotes.
+  // When the user blockquotes something, they expect one blockquote.  That may
+  // not be possible (for instance, if they have two table cells selected, you
+  // need two blockquotes inside the cells).
+  nsresult res;
   nsCOMPtr<Element> curBlock;
-  int32_t offset;
-  int32_t listCount = arrayOfNodes.Count();
-  
-  nsCOMPtr<nsIDOMNode> prevParent;
-  
-  int32_t i;
-  for (i=0; i<listCount; i++)
-  {
-    // get the node to act on, and its location
-    curNode = arrayOfNodes[i];
-    nsCOMPtr<nsIContent> curContent = do_QueryInterface(curNode);
-    NS_ENSURE_STATE(curContent);
-    curParent = curContent->GetParentNode();
-    offset = curParent ? curParent->IndexOf(curContent) : -1;
-
-    // if the node is a table element or list item, dive inside
-    if (nsHTMLEditUtils::IsTableElementButNotTable(curNode) || 
-        nsHTMLEditUtils::IsListItem(curNode))
-    {
-      curBlock = 0;  // forget any previous block
-      // recursion time
+  nsCOMPtr<nsINode> prevParent;
+
+  for (auto& curNode : aNodeArray) {
+    // Get the node to act on, and its location
+    NS_ENSURE_STATE(curNode->IsContent());
+
+    // If the node is a table element or list item, dive inside
+    if (nsHTMLEditUtils::IsTableElementButNotTable(curNode) ||
+        nsHTMLEditUtils::IsListItem(curNode)) {
+      // Forget any previous block
+      curBlock = nullptr;
+      // Recursion time
       nsTArray<nsCOMPtr<nsINode>> childArray;
-      nsCOMPtr<nsINode> node = do_QueryInterface(curNode);
-      NS_ENSURE_STATE(node || !curNode);
-      GetChildNodesForOperation(*node, childArray);
-      nsCOMArray<nsIDOMNode> childArrayDOM;
-      for (auto& child : childArray) {
-        childArrayDOM.AppendObject(GetAsDOMNode(child));
-      }
-      res = MakeBlockquote(childArrayDOM);
+      GetChildNodesForOperation(*curNode, childArray);
+      res = MakeBlockquote(childArray);
       NS_ENSURE_SUCCESS(res, res);
     }
-    
-    // if the node has different parent than previous node,
-    // further nodes in a new parent
-    if (prevParent)
-    {
-      nsCOMPtr<nsIDOMNode> temp;
-      curNode->GetParentNode(getter_AddRefs(temp));
-      if (temp != prevParent)
-      {
-        curBlock = 0;  // forget any previous blockquote node we were using
-        prevParent = temp;
-      }
-    }
-    else     
-
-    {
-      curNode->GetParentNode(getter_AddRefs(prevParent));
-    }
-    
-    // if no curBlock, make one
-    if (!curBlock)
-    {
+
+    // If the node has different parent than previous node, further nodes in a
+    // new parent
+    if (prevParent) {
+      if (prevParent != curNode->GetParentNode()) {
+        // Forget any previous blockquote node we were using
+        curBlock = nullptr;
+        prevParent = curNode->GetParentNode();
+      }
+    } else {
+      prevParent = curNode->GetParentNode();
+    }
+
+    // If no curBlock, make one
+    if (!curBlock) {
+      nsCOMPtr<nsINode> curParent = curNode->GetParentNode();
+      int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
       res = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset);
       NS_ENSURE_SUCCESS(res, res);
       NS_ENSURE_STATE(mHTMLEditor);
       curBlock = mHTMLEditor->CreateNode(nsGkAtoms::blockquote, curParent,
                                          offset);
       NS_ENSURE_STATE(curBlock);
       // remember our new block for postprocessing
       mNewBlock = curBlock->AsDOMNode();
       // note: doesn't matter if we set mNewBlock multiple times.
     }
-      
-    NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->MoveNode(curContent, curBlock, -1);
+
+    NS_ENSURE_STATE(mHTMLEditor);
+    res = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
     NS_ENSURE_SUCCESS(res, res);
   }
-  return res;
-}
-
+  return NS_OK;
+}
 
 
 ///////////////////////////////////////////////////////////////////////////
 // RemoveBlockStyle:  make the nodes have no special block type.  
 //                       
 nsresult 
 nsHTMLEditRules::RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes)
 {
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -297,17 +297,17 @@ protected:
   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 ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsAString *aBlockTag);
-  nsresult MakeBlockquote(nsCOMArray<nsIDOMNode>& arrayOfNodes);
+  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);
   nsresult RemoveListStructure(nsIDOMNode *aList);
   nsresult CacheInlineStyles(nsIDOMNode *aNode);