Bug 1387945 - Use nsIContent for CreateAnonymousElement. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 07 Aug 2017 14:09:51 +0900
changeset 641507 9539f37f2e98f8fbf41a9dd5974af8328bcd3ff4
parent 641444 bb8de16ce00cb57b587a14c210ecc7505f366328
child 724818 baec9a9fdb484a650e2e98566ce2cbb384701cd5
push id72557
push userbmo:m_kato@ga2.so-net.ne.jp
push dateMon, 07 Aug 2017 07:40:51 +0000
reviewersmasayuki
bugs1387945
milestone57.0a1
Bug 1387945 - Use nsIContent for CreateAnonymousElement. r?masayuki CreateAnonymousElement still uses nsIDOMNode, but we should use nsIContent for it. MozReview-Commit-ID: 2xgzlE6NVra
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/HTMLAnonymousNodeEditor.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/HTMLInlineTableEditor.cpp
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -225,21 +225,21 @@ HTMLEditor::GetElementZIndex(nsIDOMEleme
     nsresult errorCode;
     *aZindex = zIndexStr.ToInteger(&errorCode);
   }
 
   return NS_OK;
 }
 
 ManualNACPtr
-HTMLEditor::CreateGrabber(nsINode* aParentNode)
+HTMLEditor::CreateGrabber(nsIContent& aParentContent)
 {
   // let's create a grabber through the element factory
   ManualNACPtr ret =
-    CreateAnonymousElement(nsGkAtoms::span, GetAsDOMNode(aParentNode),
+    CreateAnonymousElement(nsGkAtoms::span, aParentContent,
                            NS_LITERAL_STRING("mozGrabber"), false);
   if (NS_WARN_IF(!ret)) {
     return nullptr;
   }
 
   // add the mouse listener so we can detect a click on a resizer
   nsCOMPtr<nsIDOMEventTarget> evtTarget = do_QueryInterface(ret);
   evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
@@ -250,17 +250,17 @@ HTMLEditor::CreateGrabber(nsINode* aPare
 
 NS_IMETHODIMP
 HTMLEditor::RefreshGrabber()
 {
   NS_ENSURE_TRUE(mAbsolutelyPositionedObject, NS_ERROR_NULL_POINTER);
 
   nsresult rv =
     GetPositionAndDimensions(
-      static_cast<nsIDOMElement*>(GetAsDOMNode(mAbsolutelyPositionedObject)),
+      *mAbsolutelyPositionedObject,
       mPositionedObjectX,
       mPositionedObjectY,
       mPositionedObjectWidth,
       mPositionedObjectHeight,
       mPositionedObjectBorderLeft,
       mPositionedObjectBorderTop,
       mPositionedObjectMarginLeft,
       mPositionedObjectMarginTop);
@@ -312,31 +312,39 @@ HTMLEditor::ShowGrabberOnElement(nsIDOME
 
   rv = element->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_abspos,
                         classValue, true);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // first, let's keep track of that element...
   mAbsolutelyPositionedObject = element;
 
-  mGrabber = CreateGrabber(element->GetParentNode());
+  nsIContent* parentContent = element->GetParent();
+  if (NS_WARN_IF(!parentContent)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  mGrabber = CreateGrabber(*parentContent);
   NS_ENSURE_TRUE(mGrabber, NS_ERROR_FAILURE);
 
   // and set its position
   return RefreshGrabber();
 }
 
 nsresult
 HTMLEditor::StartMoving(nsIDOMElement* aHandle)
 {
-  nsCOMPtr<nsINode> parentNode = mGrabber->GetParentNode();
+  nsCOMPtr<nsIContent> parentContent = mGrabber->GetParent();
+  if (NS_WARN_IF(!parentContent) || NS_WARN_IF(!mAbsolutelyPositionedObject)) {
+    return NS_ERROR_FAILURE;
+  }
 
   // now, let's create the resizing shadow
-  mPositioningShadow = CreateShadow(GetAsDOMNode(parentNode),
-      static_cast<nsIDOMElement*>(GetAsDOMNode(mAbsolutelyPositionedObject)));
+  mPositioningShadow =
+    CreateShadow(*parentContent, *mAbsolutelyPositionedObject);
   NS_ENSURE_TRUE(mPositioningShadow, NS_ERROR_FAILURE);
   nsresult rv = SetShadowPosition(mPositioningShadow,
                                   mAbsolutelyPositionedObject,
                                   mPositionedObjectX, mPositionedObjectY);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // make the shadow appear
   mPositioningShadow->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
@@ -475,17 +483,17 @@ HTMLEditor::AbsolutelyPositionElement(ns
   // nothing to do if the element is already in the state we want
   if (isPositioned == aEnabled)
     return NS_OK;
 
   AutoEditBatch batchIt(this);
 
   if (aEnabled) {
     int32_t x, y;
-    GetElementOrigin(aElement, x, y);
+    GetElementOrigin(*element, x, y);
 
     mCSSEditUtils->SetCSSProperty(*element, *nsGkAtoms::position,
                                   NS_LITERAL_STRING("absolute"));
 
     AddPositioningOffset(x, y);
     SnapToGrid(x, y);
     SetElementPosition(*element, x, y);
 
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -158,34 +158,25 @@ ElementDeletionObserver::NodeWillBeDestr
     mNativeAnonNode = nullptr;
   }
 
   NS_RELEASE_THIS();
 }
 
 ManualNACPtr
 HTMLEditor::CreateAnonymousElement(nsIAtom* aTag,
-                                   nsIDOMNode* aParentNode,
+                                   nsIContent& aParentContent,
                                    const nsAString& aAnonClass,
                                    bool aIsCreatedHidden)
 {
-  if (NS_WARN_IF(!aParentNode)) {
-    return nullptr;
-  }
-
-  nsCOMPtr<nsIContent> parentContent = do_QueryInterface(aParentNode);
-  if (NS_WARN_IF(!parentContent)) {
-    return nullptr;
-  }
-
   // Don't put anonymous editor element into non-HTML element.
   // It is mainly for avoiding other anonymous element being inserted
   // into <svg:use>, but in general we probably don't want to insert
   // some random HTML anonymous element into a non-HTML element.
-  if (!parentContent->IsHTMLElement()) {
+  if (!aParentContent.IsHTMLElement()) {
     return nullptr;
   }
 
   nsCOMPtr<nsIDocument> doc = GetDocument();
   if (NS_WARN_IF(!doc)) {
     return nullptr;
   }
 
@@ -222,35 +213,35 @@ HTMLEditor::CreateAnonymousElement(nsIAt
   }
 
   {
     nsAutoScriptBlocker scriptBlocker;
 
     // establish parenthood of the element
     newContentRaw->SetIsNativeAnonymousRoot();
     nsresult rv =
-      newContentRaw->BindToTree(doc, parentContent, parentContent, true);
+      newContentRaw->BindToTree(doc, &aParentContent, &aParentContent, true);
     if (NS_FAILED(rv)) {
       newContentRaw->UnbindFromTree();
       return nullptr;
     }
   }
 
   ManualNACPtr newContent(newContentRaw.forget());
 
   // Must style the new element, otherwise the PostRecreateFramesFor call
   // below will do nothing.
   if (ServoStyleSet* styleSet = ps->StyleSet()->GetAsServo()) {
     styleSet->StyleNewSubtree(newContent);
   }
 
   ElementDeletionObserver* observer =
-    new ElementDeletionObserver(newContent, parentContent);
+    new ElementDeletionObserver(newContent, &aParentContent);
   NS_ADDREF(observer); // NodeWillBeDestroyed releases.
-  parentContent->AddMutationObserver(observer);
+  aParentContent.AddMutationObserver(observer);
   newContent->AddMutationObserver(observer);
 
 #ifdef DEBUG
   // Editor anonymous content gets passed to PostRecreateFramesFor... which
   // can't _really_ deal with anonymous content (because it can't get the frame
   // tree ordering right).  But for us the ordering doesn't matter so this is
   // sort of ok.
   newContent->SetProperty(nsGkAtoms::restylableAnonymousNode,
@@ -487,73 +478,68 @@ HTMLEditor::CheckSelectionStateForAnonym
   }
 
   return NS_OK;
 }
 
 // Resizing and Absolute Positioning need to know everything about the
 // containing box of the element: position, size, margins, borders
 nsresult
-HTMLEditor::GetPositionAndDimensions(nsIDOMElement* aElement,
+HTMLEditor::GetPositionAndDimensions(Element& aElement,
                                      int32_t& aX,
                                      int32_t& aY,
                                      int32_t& aW,
                                      int32_t& aH,
                                      int32_t& aBorderLeft,
                                      int32_t& aBorderTop,
                                      int32_t& aMarginLeft,
                                      int32_t& aMarginTop)
 {
-  nsCOMPtr<Element> element = do_QueryInterface(aElement);
-  NS_ENSURE_ARG_POINTER(element);
-
   // Is the element positioned ? let's check the cheap way first...
-  bool isPositioned = false;
-  nsresult rv =
-    aElement->HasAttribute(NS_LITERAL_STRING("_moz_abspos"), &isPositioned);
-  NS_ENSURE_SUCCESS(rv, rv);
+  bool isPositioned =
+    aElement.HasAttr(kNameSpaceID_None, nsGkAtoms::_moz_abspos);
   if (!isPositioned) {
     // hmmm... the expensive way now...
     nsAutoString positionStr;
-    mCSSEditUtils->GetComputedProperty(*element, *nsGkAtoms::position,
+    mCSSEditUtils->GetComputedProperty(aElement, *nsGkAtoms::position,
                                        positionStr);
     isPositioned = positionStr.EqualsLiteral("absolute");
   }
 
   if (isPositioned) {
     // Yes, it is absolutely positioned
     mResizedObjectIsAbsolutelyPositioned = true;
 
     // Get the all the computed css styles attached to the element node
     RefPtr<nsComputedDOMStyle> cssDecl =
-      mCSSEditUtils->GetComputedStyle(element);
+      mCSSEditUtils->GetComputedStyle(&aElement);
     NS_ENSURE_STATE(cssDecl);
 
     aBorderLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-left-width"));
     aBorderTop  = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-top-width"));
     aMarginLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("margin-left"));
     aMarginTop  = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("margin-top"));
 
     aX = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("left")) +
          aMarginLeft + aBorderLeft;
     aY = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("top")) +
          aMarginTop + aBorderTop;
     aW = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("width"));
     aH = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("height"));
   } else {
     mResizedObjectIsAbsolutelyPositioned = false;
-    nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(aElement);
+    nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(&aElement);
     if (!htmlElement) {
       return NS_ERROR_NULL_POINTER;
     }
     GetElementOrigin(aElement, aX, aY);
 
     if (NS_WARN_IF(NS_FAILED(htmlElement->GetOffsetWidth(&aW))) ||
         NS_WARN_IF(NS_FAILED(htmlElement->GetOffsetHeight(&aH)))) {
-      return rv;
+      return NS_ERROR_FAILURE;
     }
 
     aBorderLeft = 0;
     aBorderTop  = 0;
     aMarginLeft = 0;
     aMarginTop = 0;
   }
   return NS_OK;
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -4790,31 +4790,30 @@ HTMLEditor::CopyLastEditableChildStyles(
     RefPtr<Element> retVal = CreateBR(deepestStyle, 0);
     retVal.forget(aOutBrNode);
     NS_ENSURE_STATE(*aOutBrNode);
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditor::GetElementOrigin(nsIDOMElement* aElement,
+HTMLEditor::GetElementOrigin(Element& aElement,
                              int32_t& aX,
                              int32_t& aY)
 {
   aX = 0;
   aY = 0;
 
   if (NS_WARN_IF(!IsInitialized())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
   nsCOMPtr<nsIPresShell> ps = GetPresShell();
   NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
-  nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
-  nsIFrame *frame = content->GetPrimaryFrame();
+  nsIFrame* frame = aElement.GetPrimaryFrame();
   NS_ENSURE_TRUE(frame, NS_OK);
 
   nsIFrame *container = ps->GetAbsoluteContainingBlock(frame);
   NS_ENSURE_TRUE(container, NS_OK);
   nsPoint off = frame->GetOffsetTo(container);
   aX = nsPresContext::AppUnitsToIntCSSPixels(off.x);
   aY = nsPresContext::AppUnitsToIntCSSPixels(off.y);
 
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -854,24 +854,24 @@ protected:
   void RemoveListenerAndDeleteRef(const nsAString& aEvent,
                                   nsIDOMEventListener* aListener,
                                   bool aUseCapture,
                                   ManualNACPtr aElement,
                                   nsIPresShell* aShell);
   void DeleteRefToAnonymousNode(ManualNACPtr aContent,
                                 nsIPresShell* aShell);
 
-  nsresult ShowResizersInner(nsIDOMElement *aResizedElement);
+  nsresult ShowResizersInner(Element& aResizedElement);
 
   /**
    * Returns the offset of an element's frame to its absolute containing block.
    */
-  nsresult GetElementOrigin(nsIDOMElement* aElement,
+  nsresult GetElementOrigin(Element& aElement,
                             int32_t& aX, int32_t& aY);
-  nsresult GetPositionAndDimensions(nsIDOMElement* aElement,
+  nsresult GetPositionAndDimensions(Element& aElement,
                                     int32_t& aX, int32_t& aY,
                                     int32_t& aW, int32_t& aH,
                                     int32_t& aBorderLeft,
                                     int32_t& aBorderTop,
                                     int32_t& aMarginLeft,
                                     int32_t& aMarginTop);
 
   bool IsInObservedSubtree(nsIDocument* aDocument,
@@ -935,39 +935,38 @@ protected:
   int32_t mWidthIncrementFactor;
   int32_t mHeightIncrementFactor;
 
   int8_t  mInfoXIncrement;
   int8_t  mInfoYIncrement;
 
   nsresult SetAllResizersPosition();
 
-  ManualNACPtr CreateResizer(int16_t aLocation, nsIDOMNode* aParentNode);
+  ManualNACPtr CreateResizer(int16_t aLocation, nsIContent& aParentContent);
   void SetAnonymousElementPosition(int32_t aX, int32_t aY,
                                    Element* aResizer);
 
-  ManualNACPtr CreateShadow(nsIDOMNode* aParentNode,
-                            nsIDOMElement* aOriginalObject);
+  ManualNACPtr CreateShadow(nsIContent& aParentContent,
+                            Element& aOriginalObject);
   nsresult SetShadowPosition(Element* aShadow, Element* aOriginalObject,
                              int32_t aOriginalObjectX,
                              int32_t aOriginalObjectY);
 
-  ManualNACPtr CreateResizingInfo(nsIDOMNode* aParentNode);
+  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);
   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 DeleteRefToAnonymousNode(nsIDOMNode* aNode);
   void SetResizeIncrements(int32_t aX, int32_t aY, int32_t aW, int32_t aH,
                            bool aPreserveRatio);
   void HideAnonymousEditingUIs();
 
   // absolute positioning
   int32_t mPositionedObjectX;
   int32_t mPositionedObjectY;
   int32_t mPositionedObjectWidth;
@@ -979,17 +978,17 @@ protected:
   int32_t mPositionedObjectBorderTop;
 
   nsCOMPtr<Element> mAbsolutelyPositionedObject;
   ManualNACPtr mGrabber;
   ManualNACPtr mPositioningShadow;
 
   int32_t mGridSize;
 
-  ManualNACPtr CreateGrabber(nsINode* aParentNode);
+  ManualNACPtr CreateGrabber(nsIContent& aParentContent);
   nsresult StartMoving(nsIDOMElement* aHandle);
   nsresult SetFinalPosition(int32_t aX, int32_t aY);
   void AddPositioningOffset(int32_t& aX, int32_t& aY);
   void SnapToGrid(int32_t& newX, int32_t& newY);
   nsresult GrabberClicked();
   nsresult EndMoving();
   nsresult CheckPositionedElementBGandFG(nsIDOMElement* aElement,
                                          nsAString& aReturn);
@@ -1032,30 +1031,30 @@ private:
                          nsIContent* aChild, int32_t aIndexInContainer,
                          InsertedOrAppended aInsertedOrAppended);
   already_AddRefed<Element> GetElementOrParentByTagName(
                               const nsAString& aTagName, nsINode* aNode);
   already_AddRefed<Element> CreateElementWithDefaults(
                               const nsAString& aTagName);
   /**
    * Returns an anonymous Element of type aTag,
-   * child of aParentNode. If aIsCreatedHidden is true, the class
+   * child of aParentContent. If aIsCreatedHidden is true, the class
    * "hidden" is added to the created element. If aAnonClass is not
    * the empty string, it becomes the value of the attribute "_moz_anonclass"
    * @return a Element
    * @param aTag             [IN] desired type of the element to create
-   * @param aParentNode      [IN] the parent node of the created anonymous
+   * @param aParentContent   [IN] the parent node of the created anonymous
    *                              element
    * @param aAnonClass       [IN] contents of the _moz_anonclass attribute
    * @param aIsCreatedHidden [IN] a boolean specifying if the class "hidden"
    *                              is to be added to the created anonymous
    *                              element
    */
   ManualNACPtr CreateAnonymousElement(nsIAtom* aTag,
-                                      nsIDOMNode* aParentNode,
+                                      nsIContent& aParentContent,
                                       const nsAString& aAnonClass,
                                       bool aIsCreatedHidden);
 };
 
 HTMLEditor*
 EditorBase::AsHTMLEditor()
 {
   return mIsHTMLEditorClass ? static_cast<HTMLEditor*>(this) : nullptr;
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -128,21 +128,21 @@ ResizerMouseMotionListener::HandleEvent(
 }
 
 /******************************************************************************
  * mozilla::HTMLEditor
  ******************************************************************************/
 
 ManualNACPtr
 HTMLEditor::CreateResizer(int16_t aLocation,
-                          nsIDOMNode* aParentNode)
+                          nsIContent& aParentContent)
 {
   ManualNACPtr ret =
     CreateAnonymousElement(nsGkAtoms::span,
-                           aParentNode,
+                           aParentContent,
                            NS_LITERAL_STRING("mozResizer"),
                            false);
   if (NS_WARN_IF(!ret)) {
     return nullptr;
   }
 
   // add the mouse listener so we can detect a click on a resizer
   nsCOMPtr<nsIDOMEventTarget> evtTarget = do_QueryInterface(ret);
@@ -181,36 +181,36 @@ HTMLEditor::CreateResizer(int16_t aLocat
 
   nsresult rv =
     ret->SetAttr(kNameSpaceID_None, nsGkAtoms::anonlocation, locationStr, true);
   NS_ENSURE_SUCCESS(rv, nullptr);
   return Move(ret);
 }
 
 ManualNACPtr
-HTMLEditor::CreateShadow(nsIDOMNode* aParentNode,
-                         nsIDOMElement* aOriginalObject)
+HTMLEditor::CreateShadow(nsIContent& aParentContent,
+                         Element& aOriginalObject)
 {
   // let's create an image through the element factory
   nsCOMPtr<nsIAtom> name;
-  if (HTMLEditUtils::IsImage(aOriginalObject)) {
+  if (HTMLEditUtils::IsImage(&aOriginalObject)) {
     name = nsGkAtoms::img;
   } else {
     name = nsGkAtoms::span;
   }
 
-  return CreateAnonymousElement(name, aParentNode,
+  return CreateAnonymousElement(name, aParentContent,
                                 NS_LITERAL_STRING("mozResizingShadow"), true);
 }
 
 ManualNACPtr
-HTMLEditor::CreateResizingInfo(nsIDOMNode* aParentNode)
+HTMLEditor::CreateResizingInfo(nsIContent& aParentContent)
 {
   // let's create an info box through the element factory
-  return CreateAnonymousElement(nsGkAtoms::span, aParentNode,
+  return CreateAnonymousElement(nsGkAtoms::span, aParentContent,
                                 NS_LITERAL_STRING("mozResizingInfo"), true);
 }
 
 nsresult
 HTMLEditor::SetAllResizersPosition()
 {
   NS_ENSURE_TRUE(mTopLeftHandle, NS_ERROR_FAILURE);
 
@@ -252,17 +252,17 @@ HTMLEditor::SetAllResizersPosition()
 NS_IMETHODIMP
 HTMLEditor::RefreshResizers()
 {
   // nothing to do if resizers are not displayed...
   NS_ENSURE_TRUE(mResizedObject, NS_OK);
 
   nsresult rv =
     GetPositionAndDimensions(
-      static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)),
+      *mResizedObject,
       mResizedObjectX,
       mResizedObjectY,
       mResizedObjectWidth,
       mResizedObjectHeight,
       mResizedObjectBorderLeft,
       mResizedObjectBorderTop,
       mResizedObjectMarginLeft,
       mResizedObjectMarginTop);
@@ -272,106 +272,123 @@ HTMLEditor::RefreshResizers()
   NS_ENSURE_SUCCESS(rv, rv);
   return SetShadowPosition(mResizingShadow, mResizedObject,
                            mResizedObjectX, mResizedObjectY);
 }
 
 NS_IMETHODIMP
 HTMLEditor::ShowResizers(nsIDOMElement* aResizedElement)
 {
-  nsresult rv = ShowResizersInner(aResizedElement);
+  if (NS_WARN_IF(!aResizedElement)) {
+   return NS_ERROR_NULL_POINTER;
+  }
+  nsCOMPtr<Element> element = do_QueryInterface(aResizedElement);
+  if (NS_WARN_IF(!element)) {
+    return NS_ERROR_FAILURE;
+  }
+  nsresult rv = ShowResizersInner(*element);
   if (NS_FAILED(rv)) {
     HideResizers();
   }
   return rv;
 }
 
 nsresult
-HTMLEditor::ShowResizersInner(nsIDOMElement* aResizedElement)
+HTMLEditor::ShowResizersInner(Element& aResizedElement)
 {
-  NS_ENSURE_ARG_POINTER(aResizedElement);
-
-  nsCOMPtr<nsIDOMNode> parentNode;
-  nsresult rv = aResizedElement->GetParentNode(getter_AddRefs(parentNode));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   if (mResizedObject) {
     NS_ERROR("call HideResizers first");
     return NS_ERROR_UNEXPECTED;
   }
-  mResizedObject = do_QueryInterface(aResizedElement);
-  NS_ENSURE_STATE(mResizedObject);
+
+  nsCOMPtr<nsIContent> parentContent = aResizedElement.GetParent();
+  if (NS_WARN_IF(!parentContent)) {
+   return NS_ERROR_FAILURE;
+  }
+
+  mResizedObject = &aResizedElement;
 
   // The resizers and the shadow will be anonymous siblings of the element.
-  mTopLeftHandle = CreateResizer(nsIHTMLObjectResizer::eTopLeft, parentNode);
+  mTopLeftHandle =
+    CreateResizer(nsIHTMLObjectResizer::eTopLeft, *parentContent);
   NS_ENSURE_TRUE(mTopLeftHandle, NS_ERROR_FAILURE);
-  mTopHandle = CreateResizer(nsIHTMLObjectResizer::eTop, parentNode);
+  mTopHandle = CreateResizer(nsIHTMLObjectResizer::eTop, *parentContent);
   NS_ENSURE_TRUE(mTopHandle, NS_ERROR_FAILURE);
-  mTopRightHandle = CreateResizer(nsIHTMLObjectResizer::eTopRight, parentNode);
+  mTopRightHandle =
+    CreateResizer(nsIHTMLObjectResizer::eTopRight, *parentContent);
   NS_ENSURE_TRUE(mTopRightHandle, NS_ERROR_FAILURE);
 
-  mLeftHandle = CreateResizer(nsIHTMLObjectResizer::eLeft, parentNode);
+  mLeftHandle = CreateResizer(nsIHTMLObjectResizer::eLeft, *parentContent);
   NS_ENSURE_TRUE(mLeftHandle, NS_ERROR_FAILURE);
-  mRightHandle = CreateResizer(nsIHTMLObjectResizer::eRight, parentNode);
+  mRightHandle = CreateResizer(nsIHTMLObjectResizer::eRight, *parentContent);
   NS_ENSURE_TRUE(mRightHandle, NS_ERROR_FAILURE);
 
-  mBottomLeftHandle = CreateResizer(nsIHTMLObjectResizer::eBottomLeft,  parentNode);
+  mBottomLeftHandle =
+    CreateResizer(nsIHTMLObjectResizer::eBottomLeft, *parentContent);
   NS_ENSURE_TRUE(mBottomLeftHandle, NS_ERROR_FAILURE);
-  mBottomHandle = CreateResizer(nsIHTMLObjectResizer::eBottom,      parentNode);
+  mBottomHandle = CreateResizer(nsIHTMLObjectResizer::eBottom, *parentContent);
   NS_ENSURE_TRUE(mBottomHandle, NS_ERROR_FAILURE);
-  mBottomRightHandle = CreateResizer(nsIHTMLObjectResizer::eBottomRight, parentNode);
+  mBottomRightHandle =
+    CreateResizer(nsIHTMLObjectResizer::eBottomRight, *parentContent);
   NS_ENSURE_TRUE(mBottomRightHandle, NS_ERROR_FAILURE);
 
-  rv = GetPositionAndDimensions(aResizedElement,
-                                mResizedObjectX,
-                                mResizedObjectY,
-                                mResizedObjectWidth,
-                                mResizedObjectHeight,
-                                mResizedObjectBorderLeft,
-                                mResizedObjectBorderTop,
-                                mResizedObjectMarginLeft,
-                                mResizedObjectMarginTop);
+  nsresult rv =
+    GetPositionAndDimensions(aResizedElement,
+                             mResizedObjectX,
+                             mResizedObjectY,
+                             mResizedObjectWidth,
+                             mResizedObjectHeight,
+                             mResizedObjectBorderLeft,
+                             mResizedObjectBorderTop,
+                             mResizedObjectMarginLeft,
+                             mResizedObjectMarginTop);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // and let's set their absolute positions in the document
   rv = SetAllResizersPosition();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // now, let's create the resizing shadow
-  mResizingShadow = CreateShadow(parentNode, aResizedElement);
+  mResizingShadow = CreateShadow(*parentContent, aResizedElement);
   NS_ENSURE_TRUE(mResizingShadow, NS_ERROR_FAILURE);
   // and set its position
-  rv = SetShadowPosition(mResizingShadow, mResizedObject,
+  rv = SetShadowPosition(mResizingShadow, &aResizedElement,
                          mResizedObjectX, mResizedObjectY);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // and then the resizing info tooltip
-  mResizingInfo = CreateResizingInfo(parentNode);
+  mResizingInfo = CreateResizingInfo(*parentContent);
   NS_ENSURE_TRUE(mResizingInfo, NS_ERROR_FAILURE);
 
   // and listen to the "resize" event on the window first, get the
   // window from the document...
   nsCOMPtr<nsIDocument> doc = GetDocument();
   NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(doc->GetWindow());
   if (!target) {
     return NS_ERROR_NULL_POINTER;
   }
 
   mResizeEventListenerP = new DocumentResizeEventListener(*this);
-  if (!mResizeEventListenerP) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
   rv = target->AddEventListener(NS_LITERAL_STRING("resize"),
                                 mResizeEventListenerP, false);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
   // XXX Even when it failed to add event listener, should we need to set
   //     _moz_resizing attribute?
-  aResizedElement->SetAttribute(NS_LITERAL_STRING("_moz_resizing"), NS_LITERAL_STRING("true"));
-  return rv;
+  aResizedElement.SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing,
+                          NS_LITERAL_STRING("true"), true);
+
+  if (NS_WARN_IF(mResizedObject != &aResizedElement)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::HideResizers()
 {
   NS_ENSURE_TRUE(mResizedObject, NS_OK);
 
   // get the presshell's document observer interface.
--- a/editor/libeditor/HTMLInlineTableEditor.cpp
+++ b/editor/libeditor/HTMLInlineTableEditor.cpp
@@ -53,37 +53,37 @@ HTMLEditor::ShowInlineTableEditingUI(nsI
   }
 
   if (mInlineEditedCell) {
     NS_ERROR("call HideInlineTableEditingUI first");
     return NS_ERROR_UNEXPECTED;
   }
 
   // the resizers and the shadow will be anonymous children of the body
-  nsCOMPtr<nsIDOMElement> bodyElement = do_QueryInterface(GetRoot());
+  RefPtr<Element> bodyElement = GetRoot();
   NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER);
 
   mAddColumnBeforeButton =
-    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
+    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                            NS_LITERAL_STRING("mozTableAddColumnBefore"), false);
   mRemoveColumnButton =
-    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
+    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                            NS_LITERAL_STRING("mozTableRemoveColumn"), false);
   mAddColumnAfterButton =
-    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
+    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                            NS_LITERAL_STRING("mozTableAddColumnAfter"), false);
 
   mAddRowBeforeButton =
-    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
+    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                            NS_LITERAL_STRING("mozTableAddRowBefore"), false);
   mRemoveRowButton =
-    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
+    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                            NS_LITERAL_STRING("mozTableRemoveRow"), false);
   mAddRowAfterButton =
-    CreateAnonymousElement(nsGkAtoms::a, bodyElement,
+    CreateAnonymousElement(nsGkAtoms::a, *bodyElement,
                            NS_LITERAL_STRING("mozTableAddRowAfter"), false);
 
   AddMouseClickListener(mAddColumnBeforeButton);
   AddMouseClickListener(mRemoveColumnButton);
   AddMouseClickListener(mAddColumnAfterButton);
   AddMouseClickListener(mAddRowBeforeButton);
   AddMouseClickListener(mRemoveRowButton);
   AddMouseClickListener(mAddRowAfterButton);
@@ -207,17 +207,21 @@ NS_IMETHODIMP
 HTMLEditor::RefreshInlineTableEditingUI()
 {
   nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(mInlineEditedCell);
   if (!htmlElement) {
     return NS_ERROR_NULL_POINTER;
   }
 
   int32_t xCell, yCell, wCell, hCell;
-  GetElementOrigin(mInlineEditedCell, xCell, yCell);
+  nsCOMPtr<Element> element = do_QueryInterface(mInlineEditedCell);
+  if (NS_WARN_IF(!element)) {
+   return NS_ERROR_FAILURE;
+  }
+  GetElementOrigin(*element, xCell, yCell);
 
   nsresult rv = htmlElement->GetOffsetWidth(&wCell);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = htmlElement->GetOffsetHeight(&hCell);
   NS_ENSURE_SUCCESS(rv, rv);
 
   int32_t xHoriz = xCell + wCell/2;
   int32_t yVert  = yCell + hCell/2;