Bug 1190172 part 11 - Clean up nsHTMLEditRules::IsEmptyBlock; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Tue, 19 Apr 2016 06:56:00 +0200
changeset 331779 64d71b941c15d6daba17ec1f935a92253c3f1d21
parent 331778 19fbefce0e94796010c00a7525a23cab40c7bcf0
child 331780 2f3002536fe449de34fa2bcf3a6c13428b9097f3
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1190172
milestone48.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 1190172 part 11 - Clean up nsHTMLEditRules::IsEmptyBlock; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -1551,17 +1551,17 @@ nsHTMLEditRules::WillInsertBreak(Selecti
     return NS_OK;
   }
 
   // If block is empty, populate with br.  (For example, imagine a div that
   // contains the word "text".  The user selects "text" and types return.
   // "Text" is deleted leaving an empty block.  We want to put in one br to
   // make block have a line.  Then code further below will put in a second br.)
   bool isEmpty;
-  IsEmptyBlock(GetAsDOMNode(blockParent), &isEmpty);
+  IsEmptyBlock(*blockParent, &isEmpty);
   if (isEmpty) {
     nsCOMPtr<Element> br = mHTMLEditor->CreateBR(blockParent,
                                                  blockParent->Length());
     NS_ENSURE_STATE(br);
   }
 
   nsCOMPtr<Element> listItem = IsInListItem(blockParent);
   if (listItem && listItem != host) {
@@ -4484,39 +4484,34 @@ nsHTMLEditRules::CreateStyleForInsertTex
   if (weDidSomething) {
     return aSelection.Collapse(node, offset);
   }
 
   return NS_OK;
 }
 
 
-///////////////////////////////////////////////////////////////////////////
-// IsEmptyBlock: figure out if aNode is (or is inside) an empty block.
-//               A block can have children and still be considered empty,
-//               if the children are empty or non-editable.
-//
+/**
+ * Figure out if aNode is (or is inside) an empty block.  A block can have
+ * children and still be considered empty, if the children are empty or
+ * non-editable.
+ */
 nsresult
-nsHTMLEditRules::IsEmptyBlock(nsIDOMNode *aNode,
-                              bool *outIsEmptyBlock,
-                              bool aMozBRDoesntCount,
-                              bool aListItemsNotEmpty)
-{
-  NS_ENSURE_TRUE(aNode && outIsEmptyBlock, NS_ERROR_NULL_POINTER);
-  *outIsEmptyBlock = true;
-
-//  nsresult res = NS_OK;
-  nsCOMPtr<nsIDOMNode> nodeToTest;
-  if (IsBlockNode(aNode)) nodeToTest = do_QueryInterface(aNode);
-//  else nsCOMPtr<nsIDOMElement> block;
-//  looks like I forgot to finish this.  Wonder what I was going to do?
-
-  NS_ENSURE_TRUE(nodeToTest, NS_ERROR_NULL_POINTER);
-  return mHTMLEditor->IsEmptyNode(nodeToTest, outIsEmptyBlock,
-                     aMozBRDoesntCount, aListItemsNotEmpty);
+nsHTMLEditRules::IsEmptyBlock(Element& aNode,
+                              bool* aOutIsEmptyBlock,
+                              MozBRCounts aMozBRCounts)
+{
+  MOZ_ASSERT(aOutIsEmptyBlock);
+  *aOutIsEmptyBlock = true;
+
+  NS_ENSURE_TRUE(IsBlockNode(aNode.AsDOMNode()), NS_ERROR_NULL_POINTER);
+
+  return mHTMLEditor->IsEmptyNode(aNode.AsDOMNode(), aOutIsEmptyBlock,
+                                  aMozBRCounts == MozBRCounts::yes ? false
+                                                                   : true);
 }
 
 
 nsresult
 nsHTMLEditRules::WillAlign(Selection& aSelection,
                            const nsAString& aAlignType,
                            bool* aCancel,
                            bool* aHandled)
@@ -6284,17 +6279,17 @@ nsHTMLEditRules::ReturnInHeader(Selectio
     if (isEmptyNode) {
       res = CreateMozBR(prevItem->AsDOMNode(), 0);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
 
   // If the new (righthand) header node is empty, delete it
   bool isEmpty;
-  res = IsEmptyBlock(aHeader.AsDOMNode(), &isEmpty, true);
+  res = IsEmptyBlock(aHeader, &isEmpty, MozBRCounts::no);
   NS_ENSURE_SUCCESS(res, res);
   if (isEmpty) {
     res = mHTMLEditor->DeleteNode(&aHeader);
     NS_ENSURE_SUCCESS(res, res);
     // Layout tells the caret to blink in a weird place if we don't place a
     // break after the header.
     nsCOMPtr<nsIContent> sibling =
       mHTMLEditor->GetNextHTMLSibling(headerParent, offset + 1);
@@ -6537,17 +6532,17 @@ nsHTMLEditRules::ReturnInListItem(Select
 
   nsCOMPtr<Element> list = aListItem.GetParentElement();
   int32_t itemOffset = list ? list->IndexOf(&aListItem) : -1;
 
   // If we are in an empty item, then we want to pop up out of the list, but
   // only if prefs say it's okay and if the parent isn't the active editing
   // host.
   bool isEmpty;
-  nsresult res = IsEmptyBlock(aListItem.AsDOMNode(), &isEmpty, true, false);
+  nsresult res = IsEmptyBlock(aListItem, &isEmpty, MozBRCounts::no);
   NS_ENSURE_SUCCESS(res, res);
   if (isEmpty && root != list && mReturnInEmptyLIKillsList) {
     // Get the list offset now -- before we might eventually split the list
     nsCOMPtr<nsINode> listParent = list->GetParentNode();
     int32_t offset = listParent ? listParent->IndexOf(list) : -1;
 
     // Are we the last list item in the list?
     bool isLast;
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -243,20 +243,20 @@ protected:
                            nsIAtom* aItemType);
   nsresult ConvertListType(mozilla::dom::Element* aList,
                            mozilla::dom::Element** aOutList,
                            nsIAtom* aListType,
                            nsIAtom* aItemType);
 
   nsresult CreateStyleForInsertText(mozilla::dom::Selection& aSelection,
                                     nsIDocument& aDoc);
-  nsresult IsEmptyBlock(nsIDOMNode *aNode,
-                        bool *outIsEmptyBlock,
-                        bool aMozBRDoesntCount = false,
-                        bool aListItemsNotEmpty = false);
+  enum class MozBRCounts { yes, no };
+  nsresult IsEmptyBlock(mozilla::dom::Element& aNode,
+                        bool* aOutIsEmptyBlock,
+                        MozBRCounts aMozBRCounts = MozBRCounts::yes);
   nsresult CheckForEmptyBlock(nsINode* aStartNode,
                               mozilla::dom::Element* aBodyNode,
                               mozilla::dom::Selection* aSelection,
                               nsIEditor::EDirection aAction,
                               bool* aHandled);
   nsresult CheckForInvisibleBR(nsIDOMNode *aBlock, nsHTMLEditRules::BRLocation aWhere,
                                nsCOMPtr<nsIDOMNode> *outBRNode, int32_t aOffset=0);
   nsresult ExpandSelectionForDeletion(mozilla::dom::Selection* aSelection);