mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1572375 - part 7: Get rid of HTMLEditRules::OnModifyDocument()
r=m_kato
`HTMLEditRules::OnModifyDocument()` is same as just calling `EditorBase::EnsureNoPaddingBRElementForEmptyEditor()` and `EditorBase::MaybeCreatePaddingBRElementForEmptyEditor()` so that this patch gets rid of the method, then, creates `HTMLEditor::OnModifyDocumentInternal()` and makes it do same thing. Differential Revision: https://phabricator.services.mozilla.com/D41161 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
1df80236d6
commit
485a59c303
@ -11118,38 +11118,9 @@ void HTMLEditRules::DocumentModifiedWorker() {
|
||||
}
|
||||
|
||||
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
|
||||
htmlEditor->OnModifyDocument();
|
||||
}
|
||||
|
||||
void HTMLEditRules::OnModifyDocument() {
|
||||
MOZ_ASSERT(mHTMLEditor);
|
||||
|
||||
AutoSafeEditorData setData(*this, *mHTMLEditor);
|
||||
|
||||
// DeleteNodeWithTransaction() below may cause a flush, which could destroy
|
||||
// the editor
|
||||
nsAutoScriptBlockerSuppressNodeRemoved scriptBlocker;
|
||||
|
||||
// Delete our padding <br> element for empty editor, if we have one, since
|
||||
// the document might not be empty any more.
|
||||
if (HTMLEditorRef().mPaddingBRElementForEmptyEditor) {
|
||||
// A mutation event listener may recreate padding <br> element for empty
|
||||
// editor again during the call of DeleteNodeWithTransaction(). So, move
|
||||
// it first.
|
||||
RefPtr<HTMLBRElement> paddingBRElement(
|
||||
std::move(HTMLEditorRef().mPaddingBRElementForEmptyEditor));
|
||||
DebugOnly<nsresult> rv = MOZ_KnownLive(HTMLEditorRef())
|
||||
.DeleteNodeWithTransaction(*paddingBRElement);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Failed to remove the padding <br> element");
|
||||
}
|
||||
|
||||
// Try to recreate the padding <br> element for empty editor if needed.
|
||||
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
|
||||
.MaybeCreatePaddingBRElementForEmptyEditor();
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_ERROR_EDITOR_DESTROYED,
|
||||
"The editor has been destroyed during creating a padding <br> element");
|
||||
nsresult rv = htmlEditor->OnModifyDocument();
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"HTMLEditor::OnModifyDocument() failed");
|
||||
Unused << rv;
|
||||
}
|
||||
|
||||
|
@ -136,13 +136,6 @@ class HTMLEditRules : public TextEditRules {
|
||||
void StartToListenToEditSubActions() { mListenerEnabled = true; }
|
||||
void EndListeningToEditSubActions() { mListenerEnabled = false; }
|
||||
|
||||
/**
|
||||
* OnModifyDocument() is called when DocumentModifiedWorker() calls
|
||||
* HTMLEditor::OnModifyDocument(). The caller guarantees that there
|
||||
* is AutoEditActionDataSetter instance in the editor.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT void OnModifyDocument();
|
||||
|
||||
protected:
|
||||
virtual ~HTMLEditRules() = default;
|
||||
|
||||
|
@ -5267,22 +5267,42 @@ nsHTMLDocument* HTMLEditor::GetHTMLDocument() const {
|
||||
return doc->AsHTMLDocument();
|
||||
}
|
||||
|
||||
void HTMLEditor::OnModifyDocument() {
|
||||
MOZ_ASSERT(mRules);
|
||||
|
||||
RefPtr<HTMLEditRules> htmlRules = mRules->AsHTMLEditRules();
|
||||
nsresult HTMLEditor::OnModifyDocument() {
|
||||
if (IsEditActionDataAvailable()) {
|
||||
htmlRules->OnModifyDocument();
|
||||
return;
|
||||
return OnModifyDocumentInternal();
|
||||
}
|
||||
|
||||
AutoEditActionDataSetter editActionData(
|
||||
*this, EditAction::eCreatePaddingBRElementForEmptyEditor);
|
||||
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
||||
return;
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
htmlRules->OnModifyDocument();
|
||||
return OnModifyDocumentInternal();
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::OnModifyDocumentInternal() {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
// EnsureNoPaddingBRElementForEmptyEditor() below may cause a flush, which
|
||||
// could destroy the editor
|
||||
nsAutoScriptBlockerSuppressNodeRemoved scriptBlocker;
|
||||
|
||||
// Delete our padding <br> element for empty editor, if we have one, since
|
||||
// the document might not be empty any more.
|
||||
nsresult rv = EnsureNoPaddingBRElementForEmptyEditor();
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Failed to remove the padding <br> element");
|
||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Try to recreate the padding <br> element for empty editor if needed.
|
||||
rv = MaybeCreatePaddingBRElementForEmptyEditor();
|
||||
NS_WARNING_ASSERTION(
|
||||
rv != NS_ERROR_EDITOR_DESTROYED,
|
||||
"The editor has been destroyed during creating a padding <br> element");
|
||||
return rv;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -1092,7 +1092,7 @@ class HTMLEditor final : public TextEditor,
|
||||
* HTMLEditRules::OnModifyDocument() with AutoEditActionDataSetter
|
||||
* instance.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT void OnModifyDocument();
|
||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult OnModifyDocument();
|
||||
|
||||
protected: // Called by helper classes.
|
||||
virtual void OnStartToHandleTopLevelEditSubAction(
|
||||
@ -2538,6 +2538,11 @@ class HTMLEditor final : public TextEditor,
|
||||
static nsresult SlurpBlob(dom::Blob* aBlob, nsPIDOMWindowOuter* aWindow,
|
||||
BlobReader* aBlobReader);
|
||||
|
||||
/**
|
||||
* OnModifyDocumentInternal() is called by OnModifyDocument().
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult OnModifyDocumentInternal();
|
||||
|
||||
protected:
|
||||
RefPtr<TypeInState> mTypeInState;
|
||||
RefPtr<ComposerCommandsUpdater> mComposerCommandsUpdater;
|
||||
|
Loading…
Reference in New Issue
Block a user