Bug 1313986 - Part 3. Use CreateAnonymousElement with nsIAtom for simple case. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 24 Nov 2016 18:07:47 +0900
changeset 324074 458c739c920a2f89af836f77144391f2f014f2d3
parent 324073 4205c3ed2ce5999aad02cceb0a8917ddf4c0e831
child 324075 f2593e79b289aede3294d8cfa77d2a47d89eddb6
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersmasayuki
bugs1313986
milestone53.0a1
Bug 1313986 - Part 3. Use CreateAnonymousElement with nsIAtom for simple case. r=masayuki Now we can return Element directly via CreateAnonymousElement. We should use it. MozReview-Commit-ID: Et1i3hLVSqc
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/HTMLEditorObjectResizer.cpp
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -230,29 +230,28 @@ HTMLEditor::GetElementZIndex(nsIDOMEleme
 
   return NS_OK;
 }
 
 already_AddRefed<Element>
 HTMLEditor::CreateGrabber(nsINode* aParentNode)
 {
   // let's create a grabber through the element factory
-  nsCOMPtr<nsIDOMElement> retDOM;
-  CreateAnonymousElement(NS_LITERAL_STRING("span"), GetAsDOMNode(aParentNode),
-                         NS_LITERAL_STRING("mozGrabber"), false,
-                         getter_AddRefs(retDOM));
-
-  NS_ENSURE_TRUE(retDOM, nullptr);
+  RefPtr<Element> ret =
+    CreateAnonymousElement(nsGkAtoms::span, GetAsDOMNode(aParentNode),
+                           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(retDOM));
+  nsCOMPtr<nsIDOMEventTarget> evtTarget = do_QueryInterface(ret);
   evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
                               mEventListener, false);
 
-  nsCOMPtr<Element> ret = do_QueryInterface(retDOM);
   return ret.forget();
 }
 
 NS_IMETHODIMP
 HTMLEditor::RefreshGrabber()
 {
   NS_ENSURE_TRUE(mAbsolutelyPositionedObject, NS_ERROR_NULL_POINTER);
 
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -133,28 +133,27 @@ ResizerMouseMotionListener::HandleEvent(
 /******************************************************************************
  * mozilla::HTMLEditor
  ******************************************************************************/
 
 already_AddRefed<Element>
 HTMLEditor::CreateResizer(int16_t aLocation,
                           nsIDOMNode* aParentNode)
 {
-  nsCOMPtr<nsIDOMElement> retDOM;
-  nsresult rv = CreateAnonymousElement(NS_LITERAL_STRING("span"),
-                                       aParentNode,
-                                       NS_LITERAL_STRING("mozResizer"),
-                                       false,
-                                       getter_AddRefs(retDOM));
-
-  NS_ENSURE_SUCCESS(rv, nullptr);
-  NS_ENSURE_TRUE(retDOM, nullptr);
+  RefPtr<Element> ret =
+    CreateAnonymousElement(nsGkAtoms::span,
+                           aParentNode,
+                           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(retDOM);
+  nsCOMPtr<nsIDOMEventTarget> evtTarget = do_QueryInterface(ret);
   evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), mEventListener,
                               true);
 
   nsAutoString locationStr;
   switch (aLocation) {
     case nsIHTMLObjectResizer::eTopLeft:
       locationStr = kTopLeft;
       break;
@@ -178,55 +177,46 @@ HTMLEditor::CreateResizer(int16_t aLocat
     case nsIHTMLObjectResizer::eBottom:
       locationStr = kBottom;
       break;
     case nsIHTMLObjectResizer::eBottomRight:
       locationStr = kBottomRight;
       break;
   }
 
-  nsCOMPtr<Element> ret = do_QueryInterface(retDOM);
-  rv = ret->SetAttr(kNameSpaceID_None, nsGkAtoms::anonlocation, locationStr,
-                    true);
+  nsresult rv =
+    ret->SetAttr(kNameSpaceID_None, nsGkAtoms::anonlocation, locationStr, true);
   NS_ENSURE_SUCCESS(rv, nullptr);
   return ret.forget();
 }
 
 already_AddRefed<Element>
 HTMLEditor::CreateShadow(nsIDOMNode* aParentNode,
                          nsIDOMElement* aOriginalObject)
 {
   // let's create an image through the element factory
-  nsAutoString name;
+  nsCOMPtr<nsIAtom> name;
   if (HTMLEditUtils::IsImage(aOriginalObject)) {
-    name.AssignLiteral("img");
+    name = nsGkAtoms::img;
   } else {
-    name.AssignLiteral("span");
+    name = nsGkAtoms::span;
   }
-  nsCOMPtr<nsIDOMElement> retDOM;
-  CreateAnonymousElement(name, aParentNode,
-                         NS_LITERAL_STRING("mozResizingShadow"), true,
-                         getter_AddRefs(retDOM));
-
-  NS_ENSURE_TRUE(retDOM, nullptr);
-
-  nsCOMPtr<Element> ret = do_QueryInterface(retDOM);
+  RefPtr<Element> ret =
+    CreateAnonymousElement(name, aParentNode,
+                           NS_LITERAL_STRING("mozResizingShadow"), true);
   return ret.forget();
 }
 
 already_AddRefed<Element>
 HTMLEditor::CreateResizingInfo(nsIDOMNode* aParentNode)
 {
   // let's create an info box through the element factory
-  nsCOMPtr<nsIDOMElement> retDOM;
-  CreateAnonymousElement(NS_LITERAL_STRING("span"), aParentNode,
-                         NS_LITERAL_STRING("mozResizingInfo"), true,
-                         getter_AddRefs(retDOM));
-
-  nsCOMPtr<Element> ret = do_QueryInterface(retDOM);
+  RefPtr<Element> ret =
+    CreateAnonymousElement(nsGkAtoms::span, aParentNode,
+                           NS_LITERAL_STRING("mozResizingInfo"), true);
   return ret.forget();
 }
 
 nsresult
 HTMLEditor::SetAllResizersPosition()
 {
   NS_ENSURE_TRUE(mTopLeftHandle, NS_ERROR_FAILURE);