| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 marker.SetStartOffset(result.value().start_offset); | 159 marker.SetStartOffset(result.value().start_offset); |
| 160 marker.SetEndOffset(result.value().end_offset); | 160 marker.SetEndOffset(result.value().end_offset); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 list->erase(erase_range_begin - list->begin(), | 164 list->erase(erase_range_begin - list->begin(), |
| 165 erase_range_end - erase_range_begin); | 165 erase_range_end - erase_range_begin); |
| 166 return did_shift_marker; | 166 return did_shift_marker; |
| 167 } | 167 } |
| 168 | 168 |
| 169 DocumentMarker* DocumentMarkerListEditor::FirstMarkerIntersectingRange( |
| 170 const MarkerList& list, |
| 171 unsigned start_offset, |
| 172 unsigned end_offset) { |
| 173 DCHECK_LE(start_offset, end_offset); |
| 174 |
| 175 const auto& marker_it = |
| 176 std::lower_bound(list.begin(), list.end(), start_offset, |
| 177 [](const DocumentMarker* marker, unsigned start_offset) { |
| 178 return marker->EndOffset() <= start_offset; |
| 179 }); |
| 180 if (marker_it == list.end()) |
| 181 return nullptr; |
| 182 |
| 183 DocumentMarker* marker = *marker_it; |
| 184 if (marker->StartOffset() >= end_offset) |
| 185 return nullptr; |
| 186 return marker; |
| 187 } |
| 188 |
| 169 HeapVector<Member<DocumentMarker>> | 189 HeapVector<Member<DocumentMarker>> |
| 170 DocumentMarkerListEditor::MarkersIntersectingRange(const MarkerList& list, | 190 DocumentMarkerListEditor::MarkersIntersectingRange(const MarkerList& list, |
| 171 unsigned start_offset, | 191 unsigned start_offset, |
| 172 unsigned end_offset) { | 192 unsigned end_offset) { |
| 173 DCHECK_LE(start_offset, end_offset); | 193 DCHECK_LE(start_offset, end_offset); |
| 174 | 194 |
| 175 const auto& start_it = | 195 const auto& start_it = |
| 176 std::lower_bound(list.begin(), list.end(), start_offset, | 196 std::lower_bound(list.begin(), list.end(), start_offset, |
| 177 [](const DocumentMarker* marker, unsigned start_offset) { | 197 [](const DocumentMarker* marker, unsigned start_offset) { |
| 178 return marker->EndOffset() <= start_offset; | 198 return marker->EndOffset() <= start_offset; |
| 179 }); | 199 }); |
| 180 const auto& end_it = | 200 const auto& end_it = |
| 181 std::upper_bound(list.begin(), list.end(), end_offset, | 201 std::upper_bound(list.begin(), list.end(), end_offset, |
| 182 [](unsigned end_offset, const DocumentMarker* marker) { | 202 [](unsigned end_offset, const DocumentMarker* marker) { |
| 183 return end_offset <= marker->StartOffset(); | 203 return end_offset <= marker->StartOffset(); |
| 184 }); | 204 }); |
| 185 | 205 |
| 186 HeapVector<Member<DocumentMarker>> results; | 206 HeapVector<Member<DocumentMarker>> results; |
| 187 std::copy(start_it, end_it, std::back_inserter(results)); | 207 std::copy(start_it, end_it, std::back_inserter(results)); |
| 188 return results; | 208 return results; |
| 189 } | 209 } |
| 190 | 210 |
| 191 } // namespace blink | 211 } // namespace blink |
| OLD | NEW |