Chromium Code Reviews| 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/RenderedDocumentMarker.h" | 7 #include "core/editing/markers/RenderedDocumentMarker.h" |
| 8 #include "core/editing/markers/SpellCheckMarkerListImpl.h" | |
| 8 | 9 |
| 9 namespace blink { | 10 namespace blink { |
| 10 | 11 |
| 11 void DocumentMarkerListEditor::AddMarkerWithoutMergingOverlapping( | 12 void DocumentMarkerListEditor::AddMarkerWithoutMergingOverlapping( |
| 12 MarkerList* list, | 13 MarkerList* list, |
| 13 const DocumentMarker* marker) { | 14 const DocumentMarker* marker) { |
| 14 RenderedDocumentMarker* rendered_marker = | 15 RenderedDocumentMarker* rendered_marker = |
| 15 RenderedDocumentMarker::Create(*marker); | 16 RenderedDocumentMarker::Create(*marker); |
| 16 if (list->IsEmpty() || list->back()->EndOffset() <= marker->StartOffset()) { | 17 if (list->IsEmpty() || list->back()->EndOffset() <= marker->StartOffset()) { |
| 17 list->push_back(rendered_marker); | 18 list->push_back(rendered_marker); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 if (marker.StartOffset() >= end_offset) | 76 if (marker.StartOffset() >= end_offset) |
| 76 break; | 77 break; |
| 77 | 78 |
| 78 list->erase(i - list->begin()); | 79 list->erase(i - list->begin()); |
| 79 doc_dirty = true; | 80 doc_dirty = true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 return doc_dirty; | 83 return doc_dirty; |
| 83 } | 84 } |
| 84 | 85 |
| 85 bool DocumentMarkerListEditor::RemoveMarkersUnderWords( | 86 bool SpellCheckMarkerListImpl::RemoveMarkersUnderWords( |
|
Xiaocheng
2017/04/27 22:04:38
nit: Please add a TODO for moving it to SCMLImpl.c
| |
| 86 MarkerList* list, | |
| 87 const String& node_text, | 87 const String& node_text, |
| 88 const Vector<String>& words) { | 88 const Vector<String>& words) { |
| 89 bool removed_markers = false; | 89 bool removed_markers = false; |
| 90 for (size_t j = list->size(); j > 0; --j) { | 90 for (size_t j = markers_.size(); j > 0; --j) { |
| 91 const DocumentMarker& marker = *(*list)[j - 1]; | 91 const DocumentMarker& marker = *markers_[j - 1]; |
| 92 const unsigned start = marker.StartOffset(); | 92 const unsigned start = marker.StartOffset(); |
| 93 const unsigned length = marker.EndOffset() - marker.StartOffset(); | 93 const unsigned length = marker.EndOffset() - marker.StartOffset(); |
| 94 const String& marker_text = node_text.Substring(start, length); | 94 const String& marker_text = node_text.Substring(start, length); |
| 95 if (words.Contains(marker_text)) { | 95 if (words.Contains(marker_text)) { |
| 96 list->erase(j - 1); | 96 markers_.erase(j - 1); |
| 97 removed_markers = true; | 97 removed_markers = true; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 return removed_markers; | 101 return removed_markers; |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool DocumentMarkerListEditor::ShiftMarkers(MarkerList* list, | 104 bool DocumentMarkerListEditor::ShiftMarkers(MarkerList* list, |
| 105 unsigned offset, | 105 unsigned offset, |
| 106 unsigned old_length, | 106 unsigned old_length, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 121 marker.EndOffset() != result.value().end_offset) { | 121 marker.EndOffset() != result.value().end_offset) { |
| 122 did_shift_marker = true; | 122 did_shift_marker = true; |
| 123 marker.SetStartOffset(result.value().start_offset); | 123 marker.SetStartOffset(result.value().start_offset); |
| 124 marker.SetEndOffset(result.value().end_offset); | 124 marker.SetEndOffset(result.value().end_offset); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 return did_shift_marker; | 128 return did_shift_marker; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void DocumentMarkerListEditor::AddMarkerAndMergeOverlapping( | 131 void SpellCheckMarkerListImpl::Add(DocumentMarker* marker) { |
|
Xiaocheng
2017/04/27 22:04:38
nit: Please add a TODO for moving it to SCMLImpl.c
| |
| 132 MarkerList* list, | |
| 133 const DocumentMarker* marker) { | |
| 134 RenderedDocumentMarker* rendered_marker = | 132 RenderedDocumentMarker* rendered_marker = |
| 135 RenderedDocumentMarker::Create(*marker); | 133 RenderedDocumentMarker::Create(*marker); |
| 136 if (list->IsEmpty() || list->back()->EndOffset() < marker->StartOffset()) { | 134 if (markers_.IsEmpty() || |
| 137 list->push_back(rendered_marker); | 135 markers_.back()->EndOffset() < marker->StartOffset()) { |
| 136 markers_.push_back(rendered_marker); | |
| 138 return; | 137 return; |
| 139 } | 138 } |
| 140 | 139 |
| 141 auto first_overlapping = std::lower_bound( | 140 auto first_overlapping = std::lower_bound( |
| 142 list->begin(), list->end(), rendered_marker, | 141 markers_.begin(), markers_.end(), rendered_marker, |
| 143 [](const Member<RenderedDocumentMarker>& marker_in_list, | 142 [](const Member<RenderedDocumentMarker>& marker_in_list, |
| 144 const DocumentMarker* marker_to_insert) { | 143 const DocumentMarker* marker_to_insert) { |
| 145 return marker_in_list->EndOffset() < marker_to_insert->StartOffset(); | 144 return marker_in_list->EndOffset() < marker_to_insert->StartOffset(); |
| 146 }); | 145 }); |
| 147 | 146 |
| 148 size_t index = first_overlapping - list->begin(); | 147 size_t index = first_overlapping - markers_.begin(); |
| 149 list->insert(index, rendered_marker); | 148 markers_.insert(index, rendered_marker); |
| 150 const auto inserted = list->begin() + index; | 149 const auto inserted = markers_.begin() + index; |
| 151 first_overlapping = inserted + 1; | 150 first_overlapping = inserted + 1; |
| 152 // TODO(rlanday): optimize this loop so it runs in O(N) time and not O(N^2) | 151 // TODO(rlanday): optimize this loop so it runs in O(N) time and not O(N^2) |
| 153 for (const auto i = first_overlapping; | 152 for (const auto i = first_overlapping; |
| 154 i != list->end() && (*i)->StartOffset() <= (*inserted)->EndOffset();) { | 153 i != markers_.end() && |
| 154 (*i)->StartOffset() <= (*inserted)->EndOffset();) { | |
| 155 (*inserted)->SetStartOffset( | 155 (*inserted)->SetStartOffset( |
| 156 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); | 156 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); |
| 157 (*inserted)->SetEndOffset( | 157 (*inserted)->SetEndOffset( |
| 158 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); | 158 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); |
| 159 list->erase(i - list->begin()); | 159 markers_.erase(i - markers_.begin()); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace blink | 163 } // namespace blink |
| OLD | NEW |