Bug 1832726 - part 1: Make Android widget always dispatch keyboard events during composition r=m_kato,geckoview-reviewers

I think that we don't need the prefs to disable the behavior because the
behavior conforms to UI Events definition and we've shipped the behavior in
2018.  Therefore, nobody shouldn't require to disable the behavior.

Differential Revision: https://phabricator.services.mozilla.com/D177999
This commit is contained in:
Masayuki Nakano 2023-05-16 22:42:59 +00:00
parent 8fe167ce01
commit 1fb277421c
6 changed files with 7 additions and 65 deletions

View file

@ -1416,23 +1416,6 @@ IMEState IMEStateManager::GetNewIMEState(const nsPresContext& aPresContext,
return newIMEState;
}
static bool MayBeIMEUnawareWebApp(nsINode* aNode) {
bool haveKeyEventsListener = false;
while (aNode) {
EventListenerManager* const mgr = aNode->GetExistingListenerManager();
if (mgr) {
if (mgr->MayHaveInputOrCompositionEventListener()) {
return false;
}
haveKeyEventsListener |= mgr->MayHaveKeyEventListener();
}
aNode = aNode->GetParentNode();
}
return haveKeyEventsListener;
}
// static
void IMEStateManager::ResetActiveChildInputContext() {
sActiveChildInputContext.mIMEState.mEnabled = IMEEnabled::Unknown;
@ -1743,11 +1726,6 @@ void IMEStateManager::SetIMEState(const IMEState& aState,
}
}
context.mOrigin = aOrigin;
context.mMayBeIMEUnaware =
context.mIMEState.IsEditable() &&
StaticPrefs::
intl_ime_hack_on_ime_unaware_apps_fire_key_events_for_composition() &&
MayBeIMEUnawareWebApp(aElement);
context.mHasHandledUserInput =
aPresContext && aPresContext->PresShell()->HasHandledUserInput();

View file

@ -7208,25 +7208,6 @@
# Prefs starting with "intl."
#---------------------------------------------------------------------------
# If true, dispatch the keydown and keyup events on any web apps even during
# composition.
- name: intl.ime.hack.on_any_apps.fire_key_events_for_composition
type: bool
value: @IS_ANDROID@
mirror: always
# Android-specific pref to control if keydown and keyup events are fired even
# during composition. Note that those prefs are ignored if
# dom.keyboardevent.dispatch_during_composition is false.
- name: intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition
type: bool
# If true and intl.ime.hack.on_any_apps.fire_key_events_for_composition is
# false, dispatch the keydown and keyup events only on IME-unaware web apps.
# So, this supports web apps which listen to only keydown or keyup events
# to get a change to do something at every text input.
value: @IS_ANDROID@
mirror: always
#ifdef XP_WIN
# Whether making Gecko TSF-aware or only working with IMM. TSF is a modern
# IME API set of Windows which replaces IMM APIs. Unless you can avoid the

View file

@ -244,9 +244,7 @@ std::ostream& operator<<(std::ostream& aStream, const InputContext& aContext) {
<< aContext.mHTMLInputType << "\", mHTMLInputMode=\""
<< aContext.mHTMLInputMode << "\", mActionHint=\""
<< aContext.mActionHint << "\", mAutocapitalize=\""
<< aContext.mAutocapitalize << "\", mMayBeIMEUnaware="
<< (aContext.mMayBeIMEUnaware ? "true" : "false")
<< ", mIsPrivateBrowsing="
<< aContext.mAutocapitalize << "\", mIsPrivateBrowsing="
<< (aContext.mInPrivateBrowsing ? "true" : "false") << " }";
return aStream;
}

View file

@ -405,7 +405,6 @@ struct NativeIMEContext final {
struct InputContext final {
InputContext()
: mOrigin(XRE_IsParentProcess() ? ORIGIN_MAIN : ORIGIN_CONTENT),
mMayBeIMEUnaware(false),
mHasHandledUserInput(false),
mInPrivateBrowsing(false) {}
@ -490,11 +489,6 @@ struct InputContext final {
};
Origin mOrigin;
/* True if the webapp may be unaware of IME events such as input event or
* composiion events. This enables a key-events-only mode on Android for
* compatibility with webapps relying on key listeners. */
bool mMayBeIMEUnaware;
/**
* True if the document has ever received user input
*/

View file

@ -994,13 +994,9 @@ bool GeckoEditableSupport::DoReplaceText(int32_t aStart, int32_t aEnd,
textChanged = true;
}
if (StaticPrefs::
intl_ime_hack_on_any_apps_fire_key_events_for_composition() ||
mInputContext.mMayBeIMEUnaware) {
SendIMEDummyKeyEvent(widget, eKeyDown);
if (!mDispatcher || widget->Destroyed()) {
return false;
}
SendIMEDummyKeyEvent(widget, eKeyDown);
if (!mDispatcher || widget->Destroyed()) {
return false;
}
if (needDispatchCompositionStart) {
@ -1034,12 +1030,9 @@ bool GeckoEditableSupport::DoReplaceText(int32_t aStart, int32_t aEnd,
return false;
}
if (StaticPrefs::
intl_ime_hack_on_any_apps_fire_key_events_for_composition() ||
mInputContext.mMayBeIMEUnaware) {
SendIMEDummyKeyEvent(widget, eKeyUp);
// Widget may be destroyed after dispatching the above event.
}
SendIMEDummyKeyEvent(widget, eKeyUp);
// Widget may be destroyed after dispatching the above event.
return textChanged;
}

View file

@ -815,7 +815,6 @@ struct ParamTraits<mozilla::widget::InputContext> {
WriteParam(aWriter, aParam.mActionHint);
WriteParam(aWriter, aParam.mAutocapitalize);
WriteParam(aWriter, aParam.mOrigin);
WriteParam(aWriter, aParam.mMayBeIMEUnaware);
WriteParam(aWriter, aParam.mHasHandledUserInput);
WriteParam(aWriter, aParam.mInPrivateBrowsing);
mozilla::ipc::WriteIPDLParam(aWriter, aWriter->GetActor(), aParam.mURI);
@ -828,7 +827,6 @@ struct ParamTraits<mozilla::widget::InputContext> {
ReadParam(aReader, &aResult->mActionHint) &&
ReadParam(aReader, &aResult->mAutocapitalize) &&
ReadParam(aReader, &aResult->mOrigin) &&
ReadParam(aReader, &aResult->mMayBeIMEUnaware) &&
ReadParam(aReader, &aResult->mHasHandledUserInput) &&
ReadParam(aReader, &aResult->mInPrivateBrowsing) &&
mozilla::ipc::ReadIPDLParam(aReader, aReader->GetActor(),