Bug 729774 part.2 nsGtkIMModule should store selected text which will be removed by first text event r=karlt

This commit is contained in:
Masayuki Nakano 2012-03-09 13:27:51 +09:00
parent c29ddcb682
commit 84e76f90cd
2 changed files with 26 additions and 0 deletions

View File

@ -454,6 +454,10 @@ nsGtkIMModule::OnFocusChangeInGecko(bool aFocus)
this, aFocus ? "YES" : "NO", GetCompositionStateName(),
mIsIMFocused ? "YES" : "NO",
mIgnoreNativeCompositionEvent ? "YES" : "NO"));
// We shouldn't carry over the removed string to another editor.
mSelectedString.Truncate();
if (aFocus) {
// If we failed to commit forcedely in previous focused editor,
// we should reopen the gate for native signals in new focused editor.
@ -1093,6 +1097,10 @@ nsGtkIMModule::DispatchCompositionStart()
return false;
}
// XXX The composition start point might be changed by composition events
// even though we strongly hope it doesn't happen.
// Every composition event should have the start offset for the result
// because it may high cost if we query the offset every time.
mCompositionStart = selection.mReply.mOffset;
mDispatchedCompositionString.Truncate();
@ -1220,6 +1228,20 @@ nsGtkIMModule::DispatchTextEvent(const nsAString &aCompositionString,
}
}
// Store the selected string which will be removed by following text event.
if (mCompositionState == eCompositionState_CompositionStartDispatched) {
// XXX We should assume, for now, any web applications don't change
// selection at handling this text event.
nsQueryContentEvent querySelectedTextEvent(true,
NS_QUERY_SELECTED_TEXT,
mLastFocusedWindow);
mLastFocusedWindow->DispatchEvent(&querySelectedTextEvent, status);
if (querySelectedTextEvent.mSucceeded) {
mSelectedString = querySelectedTextEvent.mReply.mString;
mCompositionStart = querySelectedTextEvent.mReply.mOffset;
}
}
nsTextEvent textEvent(true, NS_TEXT_TEXT, mLastFocusedWindow);
InitEvent(textEvent);

View File

@ -169,6 +169,10 @@ protected:
// was dispatched by compositionupdate event.
nsString mDispatchedCompositionString;
// mSelectedString is the selected string which was removed by first
// text event.
nsString mSelectedString;
// OnKeyEvent() temporarily sets mProcessingKeyEvent to the given native
// event.
GdkEventKey* mProcessingKeyEvent;