Bug 801989 part.1 Add mNativeIMEContext to InputContext and TextComposition should use it instead of nsIWidget r=smaug, sr=roc
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 27 Oct 2012 08:35:20 +0900
changeset 111714 a0c4f4bd8a9d7702b139eebd0f7b419baff6117e
parent 111713 9c064c78d86aeb5b37cbd595484475bc150ee9ff
child 111715 8d2392ef0082135f2faad84c7a6e00fdb935212c
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerssmaug, roc
bugs801989
milestone19.0a1
Bug 801989 part.1 Add mNativeIMEContext to InputContext and TextComposition should use it instead of nsIWidget r=smaug, sr=roc
content/events/src/TextComposition.cpp
dom/ipc/PBrowser.ipdl
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
widget/nsIWidget.h
widget/xpwidgets/PuppetWidget.cpp
--- a/content/events/src/TextComposition.cpp
+++ b/content/events/src/TextComposition.cpp
@@ -19,19 +19,17 @@ namespace mozilla {
 /******************************************************************************
  * TextComposition
  ******************************************************************************/
 
 TextComposition::TextComposition(nsPresContext* aPresContext,
                                  nsINode* aNode,
                                  nsGUIEvent* aEvent) :
   mPresContext(aPresContext), mNode(aNode),
-  // temporarily, we should assume that one native IME context is per native
-  // widget.
-  mNativeContext(aEvent->widget),
+  mNativeContext(aEvent->widget->GetInputContext().mNativeIMEContext),
   mIsSynthesizedForTests(
     (aEvent->flags & NS_EVENT_FLAG_SYNTHETIC_TEST_EVENT) != 0)
 {
 }
 
 TextComposition::TextComposition(const TextComposition& aOther)
 {
   mNativeContext = aOther.mNativeContext;
@@ -39,19 +37,17 @@ TextComposition::TextComposition(const T
   mNode = aOther.mNode;
   mLastData = aOther.mLastData;
   mIsSynthesizedForTests = aOther.mIsSynthesizedForTests;
 }
 
 bool
 TextComposition::MatchesNativeContext(nsIWidget* aWidget) const
 {
-  // temporarily, we should assume that one native IME context is per one
-  // native widget.
-  return mNativeContext == static_cast<void*>(aWidget);
+  return mNativeContext == aWidget->GetInputContext().mNativeIMEContext;
 }
 
 bool
 TextComposition::MatchesEventTarget(nsPresContext* aPresContext,
                                     nsINode* aNode) const
 {
   return mPresContext == aPresContext && mNode == aNode;
 }
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -151,17 +151,18 @@ parent:
      *
      *  if cancel is PR_TRUE,
      *    widget should return empty string for composition
      *  if cancel is PR_FALSE,
      *    widget should return the current composition text
      */
     sync EndIMEComposition(bool cancel) returns (nsString composition);
 
-    sync GetInputContext() returns (int32_t IMEEnabled, int32_t IMEOpen);
+    sync GetInputContext() returns (int32_t IMEEnabled, int32_t IMEOpen,
+                                    int64_t NativeIMEContext);
 
     SetInputContext(int32_t IMEEnabled,
                     int32_t IMEOpen,
                     nsString type,
                     nsString inputmode,
                     nsString actionHint,
                     int32_t cause,
                     int32_t focusChange);
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -738,28 +738,31 @@ TabParent::RecvEndIMEComposition(const b
   mIMECompositionEnding = false;
   *aComposition = mIMECompositionText;
   mIMECompositionText.Truncate(0);  
   return true;
 }
 
 bool
 TabParent::RecvGetInputContext(int32_t* aIMEEnabled,
-                               int32_t* aIMEOpen)
+                               int32_t* aIMEOpen,
+                               int64_t* aNativeIMEContext)
 {
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget) {
     *aIMEEnabled = IMEState::DISABLED;
     *aIMEOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
+    *aNativeIMEContext = 0;
     return true;
   }
 
   InputContext context = widget->GetInputContext();
   *aIMEEnabled = static_cast<int32_t>(context.mIMEState.mEnabled);
   *aIMEOpen = static_cast<int32_t>(context.mIMEState.mOpen);
+  *aNativeIMEContext = reinterpret_cast<int64_t>(context.mNativeIMEContext);
   return true;
 }
 
 bool
 TabParent::RecvSetInputContext(const int32_t& aIMEEnabled,
                                const int32_t& aIMEOpen,
                                const nsString& aType,
                                const nsString& aInputmode,
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -118,17 +118,18 @@ public:
                                          const uint32_t& aNewEnd);
     virtual bool RecvNotifyIMESelection(const uint32_t& aSeqno,
                                         const uint32_t& aAnchor,
                                         const uint32_t& aFocus);
     virtual bool RecvNotifyIMETextHint(const nsString& aText);
     virtual bool RecvEndIMEComposition(const bool& aCancel,
                                        nsString* aComposition);
     virtual bool RecvGetInputContext(int32_t* aIMEEnabled,
-                                     int32_t* aIMEOpen);
+                                     int32_t* aIMEOpen,
+                                     int64_t* aNativeIMEContext);
     virtual bool RecvSetInputContext(const int32_t& aIMEEnabled,
                                      const int32_t& aIMEOpen,
                                      const nsString& aType,
                                      const nsString& aInputmode,
                                      const nsString& aActionHint,
                                      const int32_t& aCause,
                                      const int32_t& aFocusChange);
     virtual bool RecvSetCursor(const uint32_t& aValue);
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -273,26 +273,33 @@ struct IMEState {
 
   IMEState(Enabled aEnabled, Open aOpen = DONT_CHANGE_OPEN_STATE) :
     mEnabled(aEnabled), mOpen(aOpen)
   {
   }
 };
 
 struct InputContext {
+  InputContext() : mNativeIMEContext(nullptr) {}
+
   IMEState mIMEState;
 
   /* The type of the input if the input is a html input field */
   nsString mHTMLInputType;
 
   /* The type of the inputmode */
   nsString mHTMLInputInputmode;
 
   /* A hint for the action that is performed when the input is submitted */
   nsString mActionHint;
+
+  /* Native IME context for the widget.  This doesn't come from the argument of
+     SetInputContext().  If there is only one context in the process, this may
+     be nullptr. */
+  void* mNativeIMEContext;
 };
 
 struct InputContextAction {
   /**
    * mCause indicates what action causes calling nsIWidget::SetInputContext().
    * It must be one of following values.
    */
   enum Cause {
--- a/widget/xpwidgets/PuppetWidget.cpp
+++ b/widget/xpwidgets/PuppetWidget.cpp
@@ -377,19 +377,21 @@ PuppetWidget::SetInputContext(const Inpu
 }
 
 NS_IMETHODIMP_(InputContext)
 PuppetWidget::GetInputContext()
 {
   InputContext context;
   if (mTabChild) {
     int32_t enabled, open;
-    mTabChild->SendGetInputContext(&enabled, &open);
+    int64_t nativeIMEContext;
+    mTabChild->SendGetInputContext(&enabled, &open, &nativeIMEContext);
     context.mIMEState.mEnabled = static_cast<IMEState::Enabled>(enabled);
     context.mIMEState.mOpen = static_cast<IMEState::Open>(open);
+    context.mNativeIMEContext = reinterpret_cast<void*>(nativeIMEContext);
   }
   return context;
 }
 
 NS_IMETHODIMP
 PuppetWidget::OnIMEFocusChange(bool aFocus)
 {
   if (!mTabChild)