mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-02 20:42:49 +00:00
Bug 1077345 part.12 IMEInputHandler of Cocoa should use NS_COMPOSITION_COMMIT* event r=smichaud
This commit is contained in:
parent
201fb4b702
commit
c89e5a665c
@ -853,13 +853,19 @@ public:
|
||||
* @param aAttrString An NSAttributedString instance which indicates
|
||||
* current composition string.
|
||||
* @param aSelectedRange Current selected range (or caret position).
|
||||
* @param aDoCommit TRUE if the composition string should be
|
||||
* committed. Otherwise, FALSE.
|
||||
*/
|
||||
bool DispatchCompositionChangeEvent(const nsString& aText,
|
||||
NSAttributedString* aAttrString,
|
||||
NSRange& aSelectedRange,
|
||||
bool aDoCommit);
|
||||
NSRange& aSelectedRange);
|
||||
|
||||
/**
|
||||
* DispatchCompositionCommitEvent() dispatches a compositioncommit event or
|
||||
* compositioncommitasis event. If aCommitString is null, dispatches
|
||||
* compositioncommitasis event. I.e., if aCommitString is null, this
|
||||
* commits the composition with the last data. Otherwise, commits the
|
||||
* composition with aCommitString value.
|
||||
*/
|
||||
bool DispatchCompositionCommitEvent(const nsAString* aCommitString = nullptr);
|
||||
|
||||
/**
|
||||
* SetMarkedText() is a handler of setMarkedText of NSTextInput.
|
||||
|
@ -2691,18 +2691,17 @@ IMEInputHandler::CreateTextRangeArray(NSAttributedString *aAttrString,
|
||||
bool
|
||||
IMEInputHandler::DispatchCompositionChangeEvent(const nsString& aText,
|
||||
NSAttributedString* aAttrString,
|
||||
NSRange& aSelectedRange,
|
||||
bool aDoCommit)
|
||||
NSRange& aSelectedRange)
|
||||
{
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p IMEInputHandler::DispatchCompositionChangeEvent, "
|
||||
"aText=\"%s\", aAttrString=\"%s\", "
|
||||
"aSelectedRange={ location=%llu, length=%llu }, "
|
||||
"aDoCommit=%s, Destroyed()=%s",
|
||||
"Destroyed()=%s",
|
||||
this, NS_ConvertUTF16toUTF8(aText).get(),
|
||||
GetCharacters([aAttrString string]),
|
||||
aSelectedRange.location, aSelectedRange.length,
|
||||
TrueOrFalse(aDoCommit), TrueOrFalse(Destroyed())));
|
||||
TrueOrFalse(Destroyed())));
|
||||
|
||||
NS_ENSURE_TRUE(!Destroyed(), false);
|
||||
|
||||
@ -2712,14 +2711,37 @@ IMEInputHandler::DispatchCompositionChangeEvent(const nsString& aText,
|
||||
mWidget);
|
||||
compositionChangeEvent.time = PR_IntervalNow();
|
||||
compositionChangeEvent.mData = aText;
|
||||
if (!aDoCommit) {
|
||||
compositionChangeEvent.mRanges =
|
||||
CreateTextRangeArray(aAttrString, aSelectedRange);
|
||||
}
|
||||
mLastDispatchedCompositionString = compositionChangeEvent.mData;
|
||||
compositionChangeEvent.mRanges =
|
||||
CreateTextRangeArray(aAttrString, aSelectedRange);
|
||||
return DispatchEvent(compositionChangeEvent);
|
||||
}
|
||||
|
||||
bool
|
||||
IMEInputHandler::DispatchCompositionCommitEvent(const nsAString* aCommitString)
|
||||
{
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p IMEInputHandler::DispatchCompositionCommitEvent, "
|
||||
"aCommitString=0x%p (\"%s\"), Destroyed()=%s",
|
||||
this, aCommitString,
|
||||
aCommitString ? NS_ConvertUTF16toUTF8(*aCommitString).get() : "",
|
||||
TrueOrFalse(Destroyed())));
|
||||
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsRefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
||||
|
||||
uint32_t message =
|
||||
aCommitString ? NS_COMPOSITION_COMMIT : NS_COMPOSITION_COMMIT_AS_IS;
|
||||
WidgetCompositionEvent compositionCommitEvent(true, message, mWidget);
|
||||
compositionCommitEvent.time = PR_IntervalNow();
|
||||
if (aCommitString) {
|
||||
compositionCommitEvent.mData = *aCommitString;
|
||||
}
|
||||
return DispatchEvent(compositionCommitEvent);
|
||||
}
|
||||
|
||||
void
|
||||
IMEInputHandler::InitCompositionEvent(WidgetCompositionEvent& aCompositionEvent)
|
||||
{
|
||||
@ -2758,11 +2780,7 @@ IMEInputHandler::InsertTextAsCommittingComposition(
|
||||
if (IsIMEComposing() && aReplacementRange &&
|
||||
aReplacementRange->location != NSNotFound &&
|
||||
!NSEqualRanges(MarkedRange(), *aReplacementRange)) {
|
||||
NSString* latestStr =
|
||||
nsCocoaUtils::ToNSString(mLastDispatchedCompositionString);
|
||||
NSAttributedString* attrLatestStr =
|
||||
[[[NSAttributedString alloc] initWithString:latestStr] autorelease];
|
||||
InsertTextAsCommittingComposition(attrLatestStr, nullptr);
|
||||
DispatchCompositionCommitEvent();
|
||||
if (Destroyed()) {
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p IMEInputHandler::InsertTextAsCommittingComposition, "
|
||||
@ -2770,6 +2788,7 @@ IMEInputHandler::InsertTextAsCommittingComposition(
|
||||
this));
|
||||
return;
|
||||
}
|
||||
OnEndIMEComposition();
|
||||
}
|
||||
|
||||
nsRefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
||||
@ -2801,25 +2820,11 @@ IMEInputHandler::InsertTextAsCommittingComposition(
|
||||
OnStartIMEComposition();
|
||||
}
|
||||
|
||||
NSRange range = NSMakeRange(0, str.Length());
|
||||
DispatchCompositionChangeEvent(str, aAttrString, range, true);
|
||||
DispatchCompositionCommitEvent(&str);
|
||||
if (Destroyed()) {
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p IMEInputHandler::InsertTextAsCommittingComposition, "
|
||||
"destroyed by compositionchange event", this));
|
||||
return;
|
||||
}
|
||||
|
||||
OnUpdateIMEComposition([aAttrString string]);
|
||||
|
||||
WidgetCompositionEvent compEnd(true, NS_COMPOSITION_END, mWidget);
|
||||
InitCompositionEvent(compEnd);
|
||||
compEnd.mData = mLastDispatchedCompositionString;
|
||||
DispatchEvent(compEnd);
|
||||
if (Destroyed()) {
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p IMEInputHandler::InsertTextAsCommittingComposition, "
|
||||
"destroyed by compositionend event", this));
|
||||
"destroyed by compositioncommit event", this));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2862,13 +2867,9 @@ IMEInputHandler::SetMarkedText(NSAttributedString* aAttrString,
|
||||
if (IsIMEComposing() && aReplacementRange &&
|
||||
aReplacementRange->location != NSNotFound &&
|
||||
!NSEqualRanges(MarkedRange(), *aReplacementRange)) {
|
||||
NSString* latestStr =
|
||||
nsCocoaUtils::ToNSString(mLastDispatchedCompositionString);
|
||||
NSAttributedString* attrLatestStr =
|
||||
[[[NSAttributedString alloc] initWithString:latestStr] autorelease];
|
||||
bool ignoreIMECommit = mIgnoreIMECommit;
|
||||
mIgnoreIMECommit = false;
|
||||
InsertTextAsCommittingComposition(attrLatestStr, nullptr);
|
||||
DispatchCompositionCommitEvent();
|
||||
mIgnoreIMECommit = ignoreIMECommit;
|
||||
if (Destroyed()) {
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
@ -2877,6 +2878,7 @@ IMEInputHandler::SetMarkedText(NSAttributedString* aAttrString,
|
||||
this));
|
||||
return;
|
||||
}
|
||||
OnEndIMEComposition();
|
||||
}
|
||||
|
||||
nsString str;
|
||||
@ -2908,33 +2910,33 @@ IMEInputHandler::SetMarkedText(NSAttributedString* aAttrString,
|
||||
OnStartIMEComposition();
|
||||
}
|
||||
|
||||
if (IsIMEComposing()) {
|
||||
if (!IsIMEComposing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!str.IsEmpty()) {
|
||||
OnUpdateIMEComposition([aAttrString string]);
|
||||
|
||||
bool doCommit = str.IsEmpty();
|
||||
DispatchCompositionChangeEvent(str, aAttrString, aSelectedRange, doCommit);
|
||||
DispatchCompositionChangeEvent(str, aAttrString, aSelectedRange);
|
||||
if (Destroyed()) {
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p IMEInputHandler::SetMarkedText, "
|
||||
"destroyed by compositionchange event", this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (doCommit) {
|
||||
WidgetCompositionEvent compEnd(true, NS_COMPOSITION_END, mWidget);
|
||||
InitCompositionEvent(compEnd);
|
||||
compEnd.mData = mLastDispatchedCompositionString;
|
||||
DispatchEvent(compEnd);
|
||||
if (Destroyed()) {
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p IMEInputHandler::SetMarkedText, "
|
||||
"destroyed by compositionend event", this));
|
||||
return;
|
||||
}
|
||||
OnEndIMEComposition();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If the composition string becomes empty string, we should commit
|
||||
// current composition.
|
||||
DispatchCompositionCommitEvent(&EmptyString());
|
||||
if (Destroyed()) {
|
||||
PR_LOG(gLog, PR_LOG_ALWAYS,
|
||||
("%p IMEInputHandler::SetMarkedText, "
|
||||
"destroyed by compositioncommit event", this));
|
||||
return;
|
||||
}
|
||||
OnEndIMEComposition();
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
@ -3335,8 +3337,6 @@ IMEInputHandler::OnStartIMEComposition()
|
||||
NS_ASSERTION(!mIsIMEComposing, "There is a composition already");
|
||||
mIsIMEComposing = true;
|
||||
|
||||
mLastDispatchedCompositionString.Truncate();
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
@ -3380,8 +3380,6 @@ IMEInputHandler::OnEndIMEComposition()
|
||||
mIMECompositionString = nullptr;
|
||||
}
|
||||
|
||||
mLastDispatchedCompositionString.Truncate();
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user