OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/editing/markers/DocumentMarkerListEditor.h" | 5 #include "core/editing/markers/DocumentMarkerListEditor.h" |
6 | 6 |
7 #include "core/editing/markers/SpellCheckMarkerListImpl.h" | 7 #include "core/editing/markers/SpellCheckMarkerListImpl.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 dst_list->Add(&marker); | 45 dst_list->Add(&marker); |
46 didMoveMarker = true; | 46 didMoveMarker = true; |
47 } | 47 } |
48 | 48 |
49 // Remove the range of markers that were moved to dstNode | 49 // Remove the range of markers that were moved to dstNode |
50 src_list->erase(0, it - src_list->begin()); | 50 src_list->erase(0, it - src_list->begin()); |
51 | 51 |
52 return didMoveMarker; | 52 return didMoveMarker; |
53 } | 53 } |
54 | 54 |
55 // TODO(rlanday): this method was created by cutting and pasting code from | |
56 // DocumentMarkerController::RemoveMarkers(), it should be refactored in a | |
57 // future CL | |
58 bool DocumentMarkerListEditor::RemoveMarkers(MarkerList* list, | 55 bool DocumentMarkerListEditor::RemoveMarkers(MarkerList* list, |
59 unsigned start_offset, | 56 unsigned start_offset, |
60 int length) { | 57 int length) { |
61 bool doc_dirty = false; | |
62 const unsigned end_offset = start_offset + length; | 58 const unsigned end_offset = start_offset + length; |
63 MarkerList::iterator start_pos = std::upper_bound( | 59 MarkerList::iterator start_pos = std::upper_bound( |
64 list->begin(), list->end(), start_offset, | 60 list->begin(), list->end(), start_offset, |
65 [](size_t start_offset, const Member<DocumentMarker>& marker) { | 61 [](size_t start_offset, const Member<DocumentMarker>& marker) { |
66 return start_offset < marker->EndOffset(); | 62 return start_offset < marker->EndOffset(); |
67 }); | 63 }); |
68 for (MarkerList::iterator i = start_pos; i != list->end();) { | |
69 const DocumentMarker& marker = *i->Get(); | |
70 | 64 |
71 // markers are returned in order, so stop if we are now past the specified | 65 MarkerList::iterator end_pos = std::lower_bound( |
72 // range | 66 list->begin(), list->end(), end_offset, |
73 if (marker.StartOffset() >= end_offset) | 67 [](const Member<DocumentMarker>& marker, size_t end_offset) { |
74 break; | 68 return marker->StartOffset() < end_offset; |
| 69 }); |
75 | 70 |
76 list->erase(i - list->begin()); | 71 list->erase(start_pos - list->begin(), end_pos - start_pos); |
77 doc_dirty = true; | 72 return start_pos != end_pos; |
78 } | |
79 | |
80 return doc_dirty; | |
81 } | 73 } |
82 | 74 |
83 // TODO(rlanday): make this not take O(n^2) time when all the markers are | 75 // TODO(rlanday): make this not take O(n^2) time when all the markers are |
84 // removed | 76 // removed |
85 bool DocumentMarkerListEditor::ShiftMarkersContentDependent( | 77 bool DocumentMarkerListEditor::ShiftMarkersContentDependent( |
86 MarkerList* list, | 78 MarkerList* list, |
87 unsigned offset, | 79 unsigned offset, |
88 unsigned old_length, | 80 unsigned old_length, |
89 unsigned new_length) { | 81 unsigned new_length) { |
90 bool did_shift_marker = false; | 82 bool did_shift_marker = false; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 did_shift_marker = true; | 127 did_shift_marker = true; |
136 marker.SetStartOffset(result.value().start_offset); | 128 marker.SetStartOffset(result.value().start_offset); |
137 marker.SetEndOffset(result.value().end_offset); | 129 marker.SetEndOffset(result.value().end_offset); |
138 } | 130 } |
139 } | 131 } |
140 | 132 |
141 return did_shift_marker; | 133 return did_shift_marker; |
142 } | 134 } |
143 | 135 |
144 } // namespace blink | 136 } // namespace blink |
OLD | NEW |