Bug 1191354 part 5 - Clean up nsHTMLEditRules::IsEmptyInline; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 16:14:39 +0300
changeset 295643 47f7ab7dc09b3bd045c7f3357d11b4246ebb50ad
parent 295642 6c6fd98812c7fe979ce4d0c6f9f38bc712d74d77
child 295644 14fb48ed9c8d2961095277c15637b3df31d1cd51
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 5 - Clean up nsHTMLEditRules::IsEmptyInline; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -3014,17 +3014,17 @@ nsHTMLEditRules::WillMakeList(Selection*
                            aEntireList ? EntireList::yes : EntireList::no);
   NS_ENSURE_SUCCESS(res, res);
 
   // check if all our nodes are <br>s, or empty inlines
   bool bOnlyBreaks = true;
   for (auto& curNode : arrayOfNodes) {
     // if curNode is not a Break or empty inline, we're done
     if (!nsTextEditUtils::IsBreak(curNode) &&
-        !IsEmptyInline(GetAsDOMNode(curNode))) {
+        !IsEmptyInline(curNode)) {
       bOnlyBreaks = false;
       break;
     }
   }
 
   // if no nodes, we make empty list.  Ditto if the user tried to make a list
   // of some # of breaks.
   if (!arrayOfNodes.Length() || bOnlyBreaks) {
@@ -3082,34 +3082,34 @@ nsHTMLEditRules::WillMakeList(Selection*
   uint32_t listCount = arrayOfNodes.Length();
   nsCOMPtr<nsINode> curParent;
   nsCOMPtr<Element> curList, prevListItem;
 
   for (uint32_t i = 0; i < listCount; i++) {
     // here's where we actually figure out what to do
     nsCOMPtr<nsIDOMNode> newBlock;
     NS_ENSURE_STATE(arrayOfNodes[i]->IsContent());
-    nsCOMPtr<nsIContent> curNode = arrayOfNodes[i]->AsContent();
+    OwningNonNull<nsIContent> curNode = *arrayOfNodes[i]->AsContent();
     int32_t offset;
     curParent = nsEditor::GetNodeLocation(curNode, &offset);
 
     // make sure we don't assemble content that is in different table cells
     // into the same list.  respect table cell boundaries when listifying.
     if (curList && InDifferentTableElements(curList, curNode)) {
       curList = nullptr;
     }
 
     // if curNode is a Break, delete it, and quit remembering prev list item
     if (nsTextEditUtils::IsBreak(curNode)) {
       NS_ENSURE_STATE(mHTMLEditor);
       res = mHTMLEditor->DeleteNode(curNode);
       NS_ENSURE_SUCCESS(res, res);
       prevListItem = 0;
       continue;
-    } else if (IsEmptyInline(GetAsDOMNode(curNode))) {
+    } else if (IsEmptyInline(curNode)) {
       // if curNode is an empty inline container, delete it
       NS_ENSURE_STATE(mHTMLEditor);
       res = mHTMLEditor->DeleteNode(curNode);
       NS_ENSURE_SUCCESS(res, res);
       continue;
     }
 
     if (nsHTMLEditUtils::IsList(curNode)) {
@@ -7771,30 +7771,29 @@ nsHTMLEditRules::SelectionEndpointInNode
         *aResult = true;
         return NS_OK;
       }
     }
   }
   return NS_OK;
 }
 
-///////////////////////////////////////////////////////////////////////////
-// IsEmptyInline:  return true if aNode is an empty inline container
-//
-//
+/**
+ * IsEmptyInline: Return true if aNode is an empty inline container
+ */
 bool
-nsHTMLEditRules::IsEmptyInline(nsIDOMNode *aNode)
-{
-  if (aNode && IsInlineNode(aNode) && mHTMLEditor &&
-      mHTMLEditor->IsContainer(aNode))
-  {
-    bool bEmpty;
-    NS_ENSURE_TRUE(mHTMLEditor, false);
-    mHTMLEditor->IsEmptyNode(aNode, &bEmpty);
-    return bEmpty;
+nsHTMLEditRules::IsEmptyInline(nsINode& aNode)
+{
+  NS_ENSURE_TRUE(mHTMLEditor, false);
+  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
+
+  if (IsInlineNode(aNode.AsDOMNode()) && mHTMLEditor->IsContainer(&aNode)) {
+    bool isEmpty = true;
+    mHTMLEditor->IsEmptyNode(&aNode, &isEmpty);
+    return isEmpty;
   }
   return false;
 }
 
 
 bool
 nsHTMLEditRules::ListIsEmptyLine(nsTArray<OwningNonNull<nsINode>>& aArrayOfNodes)
 {
@@ -7813,17 +7812,17 @@ nsHTMLEditRules::ListIsEmptyLine(nsTArra
       continue;
     }
     if (nsTextEditUtils::IsBreak(node)) {
       // First break doesn't count
       if (brCount) {
         return false;
       }
       brCount++;
-    } else if (IsEmptyInline(GetAsDOMNode(node))) {
+    } else if (IsEmptyInline(node)) {
       // Empty inline, keep looking
     } else {
       return false;
     }
   }
   return true;
 }
 
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -334,17 +334,17 @@ protected:
    */
   bool     InDifferentTableElements(nsIDOMNode* aNode1, nsIDOMNode* aNode2);
   bool     InDifferentTableElements(nsINode* aNode1, nsINode* aNode2);
   nsresult RemoveEmptyNodes();
   nsresult SelectionEndpointInNode(nsINode *aNode, bool *aResult);
   nsresult UpdateDocChangeRange(nsRange* aRange);
   nsresult ConfirmSelectionInBody();
   nsresult InsertMozBRIfNeeded(nsINode& aNode);
-  bool     IsEmptyInline(nsIDOMNode *aNode);
+  bool     IsEmptyInline(nsINode& aNode);
   bool     ListIsEmptyLine(nsTArray<mozilla::OwningNonNull<nsINode>>& arrayOfNodes);
   nsresult RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignType, bool aChildrenOnly);
   nsresult MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode, bool aStarts);
   enum class ContentsOnly { no, yes };
   nsresult AlignBlock(mozilla::dom::Element& aElement,
                       const nsAString& aAlignType, ContentsOnly aContentsOnly);
   nsresult RelativeChangeIndentationOfElementNode(nsIDOMNode *aNode, int8_t aRelativeChange);
   void DocumentModifiedWorker();