Bug 1224994 part.5 Implement TSFTextStore::IsComposingInContent() to check if the focused editor has composition r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 29 Jun 2016 17:39:59 +0900
changeset 383444 394d089cc6767e310d6ba6c2add43678b2548e59
parent 383443 ddaac00d1b8a870bda4a7e5dcaa8fff4f07567be
child 383445 29a6f23f88f735bf12d806611af7bcf6cfdc33f7
push id22031
push usermasayuki@d-toybox.com
push dateMon, 04 Jul 2016 06:55:01 +0000
reviewersm_kato
bugs1224994
milestone50.0a1
Bug 1224994 part.5 Implement TSFTextStore::IsComposingInContent() to check if the focused editor has composition r?m_kato MozReview-Commit-ID: 2bmGeaxUpUU
widget/TextEventDispatcher.h
widget/windows/TSFTextStore.cpp
widget/windows/TSFTextStore.h
--- a/widget/TextEventDispatcher.h
+++ b/widget/TextEventDispatcher.h
@@ -89,16 +89,25 @@ public:
 
   /**
    * IsComposing() returns true after calling StartComposition() and before
    * calling CommitComposition().
    */
   bool IsComposing() const { return mIsComposing; }
 
   /**
+   * IsInNativeInputTransaction() returns true if native IME handler began a
+   * transaction and it's not finished yet.
+   */
+  bool IsInNativeInputTransaction() const
+  {
+    return mInputTransactionType == eNativeInputTransaction;
+  }
+
+  /**
    * IsDispatchingEvent() returns true while this instance dispatching an event.
    */
   bool IsDispatchingEvent() const { return mDispatchingEvent > 0; }
 
   /**
    * GetPseudoIMEContext() returns pseudo native IME context if there is an
    * input transaction whose type is not for native event handler.
    * Otherwise, returns nullptr.
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -1972,16 +1972,28 @@ TSFTextStore::GetSelection(ULONG ulIndex
   }
   *pSelection = currentSel.ACP();
   *pcFetched = 1;
   MOZ_LOG(sTextStoreLog, LogLevel::Info,
          ("TSF: 0x%p   TSFTextStore::GetSelection() succeeded", this));
   return S_OK;
 }
 
+bool
+TSFTextStore::IsComposingInContent() const
+{
+  if (!mDispatcher) {
+    return false;
+  }
+  if (!mDispatcher->IsInNativeInputTransaction()) {
+    return false;
+  }
+  return mDispatcher->IsComposing();
+}
+
 TSFTextStore::Content&
 TSFTextStore::ContentForTSFRef()
 {
   // This should be called when the document is locked or the content hasn't
   // been abandoned yet.
   if (NS_WARN_IF(!IsReadLocked() && !mContentForTSF.IsInitialized())) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::ContentForTSFRef(), FAILED, due to "
--- a/widget/windows/TSFTextStore.h
+++ b/widget/windows/TSFTextStore.h
@@ -402,16 +402,24 @@ protected:
   // While the document is locked, we cannot dispatch any events which cause
   // DOM events since the DOM events' handlers may modify the locked document.
   // However, even while the document is locked, TSF may queries us.
   // For that, TSFTextStore modifies mComposition even while the document is
   // locked.  With mComposition, query methods can returns the text content
   // information.
   Composition mComposition;
 
+  /**
+   * IsComposingInContent() returns true if there is a composition in the
+   * focused editor and it's caused by native IME (either TIP of TSF or IME of
+   * IMM).  I.e., returns true between eCompositionStart and
+   * eCompositionCommit(AsIs).
+   */
+  bool IsComposingInContent() const;
+
   class Selection
   {
   public:
     Selection() : mDirty(true) {}
 
     bool IsDirty() const { return mDirty; };
     void MarkDirty() { mDirty = true; }