Bug 1540029 - part 3: Move `HTMLEditRules::DocumentModified()` to `HTMLEditor` r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D45785

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-09-17 07:22:01 +00:00
Родитель 54d27f2b21
Коммит 59ca43a5a6
4 изменённых файлов: 25 добавлений и 36 удалений

Просмотреть файл

@ -11146,25 +11146,12 @@ EditActionResult HTMLEditor::AddZIndexAsSubAction(int32_t aChange) {
: EditActionHandled(NS_OK);
}
nsresult HTMLEditRules::DocumentModified() {
nsContentUtils::AddScriptRunner(
NewRunnableMethod("HTMLEditRules::DocumentModifiedWorker", this,
&HTMLEditRules::DocumentModifiedWorker));
// Be aware, if DocumentModifiedWorker() is called synchronously, the
nsresult HTMLEditor::OnDocumentModified() {
nsContentUtils::AddScriptRunner(NewRunnableMethod(
"HTMLEditor::OnModifyDocument", this, &HTMLEditor::OnModifyDocument));
// Be aware, if OnModifyDocument() may be called synchronously, the
// editor might have been destroyed here.
return NS_OK;
}
void HTMLEditRules::DocumentModifiedWorker() {
if (NS_WARN_IF(!CanHandleEditAction())) {
return;
}
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
nsresult rv = htmlEditor->OnModifyDocument();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HTMLEditor::OnModifyDocument() failed");
Unused << rv;
return Destroyed() ? NS_ERROR_EDITOR_DESTROYED : NS_OK;
}
} // namespace mozilla

Просмотреть файл

@ -61,11 +61,6 @@ class HTMLEditRules : public TextEditRules {
MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual nsresult BeforeEdit() override;
MOZ_CAN_RUN_SCRIPT virtual nsresult AfterEdit() override;
/**
* DocumentModified() is called when editor content is changed.
*/
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult DocumentModified();
MOZ_CAN_RUN_SCRIPT
nsresult GetListState(bool* aMixed, bool* aOL, bool* aUL, bool* aDL);
MOZ_CAN_RUN_SCRIPT
@ -91,12 +86,6 @@ class HTMLEditRules : public TextEditRules {
nsresult GetParagraphFormatNodes(
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes);
/**
* DocumentModifiedWorker() is called by DocumentModified() either
* synchronously or asynchronously.
*/
MOZ_CAN_RUN_SCRIPT void DocumentModifiedWorker();
protected:
HTMLEditor* mHTMLEditor;
bool mInitialized;

Просмотреть файл

@ -3289,10 +3289,12 @@ already_AddRefed<Element> HTMLEditor::InsertBRElementWithTransaction(
return newBRElement.forget();
}
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void HTMLEditor::ContentAppended(nsIContent* aFirstNewContent) {
DoContentInserted(aFirstNewContent, eAppended);
}
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void HTMLEditor::ContentInserted(nsIContent* aChild) {
DoContentInserted(aChild, eInserted);
}
@ -3344,10 +3346,12 @@ void HTMLEditor::DoContentInserted(nsIContent* aChild,
// Ignore insertion of the padding <br> element.
return;
}
RefPtr<HTMLEditRules> htmlRules = mRules->AsHTMLEditRules();
if (htmlRules) {
htmlRules->DocumentModified();
nsresult rv = OnDocumentModified();
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return;
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"OnDocumentModified() failed, but ignored");
// Update spellcheck for only the newly-inserted node (bug 743819)
if (mInlineSpellChecker) {
@ -3363,6 +3367,7 @@ void HTMLEditor::DoContentInserted(nsIContent* aChild,
}
}
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void HTMLEditor::ContentRemoved(nsIContent* aChild,
nsIContent* aPreviousSibling) {
if (!IsInObservedSubtree(aChild)) {
@ -3391,10 +3396,12 @@ void HTMLEditor::ContentRemoved(nsIContent* aChild,
return;
}
RefPtr<HTMLEditRules> htmlRules = mRules->AsHTMLEditRules();
if (htmlRules) {
htmlRules->DocumentModified();
nsresult rv = OnDocumentModified();
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return;
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"OnDocumentModified() failed, but ignored");
}
}

Просмотреть файл

@ -2731,6 +2731,11 @@ class HTMLEditor final : public TextEditor,
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult
AddZIndexAsSubAction(int32_t aChange);
/**
* OnDocumentModified() is called when editor content is changed.
*/
MOZ_CAN_RUN_SCRIPT nsresult OnDocumentModified();
protected: // Called by helper classes.
virtual void OnStartToHandleTopLevelEditSubAction(
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
@ -4166,7 +4171,8 @@ class HTMLEditor final : public TextEditor,
SetInlinePropertyOnNodeImpl(nsIContent& aNode, nsAtom& aProperty,
nsAtom* aAttribute, const nsAString& aValue);
typedef enum { eInserted, eAppended } InsertedOrAppended;
void DoContentInserted(nsIContent* aChild, InsertedOrAppended);
MOZ_CAN_RUN_SCRIPT void DoContentInserted(
nsIContent* aChild, InsertedOrAppended aInsertedOrAppended);
/**
* Returns an anonymous Element of type aTag,