Bug 840409 part.15 Implement widget::IMEHandler::CanOptimizeKeyAndIMEMessages() r=jimm
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 25 Feb 2013 13:00:07 +0900
changeset 122872 f98e63db4452481a55a1e1dc6b0f7533bf014201
parent 122871 5fe283c4cd7f76bc147468d10cf4ce2462558384
child 122873 03e5c19f88ca78c65b82c964c1ea234de2155a4b
push id1387
push userphilringnalda@gmail.com
push dateTue, 26 Feb 2013 22:32:56 +0000
treeherderfx-team@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs840409
milestone22.0a1
Bug 840409 part.15 Implement widget::IMEHandler::CanOptimizeKeyAndIMEMessages() r=jimm
widget/windows/WinIMEHandler.cpp
widget/windows/WinIMEHandler.h
widget/windows/nsAppShell.cpp
widget/windows/nsIMM32Handler.cpp
widget/windows/nsIMM32Handler.h
widget/windows/nsTextStore.h
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -66,16 +66,29 @@ IMEHandler::GetNativeData(uint32_t aData
   return result;
 #else // #ifdef NS_ENABLE_TSF
   return nullptr;
 #endif // #ifdef NS_ENABLE_TSF #else
 }
 
 // static
 bool
+IMEHandler::CanOptimizeKeyAndIMEMessages()
+{
+#ifdef NS_ENABLE_TSF
+  if (sIsInTSFMode) {
+    return nsTextStore::CanOptimizeKeyAndIMEMessages();
+  }
+#endif // #ifdef NS_ENABLE_TSF
+
+  return nsIMM32Handler::CanOptimizeKeyAndIMEMessages();
+}
+
+// static
+bool
 IMEHandler::IsIMEEnabled(const InputContext& aInputContext)
 {
   return IsIMEEnabled(aInputContext.mIMEState.mEnabled);
 }
 
 // static
 bool
 IMEHandler::IsIMEEnabled(IMEState::Enabled aIMEState)
--- a/widget/windows/WinIMEHandler.h
+++ b/widget/windows/WinIMEHandler.h
@@ -6,16 +6,19 @@
 #ifndef WinIMEHandler_h_
 #define WinIMEHandler_h_
 
 #include "nscore.h"
 #include "nsEvent.h"
 #include "nsIWidget.h"
 #include <windows.h>
 
+#define NS_WM_IMEFIRST WM_IME_SETCONTEXT
+#define NS_WM_IMELAST  WM_IME_KEYUP
+
 class nsWindow;
 
 namespace mozilla {
 namespace widget {
 
 /**
  * IMEHandler class is a mediator class.  On Windows, there are two IME API
  * sets: One is IMM which is legacy API set. The other is TSF which is modern
@@ -29,16 +32,22 @@ public:
   static void Terminate();
 
   /**
    * Returns TSF related native data.
    */
   static void* GetNativeData(uint32_t aDataType);
 
   /**
+   * Returns true if our message loop can optimize the message order for
+   * a key message or an IME message.  Otherwise, false.
+   */
+  static bool CanOptimizeKeyAndIMEMessages();
+
+  /**
    * Returns true if the context or IME state is enabled.  Otherwise, false.
    */
   static bool IsIMEEnabled(const InputContext& aInputContext);
   static bool IsIMEEnabled(IMEState::Enabled aIMEState);
 
   /**
    * When the message is not needed to handle anymore by the caller, this
    * returns true.  Otherwise, false.
--- a/widget/windows/nsAppShell.cpp
+++ b/widget/windows/nsAppShell.cpp
@@ -6,17 +6,17 @@
 #include "mozilla/ipc/RPCChannel.h"
 #include "nsAppShell.h"
 #include "nsToolkit.h"
 #include "nsThreadUtils.h"
 #include "WinTaskbar.h"
 #include "WinMouseScrollHandler.h"
 #include "nsWindowDefs.h"
 #include "nsString.h"
-#include "nsIMM32Handler.h"
+#include "WinIMEHandler.h"
 #include "mozilla/widget/AudioSession.h"
 #include "mozilla/HangMonitor.h"
 
 const PRUnichar* kAppShellEventId = L"nsAppShell:EventID";
 const PRUnichar* kTaskbarButtonEventId = L"TaskbarButtonCreated";
 
 static UINT sMsgId;
 
@@ -61,17 +61,17 @@ static bool PeekUIMessage(MSG* aMsg)
 
   if (haveKeyMsg) {
     pMsg = &keyMsg;
   }
   if (haveIMEMsg && (!pMsg || imeMsg.time < pMsg->time)) {
     pMsg = &imeMsg;
   }
 
-  if (pMsg && !nsIMM32Handler::CanOptimizeKeyAndIMEMessages(pMsg)) {
+  if (pMsg && !mozilla::widget::IMEHandler::CanOptimizeKeyAndIMEMessages()) {
     return false;
   }
 
   if (haveMouseMsg && (!pMsg || mouseMsg.time < pMsg->time)) {
     pMsg = &mouseMsg;
   }
 
   if (!pMsg) {
--- a/widget/windows/nsIMM32Handler.cpp
+++ b/widget/windows/nsIMM32Handler.cpp
@@ -132,17 +132,17 @@ nsIMM32Handler::InitKeyboardLayout(HKL a
 
 /* static */ UINT
 nsIMM32Handler::GetKeyboardCodePage()
 {
   return sCodePage;
 }
 
 /* static */ bool
-nsIMM32Handler::CanOptimizeKeyAndIMEMessages(MSG *aNextKeyOrIMEMessage)
+nsIMM32Handler::CanOptimizeKeyAndIMEMessages()
 {
   // If IME is opening right now, we shouldn't optimize the key and IME message
   // order because ATOK (Japanese IME of third party) has some problem with the
   // optimization.  When it finishes opening completely, it eats all key
   // messages in the message queue.  And it causes starting composition.  So,
   // we shouldn't eat the key messages before ATOK.
   return !sIsIMEOpening;
 }
--- a/widget/windows/nsIMM32Handler.h
+++ b/widget/windows/nsIMM32Handler.h
@@ -11,19 +11,16 @@
 #include "nsString.h"
 #include "nsGUIEvent.h"
 #include "nsTArray.h"
 
 class nsIWidget;
 class nsWindow;
 struct nsIntRect;
 
-#define NS_WM_IMEFIRST WM_IME_SETCONTEXT
-#define NS_WM_IMELAST  WM_IME_KEYUP
-
 class nsIMEContext
 {
 public:
   nsIMEContext(HWND aWnd) : mWnd(aWnd)
   {
     mIMC = ::ImmGetContext(mWnd);
   }
 
@@ -120,17 +117,17 @@ public:
   {
     return IsComposingOnOurEditor() || IsComposingOnPlugin();
   }
   static bool IsComposingOn(nsWindow* aWindow)
   {
     return IsComposing() && IsComposingWindow(aWindow);
   }
 
-  static bool CanOptimizeKeyAndIMEMessages(MSG *aNextKeyOrIMEMessage);
+  static bool CanOptimizeKeyAndIMEMessages();
 
 #ifdef DEBUG
   /**
    * IsIMEAvailable() returns TRUE when current keyboard layout has IME.
    * Otherwise, FALSE.
    */
   static bool IsIMEAvailable() { return sIsIME; }
 #endif
--- a/widget/windows/nsTextStore.h
+++ b/widget/windows/nsTextStore.h
@@ -140,16 +140,22 @@ public:
   static nsIMEUpdatePreference GetIMEUpdatePreference();
 
   static void CompositionTimerCallbackFunc(nsITimer *aTimer, void *aClosure)
   {
     nsTextStore *ts = static_cast<nsTextStore*>(aClosure);
     ts->OnCompositionTimer();
   }
 
+  static bool CanOptimizeKeyAndIMEMessages()
+  {
+    // TODO: We need to implement this for ATOK.
+    return true;
+  }
+
   // Returns the address of the pointer so that the TSF automatic test can
   // replace the system object with a custom implementation for testing.
   static void* GetNativeData(uint32_t aDataType)
   {
     switch (aDataType) {
       case NS_NATIVE_TSF_THREAD_MGR:
         Initialize(); // Apply any previous changes
         return static_cast<void*>(&sTsfThreadMgr);