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 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 return marker_in_list->StartOffset() < | 28 return marker_in_list->StartOffset() < |
29 marker_to_insert->StartOffset(); | 29 marker_to_insert->StartOffset(); |
30 }); | 30 }); |
31 list->insert(pos - list->begin(), rendered_marker); | 31 list->insert(pos - list->begin(), rendered_marker); |
32 } | 32 } |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 bool DocumentMarkerListEditor::MoveMarkers(MarkerList* src_list, | 36 bool DocumentMarkerListEditor::MoveMarkers(MarkerList* src_list, |
37 int length, | 37 int length, |
38 MarkerList* dst_list) { | 38 DocumentMarkerList* dst_list) { |
39 DCHECK_GT(length, 0); | 39 DCHECK_GT(length, 0); |
40 bool didMoveMarker = false; | 40 bool didMoveMarker = false; |
41 unsigned end_offset = length - 1; | 41 unsigned end_offset = length - 1; |
42 | 42 |
43 MarkerList::iterator it; | 43 MarkerList::iterator it; |
44 for (it = src_list->begin(); it != src_list->end(); ++it) { | 44 for (it = src_list->begin(); it != src_list->end(); ++it) { |
45 DocumentMarker& marker = **it; | 45 DocumentMarker& marker = **it; |
46 if (marker.StartOffset() > end_offset) | 46 if (marker.StartOffset() > end_offset) |
47 break; | 47 break; |
48 | 48 |
49 // pin the marker to the specified range and apply the shift delta | 49 // pin the marker to the specified range and apply the shift delta |
50 if (marker.EndOffset() > end_offset) | 50 if (marker.EndOffset() > end_offset) |
51 marker.SetEndOffset(end_offset); | 51 marker.SetEndOffset(end_offset); |
52 | 52 |
53 DocumentMarkerListEditor::AddMarker(dst_list, &marker); | 53 dst_list->Add(&marker); |
54 didMoveMarker = true; | 54 didMoveMarker = true; |
55 } | 55 } |
56 | 56 |
57 // Remove the range of markers that were moved to dstNode | 57 // Remove the range of markers that were moved to dstNode |
58 src_list->erase(0, it - src_list->begin()); | 58 src_list->erase(0, it - src_list->begin()); |
59 | 59 |
60 return didMoveMarker; | 60 return didMoveMarker; |
61 } | 61 } |
62 | 62 |
63 // TODO(rlanday): this method was created by cutting and pasting code from | 63 // TODO(rlanday): this method was created by cutting and pasting code from |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 i != list->end() && (*i)->StartOffset() <= (*inserted)->EndOffset();) { | 151 i != list->end() && (*i)->StartOffset() <= (*inserted)->EndOffset();) { |
152 (*inserted)->SetStartOffset( | 152 (*inserted)->SetStartOffset( |
153 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); | 153 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); |
154 (*inserted)->SetEndOffset( | 154 (*inserted)->SetEndOffset( |
155 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); | 155 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); |
156 list->erase(i - list->begin()); | 156 list->erase(i - list->begin()); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 } // namespace blink | 160 } // namespace blink |
OLD | NEW |