| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/editing/markers/TextMatchMarkerListImpl.h" | 5 #include "core/editing/markers/TextMatchMarkerListImpl.h" |
| 6 | 6 |
| 7 #include "core/dom/Node.h" | 7 #include "core/dom/Node.h" |
| 8 #include "core/dom/Range.h" | 8 #include "core/dom/Range.h" |
| 9 #include "core/editing/EphemeralRange.h" | 9 #include "core/editing/EphemeralRange.h" |
| 10 #include "core/editing/markers/DocumentMarkerListEditor.h" | 10 #include "core/editing/markers/DocumentMarkerListEditor.h" |
| 11 #include "core/editing/markers/RenderedDocumentMarker.h" | 11 #include "core/editing/markers/TextMatchMarker.h" |
| 12 #include "third_party/WebKit/Source/core/editing/VisibleUnits.h" | 12 #include "third_party/WebKit/Source/core/editing/VisibleUnits.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 DocumentMarker::MarkerType TextMatchMarkerListImpl::MarkerType() const { | 16 DocumentMarker::MarkerType TextMatchMarkerListImpl::MarkerType() const { |
| 17 return DocumentMarker::kTextMatch; | 17 return DocumentMarker::kTextMatch; |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool TextMatchMarkerListImpl::IsEmpty() const { | 20 bool TextMatchMarkerListImpl::IsEmpty() const { |
| 21 return markers_.IsEmpty(); | 21 return markers_.IsEmpty(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void TextMatchMarkerListImpl::Add(DocumentMarker* marker) { | 24 void TextMatchMarkerListImpl::Add(DocumentMarker* marker) { |
| 25 DocumentMarkerListEditor::AddMarkerWithoutMergingOverlapping( | 25 DocumentMarkerListEditor::AddMarkerWithoutMergingOverlapping( |
| 26 &markers_, RenderedDocumentMarker::Create(*marker)); | 26 &markers_, TextMatchMarker::Create(*marker)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void TextMatchMarkerListImpl::Clear() { | 29 void TextMatchMarkerListImpl::Clear() { |
| 30 markers_.clear(); | 30 markers_.clear(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 const HeapVector<Member<DocumentMarker>>& TextMatchMarkerListImpl::GetMarkers() | 33 const HeapVector<Member<DocumentMarker>>& TextMatchMarkerListImpl::GetMarkers() |
| 34 const { | 34 const { |
| 35 return markers_; | 35 return markers_; |
| 36 } | 36 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 51 return DocumentMarkerListEditor::ShiftMarkersContentDependent( | 51 return DocumentMarkerListEditor::ShiftMarkersContentDependent( |
| 52 &markers_, offset, old_length, new_length); | 52 &markers_, offset, old_length, new_length); |
| 53 } | 53 } |
| 54 | 54 |
| 55 DEFINE_TRACE(TextMatchMarkerListImpl) { | 55 DEFINE_TRACE(TextMatchMarkerListImpl) { |
| 56 visitor->Trace(markers_); | 56 visitor->Trace(markers_); |
| 57 DocumentMarkerList::Trace(visitor); | 57 DocumentMarkerList::Trace(visitor); |
| 58 } | 58 } |
| 59 | 59 |
| 60 static void UpdateMarkerRenderedRect(const Node& node, | 60 static void UpdateMarkerRenderedRect(const Node& node, |
| 61 RenderedDocumentMarker& marker) { | 61 TextMatchMarker& marker) { |
| 62 const Position start_position(&const_cast<Node&>(node), marker.StartOffset()); | 62 const Position start_position(&const_cast<Node&>(node), marker.StartOffset()); |
| 63 const Position end_position(&const_cast<Node&>(node), marker.EndOffset()); | 63 const Position end_position(&const_cast<Node&>(node), marker.EndOffset()); |
| 64 EphemeralRange range(start_position, end_position); | 64 EphemeralRange range(start_position, end_position); |
| 65 marker.SetRenderedRect(LayoutRect(ComputeTextRect(range))); | 65 marker.SetRenderedRect(LayoutRect(ComputeTextRect(range))); |
| 66 } | 66 } |
| 67 | 67 |
| 68 Vector<IntRect> TextMatchMarkerListImpl::RenderedRects(const Node& node) const { | 68 Vector<IntRect> TextMatchMarkerListImpl::RenderedRects(const Node& node) const { |
| 69 Vector<IntRect> result; | 69 Vector<IntRect> result; |
| 70 | 70 |
| 71 for (DocumentMarker* marker : markers_) { | 71 for (DocumentMarker* marker : markers_) { |
| 72 RenderedDocumentMarker* const rendered_marker = | 72 TextMatchMarker* const text_match_marker = ToTextMatchMarker(marker); |
| 73 ToRenderedDocumentMarker(marker); | 73 if (!text_match_marker->IsValid()) |
| 74 if (!rendered_marker->IsValid()) | 74 UpdateMarkerRenderedRect(node, *text_match_marker); |
| 75 UpdateMarkerRenderedRect(node, *rendered_marker); | 75 if (!text_match_marker->IsRendered()) |
| 76 if (!rendered_marker->IsRendered()) | |
| 77 continue; | 76 continue; |
| 78 result.push_back(rendered_marker->RenderedRect()); | 77 result.push_back(text_match_marker->RenderedRect()); |
| 79 } | 78 } |
| 80 | 79 |
| 81 return result; | 80 return result; |
| 82 } | 81 } |
| 83 | 82 |
| 84 bool TextMatchMarkerListImpl::SetTextMatchMarkersActive(unsigned start_offset, | 83 bool TextMatchMarkerListImpl::SetTextMatchMarkersActive(unsigned start_offset, |
| 85 unsigned end_offset, | 84 unsigned end_offset, |
| 86 bool active) { | 85 bool active) { |
| 87 bool doc_dirty = false; | 86 bool doc_dirty = false; |
| 88 const auto start = std::upper_bound( | 87 const auto start = std::upper_bound( |
| 89 markers_.begin(), markers_.end(), start_offset, | 88 markers_.begin(), markers_.end(), start_offset, |
| 90 [](size_t start_offset, const Member<DocumentMarker>& marker) { | 89 [](size_t start_offset, const Member<DocumentMarker>& marker) { |
| 91 return start_offset < marker->EndOffset(); | 90 return start_offset < marker->EndOffset(); |
| 92 }); | 91 }); |
| 93 for (auto it = start; it != markers_.end(); ++it) { | 92 for (auto it = start; it != markers_.end(); ++it) { |
| 94 DocumentMarker& marker = **it; | 93 DocumentMarker& marker = **it; |
| 95 // Markers are returned in order, so stop if we are now past the specified | 94 // Markers are returned in order, so stop if we are now past the specified |
| 96 // range. | 95 // range. |
| 97 if (marker.StartOffset() >= end_offset) | 96 if (marker.StartOffset() >= end_offset) |
| 98 break; | 97 break; |
| 99 marker.SetIsActiveMatch(active); | 98 marker.SetIsActiveMatch(active); |
| 100 doc_dirty = true; | 99 doc_dirty = true; |
| 101 } | 100 } |
| 102 return doc_dirty; | 101 return doc_dirty; |
| 103 } | 102 } |
| 104 | 103 |
| 105 } // namespace blink | 104 } // namespace blink |
| OLD | NEW |