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 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_EDITING_MARKERS_UNSORTED_DOCUMENT_MARKER_LIST_EDITOR_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_CORE_EDITING_MARKERS_UNSORTED_DOCUMENT_MARKER_LIST_EDITOR_H_ 7 8 #include "third_party/blink/renderer/core/editing/markers/document_marker_list.h" 9 #include "third_party/blink/renderer/platform/heap/handle.h" 10 11 namespace blink { 12 13 class DocumentMarker; 14 15 // This class holds static utility methods to be used in DocumentMarkerList 16 // implementations that store potentially overlapping markers in unsorted order. 17 class CORE_EXPORT UnsortedDocumentMarkerListEditor final { 18 public: 19 using MarkerList = HeapVector<Member<DocumentMarker>>; 20 21 // Returns true if a marker was moved, false otherwise. 22 static bool MoveMarkers(MarkerList* src_list, 23 int length, 24 DocumentMarkerList* dst_list); 25 26 // Returns true if a marker was removed, false otherwise. 27 static bool RemoveMarkers(MarkerList*, unsigned start_offset, int length); 28 29 // Returns true if a marker was shifted or removed, false otherwise. 30 // If the text marked by a marker is changed by the edit, this method attempts 31 // to keep the marker tracking the marked region rather than removing the 32 // marker. 33 static bool ShiftMarkersContentIndependent(MarkerList*, 34 unsigned offset, 35 unsigned old_length, 36 unsigned new_length); 37 38 // Returns the first marker in the specified MarkerList whose interior 39 // overlaps overlap with the range [start_offset, end_offset], or null if 40 // there is no such marker. 41 // Note: since the markers aren't stored in order in an unsorted marker list, 42 // the first marker found isn't necessarily going to be the first marker 43 // ordered by start or end offset. 44 static DocumentMarker* FirstMarkerIntersectingRange(const MarkerList&, 45 unsigned start_offset, 46 unsigned end_offset); 47 48 // Returns all markers in the specified MarkerList whose interior overlaps 49 // with the range [start_offset, end_offset]. 50 static HeapVector<Member<DocumentMarker>> MarkersIntersectingRange( 51 const MarkerList&, 52 unsigned start_offset, 53 unsigned end_offset); 54 }; 55 56 } // namespace blink 57 58 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_EDITING_MARKERS_UNSORTED_DOCUMENT_MARKER_LIST_EDITOR_H_ 59