Bug 1391978 - Part 4. Replace nsISelection::GetFocusNode with Selection::GetFocusNode. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 25 Aug 2017 16:12:38 +0900
changeset 654195 c11007a58ee312a7845ba4b8c0886dec49cd8c39
parent 654194 2c45cffa7d526a9e07126c90f17232b02b1612ea
child 654196 3e57ddbebc7985ec0e5ada4b1e83631d6f1c83b5
push id76495
push userbmo:m_kato@ga2.so-net.ne.jp
push dateMon, 28 Aug 2017 10:39:27 +0000
reviewersmasayuki
bugs1391978
milestone57.0a1
Bug 1391978 - Part 4. Replace nsISelection::GetFocusNode with Selection::GetFocusNode. r?masayuki MozReview-Commit-ID: GFtkRvsFaYI
editor/libeditor/HTMLEditor.cpp
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2466,19 +2466,17 @@ HTMLEditor::GetSelectedElement(const nsA
       nsCOMPtr<nsIDOMNode> anchorNode;
       rv = selection->GetAnchorNode(getter_AddRefs(anchorNode));
       NS_ENSURE_SUCCESS(rv, rv);
       int32_t anchorOffset = -1;
       if (anchorNode) {
         selection->GetAnchorOffset(&anchorOffset);
       }
 
-      nsCOMPtr<nsIDOMNode> focusNode;
-      rv = selection->GetFocusNode(getter_AddRefs(focusNode));
-      NS_ENSURE_SUCCESS(rv, rv);
+      nsCOMPtr<nsINode> focusNode = selection->GetFocusNode();
       int32_t focusOffset = -1;
       if (focusNode) {
         selection->GetFocusOffset(&focusOffset);
       }
 
       // Link node must be the same for both ends of selection
       if (NS_SUCCEEDED(rv) && anchorNode) {
         nsCOMPtr<nsIDOMElement> parentLinkOfAnchor;
@@ -2489,17 +2487,17 @@ HTMLEditor::GetSelectedElement(const nsA
         if (NS_SUCCEEDED(rv) && parentLinkOfAnchor) {
           if (isCollapsed) {
             // We have just a caret in the link
             bNodeFound = true;
           } else if (focusNode) {
             // Link node must be the same for both ends of selection.
             nsCOMPtr<nsIDOMElement> parentLinkOfFocus;
             rv = GetElementOrParentByTagName(NS_LITERAL_STRING("href"),
-                                             focusNode,
+                                             GetAsDOMNode(focusNode),
                                              getter_AddRefs(parentLinkOfFocus));
             if (NS_SUCCEEDED(rv) && parentLinkOfFocus == parentLinkOfAnchor) {
               bNodeFound = true;
             }
           }
 
           // We found a link node parent
           if (bNodeFound) {
@@ -2508,17 +2506,18 @@ HTMLEditor::GetSelectedElement(const nsA
             NS_IF_ADDREF(*aReturn);
             return NS_OK;
           }
         } else if (anchorOffset >= 0) {
           // Check if link node is the only thing selected
           nsCOMPtr<nsIDOMNode> anchorChild;
           anchorChild = GetChildAt(anchorNode,anchorOffset);
           if (anchorChild && HTMLEditUtils::IsLink(anchorChild) &&
-              anchorNode == focusNode && focusOffset == anchorOffset + 1) {
+              anchorNode == GetAsDOMNode(focusNode) &&
+              focusOffset == anchorOffset + 1) {
             selectedElement = do_QueryInterface(anchorChild);
             bNodeFound = true;
           }
         }
       }
     }
 
     if (!isCollapsed) {
@@ -5023,23 +5022,21 @@ HTMLEditor::GetActiveEditingHost()
   }
   if (document->HasFlag(NODE_IS_EDITABLE)) {
     return document->GetBodyElement();
   }
 
   // We're HTML editor for contenteditable
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, nullptr);
-  nsCOMPtr<nsIDOMNode> focusNode;
-  nsresult rv = selection->GetFocusNode(getter_AddRefs(focusNode));
-  NS_ENSURE_SUCCESS(rv, nullptr);
-  nsCOMPtr<nsIContent> content = do_QueryInterface(focusNode);
-  if (!content) {
+  nsINode* focusNode = selection->GetFocusNode();
+  if (NS_WARN_IF(!focusNode) || NS_WARN_IF(!focusNode->IsContent())) {
     return nullptr;
   }
+  nsIContent* content = focusNode->AsContent();
 
   // If the active content isn't editable, or it has independent selection,
   // we're not active.
   if (!content->HasFlag(NODE_IS_EDITABLE) ||
       content->HasIndependentSelection()) {
     return nullptr;
   }
   return content->GetEditingHost();