本文整理汇总了C++中VisiblePosition::toParentAnchoredPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ VisiblePosition::toParentAnchoredPosition方法的具体用法?C++ VisiblePosition::toParentAnchoredPosition怎么用?C++ VisiblePosition::toParentAnchoredPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisiblePosition
的用法示例。
在下文中一共展示了VisiblePosition::toParentAnchoredPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findFirstMisspellingOrBadGrammar
String TextCheckingHelper::findFirstMisspellingOrBadGrammar(bool& outIsSpelling, int& outFirstFoundOffset, GrammarDetail& outGrammarDetail)
{
if (!unifiedTextCheckerEnabled())
return "";
String firstFoundItem;
String misspelledWord;
String badGrammarPhrase;
// Initialize out parameters; these will be updated if we find something to return.
outIsSpelling = true;
outFirstFoundOffset = 0;
outGrammarDetail.location = -1;
outGrammarDetail.length = 0;
outGrammarDetail.guesses.clear();
outGrammarDetail.userDescription = "";
// Expand the search range to encompass entire paragraphs, since text checking needs that much context.
// Determine the character offset from the start of the paragraph to the start of the original search range,
// since we will want to ignore results in this area.
Position paragraphStart = startOfParagraph(createVisiblePosition(m_start)).toParentAnchoredPosition();
Position paragraphEnd = m_end;
int totalRangeLength = TextIterator::rangeLength(paragraphStart, paragraphEnd);
paragraphEnd = endOfParagraph(createVisiblePosition(m_start)).toParentAnchoredPosition();
int rangeStartOffset = TextIterator::rangeLength(paragraphStart, m_start);
int totalLengthProcessed = 0;
bool firstIteration = true;
bool lastIteration = false;
while (totalLengthProcessed < totalRangeLength) {
// Iterate through the search range by paragraphs, checking each one for spelling and grammar.
int currentLength = TextIterator::rangeLength(paragraphStart, paragraphEnd);
int currentStartOffset = firstIteration ? rangeStartOffset : 0;
int currentEndOffset = currentLength;
if (inSameParagraph(createVisiblePosition(paragraphStart), createVisiblePosition(m_end))) {
// Determine the character offset from the end of the original search range to the end of the paragraph,
// since we will want to ignore results in this area.
currentEndOffset = TextIterator::rangeLength(paragraphStart, m_end);
lastIteration = true;
}
if (currentStartOffset < currentEndOffset) {
String paragraphString = plainText(EphemeralRange(paragraphStart, paragraphEnd));
if (paragraphString.length() > 0) {
bool foundGrammar = false;
int spellingLocation = 0;
int grammarPhraseLocation = 0;
int grammarDetailLocation = 0;
unsigned grammarDetailIndex = 0;
Vector<TextCheckingResult> results;
TextCheckingTypeMask checkingTypes = TextCheckingTypeSpelling | TextCheckingTypeGrammar;
checkTextOfParagraph(m_client->textChecker(), paragraphString, checkingTypes, results);
for (unsigned i = 0; i < results.size(); i++) {
const TextCheckingResult* result = &results[i];
if (result->decoration == TextDecorationTypeSpelling && result->location >= currentStartOffset && result->location + result->length <= currentEndOffset) {
ASSERT(result->length > 0 && result->location >= 0);
spellingLocation = result->location;
misspelledWord = paragraphString.substring(result->location, result->length);
ASSERT(misspelledWord.length());
break;
}
if (result->decoration == TextDecorationTypeGrammar && result->location < currentEndOffset && result->location + result->length > currentStartOffset) {
ASSERT(result->length > 0 && result->location >= 0);
// We can't stop after the first grammar result, since there might still be a spelling result after
// it begins but before the first detail in it, but we can stop if we find a second grammar result.
if (foundGrammar)
break;
for (unsigned j = 0; j < result->details.size(); j++) {
const GrammarDetail* detail = &result->details[j];
ASSERT(detail->length > 0 && detail->location >= 0);
if (result->location + detail->location >= currentStartOffset && result->location + detail->location + detail->length <= currentEndOffset && (!foundGrammar || result->location + detail->location < grammarDetailLocation)) {
grammarDetailIndex = j;
grammarDetailLocation = result->location + detail->location;
foundGrammar = true;
}
}
if (foundGrammar) {
grammarPhraseLocation = result->location;
outGrammarDetail = result->details[grammarDetailIndex];
badGrammarPhrase = paragraphString.substring(result->location, result->length);
ASSERT(badGrammarPhrase.length());
}
}
}
if (!misspelledWord.isEmpty() && (badGrammarPhrase.isEmpty() || spellingLocation <= grammarDetailLocation)) {
int spellingOffset = spellingLocation - currentStartOffset;
if (!firstIteration)
spellingOffset += TextIterator::rangeLength(m_start, paragraphStart);
outIsSpelling = true;
outFirstFoundOffset = spellingOffset;
firstFoundItem = misspelledWord;
break;
}
if (!badGrammarPhrase.isEmpty()) {
int grammarPhraseOffset = grammarPhraseLocation - currentStartOffset;
if (!firstIteration)
grammarPhraseOffset += TextIterator::rangeLength(m_start, paragraphStart);
//.........这里部分代码省略.........