Bug 840409 part.16 Use IMM even in TSF mode when plugin has focus r=jimm

This commit is contained in:
Masayuki Nakano 2013-02-25 13:00:07 +09:00
Родитель ffde20f09f
Коммит 5f44ab0ead
3 изменённых файлов: 35 добавлений и 10 удалений

Просмотреть файл

@ -21,6 +21,7 @@ namespace widget {
#ifdef NS_ENABLE_TSF
bool IMEHandler::sIsInTSFMode = false;
bool IMEHandler::sPluginHasFocus = false;
#endif // #ifdef NS_ENABLE_TSF
// static
@ -74,7 +75,7 @@ bool
IMEHandler::CanOptimizeKeyAndIMEMessages()
{
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
return nsTextStore::CanOptimizeKeyAndIMEMessages();
}
#endif // #ifdef NS_ENABLE_TSF
@ -104,7 +105,7 @@ IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage,
LRESULT* aRetValue, bool& aEatMessage)
{
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
if (aMessage == WM_USER_TSF_TEXTCHANGE) {
nsTextStore::OnTextChangeMsg();
aEatMessage = true;
@ -123,7 +124,7 @@ bool
IMEHandler::IsComposing()
{
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
return nsTextStore::IsComposing();
}
#endif // #ifdef NS_ENABLE_TSF
@ -136,7 +137,7 @@ bool
IMEHandler::IsComposingOn(nsWindow* aWindow)
{
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
return nsTextStore::IsComposingOn(aWindow);
}
#endif // #ifdef NS_ENABLE_TSF
@ -150,7 +151,7 @@ IMEHandler::NotifyIME(nsWindow* aWindow,
NotificationToIME aNotification)
{
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
switch (aNotification) {
case NOTIFY_IME_OF_SELECTION_CHANGE:
return nsTextStore::OnSelectionChange();
@ -183,6 +184,16 @@ IMEHandler::NotifyIME(nsWindow* aWindow,
case REQUEST_TO_CANCEL_COMPOSITION:
nsIMM32Handler::CancelComposition(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.mEnabled);
}
return NS_ERROR_NOT_IMPLEMENTED;
#endif //NS_ENABLE_TSF
default:
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -195,7 +206,7 @@ IMEHandler::NotifyIMEOfTextChange(uint32_t aStart,
uint32_t aNewEnd)
{
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
return nsTextStore::OnTextChange(aStart, aOldEnd, aNewEnd);
}
#endif //NS_ENABLE_TSF
@ -208,7 +219,7 @@ nsIMEUpdatePreference
IMEHandler::GetUpdatePreference()
{
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
return nsTextStore::GetIMEUpdatePreference();
}
#endif //NS_ENABLE_TSF
@ -221,7 +232,7 @@ bool
IMEHandler::GetOpenState(nsWindow* aWindow)
{
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
return nsTextStore::GetIMEOpenState();
}
#endif //NS_ENABLE_TSF
@ -247,6 +258,9 @@ 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);
@ -256,9 +270,12 @@ IMEHandler::SetInputContext(nsWindow* aWindow, InputContext& aInputContext)
aInputContext.mNativeIMEContext = nullptr;
#ifdef NS_ENABLE_TSF
// Note that even while a plugin has focus, we need to notify TSF of that.
if (sIsInTSFMode) {
aInputContext.mNativeIMEContext = nsTextStore::GetTextStore();
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.
}
@ -282,7 +299,7 @@ IMEHandler::SetInputContext(nsWindow* aWindow, InputContext& aInputContext)
if (adjustOpenState) {
#ifdef NS_ENABLE_TSF
if (sIsInTSFMode) {
if (IsTSFAvailable()) {
nsTextStore::SetIMEOpenState(open);
return;
}

Просмотреть файл

@ -125,6 +125,9 @@ public:
private:
#ifdef NS_ENABLE_TSF
static bool sIsInTSFMode;
static bool sPluginHasFocus;
static bool IsTSFAvailable() { return (sIsInTSFMode && !sPluginHasFocus); }
#endif // #ifdef NS_ENABLE_TSF
};

Просмотреть файл

@ -173,6 +173,11 @@ public:
return static_cast<void*>(sTsfTextStore);
}
static bool ThinksHavingFocus()
{
return (sTsfTextStore && sTsfTextStore->mContext);
}
static bool IsInTSFMode()
{
return sTsfThreadMgr != nullptr;