Bug 1137572 part.1 TextEventDispatcher should manage its input transaction type r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 16 Mar 2016 13:47:47 +0900
changeset 288894 a9f1b8cc65f68a638e15ab489280288bcf90b985
parent 288893 29022393615224517283b16adae938128f75e27b
child 288895 b8af9e4c043927f01a858538b0d7e46b6e5c25b0
push id30091
push usercbook@mozilla.com
push dateWed, 16 Mar 2016 09:56:40 +0000
treeherdermozilla-central@341344bdec8f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1137572
milestone48.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 1137572 part.1 TextEventDispatcher should manage its input transaction type r=smaug
dom/base/TextInputProcessor.cpp
widget/TextEventDispatcher.cpp
widget/TextEventDispatcher.h
--- a/dom/base/TextInputProcessor.cpp
+++ b/dom/base/TextInputProcessor.cpp
@@ -192,17 +192,17 @@ TextInputProcessor::BeginInputTransactio
     if (NS_WARN_IF(mDispatcher)) {
       // Forcibly initialize the members if we failed to end the input
       // transaction.
       UnlinkFromTextEventDispatcher();
     }
   }
 
   if (aForTests) {
-    rv = dispatcher->BeginInputTransactionForTests(this);
+    rv = dispatcher->BeginTestInputTransaction(this);
   } else {
     rv = dispatcher->BeginInputTransaction(this);
   }
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
--- a/widget/TextEventDispatcher.cpp
+++ b/widget/TextEventDispatcher.cpp
@@ -20,17 +20,17 @@ namespace widget {
  * TextEventDispatcher
  *****************************************************************************/
 
 bool TextEventDispatcher::sDispatchKeyEventsDuringComposition = false;
 
 TextEventDispatcher::TextEventDispatcher(nsIWidget* aWidget)
   : mWidget(aWidget)
   , mDispatchingEvent(0)
-  , mForTests(false)
+  , mInputTransactionType(eNoInputTransaction)
   , mIsComposing(false)
 {
   MOZ_RELEASE_ASSERT(mWidget, "aWidget must not be nullptr");
 
   static bool sInitialized = false;
   if (!sInitialized) {
     Preferences::AddBoolVarCache(
       &sDispatchKeyEventsDuringComposition,
@@ -39,62 +39,71 @@ TextEventDispatcher::TextEventDispatcher
     sInitialized = true;
   }
 }
 
 nsresult
 TextEventDispatcher::BeginInputTransaction(
                        TextEventDispatcherListener* aListener)
 {
-  return BeginInputTransactionInternal(aListener, false);
+  return BeginInputTransactionInternal(aListener, eOtherInputTransaction);
 }
 
 nsresult
-TextEventDispatcher::BeginInputTransactionForTests(
+TextEventDispatcher::BeginTestInputTransaction(
                        TextEventDispatcherListener* aListener)
 {
-  return BeginInputTransactionInternal(aListener, true);
+  return BeginInputTransactionInternal(aListener, eTestInputTransaction);
+}
+
+nsresult
+TextEventDispatcher::BeginNativeInputTransaction(
+                       TextEventDispatcherListener* aListener)
+{
+  return BeginInputTransactionInternal(aListener, eNativeInputTransaction);
 }
 
 nsresult
 TextEventDispatcher::BeginInputTransactionInternal(
                        TextEventDispatcherListener* aListener,
-                       bool aForTests)
+                       InputTransactionType aType)
 {
   if (NS_WARN_IF(!aListener)) {
     return NS_ERROR_INVALID_ARG;
   }
   nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
   if (listener) {
-    if (listener == aListener && mForTests == aForTests) {
+    if (listener == aListener && mInputTransactionType == aType) {
       return NS_OK;
     }
     // If this has composition or is dispatching an event, any other listener
     // can steal ownership.  Especially, if the latter case is allowed,
     // nobody cannot begin input transaction with this if a modal dialog is
     // opened during dispatching an event.
     if (IsComposing() || IsDispatchingEvent()) {
       return NS_ERROR_ALREADY_INITIALIZED;
     }
   }
   mListener = do_GetWeakReference(aListener);
-  mForTests = aForTests;
+  mInputTransactionType = aType;
   if (listener && listener != aListener) {
     listener->OnRemovedFrom(this);
   }
   return NS_OK;
 }
 
 void
 TextEventDispatcher::EndInputTransaction(TextEventDispatcherListener* aListener)
 {
   if (NS_WARN_IF(IsComposing()) || NS_WARN_IF(IsDispatchingEvent())) {
     return;
   }
 
+  mInputTransactionType = eNoInputTransaction;
+
   nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
   if (NS_WARN_IF(!listener)) {
     return;
   }
 
   if (NS_WARN_IF(listener != aListener)) {
     return;
   }
@@ -105,16 +114,17 @@ TextEventDispatcher::EndInputTransaction
 
 void
 TextEventDispatcher::OnDestroyWidget()
 {
   mWidget = nullptr;
   mPendingComposition.Clear();
   nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
   mListener = nullptr;
+  mInputTransactionType = eNoInputTransaction;
   if (listener) {
     listener->OnRemovedFrom(this);
   }
 }
 
 nsresult
 TextEventDispatcher::GetState() const
 {
@@ -128,17 +138,18 @@ TextEventDispatcher::GetState() const
   return NS_OK;
 }
 
 void
 TextEventDispatcher::InitEvent(WidgetGUIEvent& aEvent) const
 {
   aEvent.time = PR_IntervalNow();
   aEvent.refPoint = LayoutDeviceIntPoint(0, 0);
-  aEvent.mFlags.mIsSynthesizedForTests = mForTests;
+  aEvent.mFlags.mIsSynthesizedForTests =
+    mInputTransactionType == eTestInputTransaction;
   if (aEvent.mClass != eCompositionEventClass) {
     return;
   }
   // Currently, we should set special native IME context when composition
   // events are dispatched from PuppetWidget since PuppetWidget may have not
   // known actual native IME context yet and it caches native IME context
   // when it dispatches every WidgetCompositionEvent.
   if (XRE_IsContentProcess()) {
--- a/widget/TextEventDispatcher.h
+++ b/widget/TextEventDispatcher.h
@@ -51,18 +51,18 @@ public:
    *
    * @param aListener       Specify the listener to listen notifications and
    *                        requests.  This must not be null.
    *                        NOTE: aListener is stored as weak reference in
    *                              TextEventDispatcher.  See mListener
    *                              definition below.
    */
   nsresult BeginInputTransaction(TextEventDispatcherListener* aListener);
-  nsresult BeginInputTransactionForTests(
-             TextEventDispatcherListener* aListener);
+  nsresult BeginTestInputTransaction(TextEventDispatcherListener* aListener);
+  nsresult BeginNativeInputTransaction(TextEventDispatcherListener* aListener);
 
   /**
    * EndInputTransaction() should be called when the listener stops using
    * the TextEventDispatcher.
    *
    * @param aListener       The listener using the TextEventDispatcher instance.
    */
   void EndInputTransaction(TextEventDispatcherListener* aListener);
@@ -275,27 +275,40 @@ private:
 
     void EnsureClauseArray();
   };
   PendingComposition mPendingComposition;
 
   // While dispatching an event, this is incremented.
   uint16_t mDispatchingEvent;
 
-  bool mForTests;
+  enum InputTransactionType : uint8_t
+  {
+    // No input transaction has been started.
+    eNoInputTransaction,
+    // Input transaction for native IME or keyboard event handler.
+    eNativeInputTransaction,
+    // Input transaction for automated tests.
+    eTestInputTransaction,
+    // Input transaction for Others (must be IME on B2G).
+    eOtherInputTransaction
+  };
+
+  InputTransactionType mInputTransactionType;
+
   // See IsComposing().
   bool mIsComposing;
 
   // If this is true, keydown and keyup events are dispatched even when there
   // is a composition.
   static bool sDispatchKeyEventsDuringComposition;
 
   nsresult BeginInputTransactionInternal(
              TextEventDispatcherListener* aListener,
-             bool aForTests);
+             InputTransactionType aType);
 
   /**
    * InitEvent() initializes aEvent.  This must be called before dispatching
    * the event.
    */
   void InitEvent(WidgetGUIEvent& aEvent) const;