Bug 1374207 - part4: Element classes should use TextEditor class instead of nIEditor r=smaug

Unfortunately, nsGenericHTMLElement::GetAssociatedEditor() cannot use concrete classes because it may return nsIEditor which is set via nsIDocShell.editor.  The editor set to nsIDocShell may be implemented by JS since nsIEditor isn't marked as builtinclass.

MozReview-Commit-ID: 6GY9LOYp4hM

--HG--
extra : rebase_source : 3e0464067b30daf8254805458c5358d7ea644be8
This commit is contained in:
Masayuki Nakano 2017-06-22 15:21:31 +09:00
parent c5fbe1617e
commit 9f1aec970a
13 changed files with 71 additions and 52 deletions

View File

@ -67,6 +67,7 @@
#include "mozilla/EventStates.h"
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/TextEditor.h"
#include "mozilla/TextEvents.h"
#include "nsNodeUtils.h"
#include "mozilla/dom/DirectionalityUtils.h"
@ -103,7 +104,6 @@
#include "nsICategoryManager.h"
#include "nsIDOMDocumentType.h"
#include "nsGenericHTMLElement.h"
#include "nsIEditor.h"
#include "nsContentCreatorFunctions.h"
#include "nsIControllers.h"
#include "nsView.h"
@ -3942,8 +3942,8 @@ Element::InsertAdjacentText(
InsertAdjacent(aWhere, textNode, aError);
}
nsIEditor*
Element::GetEditorInternal()
TextEditor*
Element::GetTextEditorInternal()
{
nsCOMPtr<nsITextControlElement> textCtrl = do_QueryInterface(this);
return textCtrl ? textCtrl->GetTextEditor() : nullptr;

View File

@ -62,6 +62,7 @@ class nsDOMStringMap;
namespace mozilla {
class DeclarationBlock;
class TextEditor;
namespace dom {
struct AnimationFilter;
struct ScrollIntoViewOptions;
@ -1265,9 +1266,9 @@ public:
nsINode* GetScopeChainParent() const override;
/**
* Locate an nsIEditor rooted at this content node, if there is one.
* Locate a TextEditor rooted at this content node, if there is one.
*/
nsIEditor* GetEditorInternal();
mozilla::TextEditor* GetTextEditorInternal();
/**
* Helper method for NS_IMPL_BOOL_ATTR macro.

View File

@ -24,6 +24,7 @@
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/ServoRestyleManager.h"
#include "mozilla/TextEditor.h"
#include "mozilla/URLExtraData.h"
#include "mozilla/dom/Attr.h"
#include "nsDOMAttributeMap.h"
@ -93,7 +94,6 @@
#include "nsNodeInfoManager.h"
#include "nsICategoryManager.h"
#include "nsGenericHTMLElement.h"
#include "nsIEditor.h"
#include "nsContentCreatorFunctions.h"
#include "nsIControllers.h"
#include "nsView.h"
@ -2289,8 +2289,8 @@ FragmentOrElement::GetMarkup(bool aIncludeSelf, nsAString& aMarkup)
if (IsEditable()) {
nsCOMPtr<Element> elem = do_QueryInterface(this);
nsIEditor* editor = elem ? elem->GetEditorInternal() : nullptr;
if (editor && editor->OutputsMozDirty()) {
TextEditor* textEditor = elem ? elem->GetTextEditorInternal() : nullptr;
if (textEditor && textEditor->OutputsMozDirty()) {
flags &= ~nsIDocumentEncoder::OutputIgnoreMozDirty;
}
}

View File

@ -22,6 +22,7 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TextEditor.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/css/StyleRule.h"
#include "mozilla/dom/Element.h"
@ -230,24 +231,29 @@ static nsIContent* GetEditorRootContent(nsIEditor* aEditor)
}
nsIContent*
nsINode::GetTextEditorRootContent(nsIEditor** aEditor)
nsINode::GetTextEditorRootContent(TextEditor** aTextEditor)
{
if (aEditor)
*aEditor = nullptr;
if (aTextEditor) {
*aTextEditor = nullptr;
}
for (nsINode* node = this; node; node = node->GetParentNode()) {
if (!node->IsElement() ||
!node->IsHTMLElement())
continue;
nsCOMPtr<nsIEditor> editor =
static_cast<nsGenericHTMLElement*>(node)->GetEditorInternal();
if (!editor)
RefPtr<TextEditor> textEditor =
static_cast<nsGenericHTMLElement*>(node)->GetTextEditorInternal();
if (!textEditor) {
continue;
}
nsIContent* rootContent = GetEditorRootContent(editor);
if (aEditor)
editor.swap(*aEditor);
return rootContent;
MOZ_ASSERT(!textEditor->AsHTMLEditor(),
"If it were an HTML editor, needs to use GetRootElement()");
Element* rootElement = textEditor->GetRoot();
if (aTextEditor) {
textEditor.forget(aTextEditor);
}
return rootElement;
}
return nullptr;
}

View File

@ -41,7 +41,6 @@ class nsIContent;
class nsIDocument;
class nsIDOMElement;
class nsIDOMNodeList;
class nsIEditor;
class nsIFrame;
class nsIMutationObserver;
class nsINode;
@ -55,6 +54,7 @@ class nsDOMMutationObserver;
namespace mozilla {
class EventListenerManager;
class TextEditor;
namespace dom {
/**
* @return true if aChar is what the WHATWG defines as a 'ascii whitespace'.
@ -1242,7 +1242,8 @@ public:
* an editor. Note that this should be only used for getting input or textarea
* editor's root content. This method doesn't support HTML editors.
*/
nsIContent* GetTextEditorRootContent(nsIEditor** aEditor = nullptr);
nsIContent* GetTextEditorRootContent(
mozilla::TextEditor** aTextEditor = nullptr);
/**
* Get the nearest selection root, ie. the node that will be selected if the

View File

@ -7,6 +7,7 @@
#include "HTMLBodyElement.h"
#include "mozilla/dom/HTMLBodyElementBinding.h"
#include "mozilla/GenericSpecifiedValuesInlines.h"
#include "mozilla/TextEditor.h"
#include "nsAttrValueInlines.h"
#include "nsGkAtoms.h"
#include "nsStyleConsts.h"
@ -394,9 +395,9 @@ HTMLBodyElement::IsAttributeMapped(const nsIAtom* aAttribute) const
already_AddRefed<nsIEditor>
HTMLBodyElement::GetAssociatedEditor()
{
nsCOMPtr<nsIEditor> editor = GetEditorInternal();
if (editor) {
return editor.forget();
RefPtr<TextEditor> textEditor = GetTextEditorInternal();
if (textEditor) {
return textEditor.forget();
}
// Make sure this is the actual body of the document
@ -415,6 +416,7 @@ HTMLBodyElement::GetAssociatedEditor()
return nullptr;
}
nsCOMPtr<nsIEditor> editor;
docShell->GetEditor(getter_AddRefs(editor));
return editor.forget();
}

View File

@ -70,6 +70,7 @@
#include "mozilla/EventStates.h"
#include "mozilla/GenericSpecifiedValuesInlines.h"
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/TextEditor.h"
#include "mozilla/TextEvents.h"
#include "mozilla/TouchEvents.h"
@ -2617,6 +2618,12 @@ HTMLInputElement::SetUserInput(const nsAString& aValue)
nsIEditor*
HTMLInputElement::GetEditor()
{
return GetTextEditorFromState();
}
TextEditor*
HTMLInputElement::GetTextEditorFromState()
{
nsTextEditorState* state = GetEditorState();
if (state) {
@ -2625,10 +2632,10 @@ HTMLInputElement::GetEditor()
return nullptr;
}
NS_IMETHODIMP_(nsIEditor*)
NS_IMETHODIMP_(TextEditor*)
HTMLInputElement::GetTextEditor()
{
return GetEditor();
return GetTextEditorFromState();
}
NS_IMETHODIMP_(nsISelectionController*)

View File

@ -175,7 +175,9 @@ public:
// nsIDOMNSEditableElement
NS_IMETHOD GetEditor(nsIEditor** aEditor) override
{
return nsGenericHTMLElement::GetEditor(aEditor);
nsCOMPtr<nsIEditor> editor = GetEditor();
editor.forget(aEditor);
return NS_OK;
}
NS_IMETHOD SetUserInput(const nsAString& aInput) override;
@ -242,7 +244,7 @@ public:
NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue) override;
NS_IMETHOD_(bool) ValueChanged() const override;
NS_IMETHOD_(void) GetTextEditorValue(nsAString& aValue, bool aIgnoreWrap) const override;
NS_IMETHOD_(nsIEditor*) GetTextEditor() override;
NS_IMETHOD_(mozilla::TextEditor*) GetTextEditor() override;
NS_IMETHOD_(nsISelectionController*) GetSelectionController() override;
NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection() override;
NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame) override;
@ -873,6 +875,9 @@ public:
bool MozIsTextField(bool aExcludePassword);
/**
* GetEditor() is for webidl bindings.
*/
nsIEditor* GetEditor();
void SetUserInput(const nsAString& aInput,
@ -1122,6 +1127,8 @@ protected:
void FreeData();
nsTextEditorState *GetEditorState() const;
mozilla::TextEditor* GetTextEditorFromState();
/**
* Manages the internal data storage across type changes.
*/

View File

@ -259,10 +259,10 @@ HTMLTextAreaElement::GetValueInternal(nsAString& aValue, bool aIgnoreWrap) const
mState.GetValue(aValue, aIgnoreWrap);
}
NS_IMETHODIMP_(nsIEditor*)
NS_IMETHODIMP_(TextEditor*)
HTMLTextAreaElement::GetTextEditor()
{
return GetEditor();
return mState.GetTextEditor();
}
NS_IMETHODIMP_(nsISelectionController*)

View File

@ -20,6 +20,7 @@
#include "mozilla/dom/HTMLInputElementBinding.h"
#include "nsGkAtoms.h"
#include "mozilla/TextEditor.h"
#include "nsTextEditorState.h"
class nsIControllers;
@ -67,7 +68,9 @@ public:
// nsIDOMNSEditableElement
NS_IMETHOD GetEditor(nsIEditor** aEditor) override
{
return nsGenericHTMLElement::GetEditor(aEditor);
nsCOMPtr<nsIEditor> editor = GetEditor();
editor.forget(aEditor);
return NS_OK;
}
NS_IMETHOD SetUserInput(const nsAString& aInput) override;
@ -94,7 +97,7 @@ public:
NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue) override;
NS_IMETHOD_(bool) ValueChanged() const override;
NS_IMETHOD_(void) GetTextEditorValue(nsAString& aValue, bool aIgnoreWrap) const override;
NS_IMETHOD_(nsIEditor*) GetTextEditor() override;
NS_IMETHOD_(mozilla::TextEditor*) GetTextEditor() override;
NS_IMETHOD_(nsISelectionController*) GetSelectionController() override;
NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection() override;
NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame) override;

View File

@ -11,8 +11,9 @@
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/GenericSpecifiedValuesInlines.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Likely.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/TextEditor.h"
#include "nscore.h"
#include "nsGenericHTMLElement.h"
@ -1877,13 +1878,15 @@ nsGenericHTMLFormElement::GetForm(nsIDOMHTMLFormElement** aForm)
nsIContent::IMEState
nsGenericHTMLFormElement::GetDesiredIMEState()
{
nsIEditor* editor = GetEditorInternal();
if (!editor)
TextEditor* textEditor = GetTextEditorInternal();
if (!textEditor) {
return nsGenericHTMLElement::GetDesiredIMEState();
}
IMEState state;
nsresult rv = editor->GetPreferredIMEState(&state);
if (NS_FAILED(rv))
nsresult rv = textEditor->GetPreferredIMEState(&state);
if (NS_FAILED(rv)) {
return nsGenericHTMLElement::GetDesiredIMEState();
}
return state;
}
@ -2606,20 +2609,13 @@ nsGenericHTMLElement::DispatchSimulatedClick(nsGenericHTMLElement* aElement,
return EventDispatcher::Dispatch(ToSupports(aElement), aPresContext, &event);
}
nsresult
nsGenericHTMLElement::GetEditor(nsIEditor** aEditor)
{
NS_IF_ADDREF(*aEditor = GetEditorInternal());
return NS_OK;
}
already_AddRefed<nsIEditor>
nsGenericHTMLElement::GetAssociatedEditor()
{
// If contenteditable is ever implemented, it might need to do something different here?
nsCOMPtr<nsIEditor> editor = GetEditorInternal();
return editor.forget();
RefPtr<TextEditor> textEditor = GetTextEditorInternal();
return textEditor.forget();
}
bool

View File

@ -37,6 +37,7 @@ class EventChainPreVisitor;
class EventChainVisitor;
class EventListenerManager;
class EventStates;
class TextEditor;
namespace dom {
class HTMLFormElement;
class HTMLMenuElement;
@ -812,11 +813,6 @@ public:
*/
static bool InNavQuirksMode(nsIDocument* aDoc);
/**
* Locate an nsIEditor rooted at this content node, if there is one.
*/
nsresult GetEditor(nsIEditor** aEditor);
/**
* Helper method for NS_IMPL_URI_ATTR macro.
* Gets the absolute URI value of an attribute, by resolving any relative

View File

@ -11,7 +11,6 @@
#include "nsCOMPtr.h"
class nsIContent;
class nsAString;
class nsIEditor;
class nsISelectionController;
class nsFrameSelection;
class nsTextControlFrame;
@ -19,6 +18,7 @@ class nsTextControlFrame;
namespace mozilla {
class ErrorResult;
class TextEditor;
namespace dom {
class Element;
@ -109,7 +109,7 @@ public:
* The return value is null if the control does not support an editor
* (for example, if it is a checkbox.)
*/
NS_IMETHOD_(nsIEditor*) GetTextEditor() = 0;
NS_IMETHOD_(mozilla::TextEditor*) GetTextEditor() = 0;
/**
* Get the selection controller object associated with the text editor.