OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 misspelling.replacement = client.getAutoCorrectSuggestionForMisspell
edWord(String(text + misspelling.location, misspelling.length)); | 94 misspelling.replacement = client.getAutoCorrectSuggestionForMisspell
edWord(String(text + misspelling.location, misspelling.length)); |
95 results.append(misspelling); | 95 results.append(misspelling); |
96 } | 96 } |
97 | 97 |
98 wordStart = wordEnd; | 98 wordStart = wordEnd; |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void expandRangeToSentenceBoundary(Range& range) | 102 void expandRangeToSentenceBoundary(Range& range) |
103 { | 103 { |
104 range.setStart(startOfSentence(VisiblePosition(range.startPosition())).deepE
quivalent()); | 104 range.setStart(startOfSentence(createVisiblePosition(range.startPosition()))
.deepEquivalent()); |
105 range.setEnd(endOfSentence(VisiblePosition(range.endPosition())).deepEquival
ent()); | 105 range.setEnd(endOfSentence(createVisiblePosition(range.endPosition())).deepE
quivalent()); |
106 } | 106 } |
107 | 107 |
108 static PassRefPtrWillBeRawPtr<Range> expandToParagraphBoundary(PassRefPtrWillBeR
awPtr<Range> range) | 108 static PassRefPtrWillBeRawPtr<Range> expandToParagraphBoundary(PassRefPtrWillBeR
awPtr<Range> range) |
109 { | 109 { |
110 RefPtrWillBeRawPtr<Range> paragraphRange = range->cloneRange(); | 110 RefPtrWillBeRawPtr<Range> paragraphRange = range->cloneRange(); |
111 paragraphRange->setStart(startOfParagraph(VisiblePosition(range->startPositi
on())).deepEquivalent()); | 111 paragraphRange->setStart(startOfParagraph(createVisiblePosition(range->start
Position())).deepEquivalent()); |
112 paragraphRange->setEnd(endOfParagraph(VisiblePosition(range->endPosition()))
.deepEquivalent()); | 112 paragraphRange->setEnd(endOfParagraph(createVisiblePosition(range->endPositi
on())).deepEquivalent()); |
113 return paragraphRange; | 113 return paragraphRange; |
114 } | 114 } |
115 | 115 |
116 TextCheckingParagraph::TextCheckingParagraph(PassRefPtrWillBeRawPtr<Range> check
ingRange) | 116 TextCheckingParagraph::TextCheckingParagraph(PassRefPtrWillBeRawPtr<Range> check
ingRange) |
117 : m_checkingRange(checkingRange) | 117 : m_checkingRange(checkingRange) |
118 , m_checkingStart(-1) | 118 , m_checkingStart(-1) |
119 , m_checkingEnd(-1) | 119 , m_checkingEnd(-1) |
120 , m_checkingLength(-1) | 120 , m_checkingLength(-1) |
121 { | 121 { |
122 } | 122 } |
123 | 123 |
124 TextCheckingParagraph::TextCheckingParagraph(PassRefPtrWillBeRawPtr<Range> check
ingRange, PassRefPtrWillBeRawPtr<Range> paragraphRange) | 124 TextCheckingParagraph::TextCheckingParagraph(PassRefPtrWillBeRawPtr<Range> check
ingRange, PassRefPtrWillBeRawPtr<Range> paragraphRange) |
125 : m_checkingRange(checkingRange) | 125 : m_checkingRange(checkingRange) |
126 , m_paragraphRange(paragraphRange) | 126 , m_paragraphRange(paragraphRange) |
127 , m_checkingStart(-1) | 127 , m_checkingStart(-1) |
128 , m_checkingEnd(-1) | 128 , m_checkingEnd(-1) |
129 , m_checkingLength(-1) | 129 , m_checkingLength(-1) |
130 { | 130 { |
131 } | 131 } |
132 | 132 |
133 TextCheckingParagraph::~TextCheckingParagraph() | 133 TextCheckingParagraph::~TextCheckingParagraph() |
134 { | 134 { |
135 } | 135 } |
136 | 136 |
137 void TextCheckingParagraph::expandRangeToNextEnd() | 137 void TextCheckingParagraph::expandRangeToNextEnd() |
138 { | 138 { |
139 ASSERT(m_checkingRange); | 139 ASSERT(m_checkingRange); |
140 paragraphRange()->setEnd(endOfParagraph(startOfNextParagraph(VisiblePosition
(paragraphRange()->startPosition()))).deepEquivalent()); | 140 paragraphRange()->setEnd(endOfParagraph(startOfNextParagraph(createVisiblePo
sition(paragraphRange()->startPosition()))).deepEquivalent()); |
141 invalidateParagraphRangeValues(); | 141 invalidateParagraphRangeValues(); |
142 } | 142 } |
143 | 143 |
144 void TextCheckingParagraph::invalidateParagraphRangeValues() | 144 void TextCheckingParagraph::invalidateParagraphRangeValues() |
145 { | 145 { |
146 m_checkingStart = m_checkingEnd = -1; | 146 m_checkingStart = m_checkingEnd = -1; |
147 m_offsetAsRange = nullptr; | 147 m_offsetAsRange = nullptr; |
148 m_text = String(); | 148 m_text = String(); |
149 } | 149 } |
150 | 150 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 outIsSpelling = true; | 306 outIsSpelling = true; |
307 outFirstFoundOffset = 0; | 307 outFirstFoundOffset = 0; |
308 outGrammarDetail.location = -1; | 308 outGrammarDetail.location = -1; |
309 outGrammarDetail.length = 0; | 309 outGrammarDetail.length = 0; |
310 outGrammarDetail.guesses.clear(); | 310 outGrammarDetail.guesses.clear(); |
311 outGrammarDetail.userDescription = ""; | 311 outGrammarDetail.userDescription = ""; |
312 | 312 |
313 // Expand the search range to encompass entire paragraphs, since text checki
ng needs that much context. | 313 // Expand the search range to encompass entire paragraphs, since text checki
ng needs that much context. |
314 // Determine the character offset from the start of the paragraph to the sta
rt of the original search range, | 314 // Determine the character offset from the start of the paragraph to the sta
rt of the original search range, |
315 // since we will want to ignore results in this area. | 315 // since we will want to ignore results in this area. |
316 Position paragraphStart = startOfParagraph(VisiblePosition(m_start)).toParen
tAnchoredPosition(); | 316 Position paragraphStart = startOfParagraph(createVisiblePosition(m_start)).t
oParentAnchoredPosition(); |
317 Position paragraphEnd = m_end; | 317 Position paragraphEnd = m_end; |
318 int totalRangeLength = TextIterator::rangeLength(paragraphStart, paragraphEn
d); | 318 int totalRangeLength = TextIterator::rangeLength(paragraphStart, paragraphEn
d); |
319 paragraphEnd = endOfParagraph(VisiblePosition(m_start)).toParentAnchoredPosi
tion(); | 319 paragraphEnd = endOfParagraph(createVisiblePosition(m_start)).toParentAnchor
edPosition(); |
320 | 320 |
321 int rangeStartOffset = TextIterator::rangeLength(paragraphStart, m_start); | 321 int rangeStartOffset = TextIterator::rangeLength(paragraphStart, m_start); |
322 int totalLengthProcessed = 0; | 322 int totalLengthProcessed = 0; |
323 | 323 |
324 bool firstIteration = true; | 324 bool firstIteration = true; |
325 bool lastIteration = false; | 325 bool lastIteration = false; |
326 while (totalLengthProcessed < totalRangeLength) { | 326 while (totalLengthProcessed < totalRangeLength) { |
327 // Iterate through the search range by paragraphs, checking each one for
spelling and grammar. | 327 // Iterate through the search range by paragraphs, checking each one for
spelling and grammar. |
328 int currentLength = TextIterator::rangeLength(paragraphStart, paragraphE
nd); | 328 int currentLength = TextIterator::rangeLength(paragraphStart, paragraphE
nd); |
329 int currentStartOffset = firstIteration ? rangeStartOffset : 0; | 329 int currentStartOffset = firstIteration ? rangeStartOffset : 0; |
330 int currentEndOffset = currentLength; | 330 int currentEndOffset = currentLength; |
331 if (inSameParagraph(VisiblePosition(paragraphStart), VisiblePosition(m_e
nd))) { | 331 if (inSameParagraph(createVisiblePosition(paragraphStart), createVisible
Position(m_end))) { |
332 // Determine the character offset from the end of the original searc
h range to the end of the paragraph, | 332 // Determine the character offset from the end of the original searc
h range to the end of the paragraph, |
333 // since we will want to ignore results in this area. | 333 // since we will want to ignore results in this area. |
334 currentEndOffset = TextIterator::rangeLength(paragraphStart, m_end); | 334 currentEndOffset = TextIterator::rangeLength(paragraphStart, m_end); |
335 lastIteration = true; | 335 lastIteration = true; |
336 } | 336 } |
337 if (currentStartOffset < currentEndOffset) { | 337 if (currentStartOffset < currentEndOffset) { |
338 String paragraphString = plainText(EphemeralRange(paragraphStart, pa
ragraphEnd)); | 338 String paragraphString = plainText(EphemeralRange(paragraphStart, pa
ragraphEnd)); |
339 if (paragraphString.length() > 0) { | 339 if (paragraphString.length() > 0) { |
340 bool foundGrammar = false; | 340 bool foundGrammar = false; |
341 int spellingLocation = 0; | 341 int spellingLocation = 0; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 grammarPhraseOffset += TextIterator::rangeLength(m_start
, paragraphStart); | 395 grammarPhraseOffset += TextIterator::rangeLength(m_start
, paragraphStart); |
396 outIsSpelling = false; | 396 outIsSpelling = false; |
397 outFirstFoundOffset = grammarPhraseOffset; | 397 outFirstFoundOffset = grammarPhraseOffset; |
398 firstFoundItem = badGrammarPhrase; | 398 firstFoundItem = badGrammarPhrase; |
399 break; | 399 break; |
400 } | 400 } |
401 } | 401 } |
402 } | 402 } |
403 if (lastIteration || totalLengthProcessed + currentLength >= totalRangeL
ength) | 403 if (lastIteration || totalLengthProcessed + currentLength >= totalRangeL
ength) |
404 break; | 404 break; |
405 VisiblePosition newParagraphStart = startOfNextParagraph(VisiblePosition
(paragraphEnd)); | 405 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo
sition(paragraphEnd)); |
406 paragraphStart = newParagraphStart.toParentAnchoredPosition(); | 406 paragraphStart = newParagraphStart.toParentAnchoredPosition(); |
407 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio
n(); | 407 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio
n(); |
408 firstIteration = false; | 408 firstIteration = false; |
409 totalLengthProcessed += currentLength; | 409 totalLengthProcessed += currentLength; |
410 } | 410 } |
411 return firstFoundItem; | 411 return firstFoundItem; |
412 } | 412 } |
413 | 413 |
414 int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& gram
marDetails, int badGrammarPhraseLocation, int startOffset, int endOffset, bool m
arkAll) const | 414 int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& gram
marDetails, int badGrammarPhraseLocation, int startOffset, int endOffset, bool m
arkAll) const |
415 { | 415 { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 return false; | 568 return false; |
569 | 569 |
570 const Settings* settings = frame->settings(); | 570 const Settings* settings = frame->settings(); |
571 if (!settings) | 571 if (!settings) |
572 return false; | 572 return false; |
573 | 573 |
574 return settings->unifiedTextCheckerEnabled(); | 574 return settings->unifiedTextCheckerEnabled(); |
575 } | 575 } |
576 | 576 |
577 } | 577 } |
OLD | NEW |