Chromium Code Reviews| 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..01e5b73d03882df8482eb077ea17d79207b98d01 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/markers/TextMatchMarkerList.cpp |
| @@ -0,0 +1,72 @@ |
| +// 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/DocumentMarkerController.h" |
| + |
| +namespace blink { |
| + |
| +TextMatchMarkerList::TextMatchMarkerList() {} |
| + |
| +DocumentMarker::MarkerType TextMatchMarkerList::allowedMarkerType() const { |
| + return DocumentMarker::TextMatch; |
| +} |
| + |
| +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::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::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 = getPosOfFirstMarkerNotEndingBefore(startOffset); |
|
Xiaocheng
2017/03/30 21:12:07
I'm still not quite a fan of |getPosOf...|, but di
|
| + 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.setActiveMatch(active); |
| + docDirty = true; |
| + } |
| + |
| + return docDirty; |
| +} |
| + |
| +bool TextMatchMarkerList::markerListIsSorted() const { |
| + return true; |
| +} |
| + |
| +DEFINE_TRACE(TextMatchMarkerList) { |
| + visitor->trace(m_markers); |
| + DocumentMarkerList::trace(visitor); |
| +} |
| + |
| +} // namespace blink |