Bug 1504911 - part 2: Make nsTextEditorState::SetValue() dispatch "input" event if it's called for handling part of user input r=smaug

When editor is modified as part of user action, aFlags of
nsTextEditorState::SetValue() includes eSetValue_BySetUserInput.  In this case,
TextEditor (if there is) or the method itself (if there is no editor yet)
should dispatch "input" event by themselves because we will need to initialize
InputEvents more since we're going to implement Input Event specs.

Note that even with this patch, password field stops dispatching "input" event
with call of HTMLInputElement::SetUserInput().  This is caused by a hidden bug
of TextEditRules.   This will be fixed in a following patch.

Differential Revision: https://phabricator.services.mozilla.com/D12245
This commit is contained in:
Masayuki Nakano
2018-11-20 22:06:37 +00:00
parent 8496847b12
commit 9f338e36c6
10 changed files with 84 additions and 31 deletions

View File

@@ -2344,6 +2344,10 @@ HTMLInputElement::SetUserInput(const nsAString& aValue,
return;
}
bool isInputEventDispatchedByTextEditorState =
GetValueMode() == VALUE_MODE_VALUE &&
IsSingleLineTextControl(false);
nsresult rv =
SetValueInternal(aValue,
nsTextEditorState::eSetValue_BySetUserInput |
@@ -2351,9 +2355,11 @@ HTMLInputElement::SetUserInput(const nsAString& aValue,
nsTextEditorState::eSetValue_MoveCursorToEndIfValueChanged);
NS_ENSURE_SUCCESS_VOID(rv);
DebugOnly<nsresult> rvIgnored = nsContentUtils::DispatchInputEvent(this);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"Failed to dispatch input event");
if (!isInputEventDispatchedByTextEditorState) {
DebugOnly<nsresult> rvIgnored = nsContentUtils::DispatchInputEvent(this);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"Failed to dispatch input event");
}
// If this element is not currently focused, it won't receive a change event for this
// update through the normal channels. So fire a change event immediately, instead.
@@ -2810,6 +2816,11 @@ HTMLInputElement::SetValueInternal(const nsAString& aValue,
}
if (IsSingleLineTextControl(false)) {
// Note that if aFlags includes
// nsTextEditorState::eSetValue_BySetUserInput, "input" event is
// automatically dispatched by nsTextEditorState::SetValue().
// If you'd change condition of calling this method, you need to
// maintain SetUserInput() too.
if (!mInputData.mState->SetValue(value, aOldValue, aFlags)) {
return NS_ERROR_OUT_OF_MEMORY;
}