Bug 1455674 part 2. Mostly stop using nsIDOMElement in nsIHTMLEditor. r=masayuki
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 26 Apr 2018 23:35:18 -0400
changeset 472082 52e2af8c5e62675514fd20ba6da493cf761ddfd9
parent 472081 ec41eab9c159876bcd5a6a7b314289f5d9b04535
child 472083 667c981474f823ad581668657a52dbc9d40b845b
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1455674
milestone61.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 1455674 part 2. Mostly stop using nsIDOMElement in nsIHTMLEditor. r=masayuki MozReview-Commit-ID: Koxv2qS2gft
editor/composer/nsComposerCommands.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLEditorEventListener.cpp
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/HTMLTableEditor.cpp
editor/nsIHTMLEditor.idl
--- a/editor/composer/nsComposerCommands.cpp
+++ b/editor/composer/nsComposerCommands.cpp
@@ -1450,22 +1450,22 @@ nsInsertTagCommand::DoCommand(const char
   if (NS_WARN_IF(!editor)) {
     return NS_ERROR_FAILURE;
   }
   mozilla::HTMLEditor* htmlEditor = editor->AsHTMLEditor();
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
 
-  nsCOMPtr<nsIDOMElement> domElem;
+  RefPtr<Element> newElement;
   nsresult rv = htmlEditor->CreateElementWithDefaults(
-    nsDependentAtomString(mTagName), getter_AddRefs(domElem));
+    nsDependentAtomString(mTagName), getter_AddRefs(newElement));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  return htmlEditor->InsertElementAtSelection(domElem, true);
+  return htmlEditor->InsertElementAtSelection(newElement, true);
 }
 
 NS_IMETHODIMP
 nsInsertTagCommand::DoCommandParams(const char *aCommandName,
                                     nsICommandParams *aParams,
                                     nsISupports *refCon)
 {
   NS_ENSURE_ARG_POINTER(refCon);
@@ -1501,33 +1501,32 @@ nsInsertTagCommand::DoCommandParams(cons
   if (mTagName == nsGkAtoms::a) {
     attributeType.AssignLiteral("href");
   } else if (mTagName == nsGkAtoms::img) {
     attributeType.AssignLiteral("src");
   } else {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
-  nsCOMPtr<nsIDOMElement> domElem;
+  RefPtr<Element> elem;
   rv = htmlEditor->CreateElementWithDefaults(nsDependentAtomString(mTagName),
-                                             getter_AddRefs(domElem));
+                                             getter_AddRefs(elem));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<Element> elem = do_QueryInterface(domElem);
   ErrorResult err;
   elem->SetAttribute(attributeType, attrib, err);
   if (NS_WARN_IF(err.Failed())) {
     return err.StealNSResult();
   }
 
   // do actual insertion
   if (mTagName == nsGkAtoms::a) {
-    return htmlEditor->InsertLinkAroundSelection(domElem);
+    return htmlEditor->InsertLinkAroundSelection(elem);
   }
-  return htmlEditor->InsertElementAtSelection(domElem, true);
+  return htmlEditor->InsertElementAtSelection(elem, true);
 }
 
 NS_IMETHODIMP
 nsInsertTagCommand::GetCommandStateParams(const char *aCommandName,
                                           nsICommandParams *aParams,
                                           nsISupports *refCon)
 {
   NS_ENSURE_ARG_POINTER(aParams);
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1512,24 +1512,23 @@ HTMLEditor::GetBetterInsertionPointFor(n
   EditorRawDOMPoint afterBRNode(nextVisibleNode);
   DebugOnly<bool> advanced = afterBRNode.AdvanceOffset();
   NS_WARNING_ASSERTION(advanced,
     "Failed to advance offset to after the <br> node");
   return afterBRNode;
 }
 
 NS_IMETHODIMP
-HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
+HTMLEditor::InsertElementAtSelection(Element* aElement,
                                      bool aDeleteSelection)
 {
   // Protect the edit rules object from dying
   RefPtr<TextEditRules> rules(mRules);
 
-  nsCOMPtr<Element> element = do_QueryInterface(aElement);
-  NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
+  NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
 
   CommitComposition();
   AutoPlaceholderBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::insertElement,
                                nsIEditor::eNext);
 
   RefPtr<Selection> selection = GetSelection();
   if (!selection) {
@@ -1541,17 +1540,17 @@ HTMLEditor::InsertElementAtSelection(nsI
   RulesInfo ruleInfo(EditAction::insertElement);
   nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || NS_FAILED(rv)) {
     return rv;
   }
 
   if (!handled) {
     if (aDeleteSelection) {
-      if (!IsBlockNode(element)) {
+      if (!IsBlockNode(aElement)) {
         // E.g., inserting an image.  In this case we don't need to delete any
         // inline wrappers before we do the insertion.  Otherwise we let
         // DeleteSelectionAndPrepareToCreateNode do the deletion for us, which
         // calls DeleteSelection with aStripWrappers = eStrip.
         rv = DeleteSelectionAsAction(eNone, eNoStrip);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
@@ -1562,48 +1561,48 @@ HTMLEditor::InsertElementAtSelection(nsI
     }
 
     // If deleting, selection will be collapsed.
     // so if not, we collapse it
     if (!aDeleteSelection) {
       // Named Anchor is a special case,
       // We collapse to insert element BEFORE the selection
       // For all other tags, we insert AFTER the selection
-      if (HTMLEditUtils::IsNamedAnchor(element)) {
+      if (HTMLEditUtils::IsNamedAnchor(aElement)) {
         selection->CollapseToStart();
       } else {
         selection->CollapseToEnd();
       }
     }
 
     if (selection->GetAnchorNode()) {
       EditorRawDOMPoint atAnchor(selection->AnchorRef());
       // Adjust position based on the node we are going to insert.
       EditorRawDOMPoint pointToInsert =
-        GetBetterInsertionPointFor(*element, atAnchor);
+        GetBetterInsertionPointFor(*aElement, atAnchor);
       if (NS_WARN_IF(!pointToInsert.IsSet())) {
         return NS_ERROR_FAILURE;
       }
 
       EditorDOMPoint insertedPoint =
         InsertNodeIntoProperAncestorWithTransaction(
-          *element, pointToInsert, SplitAtEdges::eAllowToCreateEmptyContainer);
+          *aElement, pointToInsert, SplitAtEdges::eAllowToCreateEmptyContainer);
       if (NS_WARN_IF(!insertedPoint.IsSet())) {
         return NS_ERROR_FAILURE;
       }
       // Set caret after element, but check for special case
       //  of inserting table-related elements: set in first cell instead
       if (!SetCaretInTableCell(aElement)) {
         rv = SetCaretAfterElement(aElement);
         NS_ENSURE_SUCCESS(rv, rv);
       }
       // check for inserting a whole table at the end of a block. If so insert
       // a br after it.
-      if (HTMLEditUtils::IsTable(element) &&
-          IsLastEditableChild(element)) {
+      if (HTMLEditUtils::IsTable(aElement) &&
+          IsLastEditableChild(aElement)) {
         DebugOnly<bool> advanced = insertedPoint.AdvanceOffset();
         NS_WARNING_ASSERTION(advanced,
           "Failed to advance offset from inserted point");
         // Collapse selection to the new <br> element node after creating it.
         RefPtr<Element> newBrElement =
           InsertBrElementWithTransaction(*selection, insertedPoint, ePrevious);
         if (NS_WARN_IF(!newBrElement)) {
           return NS_ERROR_FAILURE;
@@ -1679,61 +1678,55 @@ HTMLEditor::InsertNodeIntoProperAncestor
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return EditorDOMPoint();
     }
   }
   return pointToInsert;
 }
 
 NS_IMETHODIMP
-HTMLEditor::SelectElement(nsIDOMElement* aElement)
+HTMLEditor::SelectElement(Element* aElement)
 {
-  nsCOMPtr<Element> element = do_QueryInterface(aElement);
-  NS_ENSURE_STATE(element || !aElement);
-
   // Must be sure that element is contained in the document body
-  if (!IsDescendantOfEditorRoot(element)) {
+  if (!IsDescendantOfEditorRoot(aElement)) {
     return NS_ERROR_NULL_POINTER;
   }
 
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
-  nsINode* parent = element->GetParentNode();
+  nsINode* parent = aElement->GetParentNode();
   if (NS_WARN_IF(!parent)) {
     return NS_ERROR_FAILURE;
   }
 
-  int32_t offsetInParent = parent->ComputeIndexOf(element);
+  int32_t offsetInParent = parent->ComputeIndexOf(aElement);
 
   // Collapse selection to just before desired element,
   nsresult rv = selection->Collapse(parent, offsetInParent);
   if (NS_SUCCEEDED(rv)) {
     // then extend it to just after
     rv = selection->Extend(parent, offsetInParent + 1);
   }
   return rv;
 }
 
 NS_IMETHODIMP
-HTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement)
+HTMLEditor::SetCaretAfterElement(Element* aElement)
 {
-  nsCOMPtr<Element> element = do_QueryInterface(aElement);
-  NS_ENSURE_STATE(element || !aElement);
-
   // Be sure the element is contained in the document body
-  if (!aElement || !IsDescendantOfEditorRoot(element)) {
+  if (!aElement || !IsDescendantOfEditorRoot(aElement)) {
     return NS_ERROR_NULL_POINTER;
   }
 
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
-  nsCOMPtr<nsINode> parent = element->GetParentNode();
+  nsCOMPtr<nsINode> parent = aElement->GetParentNode();
   NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
   // Collapse selection to just after desired element,
-  EditorRawDOMPoint afterElement(element);
+  EditorRawDOMPoint afterElement(aElement);
   if (NS_WARN_IF(!afterElement.AdvanceOffset())) {
     return NS_ERROR_FAILURE;
   }
   return selection->Collapse(afterElement);
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetParagraphFormat(const nsAString& aParagraphFormat)
@@ -2695,47 +2688,46 @@ HTMLEditor::CreateElementWithDefaults(co
   }
   // ADD OTHER TAGS HERE
 
   return newElement.forget();
 }
 
 NS_IMETHODIMP
 HTMLEditor::CreateElementWithDefaults(const nsAString& aTagName,
-                                      nsIDOMElement** aReturn)
+                                      Element** aReturn)
 {
   NS_ENSURE_TRUE(!aTagName.IsEmpty() && aReturn, NS_ERROR_NULL_POINTER);
   *aReturn = nullptr;
 
   nsCOMPtr<Element> newElement = CreateElementWithDefaults(aTagName);
-  nsCOMPtr<nsIDOMElement> ret = do_QueryInterface(newElement);
-  NS_ENSURE_TRUE(ret, NS_ERROR_FAILURE);
-
-  ret.forget(aReturn);
+  NS_ENSURE_TRUE(newElement, NS_ERROR_FAILURE);
+
+  newElement.forget(aReturn);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-HTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
+HTMLEditor::InsertLinkAroundSelection(Element* aAnchorElement)
 {
   NS_ENSURE_TRUE(aAnchorElement, NS_ERROR_NULL_POINTER);
 
   // We must have a real selection
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   if (selection->Collapsed()) {
     NS_WARNING("InsertLinkAroundSelection called but there is no selection!!!");
     return NS_OK;
   }
 
 
   // Be sure we were given an anchor element
-  nsCOMPtr<nsIContent> content = do_QueryInterface(aAnchorElement);
-  RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromNodeOrNull(content);
+  RefPtr<HTMLAnchorElement> anchor =
+    HTMLAnchorElement::FromNodeOrNull(aAnchorElement);
   if (!anchor) {
     return NS_OK;
   }
 
   nsAutoString href;
   anchor->GetHref(href);
   if (href.IsEmpty()) {
     return NS_OK;
@@ -3629,26 +3621,25 @@ HTMLEditor::IsTextPropertySetByContent(n
       }
     }
     aNode = aNode->GetParentNode();
   }
   return false;
 }
 
 bool
-HTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement)
+HTMLEditor::SetCaretInTableCell(Element* aElement)
 {
-  nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
-  if (!element || !element->IsHTMLElement() ||
-      !HTMLEditUtils::IsTableElement(element) ||
-      !IsDescendantOfEditorRoot(element)) {
+  if (!aElement || !aElement->IsHTMLElement() ||
+      !HTMLEditUtils::IsTableElement(aElement) ||
+      !IsDescendantOfEditorRoot(aElement)) {
     return false;
   }
 
-  nsIContent* node = element;
+  nsIContent* node = aElement;
   while (node->HasChildren()) {
     node = node->GetFirstChild();
   }
 
   // Set selection at beginning of the found node
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, false);
 
@@ -4682,21 +4673,19 @@ HTMLEditor::EndUpdateViewBatch()
   // to listen too (in particular when an ancestor of the selection is
   // changed but the selection itself is not changed).
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
   return CheckSelectionStateForAnonymousButtons(selection);
 }
 
 NS_IMETHODIMP
-HTMLEditor::GetSelectionContainer(nsIDOMElement** aReturn)
+HTMLEditor::GetSelectionContainer(Element** aReturn)
 {
-  nsCOMPtr<nsIDOMElement> container =
-    static_cast<nsIDOMElement*>(GetAsDOMNode(GetSelectionContainer()));
-  NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
+  RefPtr<Element> container = GetSelectionContainer();
   container.forget(aReturn);
   return NS_OK;
 }
 
 Element*
 HTMLEditor::GetSelectionContainer()
 {
   // If we don't get the selection, just skip this
@@ -4748,22 +4737,21 @@ HTMLEditor::GetSelectionContainer()
   if (focusNode && focusNode->IsElement()) {
     return focusNode->AsElement();
   }
 
   return nullptr;
 }
 
 NS_IMETHODIMP
-HTMLEditor::IsAnonymousElement(nsIDOMElement* aElement,
+HTMLEditor::IsAnonymousElement(Element* aElement,
                                bool* aReturn)
 {
   NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
-  nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
-  *aReturn = content->IsRootOfNativeAnonymousSubtree();
+  *aReturn = aElement->IsRootOfNativeAnonymousSubtree();
   return NS_OK;
 }
 
 nsresult
 HTMLEditor::SetReturnInParagraphCreatesNewParagraph(bool aCreatesNewParagraph)
 {
   mCRInParagraphCreatesParagraph = aCreatesNewParagraph;
   return NS_OK;
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -562,17 +562,17 @@ public:
 
   /**
    * event callback when a mouse button is pressed
    * @param aX      [IN] horizontal position of the pointer
    * @param aY      [IN] vertical position of the pointer
    * @param aTarget [IN] the element triggering the event
    * @param aMouseEvent [IN] the event
    */
-  nsresult OnMouseDown(int32_t aX, int32_t aY, nsIDOMElement* aTarget,
+  nsresult OnMouseDown(int32_t aX, int32_t aY, Element* aTarget,
                        dom::Event* aMouseEvent);
 
   /**
    * event callback when a mouse button is released
    * @param aX      [IN] horizontal position of the pointer
    * @param aY      [IN] vertical position of the pointer
    * @param aTarget [IN] the element triggering the event
    */
@@ -660,17 +660,17 @@ protected:
    * @return    If the editor has focus, this returns the focused node.
    *            Otherwise, returns null.
    */
   already_AddRefed<nsINode> GetFocusedNode();
 
   /**
    * Return TRUE if aElement is a table-related elemet and caret was set.
    */
-  bool SetCaretInTableCell(nsIDOMElement* aElement);
+  bool SetCaretInTableCell(dom::Element* aElement);
 
   nsresult TabInTable(bool inIsShift, bool* outHandled);
 
   /**
    * InsertBrElementAtSelectionWithTransaction() inserts a new <br> element at
    * selection.  If there is non-collapsed selection ranges, the selected
    * ranges is deleted first.
    */
@@ -1365,17 +1365,17 @@ protected:
                              int32_t aOriginalObjectX,
                              int32_t aOriginalObjectY);
 
   ManualNACPtr CreateResizingInfo(nsIContent& aParentContent);
   nsresult SetResizingInfoPosition(int32_t aX, int32_t aY,
                                    int32_t aW, int32_t aH);
 
   int32_t GetNewResizingIncrement(int32_t aX, int32_t aY, int32_t aID);
-  nsresult StartResizing(nsIDOMElement* aHandle);
+  nsresult StartResizing(Element* aHandle);
   int32_t GetNewResizingX(int32_t aX, int32_t aY);
   int32_t GetNewResizingY(int32_t aX, int32_t aY);
   int32_t GetNewResizingWidth(int32_t aX, int32_t aY);
   int32_t GetNewResizingHeight(int32_t aX, int32_t aY);
   void HideShadowAndInfo();
   void SetFinalSize(int32_t aX, int32_t aY);
   void SetResizeIncrements(int32_t aX, int32_t aY, int32_t aW, int32_t aH,
                            bool aPreserveRatio);
--- a/editor/libeditor/HTMLEditorEventListener.cpp
+++ b/editor/libeditor/HTMLEditorEventListener.cpp
@@ -96,17 +96,17 @@ HTMLEditorEventListener::MouseDown(Mouse
   int16_t buttonNumber = aMouseEvent->Button();
 
   bool isContextClick = buttonNumber == 2;
 
   int32_t clickCount = aMouseEvent->Detail();
 
   RefPtr<EventTarget> target = aMouseEvent->GetExplicitOriginalTarget();
   NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
-  nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
+  nsCOMPtr<Element> element = do_QueryInterface(target);
 
   if (isContextClick || (buttonNumber == 0 && clickCount == 2)) {
     RefPtr<Selection> selection = htmlEditor->GetSelection();
     NS_ENSURE_TRUE(selection, NS_OK);
 
     // Get location of mouse within target node
     nsCOMPtr<nsINode> parent = aMouseEvent->GetRangeParent();
     NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
@@ -142,17 +142,17 @@ HTMLEditorEventListener::MouseDown(Mouse
           // Set the selection to the point under the mouse cursor:
           selection->Collapse(parent, offset);
         } else {
           // Get enclosing link if in text so we can select the link
           RefPtr<Element> linkElement =
             htmlEditor->GetElementOrParentByTagName(NS_LITERAL_STRING("href"),
                                                     node);
           if (linkElement) {
-            element = do_QueryInterface(linkElement);
+            element = linkElement;
           }
         }
       }
       // Select entire element clicked on if NOT within an existing selection
       //   and not the entire body, or table-related elements
       if (element) {
         if (isContextClick && !HTMLEditUtils::IsImage(node)) {
           selection->Collapse(parent, offset);
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -450,20 +450,20 @@ HTMLEditor::HideShadowAndInfo()
   }
   if (mResizingInfo) {
     mResizingInfo->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
                            NS_LITERAL_STRING("hidden"), true);
   }
 }
 
 nsresult
-HTMLEditor::StartResizing(nsIDOMElement* aHandle)
+HTMLEditor::StartResizing(Element* aHandle)
 {
   mIsResizing = true;
-  mActivatedHandle = do_QueryInterface(aHandle);
+  mActivatedHandle = aHandle;
   NS_ENSURE_STATE(mActivatedHandle || !aHandle);
   mActivatedHandle->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated,
                             NS_LITERAL_STRING("true"), true);
 
   // do we want to preserve ratio or not?
   bool preserveRatio = HTMLEditUtils::IsImage(mResizedObject) &&
     Preferences::GetBool("editor.resizing.preserve_ratio", true);
 
@@ -515,24 +515,23 @@ HTMLEditor::StartResizing(nsIDOMElement*
                  "failed to register mouse motion listener");
   }
   return result;
 }
 
 nsresult
 HTMLEditor::OnMouseDown(int32_t aClientX,
                         int32_t aClientY,
-                        nsIDOMElement* aTarget,
+                        Element* aTarget,
                         Event* aEvent)
 {
-  nsCOMPtr<Element> element = do_QueryInterface(aTarget);
-  NS_ENSURE_ARG_POINTER(element);
+  NS_ENSURE_ARG_POINTER(aTarget);
 
   nsAutoString anonclass;
-  element->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
+  aTarget->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
 
   if (anonclass.EqualsLiteral("mozResizer")) {
     // If we have an anonymous element and that element is a resizer,
     // let's start resizing!
     aEvent->PreventDefault();
 
     mOriginalX = aClientX;
     mOriginalY = aClientY;
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -108,32 +108,26 @@ HTMLEditor::InsertCell(nsIDOMElement* aD
   if (NS_WARN_IF(!cell)) {
     return NS_ERROR_INVALID_ARG;
   }
   EditorDOMPoint pointToInsert(cell);
   if (NS_WARN_IF(!pointToInsert.IsSet())) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  nsCOMPtr<nsIDOMElement> newDOMCell;
-  nsresult rv =
+  RefPtr<Element> newCell =
     CreateElementWithDefaults(aIsHeader ? NS_LITERAL_STRING("th") :
-                                          NS_LITERAL_STRING("tb"),
-                              getter_AddRefs(newDOMCell));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  nsCOMPtr<Element> newCell = do_QueryInterface(newDOMCell);
+                                          NS_LITERAL_STRING("tb"));
   if (NS_WARN_IF(!newCell)) {
     return NS_ERROR_FAILURE;
   }
 
   //Optional: return new cell created
   if (aNewDOMCell) {
-    newDOMCell.forget(aNewDOMCell);
+    CallQueryInterface(newCell, aNewDOMCell);
   }
 
   if (aRowSpan > 1) {
     // Note: Do NOT use editor transaction for this
     nsAutoString newRowSpan;
     newRowSpan.AppendInt(aRowSpan, 10);
     newCell->SetAttr(kNameSpaceID_None, nsGkAtoms::rowspan, newRowSpan, true);
   }
@@ -216,28 +210,24 @@ HTMLEditor::InsertTableCell(int32_t aNum
   //We control selection resetting after the insert...
   AutoSelectionSetterAfterTableEdit setCaret(*this, table, startRowIndex,
                                              newCellIndex, ePreviousColumn,
                                              false);
   //...so suppress Rules System selection munging
   AutoTransactionsConserveSelection dontChangeSelection(this);
 
   for (int32_t i = 0; i < aNumber; i++) {
-    nsCOMPtr<nsIDOMElement> newCell;
+    RefPtr<Element> newCell;
     rv = CreateElementWithDefaults(NS_LITERAL_STRING("td"),
                                    getter_AddRefs(newCell));
     if (NS_SUCCEEDED(rv) && newCell) {
       if (aAfter) {
         cellOffset++;
       }
-      nsCOMPtr<nsIContent> cell = do_QueryInterface(newCell);
-      if (NS_WARN_IF(!cell)) {
-        return NS_ERROR_FAILURE;
-      }
-      rv = InsertNodeWithTransaction(*cell,
+      rv = InsertNodeWithTransaction(*newCell,
                                      EditorRawDOMPoint(cellParent, cellOffset));
       if (NS_FAILED(rv)) {
         break;
       }
     }
   }
   // XXX This is perhaps the result of the last call of
   //     InsertNodeWithTransaction() or CreateElementWithDefaults().
@@ -3170,17 +3160,19 @@ HTMLEditor::SetSelectionAfterTableEdit(n
     nsresult rv = GetCellAt(aTable, aRow, aCol, getter_AddRefs(cell));
     if (NS_FAILED(rv)) {
       break;
     }
 
     if (cell) {
       if (aSelected) {
         // Reselect the cell
-        SelectElement(cell);
+        // Remove "temp" once we nix nsIDOMElement from here.
+        nsCOMPtr<Element> temp = do_QueryInterface(cell);
+        SelectElement(temp);
         return;
       }
 
       // Set the caret to deepest first child
       //   but don't go into nested tables
       // TODO: Should we really be placing the caret at the END
       //  of the cell content?
       nsCOMPtr<nsINode> cellNode = do_QueryInterface(cell);
--- a/editor/nsIHTMLEditor.idl
+++ b/editor/nsIHTMLEditor.idl
@@ -5,25 +5,17 @@
 
 #include "nsISupports.idl"
 #include "domstubs.idl"
 
 interface nsIContent;
 interface nsIArray;
 interface nsISelection;
 
-%{C++
-namespace mozilla {
-namespace dom {
-class Element;
-}
-}
-%}
-
-[ptr] native Element (mozilla::dom::Element);
+webidl Element;
 
 [scriptable, builtinclass, uuid(87ee993e-985f-4a43-a974-0d9512da2fb0)]
 interface nsIHTMLEditor : nsISupports
 {
 %{C++
   typedef short EAlignment;
 %}
 
@@ -189,17 +181,17 @@ interface nsIHTMLEditor : nsISupports
     *   be useful for other elements.
     *
     * @param aElement           The element to insert
     * @param aDeleteSelection   Delete the selection before inserting
     *     If aDeleteSelection is PR_FALSE, then the element is inserted
     *     after the end of the selection for all element except
     *     Named Anchors, which insert before the selection
     */
-  void insertElementAtSelection(in nsIDOMElement aElement,
+  void insertElementAtSelection(in Element aElement,
                                 in boolean aDeleteSelection);
 
   /**
    *   Set the BaseURL for the document to the current URL
    *     but only if the page doesn't have a <base> tag
    *   This should be done after the document URL has changed,
    *     such as after saving a file
    *   This is used as base for relativizing link and image urls
@@ -210,31 +202,31 @@ interface nsIHTMLEditor : nsISupports
   /* ------------ Selection manipulation -------------- */
   /* Should these be moved to nsISelection? */
 
   /**
     * Set the selection at the suppled element
     *
     * @param aElement   An element in the document
     */
-  void selectElement(in nsIDOMElement aElement);
+  void selectElement(in Element aElement);
 
   /**
     * Create a collapsed selection just after aElement
     *
     * XXX could we parameterize SelectElement(before/select/after>?
     *
     * The selection is set to parent-of-aElement with an
     *   offset 1 greater than aElement's offset
     *   but it enforces the HTML 4.0 DTD "CanContain" rules, so it should
     *   be useful for other elements.
     *
     * @param aElement  An element in the document
     */
-  void setCaretAfterElement(in nsIDOMElement aElement);
+  void setCaretAfterElement(in Element aElement);
 
   /**
    * SetParagraphFormat       Insert a block paragraph tag around selection
    * @param aParagraphFormat  "p", "h1" to "h6", "address", "pre", or "blockquote"
    */
   void setParagraphFormat(in AString aParagraphFormat);
 
   /**
@@ -400,24 +392,24 @@ interface nsIHTMLEditor : nsISupports
    * @param aTagName  The HTML tagname
    *    Special input values for Links and Named anchors:
    *    Use "href" to get a link node
    *      (an "A" tag with the "href" attribute set)
    *    Use "anchor" or "namedanchor" to get a named anchor node
    *      (an "A" tag with the "name" attribute set)
    * @return          The new element created.
    */
-  nsIDOMElement createElementWithDefaults(in AString aTagName);
+  Element createElementWithDefaults(in AString aTagName);
 
   /**
    * Insert an link element as the parent of the current selection
    *
    * @param aElement   An "A" element with a non-empty "href" attribute
    */
-  void insertLinkAroundSelection(in nsIDOMElement aAnchorElement);
+  void insertLinkAroundSelection(in Element aAnchorElement);
 
   /**
    * Set the value of the "bgcolor" attribute on the document's <body> element
    *
    * @param aColor  The HTML color string, such as "#ffccff" or "yellow"
    */
   void setBackgroundColor(in AString aColor);
 
@@ -449,26 +441,26 @@ interface nsIHTMLEditor : nsISupports
    * @return    true if CSS handled and enabled
    */
   attribute boolean isCSSEnabled;
 
   /**
    * returns the deepest container of the selection
    * @return a DOM Element
    */
-  nsIDOMElement getSelectionContainer();
+  Element getSelectionContainer();
 
   /**
    * Checks if the anonymous nodes created by the HTML editor have to be
    * refreshed or hidden depending on a possible new state of the selection
    * @param aSelection [IN] a selection
    */
   void checkSelectionStateForAnonymousButtons(in nsISelection aSelection);
 
-  boolean isAnonymousElement(in nsIDOMElement aElement);
+  boolean isAnonymousElement(in Element aElement);
 
   /**
    * A boolean indicating if a return key pressed in a paragraph creates
    * another paragraph or just inserts a <br> at the caret
    *
    * @return    true if CR in a paragraph creates a new paragraph
    */
   attribute boolean returnInParagraphCreatesNewParagraph;