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
--- 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();