Bug 1224994 part.5 Implement TSFTextStore::IsComposingInContent() to check if the focused editor has composition r?m_kato
MozReview-Commit-ID: 2bmGeaxUpUU
--- 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; }