Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp

Issue 2857173003: Remove DocumentMarkerController::MarkersInRange() (Closed)
Patch Set: Use std::find_if() Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 =
yosin_UTC9 2017/05/11 04:36:02 nit: s/Node*/Node* const/
807 caret_range, DocumentMarker::MisspellingMarkers()); 807 caret_range.StartPosition().ComputeContainerNode();
808 if (markers.size() < 1 || 808 Node* caret_end_container = caret_range.EndPosition().ComputeContainerNode();
yosin_UTC9 2017/05/11 04:36:02 nit: s/Node*/Node* const/
809 markers[0]->StartOffset() >= markers[0]->EndOffset()) 809
810 // We don't currently support the case where a misspelling spans multiple
811 // nodes
812 if (caret_start_container != caret_end_container)
810 return; 813 return;
814
815 const unsigned caret_start_offset =
816 caret_range.StartPosition().ComputeOffsetInContainerNode();
817 const unsigned caret_end_offset =
818 caret_range.EndPosition().ComputeOffsetInContainerNode();
819
820 const DocumentMarkerVector& markers_in_node =
821 GetFrame().GetDocument()->Markers().MarkersFor(
822 caret_start_container, DocumentMarker::MisspellingMarkers());
823
824 const auto marker_it =
825 std::find_if(markers_in_node.begin(), markers_in_node.end(),
826 [=](const DocumentMarker* marker) {
827 return marker->StartOffset() < caret_end_offset &&
828 marker->EndOffset() > caret_start_offset;
829 });
830 if (marker_it == markers_in_node.end())
831 return;
832
833 const DocumentMarker* found_marker = *marker_it;
811 EphemeralRange marker_range = EphemeralRange( 834 EphemeralRange marker_range = EphemeralRange(
812 Position(caret_range.StartPosition().ComputeContainerNode(), 835 Position(caret_start_container, found_marker->StartOffset()),
813 markers[0]->StartOffset()), 836 Position(caret_start_container, found_marker->EndOffset()));
814 Position(caret_range.EndPosition().ComputeContainerNode(),
815 markers[0]->EndOffset()));
816 if (marker_range.IsNull()) 837 if (marker_range.IsNull())
817 return; 838 return;
818 839
819 GetFrame().Selection().SetSelection( 840 GetFrame().Selection().SetSelection(
820 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build()); 841 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build());
821 842
822 Document& current_document = *GetFrame().GetDocument(); 843 Document& current_document = *GetFrame().GetDocument();
823 844
824 // Dispatch 'beforeinput'. 845 // Dispatch 'beforeinput'.
825 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection(); 846 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection();
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 if (!input.IsFocusedElementInDocument()) 1219 if (!input.IsFocusedElementInDocument())
1199 return false; 1220 return false;
1200 } 1221 }
1201 } 1222 }
1202 HTMLElement* element = 1223 HTMLElement* element =
1203 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); 1224 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode());
1204 return element && element->IsSpellCheckingEnabled(); 1225 return element && element->IsSpellCheckingEnabled();
1205 } 1226 }
1206 1227
1207 } // namespace blink 1228 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698