Bug 875674 part.5 Implement attributedSubstringForProposedRange:actualRange: of NSTextInputClient r=roc+smichaud

This commit is contained in:
Masayuki Nakano 2013-07-11 16:46:35 +09:00
parent 6ab28ab804
commit 146b45259e
5 changed files with 34 additions and 8 deletions

View File

@ -529,7 +529,8 @@ nsContentEventHandler::OnQueryTextContent(nsQueryContentEvent* aEvent)
nsRefPtr<nsRange> range = new nsRange(mRootContent);
rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset,
aEvent->mInput.mLength, false);
aEvent->mInput.mLength, false,
&aEvent->mReply.mOffset);
NS_ENSURE_SUCCESS(rv, rv);
rv = GenerateFlatTextContent(range, aEvent->mReply.mString);

View File

@ -850,12 +850,15 @@ public:
* which is allocated as autorelease for aRange.
*
* @param aRange The range of string which you want.
* @param aActualRange The actual range of the result.
* @return The string in aRange. If the string is empty,
* this returns nil. If succeeded, this returns
* an instance which is allocated as autorelease.
* If this has some troubles, returns nil.
*/
NSAttributedString* GetAttributedSubstringFromRange(NSRange& aRange);
NSAttributedString* GetAttributedSubstringFromRange(
NSRange& aRange,
NSRange* aActualRange = nullptr);
/**
* SelectedRange() returns current selected range.

View File

@ -2781,14 +2781,20 @@ IMEInputHandler::ConversationIdentifier()
}
NSAttributedString*
IMEInputHandler::GetAttributedSubstringFromRange(NSRange& aRange)
IMEInputHandler::GetAttributedSubstringFromRange(NSRange& aRange,
NSRange* aActualRange)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p IMEInputHandler::GetAttributedSubstringFromRange, "
"aRange={ location=%llu, length=%llu }, Destroyed()=%s",
this, aRange.location, aRange.length, TrueOrFalse(Destroyed())));
"aRange={ location=%llu, length=%llu }, aActualRange=%p, Destroyed()=%s",
this, aRange.location, aRange.length, aActualRange,
TrueOrFalse(Destroyed())));
if (aActualRange) {
*aActualRange = NSMakeRange(NSNotFound, 0);
}
if (Destroyed() || aRange.location == NSNotFound || aRange.length == 0) {
return nil;
@ -2803,11 +2809,12 @@ IMEInputHandler::GetAttributedSubstringFromRange(NSRange& aRange)
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p IMEInputHandler::GetAttributedSubstringFromRange, "
"textContent={ mSucceeded=%s, mReply.mString=\"%s\"",
"textContent={ mSucceeded=%s, mReply={ mString=\"%s\", mOffset=%llu } }",
this, TrueOrFalse(textContent.mSucceeded),
NS_ConvertUTF16toUTF8(textContent.mReply.mString).get()));
NS_ConvertUTF16toUTF8(textContent.mReply.mString).get(),
textContent.mReply.mOffset));
if (!textContent.mSucceeded || textContent.mReply.mString.IsEmpty()) {
if (!textContent.mSucceeded) {
return nil;
}
@ -2815,6 +2822,10 @@ IMEInputHandler::GetAttributedSubstringFromRange(NSRange& aRange)
NSAttributedString* result =
[[[NSAttributedString alloc] initWithString:nsstr
attributes:nil] autorelease];
if (aActualRange) {
aActualRange->location = textContent.mReply.mOffset;
aActualRange->length = textContent.mReply.mString.Length();
}
return result;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;

View File

@ -5095,6 +5095,14 @@ static int32_t RoundUp(double aDouble)
#pragma mark -
// NSTextInputClient implementation
- (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)aRange
actualRange:(NSRangePointer)actualRange
{
NS_ENSURE_TRUE(mTextInputHandler, nil);
return mTextInputHandler->GetAttributedSubstringFromRange(aRange,
actualRange);
}
- (NSRect)firstRectForCharacterRange:(NSRange)aRange
actualRange:(NSRangePointer)actualRange
{

View File

@ -359,6 +359,9 @@ nsCocoaUtils::GetStringForNSString(const NSString *aSrc, nsAString& aDist)
NSString*
nsCocoaUtils::ToNSString(const nsAString& aString)
{
if (aString.IsEmpty()) {
return [NSString string];
}
return [NSString stringWithCharacters:aString.BeginReading()
length:aString.Length()];
}