From 1fb277421cff358bd90bbd17995583dcc390d00e Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 16 May 2023 22:42:59 +0000 Subject: [PATCH] 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 --- dom/events/IMEStateManager.cpp | 22 ---------------------- modules/libpref/init/StaticPrefList.yaml | 19 ------------------- widget/IMEData.cpp | 4 +--- widget/IMEData.h | 6 ------ widget/android/GeckoEditableSupport.cpp | 19 ++++++------------- widget/nsGUIEventIPC.h | 2 -- 6 files changed, 7 insertions(+), 65 deletions(-) diff --git a/dom/events/IMEStateManager.cpp b/dom/events/IMEStateManager.cpp index 51a521ccc1ee..a66c361d11a0 100644 --- a/dom/events/IMEStateManager.cpp +++ b/dom/events/IMEStateManager.cpp @@ -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(); diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index df6d7d15736a..8a5c8884a501 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -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 diff --git a/widget/IMEData.cpp b/widget/IMEData.cpp index a40b86a9a227..f9497a648d5c 100644 --- a/widget/IMEData.cpp +++ b/widget/IMEData.cpp @@ -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; } diff --git a/widget/IMEData.h b/widget/IMEData.h index f9549561f451..8664ce0ed9c9 100644 --- a/widget/IMEData.h +++ b/widget/IMEData.h @@ -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 */ diff --git a/widget/android/GeckoEditableSupport.cpp b/widget/android/GeckoEditableSupport.cpp index a728a6253eac..fcac5d539991 100644 --- a/widget/android/GeckoEditableSupport.cpp +++ b/widget/android/GeckoEditableSupport.cpp @@ -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; } diff --git a/widget/nsGUIEventIPC.h b/widget/nsGUIEventIPC.h index ad9c1887c6c9..53653511f8d0 100644 --- a/widget/nsGUIEventIPC.h +++ b/widget/nsGUIEventIPC.h @@ -815,7 +815,6 @@ struct ParamTraits { 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 { 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(),