mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1077345 part.13 nsGtkIMModule should use NS_COMPOSITION_COMMIT* event r=m_kato
This commit is contained in:
parent
c89e5a665c
commit
d73bc31eb2
@ -369,8 +369,7 @@ nsGtkIMModule::OnKeyEvent(nsWindow* aCaller, GdkEventKey* aEvent,
|
||||
// IM. For compromising this issue, we should dispatch
|
||||
// compositionend event, however, we don't need to reset IM
|
||||
// actually.
|
||||
DispatchCompositionEventsForCommit(activeContext,
|
||||
EmptyString());
|
||||
DispatchCompositionCommitEvent(activeContext, &EmptyString());
|
||||
filterThisEvent = false;
|
||||
}
|
||||
} else {
|
||||
@ -749,7 +748,7 @@ nsGtkIMModule::OnEndCompositionNative(GtkIMContext *aContext)
|
||||
}
|
||||
|
||||
// Be aware, widget can be gone
|
||||
DispatchCompositionEventsForCommit(aContext, mDispatchedCompositionString);
|
||||
DispatchCompositionCommitEvent(aContext);
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -921,7 +920,7 @@ nsGtkIMModule::OnCommitCompositionNative(GtkIMContext *aContext,
|
||||
|
||||
NS_ConvertUTF8toUTF16 str(commitString);
|
||||
// Be aware, widget can be gone
|
||||
DispatchCompositionEventsForCommit(aContext, str);
|
||||
DispatchCompositionCommitEvent(aContext, &str);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1096,14 +1095,15 @@ nsGtkIMModule::DispatchCompositionChangeEvent(
|
||||
}
|
||||
|
||||
bool
|
||||
nsGtkIMModule::DispatchCompositionEventsForCommit(
|
||||
nsGtkIMModule::DispatchCompositionCommitEvent(
|
||||
GtkIMContext* aContext,
|
||||
const nsAString& aCommitString)
|
||||
const nsAString* aCommitString)
|
||||
{
|
||||
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
|
||||
("GtkIMModule(%p): DispatchCompositionEventsForCommit, aContext=%p, "
|
||||
"aCommitString=\"%s\"",
|
||||
this, aContext, NS_ConvertUTF16toUTF8(aCommitString).get()));
|
||||
("GtkIMModule(%p): DispatchCompositionCommitEvent, aContext=%p, "
|
||||
"aCommitString=%p, (\"%s\")",
|
||||
this, aContext, aCommitString,
|
||||
aCommitString ? NS_ConvertUTF16toUTF8(*aCommitString).get() : ""));
|
||||
|
||||
if (!mLastFocusedWindow) {
|
||||
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
|
||||
@ -1112,7 +1112,7 @@ nsGtkIMModule::DispatchCompositionEventsForCommit(
|
||||
}
|
||||
|
||||
if (!IsComposing()) {
|
||||
if (aCommitString.IsEmpty()) {
|
||||
if (!aCommitString || aCommitString->IsEmpty()) {
|
||||
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
|
||||
(" FAILED, there is no composition and empty commit "
|
||||
"string"));
|
||||
@ -1128,56 +1128,28 @@ nsGtkIMModule::DispatchCompositionEventsForCommit(
|
||||
|
||||
nsRefPtr<nsWindow> lastFocusedWindow(mLastFocusedWindow);
|
||||
|
||||
// First, dispatch a compositionchange event for committing with
|
||||
// aCommitString.
|
||||
mCompositionState =
|
||||
eCompositionState_CommitCompositionChangeEventDispatched;
|
||||
|
||||
WidgetCompositionEvent compositionChangeEvent(true, NS_COMPOSITION_CHANGE,
|
||||
mLastFocusedWindow);
|
||||
InitEvent(compositionChangeEvent);
|
||||
compositionChangeEvent.mData = aCommitString;
|
||||
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
mLastFocusedWindow->DispatchEvent(&compositionChangeEvent, status);
|
||||
|
||||
if (!IsComposing()) {
|
||||
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
|
||||
(" FAILED, there is no composition during dispatching "
|
||||
"a compositionchange event for committing the composition"));
|
||||
if (lastFocusedWindow->IsDestroyed() ||
|
||||
lastFocusedWindow != mLastFocusedWindow) {
|
||||
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
|
||||
(" NOTE, the focused widget was destroyed/changed by "
|
||||
"compositionchange event"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Next, forget current composition before dispatching a composionend event.
|
||||
uint32_t message = aCommitString ? NS_COMPOSITION_COMMIT :
|
||||
NS_COMPOSITION_COMMIT_AS_IS;
|
||||
mCompositionState = eCompositionState_NotComposing;
|
||||
mCompositionStart = UINT32_MAX;
|
||||
mCompositionTargetOffset = UINT32_MAX;
|
||||
mDispatchedCompositionString.Truncate();
|
||||
|
||||
// Finally, dispatch a compositionend event if it's possible.
|
||||
if (!lastFocusedWindow->IsDestroyed() &&
|
||||
lastFocusedWindow == mLastFocusedWindow) {
|
||||
WidgetCompositionEvent compositionEndEvent(true, NS_COMPOSITION_END,
|
||||
mLastFocusedWindow);
|
||||
InitEvent(compositionEndEvent);
|
||||
compositionEndEvent.mData = aCommitString;
|
||||
|
||||
status = nsEventStatus_eIgnore;
|
||||
mLastFocusedWindow->DispatchEvent(&compositionEndEvent, status);
|
||||
WidgetCompositionEvent compositionCommitEvent(true, message,
|
||||
mLastFocusedWindow);
|
||||
InitEvent(compositionCommitEvent);
|
||||
if (message == NS_COMPOSITION_COMMIT) {
|
||||
compositionCommitEvent.mData = *aCommitString;
|
||||
}
|
||||
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
mLastFocusedWindow->DispatchEvent(&compositionCommitEvent, status);
|
||||
|
||||
if (lastFocusedWindow->IsDestroyed() ||
|
||||
lastFocusedWindow != mLastFocusedWindow) {
|
||||
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
|
||||
(" NOTE, the focused widget was destroyed/changed by "
|
||||
"compositionend event"));
|
||||
"compositioncommit event"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1493,7 +1465,7 @@ nsGtkIMModule::DeleteText(GtkIMContext* aContext,
|
||||
bool editorHadCompositionString = EditorHasCompositionString();
|
||||
if (wasComposing) {
|
||||
selOffset = mCompositionStart;
|
||||
if (!DispatchCompositionEventsForCommit(aContext, mSelectedString)) {
|
||||
if (!DispatchCompositionCommitEvent(aContext, &mSelectedString)) {
|
||||
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
|
||||
(" FAILED, quitting from DeletText"));
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -128,8 +128,7 @@ protected:
|
||||
enum eCompositionState {
|
||||
eCompositionState_NotComposing,
|
||||
eCompositionState_CompositionStartDispatched,
|
||||
eCompositionState_CompositionChangeEventDispatched,
|
||||
eCompositionState_CommitCompositionChangeEventDispatched
|
||||
eCompositionState_CompositionChangeEventDispatched
|
||||
};
|
||||
eCompositionState mCompositionState;
|
||||
|
||||
@ -164,8 +163,6 @@ protected:
|
||||
return "CompositionStartDispatched";
|
||||
case eCompositionState_CompositionChangeEventDispatched:
|
||||
return "CompositionChangeEventDispatched";
|
||||
case eCompositionState_CommitCompositionChangeEventDispatched:
|
||||
return "CommitCompositionChangeEventDispatched";
|
||||
default:
|
||||
return "InvaildState";
|
||||
}
|
||||
@ -317,7 +314,7 @@ protected:
|
||||
* FALSE, callers cannot continue the composition.
|
||||
* - DispatchCompositionStart
|
||||
* - DispatchCompositionChangeEvent
|
||||
* - DispatchCompositionEventsForCommit
|
||||
* - DispatchCompositionCommitEvent
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -341,17 +338,19 @@ protected:
|
||||
const nsAString& aCompositionString);
|
||||
|
||||
/**
|
||||
* Dispatches a compositionchange event for committing the composition
|
||||
* string and a compositionend event.
|
||||
* Dispatches a compositioncommit event or compositioncommitasis event.
|
||||
*
|
||||
* @param aContext A GtkIMContext which is being handled.
|
||||
* @param aCommitString The string which the composition is
|
||||
* committed with.
|
||||
* @param aCommitString If this is nullptr, the composition will
|
||||
* be committed with last dispatched data.
|
||||
* Otherwise, the composition will be
|
||||
* committed with this value.
|
||||
* @return true if the focused widget is neither
|
||||
* destroyed nor changed. Otherwise, false.
|
||||
*/
|
||||
bool DispatchCompositionEventsForCommit(GtkIMContext* aContext,
|
||||
const nsAString& aCommitString);
|
||||
bool DispatchCompositionCommitEvent(
|
||||
GtkIMContext* aContext,
|
||||
const nsAString* aCommitString = nullptr);
|
||||
};
|
||||
|
||||
#endif // __nsGtkIMModule_h__
|
||||
|
Loading…
Reference in New Issue
Block a user