Bug 1191356 part 9 - Convert nsHTMLEditRules::mNewBlock to Element; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 17:58:53 +0300
changeset 295675 690690705ac126e5c8ad3a17590f49058bedc3c8
parent 295674 c07e7e8e9140c151097573f7fb340ba705778393
child 295676 05992224611e290e9224e2f4f7a0bf96dd3b0f6e
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
bugs1191356
milestone49.0a1
Bug 1191356 part 9 - Convert nsHTMLEditRules::mNewBlock to Element; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -3039,17 +3039,17 @@ nsHTMLEditRules::WillMakeList(Selection*
     NS_ENSURE_STATE(theList);
 
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theListItem =
       mHTMLEditor->CreateNode(itemType, theList, 0);
     NS_ENSURE_STATE(theListItem);
 
     // remember our new block for postprocessing
-    mNewBlock = GetAsDOMNode(theListItem);
+    mNewBlock = theListItem;
     // put selection in new list item
     res = aSelection->Collapse(theListItem, 0);
     // to prevent selection resetter from overriding us
     selectionResetter.Abort();
     *aHandled = true;
     return res;
   }
 
@@ -3201,17 +3201,17 @@ nsHTMLEditRules::WillMakeList(Selection*
     // need to make a list to put things in if we haven't already,
     if (!curList) {
       res = SplitAsNeeded(listType, curParent, offset);
       NS_ENSURE_SUCCESS(res, res);
       NS_ENSURE_STATE(mHTMLEditor);
       curList = mHTMLEditor->CreateNode(listType, curParent, offset);
       NS_ENSURE_SUCCESS(res, res);
       // remember our new block for postprocessing
-      mNewBlock = GetAsDOMNode(curList);
+      mNewBlock = curList;
       // curList is now the correct thing to put curNode in
       prevListItem = 0;
     }
 
     // if curNode isn't a list item, we must wrap it in one
     nsCOMPtr<Element> listItem;
     if (!nsHTMLEditUtils::IsListItem(curNode)) {
       if (IsInlineNode(curNode) && prevListItem) {
@@ -3418,17 +3418,17 @@ nsHTMLEditRules::WillMakeBasicBlock(Sele
       }
       // Make sure we can put a block here
       res = SplitAsNeeded(blockType, parent, offset);
       NS_ENSURE_SUCCESS(res, res);
       nsCOMPtr<Element> block =
         mHTMLEditor->CreateNode(blockType, parent, offset);
       NS_ENSURE_STATE(block);
       // Remember our new block for postprocessing
-      mNewBlock = block->AsDOMNode();
+      mNewBlock = block;
       // Delete anything that was in the list of nodes
       while (!arrayOfNodes.IsEmpty()) {
         OwningNonNull<nsINode> curNode = arrayOfNodes[0];
         res = mHTMLEditor->DeleteNode(curNode);
         NS_ENSURE_SUCCESS(res, res);
         arrayOfNodes.RemoveElementAt(0);
       }
       // Put selection in new block
@@ -3551,17 +3551,17 @@ nsHTMLEditRules::WillCSSIndent(Selection
     // make sure we can put a block here
     res = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
     NS_ENSURE_SUCCESS(res, res);
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theBlock = mHTMLEditor->CreateNode(nsGkAtoms::div,
                                                          parent, offset);
     NS_ENSURE_STATE(theBlock);
     // remember our new block for postprocessing
-    mNewBlock = theBlock->AsDOMNode();
+    mNewBlock = theBlock;
     ChangeIndentation(*theBlock, Change::plus);
     // delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
       NS_ENSURE_STATE(mHTMLEditor);
       res = mHTMLEditor->DeleteNode(curNode);
       NS_ENSURE_SUCCESS(res, res);
       arrayOfNodes.RemoveElementAt(0);
@@ -3643,17 +3643,17 @@ nsHTMLEditRules::WillCSSIndent(Selection
                             offset);
         NS_ENSURE_SUCCESS(res, res);
         NS_ENSURE_STATE(mHTMLEditor);
         curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                           curParent, offset);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in
         // remember our new block for postprocessing
-        mNewBlock = curList->AsDOMNode();
+        mNewBlock = curList;
       }
       // tuck the node into the end of the active list
       uint32_t listLen = curList->Length();
       NS_ENSURE_STATE(mHTMLEditor);
       res = mHTMLEditor->MoveNode(curNode, curList, listLen);
       NS_ENSURE_SUCCESS(res, res);
     }
 
@@ -3674,17 +3674,17 @@ nsHTMLEditRules::WillCSSIndent(Selection
           res = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
           NS_ENSURE_SUCCESS(res, res);
           NS_ENSURE_STATE(mHTMLEditor);
           curQuote = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent,
                                              offset);
           NS_ENSURE_STATE(curQuote);
           ChangeIndentation(*curQuote, Change::plus);
           // remember our new block for postprocessing
-          mNewBlock = curQuote->AsDOMNode();
+          mNewBlock = curQuote;
           // curQuote is now the correct thing to put curNode in
         }
 
         // tuck the node into the end of the active blockquote
         uint32_t quoteLen = curQuote->Length();
         NS_ENSURE_STATE(mHTMLEditor);
         res = mHTMLEditor->MoveNode(curNode, curQuote, quoteLen);
         NS_ENSURE_SUCCESS(res, res);
@@ -3736,17 +3736,17 @@ nsHTMLEditRules::WillHTMLIndent(Selectio
     // make sure we can put a block here
     res = SplitAsNeeded(*nsGkAtoms::blockquote, parent, offset);
     NS_ENSURE_SUCCESS(res, res);
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theBlock = mHTMLEditor->CreateNode(nsGkAtoms::blockquote,
                                                          parent, offset);
     NS_ENSURE_STATE(theBlock);
     // remember our new block for postprocessing
-    mNewBlock = theBlock->AsDOMNode();
+    mNewBlock = theBlock;
     // delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
       NS_ENSURE_STATE(mHTMLEditor);
       res = mHTMLEditor->DeleteNode(curNode);
       NS_ENSURE_SUCCESS(res, res);
       arrayOfNodes.RemoveElementAt(0);
     }
@@ -3826,17 +3826,17 @@ nsHTMLEditRules::WillHTMLIndent(Selectio
                             offset);
         NS_ENSURE_SUCCESS(res, res);
         NS_ENSURE_STATE(mHTMLEditor);
         curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                           curParent, offset);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in
         // remember our new block for postprocessing
-        mNewBlock = curList->AsDOMNode();
+        mNewBlock = curList;
       }
       // tuck the node into the end of the active list
       NS_ENSURE_STATE(mHTMLEditor);
       res = mHTMLEditor->MoveNode(curNode, curList, -1);
       NS_ENSURE_SUCCESS(res, res);
       // forget curQuote, if any
       curQuote = nullptr;
     }
@@ -3903,17 +3903,17 @@ nsHTMLEditRules::WillHTMLIndent(Selectio
 
           res = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset);
           NS_ENSURE_SUCCESS(res, res);
           NS_ENSURE_STATE(mHTMLEditor);
           curQuote = mHTMLEditor->CreateNode(nsGkAtoms::blockquote, curParent,
                                              offset);
           NS_ENSURE_STATE(curQuote);
           // remember our new block for postprocessing
-          mNewBlock = curQuote->AsDOMNode();
+          mNewBlock = curQuote;
           // curQuote is now the correct thing to put curNode in
         }
 
         // tuck the node into the end of the active blockquote
         NS_ENSURE_STATE(mHTMLEditor);
         res = mHTMLEditor->MoveNode(curNode, curQuote, -1);
         NS_ENSURE_SUCCESS(res, res);
         // forget curList, if any
@@ -4552,17 +4552,17 @@ nsHTMLEditRules::WillAlign(Selection& aS
         rv = mHTMLEditor->DeleteNode(brContent);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
     nsCOMPtr<Element> div = mHTMLEditor->CreateNode(nsGkAtoms::div, parent,
                                                     offset);
     NS_ENSURE_STATE(div);
     // Remember our new block for postprocessing
-    mNewBlock = div->AsDOMNode();
+    mNewBlock = div;
     // Set up the alignment on the div, using HTML or CSS
     rv = AlignBlock(*div, aAlignType, ContentsOnly::yes);
     NS_ENSURE_SUCCESS(rv, rv);
     *aHandled = true;
     // Put in a moz-br so that it won't get deleted
     rv = CreateMozBR(div->AsDOMNode(), 0);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aSelection.Collapse(div, 0);
@@ -4651,17 +4651,17 @@ nsHTMLEditRules::WillAlign(Selection& aS
         return NS_OK;
       }
 
       rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
       NS_ENSURE_SUCCESS(rv, rv);
       curDiv = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent, offset);
       NS_ENSURE_STATE(curDiv);
       // Remember our new block for postprocessing
-      mNewBlock = curDiv->AsDOMNode();
+      mNewBlock = curDiv;
       // Set up the alignment on the div
       rv = AlignBlock(*curDiv, aAlignType, ContentsOnly::yes);
     }
 
     NS_ENSURE_STATE(curNode->IsContent());
 
     // Tuck the node into the end of the active div
     rv = mHTMLEditor->MoveNode(curNode->AsContent(), curDiv, -1);
@@ -6601,17 +6601,17 @@ nsHTMLEditRules::MakeBlockquote(nsTArray
       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();
+      mNewBlock = curBlock;
       // note: doesn't matter if we set mNewBlock multiple times.
     }
 
     NS_ENSURE_STATE(mHTMLEditor);
     res = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
     NS_ENSURE_SUCCESS(res, res);
   }
   return NS_OK;
@@ -6773,17 +6773,17 @@ nsHTMLEditRules::ApplyBlockStyle(nsTArra
       } else {
         // Make sure we can put a block here
         res = SplitAsNeeded(aBlockTag, curParent, offset);
         NS_ENSURE_SUCCESS(res, res);
         nsCOMPtr<Element> theBlock =
           mHTMLEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(theBlock);
         // Remember our new block for postprocessing
-        mNewBlock = theBlock->AsDOMNode();
+        mNewBlock = theBlock;
       }
     } else if (curNode->IsHTMLElement(nsGkAtoms::br)) {
       // If the node is a break, we honor it by putting further nodes in a new
       // parent
       if (curBlock) {
         // Forget any previous block used for previous inline nodes
         curBlock = nullptr;
         res = mHTMLEditor->DeleteNode(curNode);
@@ -6791,17 +6791,17 @@ nsHTMLEditRules::ApplyBlockStyle(nsTArra
       } else {
         // The break is the first (or even only) node we encountered.  Create a
         // block for it.
         res = SplitAsNeeded(aBlockTag, curParent, offset);
         NS_ENSURE_SUCCESS(res, res);
         curBlock = mHTMLEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(curBlock);
         // Remember our new block for postprocessing
-        mNewBlock = curBlock->AsDOMNode();
+        mNewBlock = curBlock;
         // Note: doesn't matter if we set mNewBlock multiple times.
         res = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
         NS_ENSURE_SUCCESS(res, res);
       }
     } else if (IsInlineNode(curNode)) {
       // If curNode is inline, pull it into curBlock.  Note: it's assumed that
       // consecutive inline nodes in aNodeArray are actually members of the
       // same block parent.  This happens to be true now as a side effect of
@@ -6816,17 +6816,17 @@ nsHTMLEditRules::ApplyBlockStyle(nsTArra
 
       // If no curBlock, make one
       if (!curBlock) {
         res = SplitAsNeeded(aBlockTag, curParent, offset);
         NS_ENSURE_SUCCESS(res, res);
         curBlock = mHTMLEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(curBlock);
         // Remember our new block for postprocessing
-        mNewBlock = curBlock->AsDOMNode();
+        mNewBlock = curBlock;
         // Note: doesn't matter if we set mNewBlock multiple times.
       }
 
       // XXX If curNode is a br, replace it with a return if going to <pre>
 
       // This is a continuation of some inline nodes that belong together in
       // the same block item.  Use curBlock.
       res = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
@@ -7152,28 +7152,28 @@ nsHTMLEditRules::PinSelectionToNewBlock(
   // use ranges and sRangeHelper to compare sel point to new block
   nsCOMPtr<nsINode> node = do_QueryInterface(selNode);
   NS_ENSURE_STATE(node);
   RefPtr<nsRange> range = new nsRange(node);
   res = range->SetStart(selNode, selOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = range->SetEnd(selNode, selOffset);
   NS_ENSURE_SUCCESS(res, res);
-  nsCOMPtr<nsIContent> block (do_QueryInterface(mNewBlock));
+  nsCOMPtr<nsIContent> block = mNewBlock.get();
   NS_ENSURE_TRUE(block, NS_ERROR_NO_INTERFACE);
   bool nodeBefore, nodeAfter;
   res = nsRange::CompareNodeToRange(block, range, &nodeBefore, &nodeAfter);
   NS_ENSURE_SUCCESS(res, res);
 
   if (nodeBefore && nodeAfter)
     return NS_OK;  // selection is inside block
   else if (nodeBefore)
   {
     // selection is after block.  put at end of block.
-    nsCOMPtr<nsIDOMNode> tmp = mNewBlock;
+    nsCOMPtr<nsIDOMNode> tmp = GetAsDOMNode(mNewBlock);
     NS_ENSURE_STATE(mHTMLEditor);
     tmp = GetAsDOMNode(mHTMLEditor->GetLastEditableChild(*block));
     uint32_t endPoint;
     if (mHTMLEditor->IsTextNode(tmp) ||
         mHTMLEditor->IsContainer(tmp))
     {
       res = nsEditor::GetLengthOfDOMNode(tmp, endPoint);
       NS_ENSURE_SUCCESS(res, res);
@@ -7183,17 +7183,18 @@ nsHTMLEditRules::PinSelectionToNewBlock(
       tmp = nsEditor::GetNodeLocation(tmp, (int32_t*)&endPoint);
       endPoint++;  // want to be after this node
     }
     return aSelection->Collapse(tmp, (int32_t)endPoint);
   }
   else
   {
     // selection is before block.  put at start of block.
-    nsCOMPtr<nsIDOMNode> tmp = mNewBlock;
+    nsCOMPtr<nsIDOMNode> tmp = GetAsDOMNode(mNewBlock);
+    NS_ENSURE_STATE(mHTMLEditor);
     tmp = GetAsDOMNode(mHTMLEditor->GetFirstEditableChild(*block));
     int32_t offset;
     if (mHTMLEditor->IsTextNode(tmp) ||
         mHTMLEditor->IsContainer(tmp))
     {
       tmp = nsEditor::GetNodeLocation(tmp, &offset);
     }
     return aSelection->Collapse(tmp, 0);
@@ -8480,17 +8481,17 @@ nsHTMLEditRules::WillAbsolutePosition(Se
   WillInsert(aSelection, aCancel);
 
   // We want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = true;
 
   nsCOMPtr<Element> focusElement = mHTMLEditor->GetSelectionContainer();
   if (focusElement && nsHTMLEditUtils::IsImage(focusElement)) {
-    mNewBlock = focusElement->AsDOMNode();
+    mNewBlock = focusElement;
     return NS_OK;
   }
 
   nsresult res = NormalizeSelection(&aSelection);
   NS_ENSURE_SUCCESS(res, res);
   nsAutoSelectionReset selectionResetter(&aSelection, mHTMLEditor);
 
   // Convert the selection ranges into "promoted" selection ranges: this
@@ -8519,17 +8520,17 @@ nsHTMLEditRules::WillAbsolutePosition(Se
 
     // Make sure we can put a block here
     res = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
     NS_ENSURE_SUCCESS(res, res);
     nsCOMPtr<Element> positionedDiv =
       mHTMLEditor->CreateNode(nsGkAtoms::div, parent, offset);
     NS_ENSURE_STATE(positionedDiv);
     // Remember our new block for postprocessing
-    mNewBlock = positionedDiv->AsDOMNode();
+    mNewBlock = positionedDiv;
     // Delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
       res = mHTMLEditor->DeleteNode(curNode);
       NS_ENSURE_SUCCESS(res, res);
       arrayOfNodes.RemoveElementAt(0);
     }
     // Put selection in new block
@@ -8573,17 +8574,17 @@ nsHTMLEditRules::WillAbsolutePosition(Se
                             offset);
         NS_ENSURE_SUCCESS(res, res);
         if (!curPositionedDiv) {
           nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode();
           int32_t parentOffset = curParentParent
             ? curParentParent->IndexOf(curParent) : -1;
           curPositionedDiv = mHTMLEditor->CreateNode(nsGkAtoms::div, curParentParent,
                                                      parentOffset);
-          mNewBlock = GetAsDOMNode(curPositionedDiv);
+          mNewBlock = curPositionedDiv;
         }
         curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                           curPositionedDiv, -1);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in.  Remember our
         // new block for postprocessing.
       }
       // Tuck the node into the end of the active list
@@ -8617,43 +8618,43 @@ nsHTMLEditRules::WillAbsolutePosition(Se
           NS_ENSURE_SUCCESS(res, res);
           if (!curPositionedDiv) {
             nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode();
             int32_t parentOffset = curParentParent ?
               curParentParent->IndexOf(curParent) : -1;
             curPositionedDiv = mHTMLEditor->CreateNode(nsGkAtoms::div,
                                                        curParentParent,
                                                        parentOffset);
-            mNewBlock = GetAsDOMNode(curPositionedDiv);
+            mNewBlock = curPositionedDiv;
           }
           curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                             curPositionedDiv, -1);
           NS_ENSURE_STATE(curList);
         }
         res = mHTMLEditor->MoveNode(listItem, curList, -1);
         NS_ENSURE_SUCCESS(res, res);
         // Remember we indented this li
         indentedLI = listItem;
       } else {
         // Need to make a div to put things in if we haven't already
 
         if (!curPositionedDiv) {
           if (curNode->IsHTMLElement(nsGkAtoms::div)) {
             curPositionedDiv = curNode->AsElement();
-            mNewBlock = GetAsDOMNode(curPositionedDiv);
+            mNewBlock = curPositionedDiv;
             curList = nullptr;
             continue;
           }
           res = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
           NS_ENSURE_SUCCESS(res, res);
           curPositionedDiv = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent,
                                                      offset);
           NS_ENSURE_STATE(curPositionedDiv);
           // Remember our new block for postprocessing
-          mNewBlock = GetAsDOMNode(curPositionedDiv);
+          mNewBlock = curPositionedDiv;
           // curPositionedDiv is now the correct thing to put curNode in
         }
 
         // Tuck the node into the end of the active blockquote
         res = mHTMLEditor->MoveNode(curNode, curPositionedDiv, -1);
         NS_ENSURE_SUCCESS(res, res);
         // Forget curList, if any
         curList = nullptr;
@@ -8663,17 +8664,18 @@ nsHTMLEditRules::WillAbsolutePosition(Se
   return NS_OK;
 }
 
 nsresult
 nsHTMLEditRules::DidAbsolutePosition()
 {
   NS_ENSURE_STATE(mHTMLEditor);
   nsCOMPtr<nsIHTMLAbsPosEditor> absPosHTMLEditor = mHTMLEditor;
-  nsCOMPtr<nsIDOMElement> elt = do_QueryInterface(mNewBlock);
+  nsCOMPtr<nsIDOMElement> elt =
+    static_cast<nsIDOMElement*>(GetAsDOMNode(mNewBlock));
   return absPosHTMLEditor->AbsolutelyPositionElement(elt, true);
 }
 
 nsresult
 nsHTMLEditRules::WillRemoveAbsolutePosition(Selection* aSelection,
                                             bool* aCancel, bool* aHandled) {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
   WillInsert(*aSelection, aCancel);
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -336,15 +336,15 @@ protected:
   RefPtr<nsRange>       mDocChangeRange;
   bool                    mListenerEnabled;
   bool                    mReturnInEmptyLIKillsList;
   bool                    mDidDeleteSelection;
   bool                    mDidRangedDelete;
   bool                    mRestoreContentEditableCount;
   RefPtr<nsRange>       mUtilRange;
   uint32_t                mJoinOffset;  // need to remember an int across willJoin/didJoin...
-  nsCOMPtr<nsIDOMNode>    mNewBlock;
+  nsCOMPtr<Element>       mNewBlock;
   RefPtr<nsRangeStore>  mRangeItem;
   StyleCache              mCachedStyles[SIZE_STYLE_TABLE];
 };
 
 #endif //nsHTMLEditRules_h__