Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.h

Issue 2723663002: Refactor DocumentMarkerController (Closed)
Patch Set: Remove logging Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
32 #include "core/CoreExport.h" 32 #include "core/CoreExport.h"
33 #include "core/editing/iterators/TextIterator.h" 33 #include "core/editing/iterators/TextIterator.h"
34 #include "core/editing/markers/DocumentMarker.h" 34 #include "core/editing/markers/DocumentMarker.h"
35 #include "platform/geometry/IntRect.h" 35 #include "platform/geometry/IntRect.h"
36 #include "platform/heap/Handle.h" 36 #include "platform/heap/Handle.h"
37 #include "wtf/HashMap.h" 37 #include "wtf/HashMap.h"
38 #include "wtf/Vector.h" 38 #include "wtf/Vector.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 class CompositionMarkerList;
43 class GrammarMarkerList;
42 class Node; 44 class Node;
43 class RenderedDocumentMarker; 45 class RenderedTextMatchMarker;
44 class Text; 46 class SpellingMarkerList;
47 class TextMatchMarkerList;
45 48
46 class MarkerRemoverPredicate final { 49 class MarkerRemoverPredicate final {
47 public: 50 public:
48 explicit MarkerRemoverPredicate(const Vector<String>& words); 51 explicit MarkerRemoverPredicate(const Vector<String>& words);
49 bool operator()(const DocumentMarker&, const Text&) const;
50
51 private:
52 Vector<String> m_words; 52 Vector<String> m_words;
53 }; 53 };
54 54
55 class CORE_EXPORT DocumentMarkerController final 55 class CORE_EXPORT DocumentMarkerController final
56 : public GarbageCollected<DocumentMarkerController> { 56 : public GarbageCollectedFinalized<DocumentMarkerController> {
57 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); 57 WTF_MAKE_NONCOPYABLE(DocumentMarkerController);
58 58
59 public: 59 public:
60 explicit DocumentMarkerController(const Document&); 60 explicit DocumentMarkerController(const Document&);
61 61
62 void clear(); 62 void clear();
63 void addMarker(Node*, DocumentMarker*);
63 void addMarker(const Position& start, 64 void addMarker(const Position& start,
64 const Position& end, 65 const Position& end,
65 DocumentMarker::MarkerType, 66 DocumentMarker::MarkerType,
66 const String& description = emptyString); 67 const String& description = emptyString);
67 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); 68 void addTextMatchMarker(const EphemeralRange&, bool activeMatch);
68 void addCompositionMarker(const Position& start, 69 void addCompositionMarker(const Position& start,
69 const Position& end, 70 const Position& end,
70 Color underlineColor, 71 Color underlineColor,
71 bool thick, 72 bool thick,
72 Color backgroundColor); 73 Color backgroundColor);
(...skipping 29 matching lines...) Expand all
102 void removeMarkers( 103 void removeMarkers(
103 Node*, 104 Node*,
104 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 105 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
105 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); 106 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker);
106 void repaintMarkers( 107 void repaintMarkers(
107 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 108 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
108 void shiftMarkers(Node*, unsigned startOffset, int delta); 109 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> renderedRectsForTextMatchMarkers();
123 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); 124 void updateTextMatchMarkerRenderedRectIfNeeded(const Node&,
125 RenderedTextMatchMarker&);
124 void invalidateRectsForAllMarkers(); 126 void invalidateRectsForAllMarkers();
125 void invalidateRectsForMarkersInNode(const Node&); 127 void invalidateRectsForMarkersInNode(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
133 private: 135 private:
134 void addMarker(Node*, const DocumentMarker&); 136 template <typename MarkerListType>
137 using MarkerMap = HeapHashMap<WeakMember<Node>, Member<MarkerListType>>;
135 138
136 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; 139 MarkerMap<SpellingMarkerList> m_spelling;
137 using MarkerLists = 140 MarkerMap<GrammarMarkerList> m_grammar;
138 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; 141 MarkerMap<TextMatchMarkerList> m_textMatches;
139 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; 142 MarkerMap<CompositionMarkerList> m_compositions;
140 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); 143
141 bool possiblyHasMarkers(DocumentMarker::MarkerTypes);
142 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes);
143 void removeMarkers(TextIterator&, 144 void removeMarkers(TextIterator&,
144 DocumentMarker::MarkerTypes, 145 DocumentMarker::MarkerTypes,
145 RemovePartiallyOverlappingMarkerOrNot); 146 RemovePartiallyOverlappingMarkerOrNot);
146 147
147 MarkerMap m_markers;
148 // Provide a quick way to determine whether a particular marker type is absent
149 // without going through the map.
150 DocumentMarker::MarkerTypes m_possiblyExistingMarkerTypes;
151 const Member<const Document> m_document; 148 const Member<const Document> m_document;
152 }; 149 };
153 150
154 } // namespace blink 151 } // namespace blink
155 152
156 #ifndef NDEBUG 153 #ifndef NDEBUG
157 void showDocumentMarkers(const blink::DocumentMarkerController*); 154 void showDocumentMarkers(const blink::DocumentMarkerController*);
158 #endif 155 #endif
159 156
160 #endif // DocumentMarkerController_h 157 #endif // DocumentMarkerController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698