Bug 1275528 part.2 IMEContentObserver should use selection cache for computing absolute offset of WidgetQueryContentEvent if it's possible r=smaug

IMEContentObserver may have cache of normal selection.  If it's available, IMEContentObserver should use it for computing absolute offset of WidgetQueryContentEvent whose mInput::mOffset is relative offset to selection.

This patch just improves the performance of such query.

MozReview-Commit-ID: KHLgCc2uQzs

--HG--
extra : rebase_source : 1367aee0aadb88258135690aa5a8591201129c27
This commit is contained in:
Masayuki Nakano 2016-06-20 15:57:38 +09:00
Родитель 60bb642e47
Коммит 0cf2d4de5f
1 изменённых файлов: 32 добавлений и 3 удалений

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

@ -708,9 +708,12 @@ IMEContentObserver::HandleQueryContentEvent(WidgetQueryContentEvent* aEvent)
// value. Note that don't update selection cache here since if you update
// selection cache here, IMENotificationSender won't notify IME of selection
// change because it looks like that the selection isn't actually changed.
if (aEvent->mMessage == eQuerySelectedText && aEvent->mUseNativeLineBreak &&
aEvent->mInput.mSelectionType == SelectionType::eNormal &&
mSelectionData.IsValid() && !mNeedsToNotifyIMEOfSelectionChange) {
bool isSelectionCacheAvailable =
aEvent->mUseNativeLineBreak && mSelectionData.IsValid() &&
!mNeedsToNotifyIMEOfSelectionChange;
if (isSelectionCacheAvailable &&
aEvent->mMessage == eQuerySelectedText &&
aEvent->mInput.mSelectionType == SelectionType::eNormal) {
aEvent->mReply.mContentsRoot = mRootContent;
aEvent->mReply.mHasSelection = !mSelectionData.IsCollapsed();
aEvent->mReply.mOffset = mSelectionData.mOffset;
@ -728,6 +731,32 @@ IMEContentObserver::HandleQueryContentEvent(WidgetQueryContentEvent* aEvent)
("IMECO: 0x%p IMEContentObserver::HandleQueryContentEvent(aEvent={ "
"mMessage=%s })", this, ToChar(aEvent->mMessage)));
// If we can make the event's input offset absolute with TextComposition or
// mSelection, we should set it here for reducing the cost of computing
// selection start offset. If ContentEventHandler receives a
// WidgetQueryContentEvent whose input offset is relative to insertion point,
// it computes current selection start offset (this may be expensive) and
// make the offset absolute value itself.
// Note that calling MakeOffsetAbsolute() makes the event a query event with
// absolute offset. So, ContentEventHandler doesn't pay any additional cost
// after calling MakeOffsetAbsolute() here.
if (aEvent->mInput.mRelativeToInsertionPoint &&
aEvent->mInput.IsValidEventMessage(aEvent->mMessage)) {
RefPtr<TextComposition> composition =
IMEStateManager::GetTextCompositionFor(aEvent->mWidget);
if (composition) {
uint32_t compositionStart = composition->NativeOffsetOfStartComposition();
if (NS_WARN_IF(!aEvent->mInput.MakeOffsetAbsolute(compositionStart))) {
return NS_ERROR_FAILURE;
}
} else if (isSelectionCacheAvailable) {
uint32_t selectionStart = mSelectionData.mOffset;
if (NS_WARN_IF(!aEvent->mInput.MakeOffsetAbsolute(selectionStart))) {
return NS_ERROR_FAILURE;
}
}
}
AutoRestore<bool> handling(mIsHandlingQueryContentEvent);
mIsHandlingQueryContentEvent = true;
ContentEventHandler handler(GetPresContext());