// 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 nsresult IMEHandler::NotifyIME(nsWindow* aWindow, const IMENotification& aIMENotification) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { switch (aIMENotification.mMessage) { case NOTIFY_IME_OF_SELECTION_CHANGE: return nsTextStore::OnSelectionChange(); case NOTIFY_IME_OF_TEXT_CHANGE: return nsTextStore::OnTextChange(aIMENotification); case NOTIFY_IME_OF_FOCUS: return nsTextStore::OnFocusChange(true, aWindow, aWindow->GetInputContext().mIMEState); case NOTIFY_IME_OF_BLUR: return nsTextStore::OnFocusChange(false, aWindow, aWindow->GetInputContext().mIMEState); case REQUEST_TO_COMMIT_COMPOSITION: if (nsTextStore::IsComposingOn(aWindow)) { nsTextStore::CommitComposition(false); } return NS_OK; case REQUEST_TO_CANCEL_COMPOSITION: if (nsTextStore::IsComposingOn(aWindow)) { nsTextStore::CommitComposition(true); } return NS_OK; case NOTIFY_IME_OF_POSITION_CHANGE: return nsTextStore::OnLayoutChange(); default: return NS_ERROR_NOT_IMPLEMENTED; } } #endif //NS_ENABLE_TSF switch (aIMENotification.mMessage) { case REQUEST_TO_COMMIT_COMPOSITION: nsIMM32Handler::CommitComposition(aWindow); return NS_OK; case REQUEST_TO_CANCEL_COMPOSITION: nsIMM32Handler::CancelComposition(aWindow); return NS_OK; case NOTIFY_IME_OF_POSITION_CHANGE: case NOTIFY_IME_OF_COMPOSITION_UPDATE: nsIMM32Handler::OnUpdateComposition(aWindow); return NS_OK; #ifdef NS_ENABLE_TSF case NOTIFY_IME_OF_BLUR: // If a plugin gets focus while TSF has focus, we need to notify TSF of // the blur. if (nsTextStore::ThinksHavingFocus()) { return nsTextStore::OnFocusChange(false, aWindow, aWindow->GetInputContext().mIMEState); } return NS_ERROR_NOT_IMPLEMENTED; #endif //NS_ENABLE_TSF default: return NS_ERROR_NOT_IMPLEMENTED; } }
// static bool IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage, WPARAM& aWParam, LPARAM& aLParam, MSGResult& aResult) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { nsTextStore::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aResult); if (aResult.mConsumed) { return true; } // If we don't support IMM in TSF mode, we don't use nsIMM32Handler. if (!sIsIMMEnabled) { return false; } // IME isn't implemented with IMM, nsIMM32Handler shouldn't handle any // messages. if (!nsTextStore::IsIMM_IME()) { return false; } } #endif // #ifdef NS_ENABLE_TSF return nsIMM32Handler::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aResult); }
// static bool IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage, WPARAM& aWParam, LPARAM& aLParam, MSGResult& aResult) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { if (aMessage == WM_IME_SETCONTEXT) { // If a windowless plugin had focus and IME was handled on it, composition // window was set the position. After that, even in TSF mode, WinXP keeps // to use composition window at the position if the active IME is not // aware TSF. For avoiding this issue, we need to hide the composition // window here. if (aWParam) { aLParam &= ~ISC_SHOWUICOMPOSITIONWINDOW; } return false; } if (aMessage == WM_USER_TSF_TEXTCHANGE) { nsTextStore::OnTextChangeMsg(); aResult.mConsumed = true; return true; } return false; } #endif // #ifdef NS_ENABLE_TSF return nsIMM32Handler::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aResult); }
// 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 bool IMEHandler::ProcessRawKeyMessage(const MSG& aMsg) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { return nsTextStore::ProcessRawKeyMessage(aMsg); } #endif // #ifdef NS_ENABLE_TSF return false; // noting to do in IMM mode. }
// static bool IMEHandler::CanOptimizeKeyAndIMEMessages() { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { return nsTextStore::CanOptimizeKeyAndIMEMessages(); } #endif // #ifdef NS_ENABLE_TSF return nsIMM32Handler::CanOptimizeKeyAndIMEMessages(); }
// static nsIMEUpdatePreference IMEHandler::GetUpdatePreference() { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { return nsTextStore::GetIMEUpdatePreference(); } #endif //NS_ENABLE_TSF return nsIMEUpdatePreference(false, false); }
// static bool IMEHandler::IsComposingOn(nsWindow* aWindow) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { return nsTextStore::IsComposingOn(aWindow); } #endif // #ifdef NS_ENABLE_TSF return nsIMM32Handler::IsComposingOn(aWindow); }
// 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 nsresult IMEHandler::NotifyIMEOfTextChange(uint32_t aStart, uint32_t aOldEnd, uint32_t aNewEnd) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { return nsTextStore::OnTextChange(aStart, aOldEnd, aNewEnd); } #endif //NS_ENABLE_TSF return NS_ERROR_NOT_IMPLEMENTED; }
// static bool IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage, WPARAM& aWParam, LPARAM& aLParam, LRESULT* aRetValue, bool& aEatMessage) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { if (aMessage == WM_USER_TSF_TEXTCHANGE) { nsTextStore::OnTextChangeMsg(); aEatMessage = true; return true; } return false; } #endif // #ifdef NS_ENABLE_TSF return nsIMM32Handler::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aRetValue, aEatMessage); }
// 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; }