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

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/SpellCheckMarkerListImpl.cpp

Issue 2851633003: [DMC #5.5] Move SpellCheckMarkerListImpl::Add() implementation from DMLEditor.cpp (Closed)
Patch Set: Remove RemoveMarkersUnderWords() changes that are not supposed to be in this CL 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/SpellCheckMarkerListImpl.h" 5 #include "core/editing/markers/SpellCheckMarkerListImpl.h"
6 6
7 #include "core/editing/markers/DocumentMarkerListEditor.h" 7 #include "core/editing/markers/DocumentMarkerListEditor.h"
8 #include "core/editing/markers/RenderedDocumentMarker.h" 8 #include "core/editing/markers/RenderedDocumentMarker.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 bool SpellCheckMarkerListImpl::IsEmpty() const { 12 bool SpellCheckMarkerListImpl::IsEmpty() const {
13 return markers_.IsEmpty(); 13 return markers_.IsEmpty();
14 } 14 }
15 15
16 void SpellCheckMarkerListImpl::Add(DocumentMarker* marker) {
17 RenderedDocumentMarker* rendered_marker =
18 RenderedDocumentMarker::Create(*marker);
19 if (markers_.IsEmpty() ||
20 markers_.back()->EndOffset() < marker->StartOffset()) {
21 markers_.push_back(rendered_marker);
22 return;
23 }
24
25 auto first_overlapping = std::lower_bound(
26 markers_.begin(), markers_.end(), rendered_marker,
27 [](const Member<RenderedDocumentMarker>& marker_in_list,
28 const DocumentMarker* marker_to_insert) {
29 return marker_in_list->EndOffset() < marker_to_insert->StartOffset();
30 });
31
32 size_t index = first_overlapping - markers_.begin();
33 markers_.insert(index, rendered_marker);
34 const auto inserted = markers_.begin() + index;
35 first_overlapping = inserted + 1;
36 // TODO(rlanday): optimize this loop so it runs in O(N) time and not O(N^2)
37 for (const auto i = first_overlapping;
38 i != markers_.end() &&
39 (*i)->StartOffset() <= (*inserted)->EndOffset();) {
40 (*inserted)->SetStartOffset(
41 std::min((*inserted)->StartOffset(), (*i)->StartOffset()));
42 (*inserted)->SetEndOffset(
43 std::max((*inserted)->EndOffset(), (*i)->EndOffset()));
44 markers_.erase(i - markers_.begin());
45 }
46 }
47
16 void SpellCheckMarkerListImpl::Clear() { 48 void SpellCheckMarkerListImpl::Clear() {
17 markers_.clear(); 49 markers_.clear();
18 } 50 }
19 51
20 const HeapVector<Member<RenderedDocumentMarker>>& 52 const HeapVector<Member<RenderedDocumentMarker>>&
21 SpellCheckMarkerListImpl::GetMarkers() const { 53 SpellCheckMarkerListImpl::GetMarkers() const {
22 return markers_; 54 return markers_;
23 } 55 }
24 56
25 bool SpellCheckMarkerListImpl::MoveMarkers(int length, 57 bool SpellCheckMarkerListImpl::MoveMarkers(int length,
(...skipping 20 matching lines...) Expand all
46 return DocumentMarkerListEditor::ShiftMarkers(&markers_, offset, old_length, 78 return DocumentMarkerListEditor::ShiftMarkers(&markers_, offset, old_length,
47 new_length); 79 new_length);
48 } 80 }
49 81
50 DEFINE_TRACE(SpellCheckMarkerListImpl) { 82 DEFINE_TRACE(SpellCheckMarkerListImpl) {
51 visitor->Trace(markers_); 83 visitor->Trace(markers_);
52 DocumentMarkerList::Trace(visitor); 84 DocumentMarkerList::Trace(visitor);
53 } 85 }
54 86
55 } // namespace blink 87 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698