Bug 1304620 part.5 ContentCacheInParent should store the latest composition start offset with mCompositionStartInChild r?m_kato
When ContentCacheInParent receives eCompositionStart, it temporarily sets mCompositionStart to selection start offset. However, if there is a composition in the remote process, the selection start is caret position in the composition string. Therefore, it's not useful information. Instead, the composition start offset should be used because around there are a lot of information.
For that, ContentCacheInParent should always store compostion start offset in the remote process with mCompositionStartInChild even if mWidgetHasComposition is false. And when it receives eCompositionStart, mCompositionStart should be set to mCompositionStartInChild.
MozReview-Commit-ID: DksPNEsi6Ec
--- a/widget/ContentCache.cpp
+++ b/widget/ContentCache.cpp
@@ -505,16 +505,17 @@ ContentCacheInChild::SetSelection(nsIWid
/*****************************************************************************
* mozilla::ContentCacheInParent
*****************************************************************************/
ContentCacheInParent::ContentCacheInParent()
: ContentCache()
, mCommitStringByRequest(nullptr)
, mPendingEventsNeedingAck(0)
+ , mCompositionStartInChild(UINT32_MAX)
, mPendingCompositionCount(0)
, mWidgetHasComposition(false)
{
}
void
ContentCacheInParent::AssignContent(const ContentCache& aOther,
nsIWidget* aWidget,
@@ -534,16 +535,17 @@ ContentCacheInParent::AssignContent(cons
if (mWidgetHasComposition && mPendingCompositionCount == 1) {
IMEStateManager::MaybeStartOffsetUpdatedInChild(aWidget, mCompositionStart);
}
// When the widget has composition, we should set mCompositionStart to
// *current* composition start offset. Note that, in strictly speaking,
// widget should not use WidgetQueryContentEvent if there are some pending
// compositions (i.e., when mPendingCompositionCount is 2 or more).
+ mCompositionStartInChild = aOther.mCompositionStart;
if (mWidgetHasComposition) {
if (aOther.mCompositionStart != UINT32_MAX) {
mCompositionStart = aOther.mCompositionStart;
} else {
mCompositionStart = mSelection.StartOffset();
NS_WARNING_ASSERTION(mCompositionStart != UINT32_MAX,
"mCompositionStart shouldn't be invalid offset when "
"the widget has composition");
@@ -1086,16 +1088,22 @@ ContentCacheInParent::OnCompositionEvent
mCommitStringByRequest));
// We must be able to simulate the selection because
// we might not receive selection updates in time
if (!mWidgetHasComposition) {
if (aEvent.mWidget && aEvent.mWidget->PluginHasFocus()) {
// If focus is on plugin, we cannot get selection range
mCompositionStart = 0;
+ } else if (mCompositionStartInChild != UINT32_MAX) {
+ // If there is pending composition in the remote process, let's use
+ // its start offset temporarily because this stores a lot of information
+ // around it and the user must look around there, so, showing some UI
+ // around it must make sense.
+ mCompositionStart = mCompositionStartInChild;
} else {
mCompositionStart = mSelection.StartOffset();
}
MOZ_ASSERT(aEvent.mMessage == eCompositionStart);
MOZ_RELEASE_ASSERT(mPendingCompositionCount < UINT8_MAX);
mPendingCompositionCount++;
}
--- a/widget/ContentCache.h
+++ b/widget/ContentCache.h
@@ -409,16 +409,19 @@ private:
// This is not nullptr only while the instance is requesting IME to
// composition. Then, data value of dispatched composition events should
// be stored into the instance.
nsAString* mCommitStringByRequest;
// mPendingEventsNeedingAck is increased before sending a composition event or
// a selection event and decreased after they are received in the child
// process.
uint32_t mPendingEventsNeedingAck;
+ // mCompositionStartInChild stores current composition start offset in the
+ // remote process.
+ uint32_t mCompositionStartInChild;
// mPendingCompositionCount is number of compositions which started in widget
// but not yet handled in the child process.
uint8_t mPendingCompositionCount;
// mWidgetHasComposition is true when the widget in this process thinks that
// IME has composition. So, this is set to true when eCompositionStart is
// dispatched and set to false when eCompositionCommit(AsIs) is dispatched.
bool mWidgetHasComposition;