mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 875674 part.5 Implement attributedSubstringForProposedRange:actualRange: of NSTextInputClient r=roc+smichaud
This commit is contained in:
parent
6ab28ab804
commit
146b45259e
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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()];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user