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

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

Issue 2805553003: DocumentMarkerList refactor as an interface (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
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..90d93eb2d91c681560c9c4a73c0572d5ecb910dd
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerList.cpp
@@ -0,0 +1,135 @@
+// 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/DocumentMarkerListUtils.h"
+
+namespace blink {
+
+TextMatchMarkerList::TextMatchMarkerList() {}
+
+DocumentMarker::MarkerType TextMatchMarkerList::allowedMarkerType() const {
+ return DocumentMarker::TextMatch;
+}
+
+bool TextMatchMarkerList::isTextMatchMarkerList() const {
+ return true;
+}
+
+size_t TextMatchMarkerList::size() const {
+ return m_markers.size();
+}
+
+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();
+}
+
+TextMatchMarkerList::iterator TextMatchMarkerList::begin() {
+ return m_markers.begin();
+}
+
+TextMatchMarkerList::iterator TextMatchMarkerList::end() {
+ return m_markers.end();
+}
+
+TextMatchMarkerList::const_iterator TextMatchMarkerList::begin() const {
+ return m_markers.begin();
+}
+
+TextMatchMarkerList::const_iterator TextMatchMarkerList::end() const {
+ return m_markers.end();
+}
+
+void TextMatchMarkerList::appendMarkersToInputList(
+ DocumentMarkerVector* list) const {
+ DocumentMarkerListUtils::appendMarkersToInputList(&m_markers, list);
+}
+
+DocumentMarkerList::DidCopyMarkerOrNot TextMatchMarkerList::copyMarkers(
+ unsigned startOffset,
+ int length,
+ DocumentMarkerList* dstList,
+ int delta) {
+ return DocumentMarkerListUtils::copySortedMarkers(&m_markers, startOffset,
+ length, dstList, delta);
+}
+
+DocumentMarkerList::DidRemoveMarkerOrNot TextMatchMarkerList::removeMarkers(
+ unsigned startOffset,
+ int length,
+ bool shouldRemovePartiallyOverlappingMarkers) {
+ return DocumentMarkerListUtils::removeSortedMarkers(
+ &m_markers, startOffset, length, shouldRemovePartiallyOverlappingMarkers);
+}
+
+DocumentMarkerList::DidShiftMarkerOrNot TextMatchMarkerList::shiftMarkers(
+ unsigned offset,
+ unsigned oldLength,
+ unsigned newLength) {
+ return DocumentMarkerListUtils::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 = DocumentMarkerListUtils::
+ 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

Powered by Google App Engine
This is Rietveld 408576698