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

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

Issue 2857173003: Remove DocumentMarkerController::MarkersInRange() (Closed)
Patch Set: Simplify unnecessarily complicated logic 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 // We don't currently support the case where a misspelling spans multiple
807 caret_range, DocumentMarker::MisspellingMarkers()); 807 // nodes, so we assume this is the same as caret_end_container
808 if (markers.size() < 1 || 808 Node* caret_start_container =
Xiaocheng 2017/05/10 23:55:15 We should return if |caret_end_container != caret_
809 markers[0]->StartOffset() >= markers[0]->EndOffset()) 809 caret_range.StartPosition().ComputeContainerNode();
810 const unsigned caret_start_offset =
811 caret_range.StartPosition().ComputeOffsetInContainerNode();
812 const unsigned caret_end_offset =
813 caret_range.EndPosition().ComputeOffsetInContainerNode();
814
815 const DocumentMarker* found_marker = nullptr;
816 const DocumentMarkerVector& markers_in_node =
Xiaocheng 2017/05/10 23:55:15 This chunk of code is still duplicated with that i
yosin_UTC9 2017/05/11 01:03:41 I prefer std::find_if() to reduce # of API in DMC.
817 GetFrame().GetDocument()->Markers().MarkersFor(
818 caret_start_container, DocumentMarker::MisspellingMarkers());
819 for (DocumentMarker* marker : markers_in_node) {
820 if (marker->EndOffset() <= caret_start_offset)
821 continue;
822 if (marker->StartOffset() >= caret_end_offset)
823 continue;
824
825 found_marker = marker;
826 break;
827 }
828
829 if (!found_marker)
810 return; 830 return;
831
811 EphemeralRange marker_range = EphemeralRange( 832 EphemeralRange marker_range = EphemeralRange(
812 Position(caret_range.StartPosition().ComputeContainerNode(), 833 Position(caret_start_container, found_marker->StartOffset()),
813 markers[0]->StartOffset()), 834 Position(caret_start_container, found_marker->EndOffset()));
814 Position(caret_range.EndPosition().ComputeContainerNode(),
815 markers[0]->EndOffset()));
816 if (marker_range.IsNull()) 835 if (marker_range.IsNull())
817 return; 836 return;
818 837
819 GetFrame().Selection().SetSelection( 838 GetFrame().Selection().SetSelection(
820 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build()); 839 SelectionInDOMTree::Builder().SetBaseAndExtent(marker_range).Build());
821 840
822 Document& current_document = *GetFrame().GetDocument(); 841 Document& current_document = *GetFrame().GetDocument();
823 842
824 // Dispatch 'beforeinput'. 843 // Dispatch 'beforeinput'.
825 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection(); 844 Element* const target = GetFrame().GetEditor().FindEventTargetFromSelection();
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 if (!input.IsFocusedElementInDocument()) 1217 if (!input.IsFocusedElementInDocument())
1199 return false; 1218 return false;
1200 } 1219 }
1201 } 1220 }
1202 HTMLElement* element = 1221 HTMLElement* element =
1203 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); 1222 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode());
1204 return element && element->IsSpellCheckingEnabled(); 1223 return element && element->IsSpellCheckingEnabled();
1205 } 1224 }
1206 1225
1207 } // namespace blink 1226 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698