Bug 1191354 part 1 - Clean up nsHTMLEditRules::GetHighestInlineParent; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 16:13:51 +0300
changeset 295639 ab44edac6c41ebd28e51c71c2620f888463fcc83
parent 295638 34765a76738e04e7df6d1cdb4a46bbaf5549407d
child 295640 d556b4103dee44d5669c1074f467e8874c975e14
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1191354
milestone49.0a1
Bug 1191354 part 1 - Clean up nsHTMLEditRules::GetHighestInlineParent; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -6003,18 +6003,17 @@ nsHTMLEditRules::GetParagraphFormatNodes
 ///////////////////////////////////////////////////////////////////////////
 // BustUpInlinesAtRangeEndpoints:
 //
 nsresult
 nsHTMLEditRules::BustUpInlinesAtRangeEndpoints(nsRangeStore &item)
 {
   bool isCollapsed = ((item.startNode == item.endNode) && (item.startOffset == item.endOffset));
 
-  nsCOMPtr<nsIContent> endInline =
-    do_QueryInterface(GetHighestInlineParent(GetAsDOMNode(item.endNode)));
+  nsCOMPtr<nsIContent> endInline = GetHighestInlineParent(*item.endNode);
 
   // if we have inline parents above range endpoints, split them
   if (endInline && !isCollapsed)
   {
     nsCOMPtr<nsINode> resultEndNode = endInline->GetParentNode();
     NS_ENSURE_STATE(mHTMLEditor);
     // item.endNode must be content if endInline isn't null
     int32_t resultEndOffset =
@@ -6022,18 +6021,17 @@ nsHTMLEditRules::BustUpInlinesAtRangeEnd
                                  item.endOffset,
                                  nsEditor::EmptyContainers::no);
     NS_ENSURE_TRUE(resultEndOffset != -1, NS_ERROR_FAILURE);
     // reset range
     item.endNode = resultEndNode;
     item.endOffset = resultEndOffset;
   }
 
-  nsCOMPtr<nsIContent> startInline =
-    do_QueryInterface(GetHighestInlineParent(GetAsDOMNode(item.startNode)));
+  nsCOMPtr<nsIContent> startInline = GetHighestInlineParent(*item.startNode);
 
   if (startInline)
   {
     nsCOMPtr<nsINode> resultStartNode = startInline->GetParentNode();
     NS_ENSURE_STATE(mHTMLEditor);
     int32_t resultStartOffset =
       mHTMLEditor->SplitNodeDeep(*startInline, *item.startNode->AsContent(),
                                  item.startOffset,
@@ -6106,29 +6104,28 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIC
   // Now tack on remaining rightNode, if any, to the list
   if (rightNode) {
     aOutArrayOfNodes.AppendElement(*rightNode);
   }
   return NS_OK;
 }
 
 
-nsCOMPtr<nsIDOMNode>
-nsHTMLEditRules::GetHighestInlineParent(nsIDOMNode* aNode)
-{
-  NS_ENSURE_TRUE(aNode, nullptr);
-  if (IsBlockNode(aNode)) return nullptr;
-  nsCOMPtr<nsIDOMNode> inlineNode, node=aNode;
-
-  while (node && IsInlineNode(node))
-  {
-    inlineNode = node;
-    inlineNode->GetParentNode(getter_AddRefs(node));
-  }
-  return inlineNode;
+nsIContent*
+nsHTMLEditRules::GetHighestInlineParent(nsINode& aNode)
+{
+  if (!aNode.IsContent() || IsBlockNode(aNode.AsDOMNode())) {
+    return nullptr;
+  }
+  OwningNonNull<nsIContent> node = *aNode.AsContent();
+
+  while (node->GetParent() && IsInlineNode(node->GetParent()->AsDOMNode())) {
+    node = *node->GetParent();
+  }
+  return node;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // GetNodesFromPoint: Given a particular operation, construct a list of nodes
 //                    from a point that will be operated on.
 //
 nsresult
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -293,17 +293,17 @@ protected:
   void GetDefinitionListItemTypes(mozilla::dom::Element* aElement, bool* aDT, bool* aDD);
   nsresult GetParagraphFormatNodes(
       nsTArray<mozilla::OwningNonNull<nsINode>>& outArrayOfNodes,
       TouchContent aTouchContent = TouchContent::yes);
   void LookInsideDivBQandList(nsTArray<mozilla::OwningNonNull<nsINode>>& aNodeArray);
   nsresult BustUpInlinesAtRangeEndpoints(nsRangeStore &inRange);
   nsresult BustUpInlinesAtBRs(nsIContent& aNode,
                               nsTArray<mozilla::OwningNonNull<nsINode>>& aOutArrayOfNodes);
-  nsCOMPtr<nsIDOMNode> GetHighestInlineParent(nsIDOMNode* aNode);
+  nsIContent* GetHighestInlineParent(nsINode& aNode);
   void MakeTransitionList(nsTArray<mozilla::OwningNonNull<nsINode>>& aNodeArray,
                           nsTArray<bool>& aTransitionArray);
   nsresult RemoveBlockStyle(nsTArray<mozilla::OwningNonNull<nsINode>>& aNodeArray);
   nsresult ApplyBlockStyle(nsTArray<mozilla::OwningNonNull<nsINode>>& aNodeArray,
                            nsIAtom& aBlockTag);
   nsresult MakeBlockquote(nsTArray<mozilla::OwningNonNull<nsINode>>& aNodeArray);
   nsresult SplitAsNeeded(nsIAtom& aTag, nsCOMPtr<nsINode>& inOutParent,
                          int32_t& inOutOffset);