Bug 1179632 part.6 KeyboardEvent.isComposing shouldn't expose IME state on different document r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 04 Dec 2015 18:50:43 +0900
changeset 310311 95608418cba5a6b730d22151bccfc810765ae194
parent 310310 7d06dabf27696ff8746f8d8b92f2ca6b1ce175ba
child 310312 672a8b656e19b41617692bb1bc9b03a17beb4b3a
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1179632
milestone45.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 1179632 part.6 KeyboardEvent.isComposing shouldn't expose IME state on different document r=smaug
dom/events/EventStateManager.cpp
dom/events/IMEStateManager.cpp
dom/events/IMEStateManager.h
dom/events/TextComposition.cpp
dom/events/TextComposition.h
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -755,25 +755,27 @@ EventStateManager::PreHandleEvent(nsPres
   case eBeforeKeyUp:
   case eKeyUp:
   case eAfterKeyUp:
     {
       nsIContent* content = GetFocusedContent();
       if (content)
         mCurrentTargetContent = content;
 
-      // NOTE: Don't refer TextComposition::IsComposing() since DOM Level 3
-      //       Events defines that KeyboardEvent.isComposing is true when it's
+      // NOTE: Don't refer TextComposition::IsComposing() since UI Events
+      //       defines that KeyboardEvent.isComposing is true when it's
       //       dispatched after compositionstart and compositionend.
       //       TextComposition::IsComposing() is false even before
       //       compositionend if there is no composing string.
-      WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
+      //       And also don't expose other document's composition state.
+      //       A native IME context is typically shared by multiple documents.
+      //       So, don't use GetTextCompositionFor(nsIWidget*) here.
       RefPtr<TextComposition> composition =
-        IMEStateManager::GetTextCompositionFor(keyEvent);
-      keyEvent->mIsComposing = !!composition;
+        IMEStateManager::GetTextCompositionFor(aPresContext);
+      aEvent->AsKeyboardEvent()->mIsComposing = !!composition;
     }
     break;
   case eWheel:
   case eWheelOperationStart:
   case eWheelOperationEnd:
     {
       NS_ASSERTION(aEvent->mFlags.mIsTrusted,
                    "Untrusted wheel event shouldn't be here");
--- a/dom/events/IMEStateManager.cpp
+++ b/dom/events/IMEStateManager.cpp
@@ -1658,27 +1658,31 @@ IMEStateManager::GetTextCompositionFor(n
   RefPtr<TextComposition> textComposition =
     sTextCompositions->GetCompositionFor(aWidget);
   return textComposition.forget();
 }
 
 // static
 already_AddRefed<TextComposition>
 IMEStateManager::GetTextCompositionFor(
-                   const WidgetKeyboardEvent* aKeyboardEvent)
-{
-  return GetTextCompositionFor(aKeyboardEvent->widget);
-}
-
-// static
-already_AddRefed<TextComposition>
-IMEStateManager::GetTextCompositionFor(
                    const WidgetCompositionEvent* aCompositionEvent)
 {
   if (!sTextCompositions) {
     return nullptr;
   }
   RefPtr<TextComposition> textComposition =
     sTextCompositions->GetCompositionFor(aCompositionEvent);
   return textComposition.forget();
 }
 
+// static
+already_AddRefed<TextComposition>
+IMEStateManager::GetTextCompositionFor(nsPresContext* aPresContext)
+{
+  if (!sTextCompositions) {
+    return nullptr;
+  }
+  RefPtr<TextComposition> textComposition =
+    sTextCompositions->GetCompositionFor(aPresContext);
+  return textComposition.forget();
+}
+
 } // namespace mozilla
--- a/dom/events/IMEStateManager.h
+++ b/dom/events/IMEStateManager.h
@@ -178,19 +178,25 @@ public:
    */
   static already_AddRefed<TextComposition>
     GetTextCompositionFor(nsIWidget* aWidget);
 
   /**
    * Returns TextComposition instance for the event.
    */
   static already_AddRefed<TextComposition>
-    GetTextCompositionFor(const WidgetKeyboardEvent* aKeyboardEvent);
+    GetTextCompositionFor(const WidgetCompositionEvent* aCompositionEvent);
+
+  /**
+   * Returns TextComposition instance for the pres context.
+   * Be aware, even if another pres context which shares native IME context with
+   * specified pres context has composition, this returns nullptr.
+   */
   static already_AddRefed<TextComposition>
-    GetTextCompositionFor(const WidgetCompositionEvent* aCompositionEvent);
+    GetTextCompositionFor(nsPresContext* aPresContext);
 
   /**
    * Send a notification to IME.  It depends on the IME or platform spec what
    * will occur (or not occur).
    */
   static nsresult NotifyIME(const IMENotification& aNotification,
                             nsIWidget* aWidget,
                             bool aOriginIsRemote = false);
--- a/dom/events/TextComposition.cpp
+++ b/dom/events/TextComposition.cpp
@@ -706,16 +706,26 @@ TextCompositionArray::GetCompositionFor(
   index_type i = IndexOf(aCompositionEvent->mNativeIMEContext);
   if (i == NoIndex) {
     return nullptr;
   }
   return ElementAt(i);
 }
 
 TextComposition*
+TextCompositionArray::GetCompositionFor(nsPresContext* aPresContext)
+{
+  index_type i = IndexOf(aPresContext);
+  if (i == NoIndex) {
+    return nullptr;
+  }
+  return ElementAt(i);
+}
+
+TextComposition*
 TextCompositionArray::GetCompositionFor(nsPresContext* aPresContext,
                                            nsINode* aNode)
 {
   index_type i = IndexOf(aPresContext, aNode);
   if (i == NoIndex) {
     return nullptr;
   }
   return ElementAt(i);
--- a/dom/events/TextComposition.h
+++ b/dom/events/TextComposition.h
@@ -410,16 +410,17 @@ public:
   TextComposition* GetCompositionFor(nsIWidget* aWidget);
   TextComposition* GetCompositionFor(
                      const WidgetCompositionEvent* aCompositionEvent);
 
   // Looking for per nsPresContext
   index_type IndexOf(nsPresContext* aPresContext);
   index_type IndexOf(nsPresContext* aPresContext, nsINode* aNode);
 
+  TextComposition* GetCompositionFor(nsPresContext* aPresContext);
   TextComposition* GetCompositionFor(nsPresContext* aPresContext,
                                      nsINode* aNode);
   TextComposition* GetCompositionInContent(nsPresContext* aPresContext,
                                            nsIContent* aContent);
 };
 
 } // namespace mozilla