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 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 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 Loading... | |
| 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); | |
| 110 // Returns true if markers within a range are found. | 112 // Returns true if markers within a range are found. |
| 111 bool setMarkersActive(const EphemeralRange&, bool); | 113 bool setMarkersActive(const EphemeralRange&, bool); |
| 112 // Returns true if markers within a range defined by a node, |startOffset| and | 114 // Returns true if markers within a range defined by a node, |startOffset| and |
| 113 // |endOffset| are found. | 115 // |endOffset| are found. |
| 114 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); | 116 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); |
| 115 bool hasMarkers(Node* node) const { return m_markers.contains(node); } | 117 bool hasMarkers(Node* node) const { return m_markers.contains(node); } |
| 116 | 118 |
| 117 DocumentMarkerVector markersFor( | 119 DocumentMarkerVector markersFor( |
| 118 Node*, | 120 Node*, |
| 119 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 121 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 120 DocumentMarkerVector markersInRange(const EphemeralRange&, | 122 DocumentMarkerVector markersInRange(const EphemeralRange&, |
| 121 DocumentMarker::MarkerTypes); | 123 DocumentMarker::MarkerTypes); |
| 122 DocumentMarkerVector markers(); | 124 DocumentMarkerVector markers(); |
| 123 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); | 125 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); |
| 124 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); | 126 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); |
| 125 void invalidateRectsForAllMarkers(); | 127 void invalidateRectsForAllMarkers(); |
| 126 void invalidateRectsForMarkersInNode(const Node&); | 128 void invalidateRectsForMarkersInNode(const Node&); |
| 127 | 129 |
| 128 DECLARE_TRACE(); | 130 DECLARE_TRACE(); |
| 129 | 131 |
| 130 #ifndef NDEBUG | 132 #ifndef NDEBUG |
| 131 void showMarkers() const; | 133 void showMarkers() const; |
| 132 #endif | 134 #endif |
| 133 | 135 |
| 136 // SynchronousMutationObserver | |
| 137 void didUpdateCharacterData(CharacterData*, | |
| 138 unsigned offset, | |
| 139 unsigned oldLength, | |
| 140 unsigned newLength) override; | |
| 141 | |
| 134 private: | 142 private: |
| 135 void addMarker(Node*, const DocumentMarker&); | 143 void addMarker(Node*, const DocumentMarker&); |
| 136 | 144 |
| 137 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; | 145 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; |
| 138 using MarkerLists = | 146 using MarkerLists = |
| 139 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; | 147 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; |
| 140 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; | 148 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; |
| 141 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); | 149 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); |
| 142 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); | 150 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); |
| 143 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes); | 151 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes); |
| 144 void removeMarkers(TextIterator&, | 152 void removeMarkers(TextIterator&, |
| 145 DocumentMarker::MarkerTypes, | 153 DocumentMarker::MarkerTypes, |
| 146 RemovePartiallyOverlappingMarkerOrNot); | 154 RemovePartiallyOverlappingMarkerOrNot); |
| 155 void removeZeroLengthMarkers(); | |
|
Xiaocheng
2017/02/23 18:58:35
This should be removed.
| |
| 147 | 156 |
| 148 MarkerMap m_markers; | 157 MarkerMap m_markers; |
| 149 // Provide a quick way to determine whether a particular marker type is absent | 158 // Provide a quick way to determine whether a particular marker type is absent |
| 150 // without going through the map. | 159 // without going through the map. |
| 151 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; | 160 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; |
| 152 const Member<const Document> m_document; | 161 const Member<const Document> m_document; |
| 153 }; | 162 }; |
| 154 | 163 |
| 155 } // namespace blink | 164 } // namespace blink |
| 156 | 165 |
| 157 #ifndef NDEBUG | 166 #ifndef NDEBUG |
| 158 void showDocumentMarkers(const blink::DocumentMarkerController*); | 167 void showDocumentMarkers(const blink::DocumentMarkerController*); |
| 159 #endif | 168 #endif |
| 160 | 169 |
| 161 #endif // DocumentMarkerController_h | 170 #endif // DocumentMarkerController_h |
| OLD | NEW |