Chromium Code Reviews| 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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 } | 795 } |
| 796 } | 796 } |
| 797 | 797 |
| 798 void SpellChecker::ReplaceMisspelledRange(const String& text) { | 798 void SpellChecker::ReplaceMisspelledRange(const String& text) { |
| 799 EphemeralRange caret_range = GetFrame() | 799 EphemeralRange caret_range = GetFrame() |
| 800 .Selection() | 800 .Selection() |
| 801 .ComputeVisibleSelectionInDOMTree() | 801 .ComputeVisibleSelectionInDOMTree() |
| 802 .ToNormalizedEphemeralRange(); | 802 .ToNormalizedEphemeralRange(); |
| 803 if (caret_range.IsNull()) | 803 if (caret_range.IsNull()) |
| 804 return; | 804 return; |
| 805 DocumentMarkerVector markers = | 805 |
| 806 GetFrame().GetDocument()->Markers().MarkersInRange( | 806 Node* caret_start_container = |
| 807 caret_range, DocumentMarker::MisspellingMarkers()); | 807 caret_range.StartPosition().ComputeContainerNode(); |
| 808 if (markers.size() < 1 || | 808 const unsigned caret_start_offset = |
| 809 markers[0]->StartOffset() >= markers[0]->EndOffset()) | 809 caret_range.StartPosition().ComputeOffsetInContainerNode(); |
| 810 Node* caret_end_container = caret_range.EndPosition().ComputeContainerNode(); | |
| 811 const unsigned caret_end_offset = | |
| 812 caret_range.EndPosition().ComputeOffsetInContainerNode(); | |
| 813 | |
| 814 Node* found_marker_anchor_node = nullptr; | |
| 815 const DocumentMarker* found_marker = nullptr; | |
| 816 for (Node& node : caret_range.Nodes()) { | |
|
Xiaocheng
2017/05/10 22:54:22
Since we do not plan to support the case where a m
rlanday
2017/05/10 23:17:57
I don't think that's correct; the misspelling coul
Xiaocheng
2017/05/10 23:23:42
1. caret_range has been adjusted by ToNormalizedEp
rlanday
2017/05/10 23:25:43
Ah, OK, I'll change it
| |
| 817 if (found_marker) | |
| 818 break; | |
| 819 | |
| 820 const DocumentMarkerVector& markers_in_node = | |
| 821 GetFrame().GetDocument()->Markers().MarkersFor( | |
| 822 &node, DocumentMarker::MisspellingMarkers()); | |
| 823 for (DocumentMarker* marker : markers_in_node) { | |
| 824 if (&node == caret_start_container && | |
| 825 marker->EndOffset() <= caret_start_offset) | |
| 826 continue; | |
| 827 if (&node == caret_end_container && | |
| 828 marker->StartOffset() >= caret_end_offset) | |
| 829 continue; | |
| 830 | |
| 831 found_marker_anchor_node = &node; | |
| 832 found_marker = markers_in_node[0]; | |
| 833 break; | |
| 834 } | |
| 835 } | |
| 836 | |
| 837 if (!found_marker) | |
| 810 return; | 838 return; |
| 839 | |
| 811 EphemeralRange marker_range = EphemeralRange( | 840 EphemeralRange marker_range = EphemeralRange( |
| 812 Position(caret_range.StartPosition().ComputeContainerNode(), | 841 Position(found_marker_anchor_node, found_marker->StartOffset()), |
|
Xiaocheng
2017/05/10 22:54:22
Note that the existing code doesn't work if the st
| |
| 813 markers[0]->StartOffset()), | 842 Position(found_marker_anchor_node, found_marker->EndOffset())); |
| 814 Position(caret_range.EndPosition().ComputeContainerNode(), | |
| 815 markers[0]->EndOffset())); | |
| 816 if (marker_range.IsNull()) | 843 if (marker_range.IsNull()) |
| 817 return; | 844 return; |
| 818 | 845 |
| 819 GetFrame().Selection().SetSelection( | 846 GetFrame().Selection().SetSelection( |
| 820 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build()); | 847 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build()); |
| 821 | 848 |
| 822 Document& current_document = *GetFrame().GetDocument(); | 849 Document& current_document = *GetFrame().GetDocument(); |
| 823 | 850 |
| 824 // Dispatch 'beforeinput'. | 851 // Dispatch 'beforeinput'. |
| 825 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection(); | 852 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection(); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1198 if (!input.IsFocusedElementInDocument()) | 1225 if (!input.IsFocusedElementInDocument()) |
| 1199 return false; | 1226 return false; |
| 1200 } | 1227 } |
| 1201 } | 1228 } |
| 1202 HTMLElement* element = | 1229 HTMLElement* element = |
| 1203 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); | 1230 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); |
| 1204 return element && element->IsSpellCheckingEnabled(); | 1231 return element && element->IsSpellCheckingEnabled(); |
| 1205 } | 1232 } |
| 1206 | 1233 |
| 1207 } // namespace blink | 1234 } // namespace blink |
| OLD | NEW |