Backout changeset bb29532b1b73 (bug 1190172 part 11)
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 23 Apr 2016 19:57:09 +0900
changeset 332535 ac42f08543bac98df259996e7e02b86e84b4021f
parent 332534 ae39f6f98aaee6b1e56617bde5e121e23336f412
child 332536 f22fa60009f5718f90a5447fccd17f0e7eff276e
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)
bugs1190172
milestone48.0a1
backs outbb29532b1b73e1cd5d904e7b7615c840a82b0a8a
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
Backout changeset bb29532b1b73 (bug 1190172 part 11)
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(*blockParent, &isEmpty);
+  IsEmptyBlock(GetAsDOMNode(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) {
@@ -4521,34 +4521,39 @@ nsHTMLEditRules::CreateStyleForInsertTex
   if (weDidSomething) {
     return aSelection.Collapse(node, offset);
   }
 
   return NS_OK;
 }
 
 
-/**
- * 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.
- */
+///////////////////////////////////////////////////////////////////////////
+// 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.
+//
 nsresult
-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);
+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);
 }
 
 
 nsresult
 nsHTMLEditRules::WillAlign(Selection& aSelection,
                            const nsAString& aAlignType,
                            bool* aCancel,
                            bool* aHandled)
@@ -6316,17 +6321,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, &isEmpty, MozBRCounts::no);
+  res = IsEmptyBlock(aHeader.AsDOMNode(), &isEmpty, true);
   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);
@@ -6569,17 +6574,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, &isEmpty, MozBRCounts::no);
+  nsresult res = IsEmptyBlock(aListItem.AsDOMNode(), &isEmpty, true, false);
   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
@@ -244,20 +244,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);
-  enum class MozBRCounts { yes, no };
-  nsresult IsEmptyBlock(mozilla::dom::Element& aNode,
-                        bool* aOutIsEmptyBlock,
-                        MozBRCounts aMozBRCounts = MozBRCounts::yes);
+  nsresult IsEmptyBlock(nsIDOMNode *aNode,
+                        bool *outIsEmptyBlock,
+                        bool aMozBRDoesntCount = false,
+                        bool aListItemsNotEmpty = false);
   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);