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

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

Issue 2805553003: DocumentMarkerList refactor as an interface (Closed)
Patch Set: Rebase on renaming patch, respond to comments Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/editing/markers/TextMatchMarkerList.h"
6
7 #include "core/editing/markers/DocumentMarkerListEditor.h"
8
9 namespace blink {
10
11 TextMatchMarkerList::TextMatchMarkerList() {}
12
13 DocumentMarker::MarkerType TextMatchMarkerList::GetAllowedMarkerType() const {
14 return DocumentMarker::kTextMatch;
15 }
16
17 bool TextMatchMarkerList::Empty() const {
18 return markers_.IsEmpty();
19 }
20
21 TextMatchMarker* TextMatchMarkerList::At(size_t index) {
22 return ToTextMatchMarker(markers_[index]);
23 }
24
25 void TextMatchMarkerList::Add(DocumentMarker* marker) {
26 // TextMatch markers must be added in order
27 DCHECK(marker->GetType() == GetAllowedMarkerType());
28 DCHECK(markers_.IsEmpty() ||
29 marker->StartOffset() >= markers_.back()->EndOffset());
30 markers_.push_back(marker);
31 }
32
33 void TextMatchMarkerList::Clear() {
34 markers_.Clear();
35 }
36
37 void TextMatchMarkerList::AppendMarkersToInputList(
38 DocumentMarkerVector* list) const {
39 list->AppendVector(markers_);
40 }
41
42 DocumentMarkerList::DidMoveMarkerOrNot TextMatchMarkerList::MoveMarkers(
43 int length,
44 DocumentMarkerList* dst_list) {
45 return DocumentMarkerListEditor::MoveSortedMarkers(&markers_, length,
46 dst_list);
47 }
48
49 DocumentMarkerList::DidRemoveMarkerOrNot TextMatchMarkerList::RemoveMarkers(
50 unsigned start_offset,
51 int length) {
52 return DocumentMarkerListEditor::RemoveSortedMarkers(&markers_, start_offset,
53 length);
54 }
55
56 DocumentMarkerList::DidShiftMarkerOrNot TextMatchMarkerList::ShiftMarkers(
57 unsigned offset,
58 unsigned oldLength,
59 unsigned newLength) {
60 return DocumentMarkerListEditor::ShiftSortedMarkers(&markers_, offset,
61 oldLength, newLength);
62 }
63
64 DEFINE_TRACE(TextMatchMarkerList) {
65 visitor->Trace(markers_);
66 DocumentMarkerList::Trace(visitor);
67 }
68
69 void TextMatchMarkerList::AppendRenderedRectsToInputList(
70 const Node& node,
71 Vector<IntRect>* result) const {
72 for (Member<DocumentMarker> marker : markers_) {
73 TextMatchMarker* text_match_marker = ToTextMatchMarker(marker);
74 text_match_marker->UpdateRenderedRectIfNeeded(node);
75 if (!text_match_marker->IsRendered())
76 continue;
77 result->push_back(text_match_marker->RenderedRect());
78 }
79 }
80
81 void TextMatchMarkerList::InvalidateRects() {
82 for (Member<DocumentMarker> marker : markers_) {
83 TextMatchMarker* text_match_marker = ToTextMatchMarker(marker.Get());
84 text_match_marker->Invalidate();
85 }
86 }
87
88 bool TextMatchMarkerList::SetTextMatchMarkersActive(unsigned start_offset,
89 unsigned end_offset,
90 bool active) {
91 bool doc_dirty = false;
92 for (auto it = DocumentMarkerListEditor::
93 GetPosOfFirstMarkerNotEndingBeforeInSortedList(&markers_,
94 start_offset);
95 it != markers_.end(); ++it) {
96 DocumentMarker& marker = **it;
97 // Markers are stored in order, so stop if we are now past the specified
98 // range.
99 if (marker.StartOffset() >= end_offset)
100 break;
101
102 marker.SetIsActiveMatch(active);
103 doc_dirty = true;
104 }
105
106 return doc_dirty;
107 }
108
109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698