Bug 1503457 - Add some variation of EditAction values for composition r=m_kato

Input Events Level 2 declares "deleteByComposition" for empty composition
removes selected content and "deleteCompositionText" for canceling composition.
https://w3c.github.io/input-events/#interface-InputEvent-Attributes

Therefore, TextEditor::OnCompositionChange() should use a new EditAction for
the former only when new composition string is empty, there is no composition
string and there is non-collapsed Selection.

And also TextEditor::OnCompositionEnd() should use another new EditAction for
the latter when composition is canceled with empty string (we don't restore
selected content which is removed by the composition).

Additionally, due to bug 1305387, we don't dispatch "input" event when
we handle TextEditor::OnCompositionChange().  Instead, we dispatch it
when we handle TextEditor::OnCompositionEnd().  Therefore, we need to
use EditAction::eCommitComposition in TextEditor::OnCompositionEnd().

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2018-11-01 08:07:04 +00:00
Родитель f0909ee964
Коммит 63f8b9a61d
3 изменённых файлов: 40 добавлений и 14 удалений

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

@ -68,14 +68,18 @@ enum class EditAction
eStartComposition,
// eUpdateComposition indicates that user updates composition with
// new composition string and IME selections.
// new non-empty composition string and IME selections.
eUpdateComposition,
// eCommitComposition indicates that user commits composition.
eCommitComposition,
// eEndComposition indicates that user ends composition.
eEndComposition,
// eCancelComposition indicates that user cancels composition.
eCancelComposition,
// eDeleteByComposition indicates that user starts composition with
// empty string and there was selected content.
eDeleteByComposition,
// eUndo/eRedo indicate to undo/redo a transaction.
eUndo,

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

@ -700,6 +700,11 @@ protected: // AutoEditActionDataSetter, this shouldn't be accessed by friends.
EditAction aEditAction);
~AutoEditActionDataSetter();
void UpdateEditAction(EditAction aEditAction)
{
mEditAction = aEditAction;
}
bool CanHandle() const
{
return mSelection && mEditorBase.IsInitialized();

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

@ -1371,23 +1371,36 @@ TextEditor::OnCompositionStart(WidgetCompositionEvent& aCompositionStartEvent)
}
nsresult
TextEditor::OnCompositionChange(WidgetCompositionEvent& aCompsitionChangeEvent)
TextEditor::OnCompositionChange(WidgetCompositionEvent& aCompositionChangeEvent)
{
MOZ_ASSERT(aCompsitionChangeEvent.mMessage == eCompositionChange,
MOZ_ASSERT(aCompositionChangeEvent.mMessage == eCompositionChange,
"The event should be eCompositionChange");
EditAction editAction =
aCompsitionChangeEvent.IsFollowedByCompositionEnd() ?
EditAction::eCommitComposition : EditAction::eUpdateComposition;
AutoEditActionDataSetter editActionData(*this, editAction);
if (NS_WARN_IF(!mComposition)) {
return NS_ERROR_FAILURE;
}
AutoEditActionDataSetter editActionData(*this,
EditAction::eUpdateComposition);
if (NS_WARN_IF(!editActionData.CanHandle())) {
return NS_ERROR_NOT_INITIALIZED;
}
if (!EnsureComposition(aCompsitionChangeEvent)) {
if (!EnsureComposition(aCompositionChangeEvent)) {
return NS_OK;
}
// If:
// - new composition string is not empty,
// - there is no composition string in the DOM tree,
// - and there is non-collapsed Selection,
// the selected content will be removed by this composition.
if (aCompositionChangeEvent.mData.IsEmpty() &&
mComposition->String().IsEmpty() &&
!SelectionRefPtr()->IsCollapsed()) {
editActionData.UpdateEditAction(EditAction::eDeleteByComposition);
}
nsIPresShell* presShell = GetPresShell();
if (NS_WARN_IF(!presShell)) {
return NS_ERROR_NOT_INITIALIZED;
@ -1404,7 +1417,8 @@ TextEditor::OnCompositionChange(WidgetCompositionEvent& aCompsitionChangeEvent)
MOZ_ASSERT(!mPlaceholderBatch,
"UpdateIMEComposition() must be called without place holder batch");
TextComposition::CompositionChangeEventHandlingMarker
compositionChangeEventHandlingMarker(mComposition, &aCompsitionChangeEvent);
compositionChangeEventHandlingMarker(mComposition,
&aCompositionChangeEvent);
RefPtr<nsCaret> caretP = presShell->GetCaret();
@ -1414,7 +1428,7 @@ TextEditor::OnCompositionChange(WidgetCompositionEvent& aCompsitionChangeEvent)
MOZ_ASSERT(mIsInEditSubAction,
"AutoPlaceholderBatch should've notified the observes of before-edit");
rv = InsertTextAsSubAction(aCompsitionChangeEvent.mData);
rv = InsertTextAsSubAction(aCompositionChangeEvent.mData);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"Failed to insert new composition string");
@ -1428,7 +1442,7 @@ TextEditor::OnCompositionChange(WidgetCompositionEvent& aCompsitionChangeEvent)
// compositionend event, we don't need to notify editor observes of this
// change.
// NOTE: We must notify after the auto batch will be gone.
if (!aCompsitionChangeEvent.IsFollowedByCompositionEnd()) {
if (!aCompositionChangeEvent.IsFollowedByCompositionEnd()) {
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
}
@ -1442,7 +1456,10 @@ TextEditor::OnCompositionEnd(WidgetCompositionEvent& aCompositionEndEvent)
return;
}
AutoEditActionDataSetter editActionData(*this, EditAction::eEndComposition);
EditAction editAction =
aCompositionEndEvent.mData.IsEmpty() ? EditAction::eCancelComposition :
EditAction::eCommitComposition;
AutoEditActionDataSetter editActionData(*this, editAction);
if (NS_WARN_IF(!editActionData.CanHandle())) {
return;
}