зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1436272 - Move noscript methods in nsIEditor to EditorBase. r=masayuki
Since We can use EditorBase/TextEditor/HTMLEditor directly, we can movei noscript methods in nsIEditor to each class. Also, Init is unnecessary to use nsIDOMDocument and nsIContent since method isn't in IDL. And some methods are unused now. MozReview-Commit-ID: D3B6oSlcT0L --HG-- extra : rebase_source : b89698f4ab56fdd97a4cd8c515a8b33f6a74a7af
This commit is contained in:
Родитель
f091b12272
Коммит
b845e3128e
|
@ -1387,9 +1387,10 @@ nsTextEditorState::PrepareEditor(const nsAString *aValue)
|
|||
// editor's Init() call.
|
||||
|
||||
// Get the DOM document
|
||||
nsCOMPtr<nsIDOMDocument> domdoc = do_QueryInterface(shell->GetDocument());
|
||||
if (!domdoc)
|
||||
nsCOMPtr<nsIDocument> doc = shell->GetDocument();
|
||||
if (NS_WARN_IF(!doc)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// What follows is a bit of a hack. The editor uses the public DOM APIs
|
||||
// for its content manipulations, and it causes it to fail some security
|
||||
|
@ -1400,7 +1401,7 @@ nsTextEditorState::PrepareEditor(const nsAString *aValue)
|
|||
// already does the relevant security checks.
|
||||
AutoNoJSAPI nojsapi;
|
||||
|
||||
rv = newTextEditor->Init(domdoc, GetRootNode(), mSelCon, editorFlags,
|
||||
rv = newTextEditor->Init(*doc, GetRootNode(), mSelCon, editorFlags,
|
||||
defaultValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
|
|
@ -448,16 +448,17 @@ nsEditingSession::SetupEditorOnWindow(mozIDOMWindowProxy* aWindow)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(contentViewer, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc =
|
||||
do_QueryInterface(contentViewer->GetDocument());
|
||||
NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIDocument> doc = contentViewer->GetDocument();
|
||||
if (NS_WARN_IF(!doc)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Set up as a doc state listener
|
||||
// Important! We must have this to broadcast the "obs_documentCreated" message
|
||||
rv = htmlEditor->AddDocumentStateListener(mComposerCommandsUpdater);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = htmlEditor->Init(domDoc, nullptr /* root content */,
|
||||
rv = htmlEditor->Init(*doc, nullptr /* root content */,
|
||||
nullptr, mEditorFlags, EmptyString());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
|
|
@ -216,19 +216,15 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(EditorBase)
|
|||
NS_IMPL_CYCLE_COLLECTING_RELEASE(EditorBase)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
EditorBase::Init(nsIDOMDocument* aDOMDocument,
|
||||
nsIContent* aRoot,
|
||||
nsresult
|
||||
EditorBase::Init(nsIDocument& aDocument,
|
||||
Element* aRoot,
|
||||
nsISelectionController* aSelectionController,
|
||||
uint32_t aFlags,
|
||||
const nsAString& aValue)
|
||||
{
|
||||
MOZ_ASSERT(mAction == EditAction::none,
|
||||
"Initializing during an edit action is an error");
|
||||
MOZ_ASSERT(aDOMDocument);
|
||||
if (!aDOMDocument) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// First only set flags, but other stuff shouldn't be initialized now.
|
||||
// Don't move this call after initializing mDocument.
|
||||
|
@ -240,7 +236,7 @@ EditorBase::Init(nsIDOMDocument* aDOMDocument,
|
|||
SetFlags(aFlags);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "SetFlags() failed");
|
||||
|
||||
mDocument = do_QueryInterface(aDOMDocument);
|
||||
mDocument = &aDocument;
|
||||
// HTML editors currently don't have their own selection controller,
|
||||
// so they'll pass null as aSelCon, and we'll get the selection controller
|
||||
// off of the presshell.
|
||||
|
@ -256,8 +252,9 @@ EditorBase::Init(nsIDOMDocument* aDOMDocument,
|
|||
"Selection controller should be available at this point");
|
||||
|
||||
//set up root element if we are passed one.
|
||||
if (aRoot)
|
||||
mRootElement = do_QueryInterface(aRoot);
|
||||
if (aRoot) {
|
||||
mRootElement = aRoot;
|
||||
}
|
||||
|
||||
mUpdateCount=0;
|
||||
|
||||
|
@ -1353,14 +1350,6 @@ EditorBase::RemoveAttribute(Element* aElement,
|
|||
return DoTransaction(transaction);
|
||||
}
|
||||
|
||||
bool
|
||||
EditorBase::OutputsMozDirty()
|
||||
{
|
||||
// Return true for Composer (!IsInteractionAllowed()) or mail
|
||||
// (IsMailEditor()), but false for webpages.
|
||||
return !IsInteractionAllowed() || IsMailEditor();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EditorBase::MarkNodeDirty(nsIDOMNode* aNode)
|
||||
{
|
||||
|
@ -2509,7 +2498,7 @@ EditorBase::CommitComposition()
|
|||
IMEStateManager::NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, pc) : NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
EditorBase::GetPreferredIMEState(IMEState* aState)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aState);
|
||||
|
@ -5414,12 +5403,6 @@ EditorBase::SwitchTextDirectionTo(uint32_t aDirection)
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
EditorBase::IsModifiableNode(nsIDOMNode* aNode)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
EditorBase::IsModifiableNode(nsINode* aNode)
|
||||
{
|
||||
|
@ -5567,16 +5550,6 @@ EditorBase::SetSuppressDispatchingInputEvent(bool aSuppress)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EditorBase::GetIsInEditAction(bool* aIsInEditAction)
|
||||
{
|
||||
// NOTE: If you need to override this method, you need to make
|
||||
// IsInEditAction() virtual.
|
||||
MOZ_ASSERT(aIsInEditAction, "aIsInEditAction must not be null");
|
||||
*aIsInEditAction = IsInEditAction();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int32_t
|
||||
EditorBase::GetIMESelectionStartOffsetIn(nsINode* aTextNode)
|
||||
{
|
||||
|
|
|
@ -220,6 +220,23 @@ public:
|
|||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EditorBase, nsIEditor)
|
||||
|
||||
/**
|
||||
* Init is to tell the implementation of nsIEditor to begin its services
|
||||
* @param aDoc The dom document interface being observed
|
||||
* @param aRoot This is the root of the editable section of this
|
||||
* document. If it is null then we get root
|
||||
* from document body.
|
||||
* @param aSelCon this should be used to get the selection location
|
||||
* (will be null for HTML editors)
|
||||
* @param aFlags A bitmask of flags for specifying the behavior
|
||||
* of the editor.
|
||||
*/
|
||||
virtual nsresult Init(nsIDocument& doc,
|
||||
Element* aRoot,
|
||||
nsISelectionController* aSelCon,
|
||||
uint32_t aFlags,
|
||||
const nsAString& aInitialValue);
|
||||
|
||||
bool IsInitialized() const { return !!mDocument; }
|
||||
already_AddRefed<nsIDOMDocument> GetDOMDocument();
|
||||
already_AddRefed<nsIDocument> GetDocument();
|
||||
|
@ -457,6 +474,11 @@ public:
|
|||
WidgetCompositionEvent* aCompositionChangeEvet) = 0;
|
||||
void EndIMEComposition();
|
||||
|
||||
/**
|
||||
* Get preferred IME status of current widget.
|
||||
*/
|
||||
virtual nsresult GetPreferredIMEState(widget::IMEState* aState);
|
||||
|
||||
/**
|
||||
* Commit composition if there is.
|
||||
* Note that when there is a composition, this requests to commit composition
|
||||
|
@ -470,6 +492,11 @@ public:
|
|||
|
||||
RangeUpdater& RangeUpdaterRef() { return mRangeUpdater; }
|
||||
|
||||
/**
|
||||
* Finalizes selection and caret for the editor.
|
||||
*/
|
||||
nsresult FinalizeSelection();
|
||||
|
||||
protected:
|
||||
nsresult DetermineCurrentDirection();
|
||||
void FireInputEvent();
|
||||
|
@ -1289,6 +1316,17 @@ public:
|
|||
return mDidPreDestroy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if markNodeDirty() has any effect. Returns false if
|
||||
* markNodeDirty() is a no-op.
|
||||
*/
|
||||
bool OutputsMozDirty() const
|
||||
{
|
||||
// Return true for Composer (!IsInteractionAllowed()) or mail
|
||||
// (IsMailEditor()), but false for webpages.
|
||||
return !IsInteractionAllowed() || IsMailEditor();
|
||||
}
|
||||
|
||||
/**
|
||||
* GetTransactionManager() returns transaction manager associated with the
|
||||
* editor. This may return nullptr if undo/redo hasn't been enabled.
|
||||
|
|
|
@ -231,15 +231,13 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(HTMLEditor)
|
|||
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
||||
NS_INTERFACE_MAP_END_INHERITING(TextEditor)
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLEditor::Init(nsIDOMDocument* aDoc,
|
||||
nsIContent* aRoot,
|
||||
nsresult
|
||||
HTMLEditor::Init(nsIDocument& aDoc,
|
||||
Element* aRoot,
|
||||
nsISelectionController* aSelCon,
|
||||
uint32_t aFlags,
|
||||
const nsAString& aInitialValue)
|
||||
{
|
||||
NS_PRECONDITION(aDoc && !aSelCon, "bad arg");
|
||||
NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
|
||||
MOZ_ASSERT(aInitialValue.IsEmpty(), "Non-empty initial values not supported");
|
||||
|
||||
nsresult rulesRv = NS_OK;
|
||||
|
@ -255,8 +253,7 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
|
|||
}
|
||||
|
||||
// Init mutation observer
|
||||
nsCOMPtr<nsINode> document = do_QueryInterface(aDoc);
|
||||
document->AddMutationObserverUnlessExists(this);
|
||||
aDoc.AddMutationObserverUnlessExists(this);
|
||||
|
||||
if (!mRootElement) {
|
||||
UpdateRootElement();
|
||||
|
@ -3089,7 +3086,8 @@ HTMLEditor::DeleteNode(nsIDOMNode* aNode)
|
|||
{
|
||||
// do nothing if the node is read-only
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
||||
if (NS_WARN_IF(!IsModifiableNode(aNode) && !IsMozEditorBogusNode(content))) {
|
||||
if (NS_WARN_IF(!IsModifiableNode(content) &&
|
||||
!IsMozEditorBogusNode(content))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -3249,13 +3247,6 @@ HTMLEditor::ContentRemoved(nsIDocument* aDocument,
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
HTMLEditor::IsModifiableNode(nsIDOMNode* aNode)
|
||||
{
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
||||
return IsModifiableNode(node);
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLEditor::IsModifiableNode(nsINode* aNode)
|
||||
{
|
||||
|
@ -4836,7 +4827,7 @@ HTMLEditor::IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent)
|
|||
return IsActiveInDOMWindow();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsresult
|
||||
HTMLEditor::GetPreferredIMEState(IMEState* aState)
|
||||
{
|
||||
// HTML editor don't prefer the CSS ime-mode because IE didn't do so too.
|
||||
|
|
|
@ -106,15 +106,15 @@ public:
|
|||
bool GetReturnInParagraphCreatesNewParagraph();
|
||||
Element* GetSelectionContainer();
|
||||
|
||||
// nsIEditor overrides
|
||||
NS_IMETHOD GetPreferredIMEState(widget::IMEState* aState) override;
|
||||
|
||||
// nsISelectionListener overrides
|
||||
NS_IMETHOD NotifySelectionChanged(nsIDOMDocument* aDOMDocument,
|
||||
nsISelection* aSelection,
|
||||
int16_t aReason) override;
|
||||
|
||||
// TextEditor overrides
|
||||
virtual nsresult Init(nsIDocument& aDoc, Element* aRoot,
|
||||
nsISelectionController* aSelCon, uint32_t aFlags,
|
||||
const nsAString& aValue) override;
|
||||
NS_IMETHOD BeginningOfDocument() override;
|
||||
virtual nsresult HandleKeyPressEvent(
|
||||
WidgetKeyboardEvent* aKeyboardEvent) override;
|
||||
|
@ -221,11 +221,10 @@ public:
|
|||
// Overrides of EditorBase interface methods
|
||||
virtual nsresult EndUpdateViewBatch() override;
|
||||
|
||||
NS_IMETHOD Init(nsIDOMDocument* aDoc, nsIContent* aRoot,
|
||||
nsISelectionController* aSelCon, uint32_t aFlags,
|
||||
const nsAString& aValue) override;
|
||||
NS_IMETHOD PreDestroy(bool aDestroyingFrames) override;
|
||||
|
||||
virtual nsresult GetPreferredIMEState(widget::IMEState* aState) override;
|
||||
|
||||
/**
|
||||
* @param aElement Must not be null.
|
||||
*/
|
||||
|
@ -391,7 +390,6 @@ public:
|
|||
const EditorRawDOMPoint& aPointToInsert,
|
||||
EditorRawDOMPoint* aPointAfterInsertedString =
|
||||
nullptr) override;
|
||||
NS_IMETHOD_(bool) IsModifiableNode(nsIDOMNode* aNode) override;
|
||||
virtual bool IsModifiableNode(nsINode* aNode) override;
|
||||
|
||||
NS_IMETHOD SelectAll() override;
|
||||
|
|
|
@ -113,16 +113,13 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextEditor)
|
|||
NS_INTERFACE_MAP_END_INHERITING(EditorBase)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
TextEditor::Init(nsIDOMDocument* aDoc,
|
||||
nsIContent* aRoot,
|
||||
nsresult
|
||||
TextEditor::Init(nsIDocument& aDoc,
|
||||
Element* aRoot,
|
||||
nsISelectionController* aSelCon,
|
||||
uint32_t aFlags,
|
||||
const nsAString& aInitialValue)
|
||||
{
|
||||
NS_PRECONDITION(aDoc, "bad arg");
|
||||
NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (mRules) {
|
||||
mRules->DetachEditor();
|
||||
}
|
||||
|
|
|
@ -74,9 +74,9 @@ public:
|
|||
using EditorBase::RemoveAttributeOrEquivalent;
|
||||
using EditorBase::SetAttributeOrEquivalent;
|
||||
|
||||
NS_IMETHOD Init(nsIDOMDocument* aDoc, nsIContent* aRoot,
|
||||
nsISelectionController* aSelCon, uint32_t aFlags,
|
||||
const nsAString& aValue) override;
|
||||
virtual nsresult Init(nsIDocument& aDoc, Element* aRoot,
|
||||
nsISelectionController* aSelCon, uint32_t aFlags,
|
||||
const nsAString& aValue) override;
|
||||
|
||||
nsresult DocumentIsEmpty(bool* aIsEmpty);
|
||||
NS_IMETHOD GetDocumentIsEmpty(bool* aDocumentIsEmpty) override;
|
||||
|
|
|
@ -25,14 +25,9 @@ namespace mozilla {
|
|||
class EditorBase;
|
||||
class HTMLEditor;
|
||||
class TextEditor;
|
||||
namespace widget {
|
||||
struct IMEState;
|
||||
} // namespace widget
|
||||
} // namespace mozilla
|
||||
%}
|
||||
|
||||
native IMEState(mozilla::widget::IMEState);
|
||||
|
||||
[scriptable, builtinclass, uuid(094be624-f0bf-400f-89e2-6a84baab9474)]
|
||||
interface nsIEditor : nsISupports
|
||||
{
|
||||
|
@ -53,28 +48,6 @@ interface nsIEditor : nsISupports
|
|||
|
||||
readonly attribute nsISelection selection;
|
||||
|
||||
/**
|
||||
* Finalizes selection and caret for the editor.
|
||||
*/
|
||||
[noscript] void finalizeSelection();
|
||||
|
||||
/**
|
||||
* Init is to tell the implementation of nsIEditor to begin its services
|
||||
* @param aDoc The dom document interface being observed
|
||||
* @param aRoot This is the root of the editable section of this
|
||||
* document. If it is null then we get root
|
||||
* from document body.
|
||||
* @param aSelCon this should be used to get the selection location
|
||||
* (will be null for HTML editors)
|
||||
* @param aFlags A bitmask of flags for specifying the behavior
|
||||
* of the editor.
|
||||
*/
|
||||
[noscript] void init(in nsIDOMDocument doc,
|
||||
in nsIContent aRoot,
|
||||
in nsISelectionController aSelCon,
|
||||
in unsigned long aFlags,
|
||||
in AString initialValue);
|
||||
|
||||
void setAttributeOrEquivalent(in nsIDOMElement element,
|
||||
in AString sourceAttrName,
|
||||
in AString sourceAttrValue,
|
||||
|
@ -478,12 +451,6 @@ interface nsIEditor : nsISupports
|
|||
*/
|
||||
void deleteNode(in nsIDOMNode child);
|
||||
|
||||
/**
|
||||
* Returns true if markNodeDirty() has any effect. Returns false if
|
||||
* markNodeDirty() is a no-op.
|
||||
*/
|
||||
[notxpcom] boolean outputsMozDirty();
|
||||
|
||||
/**
|
||||
* markNodeDirty() sets a special dirty attribute on the node.
|
||||
* Usually this will be called immediately after creating a new node.
|
||||
|
@ -550,29 +517,14 @@ interface nsIEditor : nsISupports
|
|||
/* Run unit tests. Noop in optimized builds */
|
||||
void debugUnitTests(out long outNumTests, out long outNumTestsFailed);
|
||||
|
||||
/* checks if a node is read-only or not */
|
||||
[notxpcom] boolean isModifiableNode(in nsIDOMNode aNode);
|
||||
|
||||
/* Set true if you want to suppress dispatching input event. */
|
||||
attribute boolean suppressDispatchingInputEvent;
|
||||
|
||||
/**
|
||||
* True if an edit action is being handled (in other words, between calls of
|
||||
* nsIEditorObserver::BeforeEditAction() and nsIEditorObserver::EditAction()
|
||||
* or nsIEditorObserver::CancelEditAction(). Otherwise, false.
|
||||
*/
|
||||
[noscript] readonly attribute boolean isInEditAction;
|
||||
|
||||
/**
|
||||
* forceCompositionEnd() force the composition end
|
||||
*/
|
||||
void forceCompositionEnd();
|
||||
|
||||
/**
|
||||
* Get preferred IME status of current widget.
|
||||
*/
|
||||
[noscript] IMEState getPreferredIMEState();
|
||||
|
||||
/**
|
||||
* whether this editor has active IME transaction
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче