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

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

Issue 2883503004: [DMC #7] Only create RenderedDocumentMarkers for TextMatchMarkerListImpl (Closed)
Patch Set: Rebase on InvalidateRectsForAllMarkers() refactor 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 // 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 #include "core/editing/markers/SpellCheckMarkerListImpl.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 void DocumentMarkerListEditor::AddMarkerWithoutMergingOverlapping( 12 void DocumentMarkerListEditor::AddMarkerWithoutMergingOverlapping(
13 MarkerList* list, 13 MarkerList* list,
14 const DocumentMarker* marker) { 14 DocumentMarker* marker) {
15 RenderedDocumentMarker* rendered_marker =
16 RenderedDocumentMarker::Create(*marker);
17 if (list->IsEmpty() || list->back()->EndOffset() <= marker->StartOffset()) { 15 if (list->IsEmpty() || list->back()->EndOffset() <= marker->StartOffset()) {
18 list->push_back(rendered_marker); 16 list->push_back(marker);
19 return; 17 return;
20 } 18 }
21 19
22 const auto pos = std::lower_bound( 20 const auto pos = std::lower_bound(
23 list->begin(), list->end(), marker, 21 list->begin(), list->end(), marker,
24 [](const Member<RenderedDocumentMarker>& marker_in_list, 22 [](const Member<DocumentMarker>& marker_in_list,
25 const DocumentMarker* marker_to_insert) { 23 const DocumentMarker* marker_to_insert) {
26 return marker_in_list->StartOffset() < marker_to_insert->StartOffset(); 24 return marker_in_list->StartOffset() < marker_to_insert->StartOffset();
27 }); 25 });
28 list->insert(pos - list->begin(), rendered_marker); 26 list->insert(pos - list->begin(), marker);
29 } 27 }
30 28
31 bool DocumentMarkerListEditor::MoveMarkers(MarkerList* src_list, 29 bool DocumentMarkerListEditor::MoveMarkers(MarkerList* src_list,
32 int length, 30 int length,
33 DocumentMarkerList* dst_list) { 31 DocumentMarkerList* dst_list) {
34 DCHECK_GT(length, 0); 32 DCHECK_GT(length, 0);
35 bool didMoveMarker = false; 33 bool didMoveMarker = false;
36 unsigned end_offset = length - 1; 34 unsigned end_offset = length - 1;
37 35
38 MarkerList::iterator it; 36 MarkerList::iterator it;
(...skipping 19 matching lines...) Expand all
58 // TODO(rlanday): this method was created by cutting and pasting code from 56 // TODO(rlanday): this method was created by cutting and pasting code from
59 // DocumentMarkerController::RemoveMarkers(), it should be refactored in a 57 // DocumentMarkerController::RemoveMarkers(), it should be refactored in a
60 // future CL 58 // future CL
61 bool DocumentMarkerListEditor::RemoveMarkers(MarkerList* list, 59 bool DocumentMarkerListEditor::RemoveMarkers(MarkerList* list,
62 unsigned start_offset, 60 unsigned start_offset,
63 int length) { 61 int length) {
64 bool doc_dirty = false; 62 bool doc_dirty = false;
65 const unsigned end_offset = start_offset + length; 63 const unsigned end_offset = start_offset + length;
66 MarkerList::iterator start_pos = std::upper_bound( 64 MarkerList::iterator start_pos = std::upper_bound(
67 list->begin(), list->end(), start_offset, 65 list->begin(), list->end(), start_offset,
68 [](size_t start_offset, const Member<RenderedDocumentMarker>& marker) { 66 [](size_t start_offset, const Member<DocumentMarker>& marker) {
69 return start_offset < marker->EndOffset(); 67 return start_offset < marker->EndOffset();
70 }); 68 });
71 for (MarkerList::iterator i = start_pos; i != list->end();) { 69 for (MarkerList::iterator i = start_pos; i != list->end();) {
72 DocumentMarker marker(*i->Get()); 70 DocumentMarker marker(*i->Get());
73 71
74 // markers are returned in order, so stop if we are now past the specified 72 // markers are returned in order, so stop if we are now past the specified
75 // range 73 // range
76 if (marker.StartOffset() >= end_offset) 74 if (marker.StartOffset() >= end_offset)
77 break; 75 break;
78 76
79 list->erase(i - list->begin()); 77 list->erase(i - list->begin());
80 doc_dirty = true; 78 doc_dirty = true;
81 } 79 }
82 80
83 return doc_dirty; 81 return doc_dirty;
84 } 82 }
85 83
86 bool DocumentMarkerListEditor::ShiftMarkers(MarkerList* list, 84 bool DocumentMarkerListEditor::ShiftMarkers(MarkerList* list,
87 unsigned offset, 85 unsigned offset,
88 unsigned old_length, 86 unsigned old_length,
89 unsigned new_length) { 87 unsigned new_length) {
90 bool did_shift_marker = false; 88 bool did_shift_marker = false;
91 for (MarkerList::iterator it = list->begin(); it != list->end(); ++it) { 89 for (MarkerList::iterator it = list->begin(); it != list->end(); ++it) {
92 RenderedDocumentMarker& marker = **it; 90 DocumentMarker& marker = **it;
93 Optional<DocumentMarker::MarkerOffsets> result = 91 Optional<DocumentMarker::MarkerOffsets> result =
94 marker.ComputeOffsetsAfterShift(offset, old_length, new_length); 92 marker.ComputeOffsetsAfterShift(offset, old_length, new_length);
95 if (result == WTF::nullopt) { 93 if (result == WTF::nullopt) {
96 list->erase(it - list->begin()); 94 list->erase(it - list->begin());
97 --it; 95 --it;
98 did_shift_marker = true; 96 did_shift_marker = true;
99 continue; 97 continue;
100 } 98 }
101 99
102 if (marker.StartOffset() != result.value().start_offset || 100 if (marker.StartOffset() != result.value().start_offset ||
103 marker.EndOffset() != result.value().end_offset) { 101 marker.EndOffset() != result.value().end_offset) {
104 did_shift_marker = true; 102 did_shift_marker = true;
105 marker.SetStartOffset(result.value().start_offset); 103 marker.SetStartOffset(result.value().start_offset);
106 marker.SetEndOffset(result.value().end_offset); 104 marker.SetEndOffset(result.value().end_offset);
107 } 105 }
108 } 106 }
109 107
110 return did_shift_marker; 108 return did_shift_marker;
111 } 109 }
112 110
113 } // namespace blink 111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698