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 383071 fdf6ea435876f708bc073997d8e59e2b4342f7f0
parent 383070 8f23298691ea9aa00f7d71fa259fcc59fb34d5e6
child 383072 4c29111bdc885cad201e50720962c72f4a11ddbe
push id21915
push usermasayuki@d-toybox.com
push dateFri, 01 Jul 2016 05:16:51 +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; }