| 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 |
| 43 class DocumentMarkerList; |
| 42 class Node; | 44 class Node; |
| 43 class RenderedDocumentMarker; | |
| 44 class Text; | |
| 45 | 45 |
| 46 class MarkerRemoverPredicate final { | 46 class MarkerRemoverPredicate final { |
| 47 public: | 47 public: |
| 48 explicit MarkerRemoverPredicate(const Vector<String>& words); | 48 explicit MarkerRemoverPredicate(const Vector<String>& words); |
| 49 bool operator()(const DocumentMarker&, const Text&) const; | 49 bool operator()(const DocumentMarker&, const Text&) const; |
| 50 | 50 |
| 51 private: | |
| 52 Vector<String> m_words; | 51 Vector<String> m_words; |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 class CORE_EXPORT DocumentMarkerController final | 54 class CORE_EXPORT DocumentMarkerController final |
| 56 : public GarbageCollected<DocumentMarkerController> { | 55 : public GarbageCollected<DocumentMarkerController>, |
| 56 public SynchronousMutationObserver { |
| 57 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); | 57 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); |
| 58 USING_GARBAGE_COLLECTED_MIXIN(DocumentMarkerController); |
| 58 | 59 |
| 59 public: | 60 public: |
| 60 explicit DocumentMarkerController(const Document&); | 61 explicit DocumentMarkerController(Document&); |
| 61 | 62 |
| 62 void clear(); | 63 void clear(); |
| 64 void addMarker(Node*, DocumentMarker*); |
| 63 void addMarker(const Position& start, | 65 void addMarker(const Position& start, |
| 64 const Position& end, | 66 const Position& end, |
| 65 DocumentMarker::MarkerType, | 67 DocumentMarker::MarkerType, |
| 66 const String& description = emptyString); | 68 const String& description = emptyString); |
| 67 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); | 69 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); |
| 68 void addCompositionMarker(const Position& start, | 70 void addCompositionMarker(const Position& start, |
| 69 const Position& end, | 71 const Position& end, |
| 70 Color underlineColor, | 72 Color underlineColor, |
| 71 bool thick, | 73 bool thick, |
| 72 Color backgroundColor); | 74 Color backgroundColor); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 98 DoNotRemovePartiallyOverlappingMarker); | 100 DoNotRemovePartiallyOverlappingMarker); |
| 99 | 101 |
| 100 void removeMarkers( | 102 void removeMarkers( |
| 101 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 103 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 102 void removeMarkers( | 104 void removeMarkers( |
| 103 Node*, | 105 Node*, |
| 104 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 106 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 105 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); | 107 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); |
| 106 void repaintMarkers( | 108 void repaintMarkers( |
| 107 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 109 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 108 void shiftMarkers(Node*, unsigned startOffset, int delta); | |
| 109 // Returns true if markers within a range are found. | 110 // Returns true if markers within a range are found. |
| 110 bool setMarkersActive(const EphemeralRange&, bool); | 111 bool setMarkersActive(const EphemeralRange&, bool); |
| 111 // Returns true if markers within a range defined by a node, |startOffset| and | 112 // Returns true if markers within a range defined by a node, |startOffset| and |
| 112 // |endOffset| are found. | 113 // |endOffset| are found. |
| 113 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); | 114 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); |
| 114 bool hasMarkers(Node* node) const { return m_markers.contains(node); } | 115 bool hasMarkers(Node*) const; |
| 115 | 116 |
| 116 DocumentMarkerVector markersFor( | 117 DocumentMarkerVector markersFor( |
| 117 Node*, | 118 Node*, |
| 118 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); | 119 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 119 DocumentMarkerVector markersInRange(const EphemeralRange&, | 120 DocumentMarkerVector markersInRange(const EphemeralRange&, |
| 120 DocumentMarker::MarkerTypes); | 121 DocumentMarker::MarkerTypes); |
| 121 DocumentMarkerVector markers(); | 122 DocumentMarkerVector markers(); |
| 122 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); | 123 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); |
| 123 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); | 124 |
| 124 void invalidateRectsForAllMarkers(); | 125 void invalidateRectsForAllMarkers(); |
| 125 void invalidateRectsForMarkersInNode(const Node&); | 126 void invalidateRectsForMarkersInNode(Node&); |
| 126 | 127 |
| 127 DECLARE_TRACE(); | 128 DECLARE_TRACE(); |
| 128 | 129 |
| 129 #ifndef NDEBUG | 130 #ifndef NDEBUG |
| 130 void showMarkers() const; | 131 void showMarkers() const; |
| 131 #endif | 132 #endif |
| 132 | 133 |
| 134 // SynchronousMutationObserver |
| 135 void didUpdateCharacterData(CharacterData*, |
| 136 unsigned offset, |
| 137 unsigned oldLength, |
| 138 unsigned newLength) final; |
| 139 |
| 133 private: | 140 private: |
| 134 void addMarker(Node*, const DocumentMarker&); | 141 using MarkerMap = HeapHashMap<WeakMember<Node>, Member<DocumentMarkerList>>; |
| 135 | 142 |
| 136 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; | 143 DocumentMarkerList* createMarkerListOfType(DocumentMarker::MarkerType); |
| 137 using MarkerLists = | 144 HeapVector<Member<DocumentMarkerList>> getMarkerListsForNode( |
| 138 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; | 145 Node*, |
| 139 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; | 146 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); |
| 140 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); | 147 MarkerMap& markerMapForType(DocumentMarker::MarkerType); |
| 141 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); | |
| 142 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes); | |
| 143 void removeMarkers(TextIterator&, | 148 void removeMarkers(TextIterator&, |
| 144 DocumentMarker::MarkerTypes, | 149 DocumentMarker::MarkerTypes, |
| 145 RemovePartiallyOverlappingMarkerOrNot); | 150 RemovePartiallyOverlappingMarkerOrNot); |
| 146 | 151 |
| 147 MarkerMap m_markers; | 152 MarkerMap m_spelling; |
| 148 // Provide a quick way to determine whether a particular marker type is absent | 153 MarkerMap m_grammar; |
| 149 // without going through the map. | 154 MarkerMap m_textMatches; |
| 150 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; | 155 MarkerMap m_compositions; |
| 156 |
| 151 const Member<const Document> m_document; | 157 const Member<const Document> m_document; |
| 152 }; | 158 }; |
| 153 | 159 |
| 154 } // namespace blink | 160 } // namespace blink |
| 155 | 161 |
| 156 #ifndef NDEBUG | 162 #ifndef NDEBUG |
| 157 void showDocumentMarkers(const blink::DocumentMarkerController*); | 163 void showDocumentMarkers(const blink::DocumentMarkerController*); |
| 158 #endif | 164 #endif |
| 159 | 165 |
| 160 #endif // DocumentMarkerController_h | 166 #endif // DocumentMarkerController_h |
| OLD | NEW |