Bug 1388004 - part3: nsINode::GetSelectionRootContent() should use HTMLEditor r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 07 Aug 2017 17:00:44 +0900
changeset 645260 274aae656d7acd52c8c19ad31e9ab7fa60490400
parent 645259 c587b5696649ac2cca9d51e130cc301f0bdb6f4e
child 725871 a9d1924506898b0e1056221715598ee648f9d667
push id73720
push usermasayuki@d-toybox.com
push dateSat, 12 Aug 2017 03:32:40 +0000
reviewerssmaug
bugs1388004
milestone57.0a1
Bug 1388004 - part3: nsINode::GetSelectionRootContent() should use HTMLEditor r?smaug nsINode::GetSelectionRootContent() uses nsIEditor since nsContentUtils::GetHTMLEditor() returned nsIEditor. Therefore, it needed to use GetEditorRootContent() to retrieve the editor root element as nsIContent*. Now, it can use HTMLEditor and HTMLEditor::GetRoot() returns the editor root element as nsIContent* directly. So, it should use HTMLEditor instead. MozReview-Commit-ID: I937a5TuxVD
dom/base/nsINode.cpp
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -57,17 +57,16 @@
 #include "nsIControllers.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMDocumentType.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMEventListener.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsIDOMNodeList.h"
-#include "nsIEditor.h"
 #include "nsILinkHandler.h"
 #include "mozilla/dom/NodeInfo.h"
 #include "mozilla/dom/NodeInfoInlines.h"
 #include "nsIPresShell.h"
 #include "nsIScriptError.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIScrollableFrame.h"
@@ -220,24 +219,16 @@ nsINode::IsEditableInternal() const
   }
 
   nsIDocument *doc = GetUncomposedDoc();
 
   // Check if the node is in a document and the document is in designMode.
   return doc && doc->HasFlag(NODE_IS_EDITABLE);
 }
 
-static nsIContent* GetEditorRootContent(nsIEditor* aEditor)
-{
-  nsCOMPtr<nsIDOMElement> rootElement;
-  aEditor->GetRootElement(getter_AddRefs(rootElement));
-  nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElement));
-  return rootContent;
-}
-
 nsIContent*
 nsINode::GetTextEditorRootContent(TextEditor** aTextEditor)
 {
   if (aTextEditor) {
     *aTextEditor = nullptr;
   }
   for (nsINode* node = this; node; node = node->GetParentNode()) {
     if (!node->IsElement() ||
@@ -361,23 +352,23 @@ nsINode::GetSelectionRootContent(nsIPres
     // This node should be a descendant of input/textarea editor.
     nsIContent* content = GetTextEditorRootContent();
     if (content)
       return content;
   }
 
   nsPresContext* presContext = aPresShell->GetPresContext();
   if (presContext) {
-    nsIEditor* editor = nsContentUtils::GetHTMLEditor(presContext);
-    if (editor) {
+    HTMLEditor* htmlEditor = nsContentUtils::GetHTMLEditor(presContext);
+    if (htmlEditor) {
       // This node is in HTML editor.
       nsIDocument* doc = GetComposedDoc();
       if (!doc || doc->HasFlag(NODE_IS_EDITABLE) ||
           !HasFlag(NODE_IS_EDITABLE)) {
-        nsIContent* editorRoot = GetEditorRootContent(editor);
+        nsIContent* editorRoot = htmlEditor->GetRoot();
         NS_ENSURE_TRUE(editorRoot, nullptr);
         return nsContentUtils::IsInSameAnonymousTree(this, editorRoot) ?
                  editorRoot :
                  GetRootForContentSubtree(static_cast<nsIContent*>(this));
       }
       // If the document isn't editable but this is editable, this is in
       // contenteditable.  Use the editing host element for selection root.
       return static_cast<nsIContent*>(this)->GetEditingHost();