Index: third_party/WebKit/Source/core/editing/markers/TextMatchMarkerList.cpp |
diff --git a/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerList.cpp b/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerList.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a9e24e5529cce577225b899a7ce56c48f0bfcd70 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerList.cpp |
@@ -0,0 +1,112 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "core/editing/markers/TextMatchMarkerList.h" |
+ |
+#include "core/editing/markers/DocumentMarkerListEditor.h" |
+ |
+namespace blink { |
+ |
+TextMatchMarkerList::TextMatchMarkerList() {} |
+ |
+DocumentMarker::MarkerType TextMatchMarkerList::allowedMarkerType() const { |
+ return DocumentMarker::TextMatch; |
+} |
+ |
+bool TextMatchMarkerList::empty() const { |
+ return m_markers.isEmpty(); |
+} |
+ |
+TextMatchMarker* TextMatchMarkerList::at(size_t index) { |
+ return toTextMatchMarker(m_markers[index]); |
+} |
+ |
+void TextMatchMarkerList::add(DocumentMarker* marker) { |
+ // TextMatch markers must be added in order |
+ DCHECK(marker->type() == allowedMarkerType()); |
+ DCHECK(m_markers.isEmpty() || |
+ marker->startOffset() >= m_markers.back()->endOffset()); |
+ m_markers.push_back(marker); |
+} |
+ |
+void TextMatchMarkerList::clear() { |
+ m_markers.clear(); |
+} |
+ |
+void TextMatchMarkerList::appendMarkersToInputList( |
+ DocumentMarkerVector* list) const { |
+ DocumentMarkerListEditor::appendMarkersToInputList(m_markers, list); |
+} |
+ |
+DocumentMarkerList::DidCopyMarkerOrNot TextMatchMarkerList::copyMarkers( |
+ unsigned startOffset, |
+ int length, |
+ DocumentMarkerList* dstList, |
+ int delta) { |
+ return DocumentMarkerListEditor::copySortedMarkers(&m_markers, startOffset, |
+ length, dstList, delta); |
+} |
+ |
+DocumentMarkerList::DidRemoveMarkerOrNot TextMatchMarkerList::removeMarkers( |
+ unsigned startOffset, |
+ int length, |
+ bool shouldRemovePartiallyOverlappingMarkers) { |
+ return DocumentMarkerListEditor::removeSortedMarkers( |
+ &m_markers, startOffset, length, shouldRemovePartiallyOverlappingMarkers); |
+} |
+ |
+DocumentMarkerList::DidShiftMarkerOrNot TextMatchMarkerList::shiftMarkers( |
+ unsigned offset, |
+ unsigned oldLength, |
+ unsigned newLength) { |
+ return DocumentMarkerListEditor::shiftSortedMarkers(&m_markers, offset, |
+ oldLength, newLength); |
+} |
+ |
+DEFINE_TRACE(TextMatchMarkerList) { |
+ visitor->trace(m_markers); |
+ DocumentMarkerList::trace(visitor); |
+} |
+ |
+void TextMatchMarkerList::appendRenderedRectsToInputList( |
+ const Node& node, |
+ Vector<IntRect>* result) const { |
+ for (Member<DocumentMarker> marker : m_markers) { |
+ TextMatchMarker* textMatchMarker = toTextMatchMarker(marker); |
+ textMatchMarker->updateRenderedRectIfNeeded(node); |
+ if (!textMatchMarker->isRendered()) |
+ continue; |
+ result->push_back(textMatchMarker->renderedRect()); |
+ } |
+} |
+ |
+void TextMatchMarkerList::invalidateRects() { |
+ for (Member<DocumentMarker> marker : m_markers) { |
+ TextMatchMarker* textMatchMarker = toTextMatchMarker(marker.get()); |
+ textMatchMarker->invalidate(); |
+ } |
+} |
+ |
+bool TextMatchMarkerList::setTextMatchMarkersActive(unsigned startOffset, |
+ unsigned endOffset, |
+ bool active) { |
+ bool docDirty = false; |
+ for (auto it = DocumentMarkerListEditor:: |
+ getPosOfFirstMarkerNotEndingBeforeInSortedList(&m_markers, |
+ startOffset); |
+ it != m_markers.end(); ++it) { |
+ DocumentMarker& marker = **it; |
+ // Markers are stored in order, so stop if we are now past the specified |
+ // range. |
+ if (marker.startOffset() >= endOffset) |
+ break; |
+ |
+ marker.setIsActiveMatch(active); |
+ docDirty = true; |
+ } |
+ |
+ return docDirty; |
+} |
+ |
+} // namespace blink |