diff --git a/widget/src/windows/nsTextStore.cpp b/widget/src/windows/nsTextStore.cpp index fdb5277d26a..18687596901 100644 --- a/widget/src/windows/nsTextStore.cpp +++ b/widget/src/windows/nsTextStore.cpp @@ -601,6 +601,46 @@ IsSameTextEvent(const nsTextEvent* aEvent1, const nsTextEvent* aEvent2) sizeof(nsTextRange) * aEvent1->rangeCount))); } +HRESULT +nsTextStore::UpdateCompositionExtent(ITfRange* aRangeNew) +{ + NS_ENSURE_TRUE(mCompositionView, E_FAIL); + + HRESULT hr; + nsRefPtr pComposition(mCompositionView); + nsRefPtr composingRange(aRangeNew); + if (!composingRange) { + hr = pComposition->GetRange(getter_AddRefs(composingRange)); + NS_ENSURE_TRUE(SUCCEEDED(hr), hr); + } + + // Get starting offset of the composition + LONG compStart = 0, compLength = 0; + hr = GetRangeExtent(composingRange, &compStart, &compLength); + NS_ENSURE_TRUE(SUCCEEDED(hr), hr); + if (mCompositionStart != compStart || + mCompositionString.Length() != compLength) { + // If the queried composition length is different from the length + // of our composition string, OnUpdateComposition is being called + // because a part of the original composition was committed. + // Reflect that by committing existing composition and starting + // a new one. OnEndComposition followed by OnStartComposition + // will accomplish this automagically. + OnEndComposition(pComposition); + OnStartCompositionInternal(pComposition, composingRange, PR_TRUE); + PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, + ("TSF: UpdateCompositionExtent, (reset) range=%ld-%ld\n", + compStart, compStart + compLength)); + } else { + mCompositionLength = compLength; + PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, + ("TSF: UpdateCompositionExtent, range=%ld-%ld\n", + compStart, compStart + compLength)); + } + + return S_OK; +} + HRESULT nsTextStore::SendTextEventForCompositionString() { @@ -704,6 +744,10 @@ nsTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection, ("TSF: SetSelection, sel=%ld-%ld\n", pSelection->acpStart, pSelection->acpEnd)); if (mCompositionView) { + if (aDispatchTextEvent) { + HRESULT hr = UpdateCompositionExtent(nsnull); + NS_ENSURE_TRUE(SUCCEEDED(hr), hr); + } // Emulate selection during compositions NS_ENSURE_TRUE(pSelection->acpStart >= mCompositionStart && pSelection->acpEnd <= mCompositionStart + @@ -1270,29 +1314,8 @@ nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, if (!pRangeNew) // pRangeNew is null when the update is not complete return S_OK; - // Get starting offset of the composition - LONG compStart = 0, compLength = 0; - HRESULT hr = GetRangeExtent(pRangeNew, &compStart, &compLength); + HRESULT hr = UpdateCompositionExtent(pRangeNew); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); - if (mCompositionStart != compStart || - mCompositionString.Length() != compLength) { - // If the queried composition length is different from the length - // of our composition string, OnUpdateComposition is being called - // because a part of the original composition was committed. - // Reflect that by committing existing composition and starting - // a new one. OnEndComposition followed by OnStartComposition - // will accomplish this automagically. - OnEndComposition(pComposition); - OnStartCompositionInternal(pComposition, pRangeNew, PR_TRUE); - PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, - ("TSF: OnUpdateComposition, (reset) range=%ld-%ld\n", - compStart, compStart + compLength)); - } else { - mCompositionLength = compLength; - PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, - ("TSF: OnUpdateComposition, range=%ld-%ld\n", - compStart, compStart + compLength)); - } return SendTextEventForCompositionString(); } diff --git a/widget/src/windows/nsTextStore.h b/widget/src/windows/nsTextStore.h index d66877bb9eb..65b0720a492 100644 --- a/widget/src/windows/nsTextStore.h +++ b/widget/src/windows/nsTextStore.h @@ -199,6 +199,7 @@ protected: HRESULT GetDisplayAttribute(ITfProperty* aProperty, ITfRange* aRange, TF_DISPLAYATTRIBUTE* aResult); + HRESULT UpdateCompositionExtent(ITfRange* pRangeNew); HRESULT SendTextEventForCompositionString(); HRESULT SaveTextEvent(const nsTextEvent* aEvent); nsresult OnCompositionTimer();