Bug 308471: Implement NSTextInput -characterIndexForPoint. Credits to mstange for virtually all the work in this patch. r=masayuki

This commit is contained in:
Stephen Pohl 2014-07-29 10:32:40 -04:00
Родитель 47d805ce84
Коммит 1e68ad9c6f
1 изменённых файлов: 23 добавлений и 4 удалений

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

@ -3199,15 +3199,34 @@ IMEInputHandler::FirstRectForCharacterRange(NSRange& aRange,
NSUInteger
IMEInputHandler::CharacterIndexForPoint(NSPoint& aPoint)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p IMEInputHandler::CharacterIndexForPoint, aPoint={ x=%f, y=%f }",
this, aPoint.x, aPoint.y));
//nsRefPtr<IMEInputHandler> kungFuDeathGrip(this);
NSWindow* mainWindow = [NSApp mainWindow];
if (!mWidget || !mainWindow) {
return NSNotFound;
}
// To implement this, we'd have to grovel in text frames looking at text
// offsets.
return 0;
WidgetQueryContentEvent charAt(true, NS_QUERY_CHARACTER_AT_POINT, mWidget);
NSPoint ptInWindow = [mainWindow convertScreenToBase:aPoint];
NSPoint ptInView = [mView convertPoint:ptInWindow fromView:nil];
charAt.refPoint.x =
static_cast<int32_t>(ptInView.x) * mWidget->BackingScaleFactor();
charAt.refPoint.y =
static_cast<int32_t>(ptInView.y) * mWidget->BackingScaleFactor();
mWidget->DispatchWindowEvent(charAt);
if (!charAt.mSucceeded ||
charAt.mReply.mOffset == WidgetQueryContentEvent::NOT_FOUND ||
charAt.mReply.mOffset >= static_cast<uint32_t>(NSNotFound)) {
return NSNotFound;
}
return charAt.mReply.mOffset;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSNotFound);
}
NSArray*