Bug 543789 part.3 Implement DOM3 composition event on Windows r=jimm+smaug

This commit is contained in:
Masayuki Nakano 2011-09-22 18:17:40 +09:00
Родитель 486e5a8522
Коммит 8a950d3782
5 изменённых файлов: 92 добавлений и 16 удалений

Просмотреть файл

@ -1050,6 +1050,7 @@ nsIMM32Handler::HandleStartComposition(nsWindow* aWindow,
}
mCompositionStart = selection.mReply.mOffset;
mLastDispatchedCompositionString.Truncate();
nsCompositionEvent event(PR_TRUE, NS_COMPOSITION_START, aWindow);
aWindow->InitEvent(event, &point);
@ -1313,9 +1314,12 @@ nsIMM32Handler::HandleEndComposition(nsWindow* aWindow)
}
aWindow->InitEvent(event, &point);
// The last dispatched composition string must be the committed string.
event.data = mLastDispatchedCompositionString;
aWindow->DispatchWindowEvent(&event);
mIsComposing = PR_FALSE;
mComposingWindow = nsnull;
mLastDispatchedCompositionString.Truncate();
}
static void
@ -1670,9 +1674,27 @@ nsIMM32Handler::DispatchTextEvent(nsWindow* aWindow,
return;
}
nsTextEvent event(PR_TRUE, NS_TEXT_TEXT, aWindow);
nsRefPtr<nsWindow> kungFuDeathGrip(aWindow);
nsIntPoint point(0, 0);
if (mCompositionString != mLastDispatchedCompositionString) {
nsCompositionEvent compositionUpdate(PR_TRUE, NS_COMPOSITION_UPDATE,
aWindow);
aWindow->InitEvent(compositionUpdate, &point);
compositionUpdate.data = mCompositionString;
mLastDispatchedCompositionString = mCompositionString;
aWindow->DispatchWindowEvent(&compositionUpdate);
if (!mIsComposing || aWindow->Destroyed()) {
return;
}
SetIMERelatedWindowsPos(aWindow, aIMEContext);
}
nsTextEvent event(PR_TRUE, NS_TEXT_TEXT, aWindow);
aWindow->InitEvent(event, &point);
nsAutoTArray<nsTextRange, 4> textRanges;

Просмотреть файл

@ -322,6 +322,7 @@ protected:
nsWindow* mComposingWindow;
nsString mCompositionString;
nsString mLastDispatchedCompositionString;
nsTArray<PRUint32> mClauseArray;
nsTArray<PRUint8> mAttributeArray;

Просмотреть файл

@ -803,9 +803,23 @@ nsTextStore::SendTextEventForCompositionString()
return S_OK;
}
mWindow->DispatchWindowEvent(&event);
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
("TSF: SendTextEventForCompositionString DISPATCHED\n"));
if (mCompositionString != mLastDispatchedCompositionString) {
nsCompositionEvent compositionUpdate(PR_TRUE, NS_COMPOSITION_UPDATE,
mWindow);
mWindow->InitEvent(compositionUpdate);
compositionUpdate.data = mCompositionString;
mLastDispatchedCompositionString = mCompositionString;
mWindow->DispatchWindowEvent(&compositionUpdate);
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
("TSF: SendTextEventForCompositionString compositionupdate "
"DISPATCHED\n"));
}
if (mWindow && !mWindow->Destroyed()) {
mWindow->DispatchWindowEvent(&event);
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
("TSF: SendTextEventForCompositionString text event DISPATCHED\n"));
}
return SaveTextEvent(&event);
}
@ -1244,19 +1258,30 @@ nsTextStore::InsertTextAtSelection(DWORD dwFlags,
nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_START, mWindow);
mWindow->InitEvent(compEvent);
mWindow->DispatchWindowEvent(&compEvent);
nsTextEvent event(PR_TRUE, NS_TEXT_TEXT, mWindow);
mWindow->InitEvent(event);
if (!cch) {
// XXX See OnEndComposition comment on inserting empty strings
event.theText = NS_LITERAL_STRING(" ");
mWindow->DispatchWindowEvent(&event);
if (mWindow && !mWindow->Destroyed()) {
compEvent.message = NS_COMPOSITION_UPDATE;
compEvent.data.Assign(pchText, cch);
mWindow->DispatchWindowEvent(&compEvent);
if (mWindow && !mWindow->Destroyed()) {
nsTextEvent event(PR_TRUE, NS_TEXT_TEXT, mWindow);
mWindow->InitEvent(event);
if (!cch) {
// XXX See OnEndComposition comment on inserting empty strings
event.theText = NS_LITERAL_STRING(" ");
mWindow->DispatchWindowEvent(&event);
}
if (mWindow && !mWindow->Destroyed()) {
event.theText.Assign(pchText, cch);
event.theText.ReplaceSubstring(NS_LITERAL_STRING("\r\n"),
NS_LITERAL_STRING("\n"));
mWindow->DispatchWindowEvent(&event);
if (mWindow && !mWindow->Destroyed()) {
compEvent.message = NS_COMPOSITION_END;
mWindow->DispatchWindowEvent(&compEvent);
}
}
}
}
event.theText.Assign(pchText, cch);
event.theText.ReplaceSubstring(NS_LITERAL_STRING("\r\n"),
NS_LITERAL_STRING("\n"));
mWindow->DispatchWindowEvent(&event);
compEvent.message = NS_COMPOSITION_END;
mWindow->DispatchWindowEvent(&compEvent);
}
pChange->acpStart = sel.acpStart;
pChange->acpOldEnd = sel.acpEnd;
@ -1398,6 +1423,20 @@ nsTextStore::OnEndComposition(ITfCompositionView* pComposition)
mCompositionTimer = nsnull;
}
if (mCompositionString != mLastDispatchedCompositionString) {
nsCompositionEvent compositionUpdate(PR_TRUE, NS_COMPOSITION_UPDATE,
mWindow);
mWindow->InitEvent(compositionUpdate);
compositionUpdate.data = mCompositionString;
mLastDispatchedCompositionString = mCompositionString;
mWindow->DispatchWindowEvent(&compositionUpdate);
if (!mWindow || mWindow->Destroyed()) {
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
("TSF: CompositionUpdate caused aborting compositionend\n"));
return S_OK;
}
}
// Use NS_TEXT_TEXT to commit composition string
nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, mWindow);
mWindow->InitEvent(textEvent);
@ -1415,12 +1454,21 @@ nsTextStore::OnEndComposition(ITfCompositionView* pComposition)
NS_LITERAL_STRING("\n"));
mWindow->DispatchWindowEvent(&textEvent);
if (!mWindow || mWindow->Destroyed()) {
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
("TSF: Text event caused aborting compositionend\n"));
return S_OK;
}
nsCompositionEvent event(PR_TRUE, NS_COMPOSITION_END, mWindow);
event.data = mLastDispatchedCompositionString;
mWindow->InitEvent(event);
mWindow->DispatchWindowEvent(&event);
mCompositionView = NULL;
mCompositionString.Truncate(0);
mLastDispatchedCompositionString.Truncate();
// Maintain selection
SetSelectionInternal(&mCompositionSelection);
return S_OK;

Просмотреть файл

@ -241,6 +241,9 @@ protected:
// The latest text event which was dispatched for composition string
// of the current composing transaction.
nsTextEvent* mLastDispatchedTextEvent;
// The latest composition string which was dispatched by composition update
// event.
nsString mLastDispatchedCompositionString;
// Timer for calling ITextStoreACPSink::OnLayoutChange. This is only used
// during composing.
nsCOMPtr<nsITimer> mCompositionTimer;

Просмотреть файл

@ -219,6 +219,8 @@ public:
};
friend class AutoUseBasicLayerManager;
PRBool Destroyed() { return mOnDestroyCalled; }
protected:
virtual void ResolveIconName(const nsAString &aIconName,