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_ACTIVE_SUGGESTION_MARKER_LIST_IMPL_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_EDITING_MARKERS_ACTIVE_SUGGESTION_MARKER_LIST_IMPL_H_
7 
8 #include "third_party/blink/renderer/core/editing/markers/document_marker_list.h"
9 
10 namespace blink {
11 
12 // Implementation of DocumentMarkerList for ActiveSuggestion markers.
13 // ActiveSuggestion markers are always inserted in order, aside from some
14 // potential oddball cases (e.g. splitting the marker list into two nodes, then
15 // undoing the split). This means we can keep the list in sorted order to do
16 // some operations more efficiently, while still being able to do inserts in
17 // O(1) time at the end of the list.
18 class CORE_EXPORT ActiveSuggestionMarkerListImpl final
19     : public DocumentMarkerList {
20  public:
21   ActiveSuggestionMarkerListImpl() = default;
22 
23   // DocumentMarkerList implementations
24   DocumentMarker::MarkerType MarkerType() const final;
25 
26   bool IsEmpty() const final;
27 
28   void Add(DocumentMarker*) final;
29   void Clear() final;
30 
31   const HeapVector<Member<DocumentMarker>>& GetMarkers() const final;
32   DocumentMarker* FirstMarkerIntersectingRange(unsigned start_offset,
33                                                unsigned end_offset) const final;
34   HeapVector<Member<DocumentMarker>> MarkersIntersectingRange(
35       unsigned start_offset,
36       unsigned end_offset) const final;
37 
38   bool MoveMarkers(int length, DocumentMarkerList* dst_list) final;
39   bool RemoveMarkers(unsigned start_offset, int length) final;
40   bool ShiftMarkers(const String& node_text,
41                     unsigned offset,
42                     unsigned old_length,
43                     unsigned new_length) final;
44 
45   void Trace(Visitor*) const override;
46 
47  private:
48   HeapVector<Member<DocumentMarker>> markers_;
49 
50   DISALLOW_COPY_AND_ASSIGN(ActiveSuggestionMarkerListImpl);
51 };
52 
53 }  // namespace blink
54 
55 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_EDITING_MARKERS_ACTIVE_SUGGESTION_MARKER_LIST_IMPL_H_
56