зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1540037 - part 17: Move `TextEditor::OnInputText()` into `EditorBase` r=m_kato
This method is semi-public method, meaning that this is commonly used by public methods which handle various user input and that causes inputting text, both in `TextEditor` and `HTMLEditor`. Therefore, for making `HTMLEditor` stop inheriting `TextEditor` class in the future, we should move it into `EditorBase`. Depends on D115784 Differential Revision: https://phabricator.services.mozilla.com/D115785
This commit is contained in:
Родитель
f62f9d4fa2
Коммит
de91059947
|
@ -4273,6 +4273,31 @@ nsresult EditorBase::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult EditorBase::OnInputText(const nsAString& aStringToInsert) {
|
||||
AutoEditActionDataSetter editActionData(*this, EditAction::eInsertText);
|
||||
MOZ_ASSERT(!aStringToInsert.IsVoid());
|
||||
editActionData.SetData(aStringToInsert);
|
||||
// FYI: For conforming to current UI Events spec, we should dispatch
|
||||
// "beforeinput" event before "keypress" event, but here is in a
|
||||
// "keypress" event listener. However, the other browsers dispatch
|
||||
// "beforeinput" event after "keypress" event. Therefore, it makes
|
||||
// sense to follow the other browsers. Spec issue:
|
||||
// https://github.com/w3c/uievents/issues/220
|
||||
nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED,
|
||||
"CanHandleAndMaybeDispatchBeforeInputEvent() failed");
|
||||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
|
||||
AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName,
|
||||
ScrollSelectionIntoView::Yes);
|
||||
rv = InsertTextAsSubAction(aStringToInsert);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"EditorBase::InsertTextAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
|
||||
nsresult EditorBase::HandleInlineSpellCheck(
|
||||
const EditorDOMPoint& aPreviouslySelectedStart,
|
||||
const AbstractRange* aRange) {
|
||||
|
|
|
@ -1524,6 +1524,14 @@ class EditorBase : public nsIEditor,
|
|||
*/
|
||||
bool IsSelectionRangeContainerNotContent() const;
|
||||
|
||||
/**
|
||||
* OnInputText() is called when user inputs text with keyboard or something.
|
||||
*
|
||||
* @param aStringToInsert The string to insert.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
||||
OnInputText(const nsAString& aStringToInsert);
|
||||
|
||||
/**
|
||||
* InsertTextAsSubAction() inserts aStringToInsert at selection. This
|
||||
* should be used for handling it as an edit sub-action.
|
||||
|
|
|
@ -344,7 +344,7 @@ nsresult TextEditor::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) {
|
|||
aKeyboardEvent->PreventDefault();
|
||||
nsresult rv = OnInputText(u"\t"_ns);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"TextEditor::OnInputText(\\t) failed");
|
||||
"EditorBase::OnInputText(\\t) failed");
|
||||
return rv;
|
||||
}
|
||||
case NS_VK_RETURN: {
|
||||
|
@ -380,35 +380,10 @@ nsresult TextEditor::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) {
|
|||
aKeyboardEvent->PreventDefault();
|
||||
nsAutoString str(charCode);
|
||||
nsresult rv = OnInputText(str);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "TextEditor::OnInputText() failed");
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::OnInputText() failed");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult TextEditor::OnInputText(const nsAString& aStringToInsert) {
|
||||
AutoEditActionDataSetter editActionData(*this, EditAction::eInsertText);
|
||||
MOZ_ASSERT(!aStringToInsert.IsVoid());
|
||||
editActionData.SetData(aStringToInsert);
|
||||
// FYI: For conforming to current UI Events spec, we should dispatch
|
||||
// "beforeinput" event before "keypress" event, but here is in a
|
||||
// "keypress" event listener. However, the other browsers dispatch
|
||||
// "beforeinput" event after "keypress" event. Therefore, it makes
|
||||
// sense to follow the other browsers. Spec issue:
|
||||
// https://github.com/w3c/uievents/issues/220
|
||||
nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED,
|
||||
"CanHandleAndMaybeDispatchBeforeInputEvent() failed");
|
||||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
|
||||
AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName,
|
||||
ScrollSelectionIntoView::Yes);
|
||||
rv = InsertTextAsSubAction(aStringToInsert);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"EditorBase::InsertTextAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
|
||||
nsresult TextEditor::InsertLineBreakAsAction(nsIPrincipal* aPrincipal) {
|
||||
AutoEditActionDataSetter editActionData(*this, EditAction::eInsertLineBreak,
|
||||
aPrincipal);
|
||||
|
|
|
@ -632,14 +632,6 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
|
|||
*/
|
||||
MOZ_CAN_RUN_SCRIPT virtual nsresult SelectEntireDocument() override;
|
||||
|
||||
/**
|
||||
* OnInputText() is called when user inputs text with keyboard or something.
|
||||
*
|
||||
* @param aStringToInsert The string to insert.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
|
||||
OnInputText(const nsAString& aStringToInsert);
|
||||
|
||||
/**
|
||||
* PrepareInsertContent() is a helper method of InsertTextAt(),
|
||||
* HTMLEditor::DoInsertHTMLWithContext(). They insert content coming from
|
||||
|
|
Загрузка…
Ссылка в новой задаче