Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 33 #include "core/dom/SynchronousMutationObserver.h" | 33 #include "core/dom/SynchronousMutationObserver.h" |
| 34 #include "core/editing/iterators/TextIterator.h" | 34 #include "core/editing/iterators/TextIterator.h" |
| 35 #include "core/editing/markers/DocumentMarker.h" | 35 #include "core/editing/markers/DocumentMarker.h" |
| 36 #include "platform/geometry/IntRect.h" | 36 #include "platform/geometry/IntRect.h" |
| 37 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
| 38 #include "wtf/HashMap.h" | 38 #include "wtf/HashMap.h" |
| 39 #include "wtf/Vector.h" | 39 #include "wtf/Vector.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 class CompositionMarkerList; | |
| 44 class DocumentMarkerList; | |
| 45 class GrammarMarkerList; | |
| 43 class Node; | 46 class Node; |
| 44 class RenderedDocumentMarker; | 47 class SpellingMarkerList; |
| 45 class Text; | 48 class TextMatchMarkerList; |
| 46 | 49 |
| 47 class MarkerRemoverPredicate final { | 50 class MarkerRemoverPredicate final { |
| 48 public: | 51 public: |
| 49 explicit MarkerRemoverPredicate(const Vector<String>& words); | 52 explicit MarkerRemoverPredicate(const Vector<String>& words); |
| 50 bool operator()(const DocumentMarker&, const Text&) const; | 53 bool operator()(const DocumentMarker&, const Text&) const; |
| 51 | 54 |
| 52 private: | |
|
Xiaocheng
2017/03/21 19:12:11
Irrelevant change.
rlanday
2017/03/21 19:49:12
This is necessary because I'm changing the impleme
| |
| 53 Vector<String> m_words; | 55 Vector<String> m_words; |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 class CORE_EXPORT DocumentMarkerController final | 58 class CORE_EXPORT DocumentMarkerController final |
| 57 : public GarbageCollected<DocumentMarkerController>, | 59 : public GarbageCollected<DocumentMarkerController>, |
| 58 public SynchronousMutationObserver { | 60 public SynchronousMutationObserver { |
| 59 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); | 61 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); |
| 60 USING_GARBAGE_COLLECTED_MIXIN(DocumentMarkerController); | 62 USING_GARBAGE_COLLECTED_MIXIN(DocumentMarkerController); |
| 61 | 63 |
| 62 public: | 64 public: |
| 63 explicit DocumentMarkerController(Document&); | 65 explicit DocumentMarkerController(Document&); |
| 64 | 66 |
| 65 void clear(); | 67 void clear(); |
| 68 void addMarker(Node*, DocumentMarker*); | |
| 66 void addMarker(const Position& start, | 69 void addMarker(const Position& start, |
| 67 const Position& end, | 70 const Position& end, |
| 68 DocumentMarker::MarkerType, | 71 DocumentMarker::MarkerType, |
| 69 const String& description = emptyString); | 72 const String& description = emptyString); |
| 70 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); | 73 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); |
| 71 void addCompositionMarker(const Position& start, | 74 void addCompositionMarker(const Position& start, |
| 72 const Position& end, | 75 const Position& end, |
| 73 Color underlineColor, | 76 Color underlineColor, |
| 74 bool thick, | 77 bool thick, |
| 75 Color backgroundColor); | 78 Color backgroundColor); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 106 Node*, | 109 Node*, |
| 107 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 110 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 108 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); | 111 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); |
| 109 void repaintMarkers( | 112 void repaintMarkers( |
| 110 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 113 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 111 // Returns true if markers within a range are found. | 114 // Returns true if markers within a range are found. |
| 112 bool setMarkersActive(const EphemeralRange&, bool); | 115 bool setMarkersActive(const EphemeralRange&, bool); |
| 113 // Returns true if markers within a range defined by a node, |startOffset| and | 116 // Returns true if markers within a range defined by a node, |startOffset| and |
| 114 // |endOffset| are found. | 117 // |endOffset| are found. |
| 115 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); | 118 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); |
| 116 bool hasMarkers(Node* node) const { return m_markers.contains(node); } | 119 bool hasMarkers(Node*) const; |
| 117 | 120 |
| 118 DocumentMarkerVector markersFor( | 121 DocumentMarkerVector markersFor( |
| 119 Node*, | 122 Node*, |
| 120 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 123 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 121 DocumentMarkerVector markersInRange(const EphemeralRange&, | 124 DocumentMarkerVector markersInRange(const EphemeralRange&, |
| 122 DocumentMarker::MarkerTypes); | 125 DocumentMarker::MarkerTypes); |
| 123 DocumentMarkerVector markers(); | 126 DocumentMarkerVector markers(); |
| 124 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); | 127 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); |
| 125 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); | 128 |
| 126 void invalidateRectsForAllMarkers(); | 129 void invalidateRectsForAllMarkers(); |
| 127 void invalidateRectsForMarkersInNode(const Node&); | 130 void invalidateRectsForMarkersInNode(Node&); |
| 128 | 131 |
| 129 DECLARE_TRACE(); | 132 DECLARE_TRACE(); |
| 130 | 133 |
| 131 #ifndef NDEBUG | 134 #ifndef NDEBUG |
| 132 void showMarkers() const; | 135 void showMarkers() const; |
| 133 #endif | 136 #endif |
| 134 | 137 |
| 135 // SynchronousMutationObserver | 138 // SynchronousMutationObserver |
| 136 void didUpdateCharacterData(CharacterData*, | 139 void didUpdateCharacterData(CharacterData*, |
| 137 unsigned offset, | 140 unsigned offset, |
| 138 unsigned oldLength, | 141 unsigned oldLength, |
| 139 unsigned newLength) final; | 142 unsigned newLength) final; |
| 140 | 143 |
| 141 private: | 144 private: |
| 142 void addMarker(Node*, const DocumentMarker&); | 145 template <typename MarkerListType> |
| 146 using MarkerMap = HeapHashMap<WeakMember<Node>, Member<MarkerListType>>; | |
| 143 | 147 |
| 144 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; | 148 template <typename MarkerListType> |
| 145 using MarkerLists = | 149 void addIntoMarkerMap(MarkerMap<MarkerListType>* markerMap, |
|
Xiaocheng
2017/03/21 19:12:11
Hmm... I forgot that templated member functions mu
rlanday
2017/03/21 19:49:12
We can try that, but then we'll have to cast the m
| |
| 146 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; | 150 Node* node, |
| 147 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; | 151 DocumentMarker* newMarker) { |
| 148 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); | 152 auto it = markerMap->find(node); |
| 149 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); | 153 if (it == markerMap->end()) { |
| 150 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes); | 154 markerMap->insert(node, new MarkerListType(this)); |
| 155 it = markerMap->find(node); | |
| 156 } | |
| 157 it->value->insert(newMarker); | |
| 158 } | |
| 159 | |
| 160 template <typename MarkerListType> | |
| 161 void shiftMarkersInNode(MarkerMap<MarkerListType>* markerMap, | |
| 162 CharacterData* node, | |
| 163 unsigned offset, | |
| 164 unsigned oldLength, | |
| 165 unsigned newLength, | |
| 166 bool* didShiftMarker) { | |
| 167 auto it = markerMap->find(node); | |
| 168 if (it != markerMap->end()) { | |
| 169 *didShiftMarker = it->value->shiftMarkers(offset, oldLength, newLength) || | |
| 170 *didShiftMarker; | |
| 171 } | |
| 172 } | |
| 173 | |
| 174 template <typename MarkerListType> | |
| 175 void removeMarkersInRangeFromNode(MarkerMap<MarkerListType>* markerMap, | |
| 176 Node* node, | |
| 177 unsigned startOffset, | |
| 178 int length, | |
| 179 RemovePartiallyOverlappingMarkerOrNot | |
| 180 shouldRemovePartiallyOverlappingMarker, | |
| 181 bool* docDirty) { | |
| 182 auto it = markerMap->find(node); | |
| 183 if (it != markerMap->end()) { | |
| 184 it->value->removeMarkers(startOffset, length, | |
| 185 shouldRemovePartiallyOverlappingMarker, | |
| 186 docDirty); | |
| 187 if (it->value->empty()) | |
| 188 markerMap->remove(node); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 HeapVector<Member<DocumentMarkerList>> getMarkerListsForNode( | |
| 193 Node*, | |
| 194 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | |
| 151 void removeMarkers(TextIterator&, | 195 void removeMarkers(TextIterator&, |
| 152 DocumentMarker::MarkerTypes, | 196 DocumentMarker::MarkerTypes, |
| 153 RemovePartiallyOverlappingMarkerOrNot); | 197 RemovePartiallyOverlappingMarkerOrNot); |
| 154 | 198 |
| 155 MarkerMap m_markers; | 199 MarkerMap<SpellingMarkerList> m_spelling; |
| 156 // Provide a quick way to determine whether a particular marker type is absent | 200 MarkerMap<GrammarMarkerList> m_grammar; |
| 157 // without going through the map. | 201 MarkerMap<TextMatchMarkerList> m_textMatches; |
| 158 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; | 202 MarkerMap<CompositionMarkerList> m_compositions; |
| 203 | |
| 159 const Member<const Document> m_document; | 204 const Member<const Document> m_document; |
| 160 }; | 205 }; |
| 161 | 206 |
| 162 } // namespace blink | 207 } // namespace blink |
| 163 | 208 |
| 164 #ifndef NDEBUG | 209 #ifndef NDEBUG |
| 165 void showDocumentMarkers(const blink::DocumentMarkerController*); | 210 void showDocumentMarkers(const blink::DocumentMarkerController*); |
| 166 #endif | 211 #endif |
| 167 | 212 |
| 168 #endif // DocumentMarkerController_h | 213 #endif // DocumentMarkerController_h |
| OLD | NEW |