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 reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
8 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 8 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 10 matching lines...) Expand all Loading... | |
21 * along with this library; see the file COPYING.LIB. If not, write to | 21 * along with this library; see the file COPYING.LIB. If not, write to |
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 * Boston, MA 02110-1301, USA. | 23 * Boston, MA 02110-1301, USA. |
24 * | 24 * |
25 */ | 25 */ |
26 | 26 |
27 #ifndef DocumentMarkerController_h | 27 #ifndef DocumentMarkerController_h |
28 #define DocumentMarkerController_h | 28 #define DocumentMarkerController_h |
29 | 29 |
30 #include "core/dom/DocumentMarker.h" | 30 #include "core/dom/DocumentMarker.h" |
31 #include "core/dom/Range.h" | |
31 #include "platform/geometry/IntRect.h" | 32 #include "platform/geometry/IntRect.h" |
32 #include "platform/heap/Handle.h" | 33 #include "platform/heap/Handle.h" |
33 #include "wtf/HashMap.h" | 34 #include "wtf/HashMap.h" |
34 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
39 class MarkerRemoverPredicate { | |
40 public: | |
41 MarkerRemoverPredicate(Document* document, const Vector<String>& words) | |
dcheng
2014/08/05 20:30:38
This can't ever be passed a non-null document righ
Klemen Forstnerič
2014/08/07 17:47:28
Done.
| |
42 : m_document(document), m_words(words) | |
43 { | |
44 } | |
45 | |
46 bool operator()(const DocumentMarker& documentMarker, | |
47 const Node* node) const { | |
48 | |
49 auto markerRange = Range::create(*m_document, | |
dcheng
2014/08/05 20:30:38
auto is not allowed in cross-platform code.
Klemen Forstnerič
2014/08/07 17:47:28
Done.
| |
50 const_cast<Node *>(node), documentMarker.startOffset(), | |
dcheng
2014/08/05 20:30:38
Convention is to have the * and & by the typename,
Klemen Forstnerič
2014/08/07 17:47:28
Done.
| |
51 const_cast<Node *>(node), documentMarker.endOffset()); | |
52 | |
53 return m_words.contains(markerRange->text()) | |
54 ? true : false; | |
55 } | |
56 | |
57 private: | |
58 Document* m_document; | |
59 Vector<String> m_words; | |
60 }; | |
61 | |
38 class LayoutPoint; | 62 class LayoutPoint; |
39 class LayoutRect; | 63 class LayoutRect; |
40 class Node; | 64 class Node; |
41 class Range; | |
42 class RenderedDocumentMarker; | 65 class RenderedDocumentMarker; |
43 | 66 |
44 class DocumentMarkerController FINAL : public NoBaseWillBeGarbageCollected<Docum entMarkerController> { | 67 class DocumentMarkerController FINAL : public NoBaseWillBeGarbageCollected<Docum entMarkerController> { |
45 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); WTF_MAKE_FAST_ALLOCATED_WILL _BE_REMOVED; | 68 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); WTF_MAKE_FAST_ALLOCATED_WILL _BE_REMOVED; |
46 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DocumentMarkerController); | 69 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DocumentMarkerController); |
47 public: | 70 public: |
48 | 71 |
49 DocumentMarkerController(); | 72 DocumentMarkerController(); |
50 | 73 |
51 void clear(); | 74 void clear(); |
52 void addMarker(Range*, DocumentMarker::MarkerType); | 75 void addMarker(Range*, DocumentMarker::MarkerType); |
53 void addMarker(Range*, DocumentMarker::MarkerType, const String& description ); | 76 void addMarker(Range*, DocumentMarker::MarkerType, const String& description ); |
54 void addMarker(Range*, DocumentMarker::MarkerType, const String& description , uint32_t hash); | 77 void addMarker(Range*, DocumentMarker::MarkerType, const String& description , uint32_t hash); |
55 void addTextMatchMarker(const Range*, bool activeMatch); | 78 void addTextMatchMarker(const Range*, bool activeMatch); |
56 | 79 |
57 void copyMarkers(Node* srcNode, unsigned startOffset, int length, Node* dstN ode, int delta); | 80 void copyMarkers(Node* srcNode, unsigned startOffset, int length, Node* dstN ode, int delta); |
58 bool hasMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::AllMar kers()); | 81 bool hasMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::AllMar kers()); |
59 | 82 |
60 void prepareForDestruction(); | 83 void prepareForDestruction(); |
61 // When a marker partially overlaps with range, if removePartiallyOverlappin gMarkers is true, we completely | 84 // When a marker partially overlaps with range, if removePartiallyOverlappin gMarkers is true, we completely |
62 // remove the marker. If the argument is false, we will adjust the span of t he marker so that it retains | 85 // remove the marker. If the argument is false, we will adjust the span of t he marker so that it retains |
63 // the portion that is outside of the range. | 86 // the portion that is outside of the range. |
64 enum RemovePartiallyOverlappingMarkerOrNot { DoNotRemovePartiallyOverlapping Marker, RemovePartiallyOverlappingMarker }; | 87 enum RemovePartiallyOverlappingMarkerOrNot { DoNotRemovePartiallyOverlapping Marker, RemovePartiallyOverlappingMarker }; |
65 void removeMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::All Markers(), RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappi ngMarker); | 88 void removeMarkers(Range*, DocumentMarker::MarkerTypes = DocumentMarker::All Markers(), RemovePartiallyOverlappingMarkerOrNot = DoNotRemovePartiallyOverlappi ngMarker); |
66 void removeMarkers(Node*, unsigned startOffset, int length, DocumentMarker:: MarkerTypes = DocumentMarker::AllMarkers(), RemovePartiallyOverlappingMarkerOrN ot = DoNotRemovePartiallyOverlappingMarker); | 89 void removeMarkers(Node*, unsigned startOffset, int length, DocumentMarker:: MarkerTypes = DocumentMarker::AllMarkers(), RemovePartiallyOverlappingMarkerOrN ot = DoNotRemovePartiallyOverlappingMarker); |
67 | 90 |
68 void removeMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers( )); | 91 void removeMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers( )); |
69 void removeMarkers(Node*, DocumentMarker::MarkerTypes = DocumentMarker::AllM arkers()); | 92 void removeMarkers(Node*, DocumentMarker::MarkerTypes = DocumentMarker::AllM arkers()); |
93 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); | |
70 void repaintMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers ()); | 94 void repaintMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers ()); |
71 void invalidateRenderedRectsForMarkersInRect(const LayoutRect&); | 95 void invalidateRenderedRectsForMarkersInRect(const LayoutRect&); |
72 void shiftMarkers(Node*, unsigned startOffset, int delta); | 96 void shiftMarkers(Node*, unsigned startOffset, int delta); |
73 void setMarkersActive(Range*, bool); | 97 void setMarkersActive(Range*, bool); |
74 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool) ; | 98 void setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool) ; |
75 | 99 |
76 DocumentMarker* markerContainingPoint(const LayoutPoint&, DocumentMarker::Ma rkerType); | 100 DocumentMarker* markerContainingPoint(const LayoutPoint&, DocumentMarker::Ma rkerType); |
77 DocumentMarkerVector markersFor(Node*, DocumentMarker::MarkerTypes = Documen tMarker::AllMarkers()); | 101 DocumentMarkerVector markersFor(Node*, DocumentMarker::MarkerTypes = Documen tMarker::AllMarkers()); |
78 DocumentMarkerVector markersInRange(Range*, DocumentMarker::MarkerTypes); | 102 DocumentMarkerVector markersInRange(Range*, DocumentMarker::MarkerTypes); |
79 DocumentMarkerVector markers(); | 103 DocumentMarkerVector markers(); |
80 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); | 104 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); |
81 | 105 |
82 void trace(Visitor*); | 106 void trace(Visitor*); |
83 | 107 |
84 #ifndef NDEBUG | 108 #ifndef NDEBUG |
85 void showMarkers() const; | 109 void showMarkers() const; |
86 #endif | 110 #endif |
87 | 111 |
88 private: | 112 private: |
89 void addMarker(Node*, const DocumentMarker&); | 113 void addMarker(Node*, const DocumentMarker&); |
90 | 114 |
91 typedef WillBeHeapVector<OwnPtrWillBeMember<RenderedDocumentMarker> > Marker List; | 115 typedef WillBeHeapVector<OwnPtrWillBeMember<RenderedDocumentMarker> > Marker List; |
92 typedef WillBeHeapVector<OwnPtrWillBeMember<MarkerList>, DocumentMarker::Mar kerTypeIndexesCount> MarkerLists; | 116 typedef WillBeHeapVector<OwnPtrWillBeMember<MarkerList>, DocumentMarker::Mar kerTypeIndexesCount> MarkerLists; |
93 typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<const Node>, OwnPtrWillBeMe mber<MarkerLists> > MarkerMap; | 117 typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<const Node>, OwnPtrWillBeMe mber<MarkerLists> > MarkerMap; |
118 | |
94 void mergeOverlapping(MarkerList*, DocumentMarker&); | 119 void mergeOverlapping(MarkerList*, DocumentMarker&); |
95 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); | 120 bool possiblyHasMarkers(DocumentMarker::MarkerTypes); |
96 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes) ; | 121 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes) ; |
97 | 122 |
98 MarkerMap m_markers; | 123 MarkerMap m_markers; |
99 // Provide a quick way to determine whether a particular marker type is abse nt without going through the map. | 124 // Provide a quick way to determine whether a particular marker type is abse nt without going through the map. |
100 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; | 125 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes; |
101 }; | 126 }; |
102 | 127 |
103 } // namespace blink | 128 } // namespace blink |
104 | 129 |
105 #ifndef NDEBUG | 130 #ifndef NDEBUG |
106 void showDocumentMarkers(const blink::DocumentMarkerController*); | 131 void showDocumentMarkers(const blink::DocumentMarkerController*); |
107 #endif | 132 #endif |
108 | 133 |
109 #endif // DocumentMarkerController_h | 134 #endif // DocumentMarkerController_h |
OLD | NEW |