OLD | NEW |
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 Loading... |
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 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); | 70 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); |
68 void addCompositionMarker(const Position& start, | 71 void addCompositionMarker(const Position& start, |
69 const Position& end, | 72 const Position& end, |
70 Color underlineColor, | 73 Color underlineColor, |
(...skipping 27 matching lines...) Expand all Loading... |
98 DoNotRemovePartiallyOverlappingMarker); | 101 DoNotRemovePartiallyOverlappingMarker); |
99 | 102 |
100 void removeMarkers( | 103 void removeMarkers( |
101 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 104 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
102 void removeMarkers( | 105 void removeMarkers( |
103 Node*, | 106 Node*, |
104 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 107 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
105 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); | 108 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); |
106 void repaintMarkers( | 109 void repaintMarkers( |
107 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 110 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
108 void shiftMarkers(Node*, unsigned startOffset, int delta); | |
109 // Returns true if markers within a range are found. | 111 // Returns true if markers within a range are found. |
110 bool setMarkersActive(const EphemeralRange&, bool); | 112 bool setMarkersActive(const EphemeralRange&, bool); |
111 // Returns true if markers within a range defined by a node, |startOffset| and | 113 // Returns true if markers within a range defined by a node, |startOffset| and |
112 // |endOffset| are found. | 114 // |endOffset| are found. |
113 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); | 115 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); |
114 bool hasMarkers(Node* node) const { return m_markers.contains(node); } | 116 bool hasMarkers(Node* node) const { return m_markers.contains(node); } |
115 | 117 |
116 DocumentMarkerVector markersFor( | 118 DocumentMarkerVector markersFor( |
117 Node*, | 119 Node*, |
118 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 120 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
119 DocumentMarkerVector markersInRange(const EphemeralRange&, | 121 DocumentMarkerVector markersInRange(const EphemeralRange&, |
120 DocumentMarker::MarkerTypes); | 122 DocumentMarker::MarkerTypes); |
121 DocumentMarkerVector markers(); | 123 DocumentMarkerVector markers(); |
122 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); | 124 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); |
123 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); | 125 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); |
124 void invalidateRectsForAllMarkers(); | 126 void invalidateRectsForAllMarkers(); |
125 void invalidateRectsForMarkersInNode(const Node&); | 127 void invalidateRectsForMarkersInNode(const Node&); |
126 | 128 |
127 DECLARE_TRACE(); | 129 DECLARE_TRACE(); |
128 | 130 |
129 #ifndef NDEBUG | 131 #ifndef NDEBUG |
130 void showMarkers() const; | 132 void showMarkers() const; |
131 #endif | 133 #endif |
132 | 134 |
| 135 // SynchronousMutationObserver |
| 136 void didUpdateCharacterData(CharacterData*, |
| 137 unsigned offset, |
| 138 unsigned oldLength, |
| 139 unsigned newLength) final; |
| 140 |
133 private: | 141 private: |
134 void addMarker(Node*, const DocumentMarker&); | 142 void addMarker(Node*, const DocumentMarker&); |
135 | 143 |
136 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; | 144 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; |
137 using MarkerLists = | 145 using MarkerLists = |
138 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; | 146 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; |
139 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; | 147 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; |
140 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); | 148 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); |
141 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); | 149 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); |
142 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes); | 150 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes); |
143 void removeMarkers(TextIterator&, | 151 void removeMarkers(TextIterator&, |
144 DocumentMarker::MarkerTypes, | 152 DocumentMarker::MarkerTypes, |
145 RemovePartiallyOverlappingMarkerOrNot); | 153 RemovePartiallyOverlappingMarkerOrNot); |
146 | 154 |
147 MarkerMap m_markers; | 155 MarkerMap m_markers; |
148 // Provide a quick way to determine whether a particular marker type is absent | 156 // Provide a quick way to determine whether a particular marker type is absent |
149 // without going through the map. | 157 // without going through the map. |
150 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; | 158 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; |
151 const Member<const Document> m_document; | 159 const Member<const Document> m_document; |
152 }; | 160 }; |
153 | 161 |
154 } // namespace blink | 162 } // namespace blink |
155 | 163 |
156 #ifndef NDEBUG | 164 #ifndef NDEBUG |
157 void showDocumentMarkers(const blink::DocumentMarkerController*); | 165 void showDocumentMarkers(const blink::DocumentMarkerController*); |
158 #endif | 166 #endif |
159 | 167 |
160 #endif // DocumentMarkerController_h | 168 #endif // DocumentMarkerController_h |
OLD | NEW |