Bug 917322 part.3 Pending composition string data should be cleared immediately before flushing a pending composition string r=smaug

This commit is contained in:
Masayuki Nakano 2015-01-28 15:27:31 +09:00
parent 16b59a9345
commit 6394c1dc0a
2 changed files with 22 additions and 5 deletions

View File

@ -62,7 +62,6 @@ TextEventDispatcher::OnDestroyWidget()
TextEventDispatcher::PendingComposition::PendingComposition()
{
mClauses = new TextRangeArray();
Clear();
}
@ -70,10 +69,19 @@ void
TextEventDispatcher::PendingComposition::Clear()
{
mString.Truncate();
mClauses->Clear();
mClauses = nullptr;
mCaret.mRangeType = 0;
}
void
TextEventDispatcher::PendingComposition::EnsureClauseArray()
{
if (mClauses) {
return;
}
mClauses = new TextRangeArray();
}
nsresult
TextEventDispatcher::PendingComposition::SetString(const nsAString& aString)
{
@ -94,6 +102,7 @@ TextEventDispatcher::PendingComposition::AppendClause(uint32_t aLength,
case NS_TEXTRANGE_SELECTEDRAWTEXT:
case NS_TEXTRANGE_CONVERTEDTEXT:
case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT: {
EnsureClauseArray();
TextRange textRange;
textRange.mStartOffset =
mClauses->IsEmpty() ? 0 : mClauses->LastElement().mEndOffset;
@ -133,7 +142,7 @@ TextEventDispatcher::PendingComposition::Flush(
return NS_ERROR_NOT_AVAILABLE;
}
if (!mClauses->IsEmpty() &&
if (mClauses && !mClauses->IsEmpty() &&
mClauses->LastElement().mEndOffset != mString.Length()) {
NS_WARNING("Sum of length of the all clauses must be same as the string "
"length");
@ -146,20 +155,26 @@ TextEventDispatcher::PendingComposition::Flush(
Clear();
return NS_ERROR_ILLEGAL_VALUE;
}
EnsureClauseArray();
mClauses->AppendElement(mCaret);
}
WidgetCompositionEvent compChangeEvent(true, NS_COMPOSITION_CHANGE, widget);
compChangeEvent.time = PR_IntervalNow();
compChangeEvent.mData = mString;
if (!mClauses->IsEmpty()) {
if (mClauses) {
MOZ_ASSERT(!mClauses->IsEmpty(),
"mClauses must be non-empty array when it's not nullptr");
compChangeEvent.mRanges = mClauses;
}
compChangeEvent.mFlags.mIsSynthesizedForTests = aDispatcher->mForTests;
nsresult rv = widget->DispatchEvent(&compChangeEvent, aStatus);
// While this method dispatches a composition event, some other event handler
// cause more clauses to be added. So, we should clear pending composition
// before dispatching the event.
Clear();
nsresult rv = widget->DispatchEvent(&compChangeEvent, aStatus);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

View File

@ -135,6 +135,8 @@ private:
nsAutoString mString;
nsRefPtr<TextRangeArray> mClauses;
TextRange mCaret;
void EnsureClauseArray();
};
PendingComposition mPendingComposition;