| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // The basic approach is to search in two phases - from the selection end to
the end of the doc, and | 167 // The basic approach is to search in two phases - from the selection end to
the end of the doc, and |
| 168 // then we wrap and search from the doc start to (approximately) where we st
arted. | 168 // then we wrap and search from the doc start to (approximately) where we st
arted. |
| 169 | 169 |
| 170 // Start at the end of the selection, search to edge of document. Starting a
t the selection end makes | 170 // Start at the end of the selection, search to edge of document. Starting a
t the selection end makes |
| 171 // repeated "check spelling" commands work. | 171 // repeated "check spelling" commands work. |
| 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().deprecatedNode()) { | 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 = start.previous(); |
| 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 } |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 if (!node) | 462 if (!node) |
| 463 return false; | 463 return false; |
| 464 const Element* focusedElement = node->isElementNode() ? toElement(node) : no
de->parentElement(); | 464 const Element* focusedElement = node->isElementNode() ? toElement(node) : no
de->parentElement(); |
| 465 if (!focusedElement) | 465 if (!focusedElement) |
| 466 return false; | 466 return false; |
| 467 return focusedElement->isSpellCheckingEnabled(); | 467 return focusedElement->isSpellCheckingEnabled(); |
| 468 } | 468 } |
| 469 | 469 |
| 470 bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const | 470 bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const |
| 471 { | 471 { |
| 472 return isSpellCheckingEnabledFor(frame().selection().start().deprecatedNode(
)); | 472 return isSpellCheckingEnabledFor(frame().selection().start().anchorNode()); |
| 473 } | 473 } |
| 474 | 474 |
| 475 void SpellChecker::markMisspellings(const VisibleSelection& selection, RefPtrWil
lBeRawPtr<Range>& firstMisspellingRange) | 475 void SpellChecker::markMisspellings(const VisibleSelection& selection, RefPtrWil
lBeRawPtr<Range>& firstMisspellingRange) |
| 476 { | 476 { |
| 477 markMisspellingsOrBadGrammar(selection, true, firstMisspellingRange); | 477 markMisspellingsOrBadGrammar(selection, true, firstMisspellingRange); |
| 478 } | 478 } |
| 479 | 479 |
| 480 void SpellChecker::markBadGrammar(const VisibleSelection& selection) | 480 void SpellChecker::markBadGrammar(const VisibleSelection& selection) |
| 481 { | 481 { |
| 482 RefPtrWillBeRawPtr<Range> firstMisspellingRange = nullptr; | 482 RefPtrWillBeRawPtr<Range> firstMisspellingRange = nullptr; |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 } | 865 } |
| 866 | 866 |
| 867 static Node* findFirstMarkable(Node* node) | 867 static Node* findFirstMarkable(Node* node) |
| 868 { | 868 { |
| 869 while (node) { | 869 while (node) { |
| 870 if (!node->layoutObject()) | 870 if (!node->layoutObject()) |
| 871 return 0; | 871 return 0; |
| 872 if (node->layoutObject()->isText()) | 872 if (node->layoutObject()->isText()) |
| 873 return node; | 873 return node; |
| 874 if (node->layoutObject()->isTextControl()) | 874 if (node->layoutObject()->isTextControl()) |
| 875 node = toLayoutTextControl(node->layoutObject())->textFormControlEle
ment()->visiblePositionForIndex(1).deepEquivalent().deprecatedNode(); | 875 node = toLayoutTextControl(node->layoutObject())->textFormControlEle
ment()->visiblePositionForIndex(1).deepEquivalent().anchorNode(); |
| 876 else if (node->hasChildren()) | 876 else if (node->hasChildren()) |
| 877 node = node->firstChild(); | 877 node = node->firstChild(); |
| 878 else | 878 else |
| 879 node = node->nextSibling(); | 879 node = node->nextSibling(); |
| 880 } | 880 } |
| 881 | 881 |
| 882 return 0; | 882 return 0; |
| 883 } | 883 } |
| 884 | 884 |
| 885 bool SpellChecker::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerT
ype, int from, int length) const | 885 bool SpellChecker::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerT
ype, int from, int length) const |
| 886 { | 886 { |
| 887 Node* node = findFirstMarkable(frame().selection().start().deprecatedNode())
; | 887 Node* node = findFirstMarkable(frame().selection().start().anchorNode()); |
| 888 if (!node) | 888 if (!node) |
| 889 return false; | 889 return false; |
| 890 | 890 |
| 891 unsigned startOffset = static_cast<unsigned>(from); | 891 unsigned startOffset = static_cast<unsigned>(from); |
| 892 unsigned endOffset = static_cast<unsigned>(from + length); | 892 unsigned endOffset = static_cast<unsigned>(from + length); |
| 893 DocumentMarkerVector markers = frame().document()->markers().markersFor(node
); | 893 DocumentMarkerVector markers = frame().document()->markers().markersFor(node
); |
| 894 for (size_t i = 0; i < markers.size(); ++i) { | 894 for (size_t i = 0; i < markers.size(); ++i) { |
| 895 DocumentMarker* marker = markers[i]; | 895 DocumentMarker* marker = markers[i]; |
| 896 if (marker->startOffset() <= startOffset && endOffset <= marker->endOffs
et() && marker->type() == markerType) | 896 if (marker->startOffset() <= startOffset && endOffset <= marker->endOffs
et() && marker->type() == markerType) |
| 897 return true; | 897 return true; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec
kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe
ck, rangeToCheck)); | 944 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec
kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe
ck, rangeToCheck)); |
| 945 } | 945 } |
| 946 | 946 |
| 947 DEFINE_TRACE(SpellChecker) | 947 DEFINE_TRACE(SpellChecker) |
| 948 { | 948 { |
| 949 visitor->trace(m_frame); | 949 visitor->trace(m_frame); |
| 950 visitor->trace(m_spellCheckRequester); | 950 visitor->trace(m_spellCheckRequester); |
| 951 } | 951 } |
| 952 | 952 |
| 953 } // namespace blink | 953 } // namespace blink |
| OLD | NEW |