OLD | NEW |
(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/DocumentMarkerController.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 TextMatchMarkerList::TextMatchMarkerList() {} |
| 12 |
| 13 DocumentMarker::MarkerType TextMatchMarkerList::allowedMarkerType() const { |
| 14 return DocumentMarker::TextMatch; |
| 15 } |
| 16 |
| 17 TextMatchMarker* TextMatchMarkerList::at(size_t index) { |
| 18 return toTextMatchMarker(DocumentMarkerList::at(index)); |
| 19 } |
| 20 |
| 21 void TextMatchMarkerList::appendRenderedRectsToInputList( |
| 22 const Node& node, |
| 23 Vector<IntRect>* result) const { |
| 24 for (Member<DocumentMarker> marker : m_markers) { |
| 25 TextMatchMarker* textMatchMarker = toTextMatchMarker(marker); |
| 26 textMatchMarker->updateRenderedRectIfNeeded(node); |
| 27 if (!textMatchMarker->isRendered()) |
| 28 continue; |
| 29 result->push_back(textMatchMarker->renderedRect()); |
| 30 } |
| 31 } |
| 32 |
| 33 void TextMatchMarkerList::add(DocumentMarker* marker) { |
| 34 // TextMatch markers must be added in order |
| 35 DCHECK(marker->type() == allowedMarkerType()); |
| 36 DCHECK(m_markers.isEmpty() || |
| 37 marker->startOffset() >= m_markers.back()->endOffset()); |
| 38 m_markers.push_back(marker); |
| 39 } |
| 40 |
| 41 void TextMatchMarkerList::invalidateRects() { |
| 42 for (Member<DocumentMarker> marker : m_markers) { |
| 43 TextMatchMarker* textMatchMarker = toTextMatchMarker(marker.get()); |
| 44 textMatchMarker->invalidate(); |
| 45 } |
| 46 } |
| 47 |
| 48 bool TextMatchMarkerList::setTextMatchMarkersActive(unsigned startOffset, |
| 49 unsigned endOffset, |
| 50 bool active) { |
| 51 bool docDirty = false; |
| 52 for (auto it = getPosOfFirstMarkerNotEndingBefore(startOffset); |
| 53 it != m_markers.end(); ++it) { |
| 54 DocumentMarker& marker = **it; |
| 55 // Markers are stored in order, so stop if we are now past the specified |
| 56 // range. |
| 57 if (marker.startOffset() >= endOffset) |
| 58 break; |
| 59 |
| 60 marker.setActiveMatch(active); |
| 61 docDirty = true; |
| 62 } |
| 63 |
| 64 return docDirty; |
| 65 } |
| 66 |
| 67 bool TextMatchMarkerList::markerListIsSorted() const { |
| 68 return true; |
| 69 } |
| 70 |
| 71 DEFINE_TRACE(TextMatchMarkerList) { |
| 72 visitor->trace(m_markers); |
| 73 DocumentMarkerList::trace(visitor); |
| 74 } |
| 75 |
| 76 } // namespace blink |
OLD | NEW |