| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 VisibleSelection selection(frame().selection().selection()); | 172 VisibleSelection selection(frame().selection().selection()); |
| 173 Position spellingSearchStart, spellingSearchEnd; | 173 Position spellingSearchStart, spellingSearchEnd; |
| 174 Range::selectNodeContents(frame().document(), spellingSearchStart, spellingS
earchEnd); | 174 Range::selectNodeContents(frame().document(), spellingSearchStart, spellingS
earchEnd); |
| 175 | 175 |
| 176 bool startedWithSelection = false; | 176 bool startedWithSelection = false; |
| 177 if (selection.start().anchorNode()) { | 177 if (selection.start().anchorNode()) { |
| 178 startedWithSelection = true; | 178 startedWithSelection = true; |
| 179 if (startBeforeSelection) { | 179 if (startBeforeSelection) { |
| 180 VisiblePosition start(selection.visibleStart()); | 180 VisiblePosition start(selection.visibleStart()); |
| 181 // We match AppKit's rule: Start 1 character before the selection. | 181 // We match AppKit's rule: Start 1 character before the selection. |
| 182 VisiblePosition oneBeforeStart = start.previous(); | 182 VisiblePosition oneBeforeStart = previousPositionOf(start); |
| 183 spellingSearchStart = (oneBeforeStart.isNotNull() ? oneBeforeStart :
start).toParentAnchoredPosition(); | 183 spellingSearchStart = (oneBeforeStart.isNotNull() ? oneBeforeStart :
start).toParentAnchoredPosition(); |
| 184 } else { | 184 } else { |
| 185 spellingSearchStart = selection.visibleEnd().toParentAnchoredPositio
n(); | 185 spellingSearchStart = selection.visibleEnd().toParentAnchoredPositio
n(); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 Position position = spellingSearchStart; | 189 Position position = spellingSearchStart; |
| 190 if (!isEditablePosition(position)) { | 190 if (!isEditablePosition(position)) { |
| 191 // This shouldn't happen in very often because the Spelling menu items a
ren't enabled unless the | 191 // This shouldn't happen in very often because the Spelling menu items a
ren't enabled unless the |
| 192 // selection is editable. | 192 // selection is editable. |
| 193 // This can happen in Mail for a mix of non-editable and editable conten
t (like Stationary), | 193 // This can happen in Mail for a mix of non-editable and editable conten
t (like Stationary), |
| 194 // when spell checking the whole document before sending the message. | 194 // when spell checking the whole document before sending the message. |
| 195 // In that case the document might not be editable, but there are editab
le pockets that need to be spell checked. | 195 // In that case the document might not be editable, but there are editab
le pockets that need to be spell checked. |
| 196 | 196 |
| 197 position = firstEditableVisiblePositionAfterPositionInRoot(position, fra
me().document()->documentElement()).deepEquivalent(); | 197 position = firstEditableVisiblePositionAfterPositionInRoot(position, fra
me().document()->documentElement()).deepEquivalent(); |
| 198 if (position.isNull()) | 198 if (position.isNull()) |
| 199 return; | 199 return; |
| 200 | 200 |
| 201 spellingSearchStart = position.parentAnchoredEquivalent(); | 201 spellingSearchStart = position.parentAnchoredEquivalent(); |
| 202 startedWithSelection = false; // won't need to wrap | 202 startedWithSelection = false; // won't need to wrap |
| 203 } | 203 } |
| 204 | 204 |
| 205 // topNode defines the whole range we want to operate on | 205 // topNode defines the whole range we want to operate on |
| 206 ContainerNode* topNode = highestEditableRoot(position); | 206 ContainerNode* topNode = highestEditableRoot(position); |
| 207 // TODO(yosin): |lastOffsetForEditing()| is wrong here if | 207 // TODO(yosin): |lastOffsetForEditing()| is wrong here if |
| 208 // |editingIgnoresContent(highestEditableRoot())| returns true, e.g. <table> | 208 // |editingIgnoresContent(highestEditableRoot())| returns true, e.g. <table> |
| 209 spellingSearchEnd = Position::editingPositionOf(topNode, EditingStrategy::la
stOffsetForEditing(topNode)); | 209 spellingSearchEnd = Position::editingPositionOf(topNode, EditingStrategy::la
stOffsetForEditing(topNode)); |
| 210 | 210 |
| 211 // If spellingSearchRange starts in the middle of a word, advance to the nex
t word so we start checking | 211 // If spellingSearchRange starts in the middle of a word, advance to the |
| 212 // at a word boundary. Going back by one char and then forward by a word doe
s the trick. | 212 // next word so we start checking at a word boundary. Going back by one char |
| 213 // and then forward by a word does the trick. |
| 213 if (startedWithSelection) { | 214 if (startedWithSelection) { |
| 214 VisiblePosition oneBeforeStart = VisiblePosition(spellingSearchStart).previo
us(); | 215 VisiblePosition oneBeforeStart = previousPositionOf(VisiblePosition(spelling
SearchStart)); |
| 215 if (oneBeforeStart.isNotNull()) | 216 if (oneBeforeStart.isNotNull()) |
| 216 spellingSearchStart = endOfWord(oneBeforeStart).toParentAnchoredPosi
tion(); | 217 spellingSearchStart = endOfWord(oneBeforeStart).toParentAnchoredPosi
tion(); |
| 217 // else we were already at the start of the editable node | 218 // else we were already at the start of the editable node |
| 218 } | 219 } |
| 219 | 220 |
| 220 if (spellingSearchStart == spellingSearchEnd) | 221 if (spellingSearchStart == spellingSearchEnd) |
| 221 return; // nothing to search in | 222 return; // nothing to search in |
| 222 | 223 |
| 223 // We go to the end of our first range instead of the start of it, just to b
e sure | 224 // We go to the end of our first range instead of the start of it, just to b
e sure |
| 224 // we don't get foiled by any word boundary problems at the start. It means
we might | 225 // we don't get foiled by any word boundary problems at the start. It means
we might |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec
kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe
ck, rangeToCheck)); | 938 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec
kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe
ck, rangeToCheck)); |
| 938 } | 939 } |
| 939 | 940 |
| 940 DEFINE_TRACE(SpellChecker) | 941 DEFINE_TRACE(SpellChecker) |
| 941 { | 942 { |
| 942 visitor->trace(m_frame); | 943 visitor->trace(m_frame); |
| 943 visitor->trace(m_spellCheckRequester); | 944 visitor->trace(m_spellCheckRequester); |
| 944 } | 945 } |
| 945 | 946 |
| 946 } // namespace blink | 947 } // namespace blink |
| OLD | NEW |