Bug 801989 part.2 Set InputContext::mNativeIMEContext on Windows r=jmathies
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 27 Oct 2012 08:35:21 +0900
changeset 111568 8d2392ef0082135f2faad84c7a6e00fdb935212c
parent 111567 a0c4f4bd8a9d7702b139eebd0f7b419baff6117e
child 111569 6e748a6c7216b23ffe9122abc6627b185e373547
push id17136
push usermasayuki@d-toybox.com
push dateFri, 26 Oct 2012 23:35:43 +0000
treeherdermozilla-inbound@19a8337465ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmathies
bugs801989
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 801989 part.2 Set InputContext::mNativeIMEContext on Windows r=jmathies
widget/windows/nsWindow.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -586,16 +586,27 @@ nsWindow::Create(nsIWidget *aParent,
     else
       oldWndProc = (WNDPROC)::SetWindowLongPtrA(scrollableWnd, GWLP_WNDPROC,
                                                 (LONG_PTR)nsWindow::WindowProc);
     ::SetWindowLongPtrW(scrollableWnd, GWLP_USERDATA, (LONG_PTR)oldWndProc);
   }
 
   SubclassWindow(TRUE);
 
+  // NOTE: mNativeIMEContext may be null if IMM module isn't installed.
+  nsIMEContext IMEContext(mWnd);
+  mInputContext.mNativeIMEContext = static_cast<void*>(IMEContext.get());
+  MOZ_ASSERT(mInputContext.mNativeIMEContext ||
+             !nsIMM32Handler::IsIMEAvailable());
+  // If no IME context is available, we should set this widget's pointer since
+  // nullptr indicates there is only one context per process on the platform.
+  if (!mInputContext.mNativeIMEContext) {
+    mInputContext.mNativeIMEContext = this;
+  }
+
   // If the internal variable set by the config.trim_on_minimize pref has not
   // been initialized, and if this is the hidden window (conveniently created
   // before any visible windows, and after the profile has been initialized),
   // do some initialization work.
   if (sTrimOnMinimize == 2 && mWindowType == eWindowType_invisible) {
     // Our internal trim prevention logic is effective on 2K/XP at maintaining
     // the working set when windows are minimized, but on Vista and up it has
     // little to no effect. Since this feature has been the source of numerous
@@ -7283,22 +7294,33 @@ nsWindow::SetInputContext(const InputCon
                           const InputContextAction& aAction)
 {
 #ifdef NS_ENABLE_TSF
   nsTextStore::SetInputContext(aContext);
 #endif //NS_ENABLE_TSF
   if (nsIMM32Handler::IsComposing()) {
     ResetInputState();
   }
+  void* nativeIMEContext = mInputContext.mNativeIMEContext;
   mInputContext = aContext;
+  mInputContext.mNativeIMEContext = nullptr;
   bool enable = (mInputContext.mIMEState.mEnabled == IMEState::ENABLED ||
                  mInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
 
   AssociateDefaultIMC(enable);
 
+  if (enable) {
+    nsIMEContext IMEContext(mWnd);
+    mInputContext.mNativeIMEContext = static_cast<void*>(IMEContext.get());
+  }
+  // Restore the latest associated context when we cannot get actual context.
+  if (!mInputContext.mNativeIMEContext) {
+    mInputContext.mNativeIMEContext = nativeIMEContext;
+  }
+
   if (enable &&
       mInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE) {
     bool open = (mInputContext.mIMEState.mOpen == IMEState::OPEN);
 #ifdef NS_ENABLE_TSF
     nsTextStore::SetIMEOpenState(open);
 #endif //NS_ENABLE_TSF
     nsIMEContext IMEContext(mWnd);
     if (IMEContext.IsValid()) {