Bug 1310454 part 2 - TSFTextStore::SetInputContext() should do nothing when it's called for initializing native IME context when a widget is created r?m_kato
On Windows, when nsWindow is created, IMEHandler::InitInputContext() is called. Then, it calls TSFTextStore::SetInputContext(). However, at least for now, TSFTextStore needs to do nothing until the widget gets focus.
MozReview-Commit-ID: HBafHEUSCtd
--- a/widget/IMEData.h
+++ b/widget/IMEData.h
@@ -360,17 +360,21 @@ struct InputContextAction final
GOT_FOCUS,
// Focused content lost focus.
LOST_FOCUS,
// Menu got pseudo focus that means focused content isn't changed but
// keyboard events will be handled by menu.
MENU_GOT_PSEUDO_FOCUS,
// Menu lost pseudo focus that means focused content will handle keyboard
// events.
- MENU_LOST_PSEUDO_FOCUS
+ MENU_LOST_PSEUDO_FOCUS,
+ // The widget is created. When a widget is crated, it may need to notify
+ // IME module to initialize its native IME context. In such case, this is
+ // used. I.e., this isn't used by IMEStateManager.
+ WIDGET_CREATED
};
FocusChange mFocusChange;
bool ContentGotFocusByTrustedCause() const
{
return (mFocusChange == GOT_FOCUS &&
mCause != CAUSE_UNKNOWN);
}
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -138,16 +138,18 @@ GetFocusChangeName(InputContextAction::F
case InputContextAction::GOT_FOCUS:
return "GOT_FOCUS";
case InputContextAction::LOST_FOCUS:
return "LOST_FOCUS";
case InputContextAction::MENU_GOT_PSEUDO_FOCUS:
return "MENU_GOT_PSEUDO_FOCUS";
case InputContextAction::MENU_LOST_PSEUDO_FOCUS:
return "MENU_LOST_PSEUDO_FOCUS";
+ case InputContextAction::WIDGET_CREATED:
+ return "WIDGET_CREATED";
default:
return "Unknown";
}
}
static nsCString
GetCLSIDNameStr(REFCLSID aCLSID)
{
@@ -5785,21 +5787,27 @@ TSFTextStore::GetIMEOpenState()
void
TSFTextStore::SetInputContext(nsWindowBase* aWidget,
const InputContext& aContext,
const InputContextAction& aAction)
{
MOZ_LOG(sTextStoreLog, LogLevel::Debug,
("TSFTextStore::SetInputContext(aWidget=%p, "
"aContext=%s, aAction.mFocusChange=%s), "
- "sEnabledTextStore=0x%p, ThinksHavingFocus()=%s",
+ "sEnabledTextStore(0x%p)={ mWidget=0x%p }, ThinksHavingFocus()=%s",
aWidget, GetInputContextString(aContext).get(),
GetFocusChangeName(aAction.mFocusChange), sEnabledTextStore.get(),
+ sEnabledTextStore ? sEnabledTextStore->mWidget.get() : nullptr,
GetBoolName(ThinksHavingFocus())));
+ // When this is called when the widget is created, there is nothing to do.
+ if (aAction.mFocusChange == InputContextAction::WIDGET_CREATED) {
+ return;
+ }
+
NS_ENSURE_TRUE_VOID(IsInTSFMode());
if (aAction.mFocusChange != InputContextAction::FOCUS_NOT_CHANGED) {
if (sEnabledTextStore) {
RefPtr<TSFTextStore> textStore(sEnabledTextStore);
textStore->SetInputScope(aContext.mHTMLInputType,
aContext.mHTMLInputInputmode);
}
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -488,17 +488,17 @@ IMEHandler::InitInputContext(nsWindow* a
{
// For a11y, the default enabled state should be 'enabled'.
aInputContext.mIMEState.mEnabled = IMEState::ENABLED;
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
TSFTextStore::SetInputContext(aWindow, aInputContext,
InputContextAction(InputContextAction::CAUSE_UNKNOWN,
- InputContextAction::GOT_FOCUS));
+ InputContextAction::WIDGET_CREATED));
// IME context isn't necessary in pure TSF mode.
if (!sIsIMMEnabled) {
AssociateIMEContext(aWindow, false);
}
return;
}
#endif // #ifdef NS_ENABLE_TSF