Bug 1455674 part 4. Stop using nsIDOMElement in nsIHTMLEditor::GetElementOrParentByTagName. r=masayuki
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 26 Apr 2018 23:35:18 -0400
changeset 472084 15071a2629d9add643a5122b74dbb58d9e490c20
parent 472083 667c981474f823ad581668657a52dbc9d40b845b
child 472085 f283a9ca271bf70ae1373a3382b22e2bc75fc754
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 4. Stop using nsIDOMElement in nsIHTMLEditor::GetElementOrParentByTagName. r=masayuki
editor/libeditor/HTMLEditor.cpp
editor/nsIHTMLEditor.idl
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2434,32 +2434,29 @@ HTMLEditor::GetElementOrParentByTagName(
     }
   }
 
   return nullptr;
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetElementOrParentByTagName(const nsAString& aTagName,
-                                        nsIDOMNode* aNode,
-                                        nsIDOMElement** aReturn)
+                                        nsINode* aNode,
+                                        Element** aReturn)
 {
   NS_ENSURE_TRUE(!aTagName.IsEmpty(), NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(aReturn, NS_ERROR_NULL_POINTER);
 
-  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
-  nsCOMPtr<Element> parent =
-    GetElementOrParentByTagName(aTagName, node);
-  nsCOMPtr<nsIDOMElement> ret = do_QueryInterface(parent);
-
-  if (!ret) {
+  RefPtr<Element> parent = GetElementOrParentByTagName(aTagName, aNode);
+
+  if (!parent) {
     return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
   }
 
-  ret.forget(aReturn);
+  parent.forget(aReturn);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetSelectedElement(const nsAString& aTagName,
                                nsISupports** aReturn)
 {
   NS_ENSURE_TRUE(aReturn , NS_ERROR_NULL_POINTER);
@@ -2513,40 +2510,36 @@ HTMLEditor::GetSelectedElement(const nsA
   if (isLinkTag) {
     // Link tag is a special case - we return the anchor node
     //  found for any selection that is totally within a link,
     //  included a collapsed selection (just a caret in a link)
     const RangeBoundary& anchor = selection->AnchorRef();
     const RangeBoundary& focus = selection->FocusRef();
     // Link node must be the same for both ends of selection
     if (anchor.IsSet()) {
-      nsCOMPtr<nsIDOMElement> parentLinkOfAnchor;
-      nsresult rv =
+      RefPtr<Element> parentLinkOfAnchor =
         GetElementOrParentByTagName(NS_LITERAL_STRING("href"),
-                                    anchor.Container()->AsDOMNode(),
-                                    getter_AddRefs(parentLinkOfAnchor));
+                                    anchor.Container());
       // XXX: ERROR_HANDLING  can parentLinkOfAnchor be null?
-      if (NS_SUCCEEDED(rv) && parentLinkOfAnchor) {
+      if (parentLinkOfAnchor) {
         if (isCollapsed) {
           // We have just a caret in the link
           bNodeFound = true;
         } else if (focus.IsSet()) {
           // Link node must be the same for both ends of selection.
-          nsCOMPtr<nsIDOMElement> parentLinkOfFocus;
-          rv = GetElementOrParentByTagName(NS_LITERAL_STRING("href"),
-                                           focus.Container()->AsDOMNode(),
-                                           getter_AddRefs(parentLinkOfFocus));
-          if (NS_SUCCEEDED(rv) && parentLinkOfFocus == parentLinkOfAnchor) {
+          RefPtr<Element> parentLinkOfFocus =
+            GetElementOrParentByTagName(NS_LITERAL_STRING("href"),
+                                        focus.Container());
+          if (parentLinkOfFocus == parentLinkOfAnchor) {
             bNodeFound = true;
           }
         }
 
         // We found a link node parent
         if (bNodeFound) {
-          // GetElementOrParentByTagName addref'd this, so we don't need to do it here
           parentLinkOfAnchor.forget(aReturn);
           return NS_OK;
         }
       } else if (anchor.GetChildAtOffset() && focus.GetChildAtOffset()) {
         // Check if link node is the only thing selected
         if (HTMLEditUtils::IsLink(anchor.GetChildAtOffset()) &&
             anchor.Container() == focus.Container() &&
             focus.GetChildAtOffset() ==
--- a/editor/nsIHTMLEditor.idl
+++ b/editor/nsIHTMLEditor.idl
@@ -6,16 +6,17 @@
 #include "nsISupports.idl"
 #include "domstubs.idl"
 
 interface nsIContent;
 interface nsIArray;
 interface nsISelection;
 
 webidl Element;
+webidl Node;
 
 [scriptable, builtinclass, uuid(87ee993e-985f-4a43-a974-0d9512da2fb0)]
 interface nsIHTMLEditor : nsISupports
 {
 %{C++
   typedef short EAlignment;
 %}
 
@@ -344,18 +345,18 @@ interface nsIHTMLEditor : nsISupports
    *    Use "list" to get an OL, UL, or DL list node
    *    Use "td" to get either a TD or TH cell node
    *
    * @param aNode    The node in the document to start the search.
    *     If it is null, the anchor node of the current selection is used.
    * @return         NS_EDITOR_ELEMENT_NOT_FOUND if an element is not found
    *                 (passes NS_SUCCEEDED macro)
    */
-  nsIDOMElement getElementOrParentByTagName(in AString aTagName,
-                                            in nsIDOMNode aNode);
+  Element getElementOrParentByTagName(in AString aTagName,
+                                      in Node aNode);
 
   /**
    * Return an Element only if it is the only node selected,
    *    such as an image, horizontal rule, etc.  The return type is
    *    nsISupports for implementation convenience; the returned object,
    *    if not null, is always a DOM Element.
    *
    * The exception is a link, which is more like a text attribute: