Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(670)

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.h

Issue 2692093003: Rewrite DocumentMarkerController to use SynchronousMutationObserver (Closed)
Patch Set: Don't try to use -1 as default value for unsigned int Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
7 * reserved. 7 * reserved.
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
(...skipping 12 matching lines...) Expand all
23 * along with this library; see the file COPYING.LIB. If not, write to 23 * along with this library; see the file COPYING.LIB. If not, write to
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA. 25 * Boston, MA 02110-1301, USA.
26 * 26 *
27 */ 27 */
28 28
29 #ifndef DocumentMarkerController_h 29 #ifndef DocumentMarkerController_h
30 #define DocumentMarkerController_h 30 #define DocumentMarkerController_h
31 31
32 #include "core/CoreExport.h" 32 #include "core/CoreExport.h"
33 #include "core/dom/SynchronousMutationObserver.h"
33 #include "core/editing/iterators/TextIterator.h" 34 #include "core/editing/iterators/TextIterator.h"
34 #include "core/editing/markers/DocumentMarker.h" 35 #include "core/editing/markers/DocumentMarker.h"
35 #include "platform/geometry/IntRect.h" 36 #include "platform/geometry/IntRect.h"
36 #include "platform/heap/Handle.h" 37 #include "platform/heap/Handle.h"
37 #include "wtf/HashMap.h" 38 #include "wtf/HashMap.h"
38 #include "wtf/Vector.h" 39 #include "wtf/Vector.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 class Node; 43 class Node;
43 class RenderedDocumentMarker; 44 class RenderedDocumentMarker;
44 class Text; 45 class Text;
45 46
46 class MarkerRemoverPredicate final { 47 class MarkerRemoverPredicate final {
47 public: 48 public:
48 explicit MarkerRemoverPredicate(const Vector<String>& words); 49 explicit MarkerRemoverPredicate(const Vector<String>& words);
49 bool operator()(const DocumentMarker&, const Text&) const; 50 bool operator()(const DocumentMarker&, const Text&) const;
50 51
51 private: 52 private:
52 Vector<String> m_words; 53 Vector<String> m_words;
53 }; 54 };
54 55
55 class CORE_EXPORT DocumentMarkerController final 56 class CORE_EXPORT DocumentMarkerController final
56 : public GarbageCollected<DocumentMarkerController> { 57 : public GarbageCollected<DocumentMarkerController>,
58 public SynchronousMutationObserver {
57 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); 59 WTF_MAKE_NONCOPYABLE(DocumentMarkerController);
60 USING_GARBAGE_COLLECTED_MIXIN(DocumentMarkerController);
58 61
59 public: 62 public:
60 explicit DocumentMarkerController(const Document&); 63 explicit DocumentMarkerController(Document&);
61 64
62 void clear(); 65 void clear();
63 void addMarker(const Position& start, 66 void addMarker(const Position& start,
64 const Position& end, 67 const Position& end,
65 DocumentMarker::MarkerType, 68 DocumentMarker::MarkerType,
66 const String& description = emptyString, 69 const String& description = emptyString,
67 uint32_t hash = 0); 70 uint32_t hash = 0);
68 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); 71 void addTextMatchMarker(const EphemeralRange&, bool activeMatch);
69 void addCompositionMarker(const Position& start, 72 void addCompositionMarker(const Position& start,
70 const Position& end, 73 const Position& end,
(...skipping 28 matching lines...) Expand all
99 DoNotRemovePartiallyOverlappingMarker); 102 DoNotRemovePartiallyOverlappingMarker);
100 103
101 void removeMarkers( 104 void removeMarkers(
102 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 105 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
103 void removeMarkers( 106 void removeMarkers(
104 Node*, 107 Node*,
105 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 108 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
106 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); 109 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker);
107 void repaintMarkers( 110 void repaintMarkers(
108 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 111 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
109 void shiftMarkers(Node*, unsigned startOffset, int delta); 112 void shiftMarkers(Node*, int startOffset, int prevLength, int newLength);
110 // Returns true if markers within a range are found. 113 // Returns true if markers within a range are found.
111 bool setMarkersActive(const EphemeralRange&, bool); 114 bool setMarkersActive(const EphemeralRange&, bool);
112 // Returns true if markers within a range defined by a node, |startOffset| and 115 // Returns true if markers within a range defined by a node, |startOffset| and
113 // |endOffset| are found. 116 // |endOffset| are found.
114 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); 117 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
115 bool hasMarkers(Node* node) const { return m_markers.contains(node); } 118 bool hasMarkers(Node* node) const { return m_markers.contains(node); }
116 119
117 DocumentMarkerVector markersFor( 120 DocumentMarkerVector markersFor(
118 Node*, 121 Node*,
119 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 122 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
120 DocumentMarkerVector markersInRange(const EphemeralRange&, 123 DocumentMarkerVector markersInRange(const EphemeralRange&,
121 DocumentMarker::MarkerTypes); 124 DocumentMarker::MarkerTypes);
122 DocumentMarkerVector markers(); 125 DocumentMarkerVector markers();
123 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); 126 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType);
124 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); 127 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&);
125 void invalidateRectsForAllMarkers(); 128 void invalidateRectsForAllMarkers();
126 void invalidateRectsForMarkersInNode(const Node&); 129 void invalidateRectsForMarkersInNode(const Node&);
127 130
128 DECLARE_TRACE(); 131 DECLARE_TRACE();
129 132
130 #ifndef NDEBUG 133 #ifndef NDEBUG
131 void showMarkers() const; 134 void showMarkers() const;
132 #endif 135 #endif
133 136
137 // SynchronousMutationObserver
138 void didUpdateCharacterData(CharacterData*,
139 unsigned offset,
140 unsigned oldLength,
141 unsigned newLength) override;
142
134 private: 143 private:
135 void addMarker(Node*, const DocumentMarker&); 144 void addMarker(Node*, const DocumentMarker&);
136 145
137 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; 146 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>;
138 using MarkerLists = 147 using MarkerLists =
139 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; 148 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>;
140 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; 149 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>;
141 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); 150 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*);
142 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); 151 bool possiblyHasMarkers(DocumentMarker::MarkerTypes);
143 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes); 152 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes);
144 void removeMarkers(TextIterator&, 153 void removeMarkers(TextIterator&,
145 DocumentMarker::MarkerTypes, 154 DocumentMarker::MarkerTypes,
146 RemovePartiallyOverlappingMarkerOrNot); 155 RemovePartiallyOverlappingMarkerOrNot);
156 void removeZeroLengthMarkers();
147 157
148 MarkerMap m_markers; 158 MarkerMap m_markers;
149 // Provide a quick way to determine whether a particular marker type is absent 159 // Provide a quick way to determine whether a particular marker type is absent
150 // without going through the map. 160 // without going through the map.
151 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; 161 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes;
152 const Member<const Document> m_document; 162 const Member<const Document> m_document;
153 }; 163 };
154 164
155 } // namespace blink 165 } // namespace blink
156 166
157 #ifndef NDEBUG 167 #ifndef NDEBUG
158 void showDocumentMarkers(const blink::DocumentMarkerController*); 168 void showDocumentMarkers(const blink::DocumentMarkerController*);
159 #endif 169 #endif
160 170
161 #endif // DocumentMarkerController_h 171 #endif // DocumentMarkerController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698