// static void IMEHandler::InitInputContext(nsWindow* aWindow, InputContext& aInputContext) { // For a11y, the default enabled state should be 'enabled'. aInputContext.mIMEState.mEnabled = IMEState::ENABLED; #ifdef NS_ENABLE_TSF if (sIsInTSFMode) { nsTextStore::SetInputContext(aInputContext); aInputContext.mNativeIMEContext = nsTextStore::GetTextStore(); MOZ_ASSERT(aInputContext.mNativeIMEContext); return; } #endif // #ifdef NS_ENABLE_TSF // NOTE: mNativeIMEContext may be null if IMM module isn't installed. nsIMEContext IMEContext(aWindow->GetWindowHandle()); aInputContext.mNativeIMEContext = static_cast<void*>(IMEContext.get()); MOZ_ASSERT(aInputContext.mNativeIMEContext || !CurrentKeyboardLayoutHasIME()); // If no IME context is available, we should set the widget's pointer since // nullptr indicates there is only one context per process on the platform. if (!aInputContext.mNativeIMEContext) { aInputContext.mNativeIMEContext = static_cast<void*>(aWindow); } }
// static void IMEHandler::OnDestroyWindow(nsWindow* aWindow) { // We need to do nothing here for TSF. Just restore the default context // if it's been disassociated. nsIMEContext IMEContext(aWindow->GetWindowHandle()); IMEContext.AssociateDefaultContext(); }
// static void IMEHandler::SetInputContext(nsWindow* aWindow, InputContext& aInputContext, const InputContextAction& aAction) { // FYI: If there is no composition, this call will do nothing. NotifyIME(aWindow, REQUEST_TO_COMMIT_COMPOSITION); // Assume that SetInputContext() is called only when aWindow has focus. sPluginHasFocus = (aInputContext.mIMEState.mEnabled == IMEState::PLUGIN); bool enable = IsIMEEnabled(aInputContext); bool adjustOpenState = (enable && aInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE); bool open = (adjustOpenState && aInputContext.mIMEState.mOpen == IMEState::OPEN); aInputContext.mNativeIMEContext = nullptr; #ifdef NS_ENABLE_TSF // Note that even while a plugin has focus, we need to notify TSF of that. if (sIsInTSFMode) { nsTextStore::SetInputContext(aWindow, aInputContext, aAction); if (IsTSFAvailable()) { aInputContext.mNativeIMEContext = nsTextStore::GetTextStore(); if (adjustOpenState) { nsTextStore::SetIMEOpenState(open); } return; } } else { // Set at least InputScope even when TextStore is not available. SetInputScopeForIMM32(aWindow, aInputContext.mHTMLInputType); } #endif // #ifdef NS_ENABLE_TSF nsIMEContext IMEContext(aWindow->GetWindowHandle()); if (enable) { IMEContext.AssociateDefaultContext(); if (!aInputContext.mNativeIMEContext) { aInputContext.mNativeIMEContext = static_cast<void*>(IMEContext.get()); } } else if (!aWindow->Destroyed()) { // Don't disassociate the context after the window is destroyed. IMEContext.Disassociate(); if (!aInputContext.mNativeIMEContext) { // The old InputContext must store the default IMC. aInputContext.mNativeIMEContext = aWindow->GetInputContext().mNativeIMEContext; } } if (adjustOpenState) { IMEContext.SetOpenState(open); } }
// static void IMEHandler::SetInputContext(nsWindow* aWindow, InputContext& aInputContext) { // FYI: If there is no composition, this call will do nothing. NotifyIME(aWindow, REQUEST_TO_COMMIT_COMPOSITION); // Assume that SetInputContext() is called only when aWindow has focus. sPluginHasFocus = (aInputContext.mIMEState.mEnabled == IMEState::PLUGIN); bool enable = IsIMEEnabled(aInputContext); bool adjustOpenState = (enable && aInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE); bool open = (adjustOpenState && aInputContext.mIMEState.mOpen == IMEState::OPEN); aInputContext.mNativeIMEContext = nullptr; #ifdef NS_ENABLE_TSF // Note that even while a plugin has focus, we need to notify TSF of that. if (sIsInTSFMode) { nsTextStore::SetInputContext(aInputContext); if (IsTSFAvailable()) { aInputContext.mNativeIMEContext = nsTextStore::GetTextStore(); } // Currently, nsTextStore doesn't set focus to keyboard disabled document. // Therefore, we still need to perform the following legacy code. } #endif // #ifdef NS_ENABLE_TSF nsIMEContext IMEContext(aWindow->GetWindowHandle()); if (enable) { IMEContext.AssociateDefaultContext(); if (!aInputContext.mNativeIMEContext) { aInputContext.mNativeIMEContext = static_cast<void*>(IMEContext.get()); } } else if (!aWindow->Destroyed()) { // Don't disassociate the context after the window is destroyed. IMEContext.Disassociate(); if (!aInputContext.mNativeIMEContext) { // The old InputContext must store the default IMC. aInputContext.mNativeIMEContext = aWindow->GetInputContext().mNativeIMEContext; } } if (adjustOpenState) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { nsTextStore::SetIMEOpenState(open); return; } #endif // #ifdef NS_ENABLE_TSF IMEContext.SetOpenState(open); } }
// static bool IMEHandler::GetOpenState(nsWindow* aWindow) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { return nsTextStore::GetIMEOpenState(); } #endif //NS_ENABLE_TSF nsIMEContext IMEContext(aWindow->GetWindowHandle()); return IMEContext.GetOpenState(); }
// static void IMEHandler::AssociateIMEContext(nsWindow* aWindow, bool aEnable) { nsIMEContext IMEContext(aWindow->GetWindowHandle()); if (aEnable) { IMEContext.AssociateDefaultContext(); return; } // Don't disassociate the context after the window is destroyed. if (aWindow->Destroyed()) { return; } IMEContext.Disassociate(); }
// static void IMEHandler::OnDestroyWindow(nsWindow* aWindow) { #ifdef NS_ENABLE_TSF // We need to do nothing here for TSF. Just restore the default context // if it's been disassociated. if (!sIsInTSFMode) { // MSDN says we need to set IS_DEFAULT to avoid memory leak when we use // SetInputScopes API. Use an empty string to do this. SetInputScopeForIMM32(aWindow, EmptyString()); } #endif // #ifdef NS_ENABLE_TSF nsIMEContext IMEContext(aWindow->GetWindowHandle()); IMEContext.AssociateDefaultContext(); }
// static void IMEHandler::SetInputContext(nsWindow* aWindow, InputContext& aInputContext, const InputContextAction& aAction) { // FYI: If there is no composition, this call will do nothing. NotifyIME(aWindow, IMENotification(REQUEST_TO_COMMIT_COMPOSITION)); const InputContext& oldInputContext = aWindow->GetInputContext(); // Assume that SetInputContext() is called only when aWindow has focus. sPluginHasFocus = (aInputContext.mIMEState.mEnabled == IMEState::PLUGIN); bool enable = WinUtils::IsIMEEnabled(aInputContext); bool adjustOpenState = (enable && aInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE); bool open = (adjustOpenState && aInputContext.mIMEState.mOpen == IMEState::OPEN); aInputContext.mNativeIMEContext = nullptr; #ifdef NS_ENABLE_TSF // Note that even while a plugin has focus, we need to notify TSF of that. if (sIsInTSFMode) { nsTextStore::SetInputContext(aWindow, aInputContext, aAction); if (IsTSFAvailable()) { aInputContext.mNativeIMEContext = nsTextStore::GetTextStore(); if (sIsIMMEnabled) { // Associate IME context for IMM-IMEs. AssociateIMEContext(aWindow, enable); } else if (oldInputContext.mIMEState.mEnabled == IMEState::PLUGIN) { // Disassociate the IME context from the window when plugin loses focus // in pure TSF mode. AssociateIMEContext(aWindow, false); } if (adjustOpenState) { nsTextStore::SetIMEOpenState(open); } return; } } else { // Set at least InputScope even when TextStore is not available. SetInputScopeForIMM32(aWindow, aInputContext.mHTMLInputType); } #endif // #ifdef NS_ENABLE_TSF AssociateIMEContext(aWindow, enable); nsIMEContext IMEContext(aWindow->GetWindowHandle()); if (adjustOpenState) { IMEContext.SetOpenState(open); } if (aInputContext.mNativeIMEContext) { return; } // The old InputContext must store the default IMC or old TextStore. // When IME context is disassociated from the window, use it. aInputContext.mNativeIMEContext = enable ? static_cast<void*>(IMEContext.get()) : oldInputContext.mNativeIMEContext; }