OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sele
ction.start().anchorNode())) { | 89 if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sele
ction.start().anchorNode())) { |
90 if (element->isSpellCheckingEnabled()) | 90 if (element->isSpellCheckingEnabled()) |
91 return true; | 91 return true; |
92 } | 92 } |
93 return false; | 93 return false; |
94 } | 94 } |
95 | 95 |
96 static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) | 96 static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) |
97 { | 97 { |
98 DCHECK(range.isNotNull()); | 98 DCHECK(range.isNotNull()); |
99 const VisiblePosition& visibleEnd = createVisiblePosition(range.endPosition(
)); | 99 const VisiblePosition& visibleEnd = createVisiblePositionDeprecated(range.en
dPosition()); |
100 DCHECK(visibleEnd.isNotNull()); | 100 DCHECK(visibleEnd.isNotNull()); |
101 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent(); | 101 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent(); |
102 // TODO(xiaochengh): |sentenceEnd < range.endPosition()| is possible, | 102 // TODO(xiaochengh): |sentenceEnd < range.endPosition()| is possible, |
103 // which would trigger a DCHECK in EphemeralRange's constructor if we return | 103 // which would trigger a DCHECK in EphemeralRange's constructor if we return |
104 // it directly. However, this shouldn't happen and needs to be fixed. | 104 // it directly. However, this shouldn't happen and needs to be fixed. |
105 return EphemeralRange(range.startPosition(), sentenceEnd.isNotNull() && sent
enceEnd > range.endPosition() ? sentenceEnd : range.endPosition()); | 105 return EphemeralRange(range.startPosition(), sentenceEnd.isNotNull() && sent
enceEnd > range.endPosition() ? sentenceEnd : range.endPosition()); |
106 } | 106 } |
107 | 107 |
108 static EphemeralRange expandRangeToSentenceBoundary(const EphemeralRange& range) | 108 static EphemeralRange expandRangeToSentenceBoundary(const EphemeralRange& range) |
109 { | 109 { |
110 DCHECK(range.isNotNull()); | 110 DCHECK(range.isNotNull()); |
111 const VisiblePosition& visibleStart = createVisiblePosition(range.startPosit
ion()); | 111 const VisiblePosition& visibleStart = createVisiblePositionDeprecated(range.
startPosition()); |
112 DCHECK(visibleStart.isNotNull()); | 112 DCHECK(visibleStart.isNotNull()); |
113 const Position& sentenceStart = startOfSentence(visibleStart).deepEquivalent
(); | 113 const Position& sentenceStart = startOfSentence(visibleStart).deepEquivalent
(); |
114 // TODO(xiaochengh): |sentenceStart > range.startPosition()| is possible, | 114 // TODO(xiaochengh): |sentenceStart > range.startPosition()| is possible, |
115 // which would trigger a DCHECK in EphemeralRange's constructor if we return | 115 // which would trigger a DCHECK in EphemeralRange's constructor if we return |
116 // it directly. However, this shouldn't happen and needs to be fixed. | 116 // it directly. However, this shouldn't happen and needs to be fixed. |
117 return expandEndToSentenceBoundary(EphemeralRange(sentenceStart.isNotNull()
&& sentenceStart < range.startPosition() ? sentenceStart : range.startPosition()
, range.endPosition())); | 117 return expandEndToSentenceBoundary(EphemeralRange(sentenceStart.isNotNull()
&& sentenceStart < range.startPosition() ? sentenceStart : range.startPosition()
, range.endPosition())); |
118 } | 118 } |
119 | 119 |
120 } // namespace | 120 } // namespace |
121 | 121 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 // topNode defines the whole range we want to operate on | 257 // topNode defines the whole range we want to operate on |
258 ContainerNode* topNode = highestEditableRoot(position); | 258 ContainerNode* topNode = highestEditableRoot(position); |
259 // TODO(yosin): |lastOffsetForEditing()| is wrong here if | 259 // TODO(yosin): |lastOffsetForEditing()| is wrong here if |
260 // |editingIgnoresContent(highestEditableRoot())| returns true, e.g. <table> | 260 // |editingIgnoresContent(highestEditableRoot())| returns true, e.g. <table> |
261 spellingSearchEnd = Position::editingPositionOf(topNode, EditingStrategy::la
stOffsetForEditing(topNode)); | 261 spellingSearchEnd = Position::editingPositionOf(topNode, EditingStrategy::la
stOffsetForEditing(topNode)); |
262 | 262 |
263 // If spellingSearchRange starts in the middle of a word, advance to the | 263 // If spellingSearchRange starts in the middle of a word, advance to the |
264 // next word so we start checking at a word boundary. Going back by one char | 264 // next word so we start checking at a word boundary. Going back by one char |
265 // and then forward by a word does the trick. | 265 // and then forward by a word does the trick. |
266 if (startedWithSelection) { | 266 if (startedWithSelection) { |
267 VisiblePosition oneBeforeStart = previousPositionOf(createVisiblePositio
n(spellingSearchStart)); | 267 VisiblePosition oneBeforeStart = previousPositionOf(createVisiblePositio
nDeprecated(spellingSearchStart)); |
268 if (oneBeforeStart.isNotNull() && rootEditableElementOf(oneBeforeStart)
== rootEditableElementOf(spellingSearchStart)) | 268 if (oneBeforeStart.isNotNull() && rootEditableElementOf(oneBeforeStart)
== rootEditableElementOf(spellingSearchStart)) |
269 spellingSearchStart = endOfWord(oneBeforeStart).toParentAnchoredPosi
tion(); | 269 spellingSearchStart = endOfWord(oneBeforeStart).toParentAnchoredPosi
tion(); |
270 // else we were already at the start of the editable node | 270 // else we were already at the start of the editable node |
271 } | 271 } |
272 | 272 |
273 if (spellingSearchStart == spellingSearchEnd) | 273 if (spellingSearchStart == spellingSearchEnd) |
274 return; // nothing to search in | 274 return; // nothing to search in |
275 | 275 |
276 // We go to the end of our first range instead of the start of it, just to b
e sure | 276 // We go to the end of our first range instead of the start of it, just to b
e sure |
277 // we don't get foiled by any word boundary problems at the start. It means
we might | 277 // we don't get foiled by any word boundary problems at the start. It means
we might |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 380 } |
381 | 381 |
382 void SpellChecker::markMisspellingsAfterTypingCommand(const TypingCommand& cmd) | 382 void SpellChecker::markMisspellingsAfterTypingCommand(const TypingCommand& cmd) |
383 { | 383 { |
384 m_spellCheckRequester->cancelCheck(); | 384 m_spellCheckRequester->cancelCheck(); |
385 | 385 |
386 // Take a look at the selection that results after typing and determine whet
her we need to spellcheck. | 386 // Take a look at the selection that results after typing and determine whet
her we need to spellcheck. |
387 // Since the word containing the current selection is never marked, this doe
s a check to | 387 // Since the word containing the current selection is never marked, this doe
s a check to |
388 // see if typing made a new word that is not in the current selection. Basic
ally, you | 388 // see if typing made a new word that is not in the current selection. Basic
ally, you |
389 // get this by being at the end of a word and typing a space. | 389 // get this by being at the end of a word and typing a space. |
390 VisiblePosition start = createVisiblePosition(cmd.endingSelection().start(),
cmd.endingSelection().affinity()); | 390 VisiblePosition start = createVisiblePositionDeprecated(cmd.endingSelection(
).start(), cmd.endingSelection().affinity()); |
391 VisiblePosition previous = previousPositionOf(start); | 391 VisiblePosition previous = previousPositionOf(start); |
392 | 392 |
393 VisiblePosition wordStartOfPrevious = startOfWord(previous, LeftWordIfOnBoun
dary); | 393 VisiblePosition wordStartOfPrevious = startOfWord(previous, LeftWordIfOnBoun
dary); |
394 | 394 |
395 if (cmd.commandTypeOfOpenCommand() == TypingCommand::InsertParagraphSeparato
r) { | 395 if (cmd.commandTypeOfOpenCommand() == TypingCommand::InsertParagraphSeparato
r) { |
396 VisiblePosition nextWord = nextWordPosition(start); | 396 VisiblePosition nextWord = nextWordPosition(start); |
397 VisibleSelection words(wordStartOfPrevious, endOfWord(nextWord)); | 397 VisibleSelection words(wordStartOfPrevious, endOfWord(nextWord)); |
398 markMisspellingsAfterLineBreak(words); | 398 markMisspellingsAfterLineBreak(words); |
399 return; | 399 return; |
400 } | 400 } |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 { | 938 { |
939 String misspelledWord; | 939 String misspelledWord; |
940 | 940 |
941 // Initialize out parameters; they will be updated if we find something to r
eturn. | 941 // Initialize out parameters; they will be updated if we find something to r
eturn. |
942 String firstFoundItem; | 942 String firstFoundItem; |
943 int firstFoundOffset = 0; | 943 int firstFoundOffset = 0; |
944 | 944 |
945 // Expand the search range to encompass entire paragraphs, since text checki
ng needs that much context. | 945 // Expand the search range to encompass entire paragraphs, since text checki
ng needs that much context. |
946 // Determine the character offset from the start of the paragraph to the sta
rt of the original search range, | 946 // Determine the character offset from the start of the paragraph to the sta
rt of the original search range, |
947 // since we will want to ignore results in this area. | 947 // since we will want to ignore results in this area. |
948 Position paragraphStart = startOfParagraph(createVisiblePosition(start)).toP
arentAnchoredPosition(); | 948 Position paragraphStart = startOfParagraph(createVisiblePositionDeprecated(s
tart)).toParentAnchoredPosition(); |
949 Position paragraphEnd = end; | 949 Position paragraphEnd = end; |
950 int totalRangeLength = TextIterator::rangeLength(paragraphStart, paragraphEn
d); | 950 int totalRangeLength = TextIterator::rangeLength(paragraphStart, paragraphEn
d); |
951 paragraphEnd = endOfParagraph(createVisiblePosition(start)).toParentAnchored
Position(); | 951 paragraphEnd = endOfParagraph(createVisiblePositionDeprecated(start)).toPare
ntAnchoredPosition(); |
952 | 952 |
953 int rangeStartOffset = TextIterator::rangeLength(paragraphStart, start); | 953 int rangeStartOffset = TextIterator::rangeLength(paragraphStart, start); |
954 int totalLengthProcessed = 0; | 954 int totalLengthProcessed = 0; |
955 | 955 |
956 bool firstIteration = true; | 956 bool firstIteration = true; |
957 bool lastIteration = false; | 957 bool lastIteration = false; |
958 while (totalLengthProcessed < totalRangeLength) { | 958 while (totalLengthProcessed < totalRangeLength) { |
959 // Iterate through the search range by paragraphs, checking each one for
spelling. | 959 // Iterate through the search range by paragraphs, checking each one for
spelling. |
960 int currentLength = TextIterator::rangeLength(paragraphStart, paragraphE
nd); | 960 int currentLength = TextIterator::rangeLength(paragraphStart, paragraphE
nd); |
961 int currentStartOffset = firstIteration ? rangeStartOffset : 0; | 961 int currentStartOffset = firstIteration ? rangeStartOffset : 0; |
962 int currentEndOffset = currentLength; | 962 int currentEndOffset = currentLength; |
963 if (inSameParagraph(createVisiblePosition(paragraphStart), createVisible
Position(end))) { | 963 if (inSameParagraph(createVisiblePositionDeprecated(paragraphStart), cre
ateVisiblePositionDeprecated(end))) { |
964 // Determine the character offset from the end of the original searc
h range to the end of the paragraph, | 964 // Determine the character offset from the end of the original searc
h range to the end of the paragraph, |
965 // since we will want to ignore results in this area. | 965 // since we will want to ignore results in this area. |
966 currentEndOffset = TextIterator::rangeLength(paragraphStart, end); | 966 currentEndOffset = TextIterator::rangeLength(paragraphStart, end); |
967 lastIteration = true; | 967 lastIteration = true; |
968 } | 968 } |
969 if (currentStartOffset < currentEndOffset) { | 969 if (currentStartOffset < currentEndOffset) { |
970 String paragraphString = plainText(EphemeralRange(paragraphStart, pa
ragraphEnd)); | 970 String paragraphString = plainText(EphemeralRange(paragraphStart, pa
ragraphEnd)); |
971 if (paragraphString.length() > 0) { | 971 if (paragraphString.length() > 0) { |
972 int spellingLocation = 0; | 972 int spellingLocation = 0; |
973 | 973 |
(...skipping 16 matching lines...) Expand all Loading... |
990 if (!firstIteration) | 990 if (!firstIteration) |
991 spellingOffset += TextIterator::rangeLength(start, parag
raphStart); | 991 spellingOffset += TextIterator::rangeLength(start, parag
raphStart); |
992 firstFoundOffset = spellingOffset; | 992 firstFoundOffset = spellingOffset; |
993 firstFoundItem = misspelledWord; | 993 firstFoundItem = misspelledWord; |
994 break; | 994 break; |
995 } | 995 } |
996 } | 996 } |
997 } | 997 } |
998 if (lastIteration || totalLengthProcessed + currentLength >= totalRangeL
ength) | 998 if (lastIteration || totalLengthProcessed + currentLength >= totalRangeL
ength) |
999 break; | 999 break; |
1000 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo
sition(paragraphEnd)); | 1000 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo
sitionDeprecated(paragraphEnd)); |
1001 paragraphStart = newParagraphStart.toParentAnchoredPosition(); | 1001 paragraphStart = newParagraphStart.toParentAnchoredPosition(); |
1002 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio
n(); | 1002 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio
n(); |
1003 firstIteration = false; | 1003 firstIteration = false; |
1004 totalLengthProcessed += currentLength; | 1004 totalLengthProcessed += currentLength; |
1005 } | 1005 } |
1006 return std::make_pair(firstFoundItem, firstFoundOffset); | 1006 return std::make_pair(firstFoundItem, firstFoundOffset); |
1007 } | 1007 } |
1008 | 1008 |
1009 } // namespace blink | 1009 } // namespace blink |
OLD | NEW |