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

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

Issue 2723663002: Refactor DocumentMarkerController (Closed)
Patch Set: 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;
45 47 class TextMatchMarkerList;
46 class MarkerRemoverPredicate final {
47 public:
48 explicit MarkerRemoverPredicate(const Vector<String>& words);
49 bool operator()(const DocumentMarker&, const Text&) const;
50
51 private:
52 Vector<String> m_words;
53 };
54 48
55 class CORE_EXPORT DocumentMarkerController final 49 class CORE_EXPORT DocumentMarkerController final
56 : public GarbageCollected<DocumentMarkerController> { 50 : public GarbageCollectedFinalized<DocumentMarkerController> {
57 WTF_MAKE_NONCOPYABLE(DocumentMarkerController); 51 WTF_MAKE_NONCOPYABLE(DocumentMarkerController);
58 52
59 public: 53 public:
60 explicit DocumentMarkerController(const Document&); 54 explicit DocumentMarkerController(const Document&);
61 55
62 void clear(); 56 void clear();
57 void addMarker(Node*, DocumentMarker*);
63 void addMarker(const Position& start, 58 void addMarker(const Position& start,
64 const Position& end, 59 const Position& end,
65 DocumentMarker::MarkerType, 60 DocumentMarker::MarkerType,
66 const String& description = emptyString); 61 const String& description = emptyString);
67 void addTextMatchMarker(const EphemeralRange&, bool activeMatch); 62 void addTextMatchMarker(const EphemeralRange&, bool activeMatch);
68 void addCompositionMarker(const Position& start, 63 void addCompositionMarker(const Position& start,
69 const Position& end, 64 const Position& end,
70 Color underlineColor, 65 Color underlineColor,
71 bool thick, 66 bool thick,
72 Color backgroundColor); 67 Color backgroundColor);
73 68
74 void copyMarkers(Node* srcNode, 69 void copyMarkers(Node* srcNode,
75 unsigned startOffset, 70 unsigned startOffset,
76 int length, 71 int length,
77 Node* dstNode, 72 Node* dstNode,
78 int delta); 73 int delta);
79 74
80 void prepareForDestruction(); 75 void prepareForDestruction();
81 // When a marker partially overlaps with range, if 76 // When a marker partially overlaps with range, if
82 // removePartiallyOverlappingMarkers is true, we completely remove the marker. 77 // removePartiallyOverlappingMarkers is true, we completely remove the marker.
83 // If the argument is false, we will adjust the span of the marker so that it 78 // If the argument is false, we will adjust the span of the marker so that it
84 // retains the portion that is outside of the range. 79 // retains the portion that is outside of the range.
85 enum RemovePartiallyOverlappingMarkerOrNot { 80 enum RemovePartiallyOverlappingMarkerOrNot {
86 DoNotRemovePartiallyOverlappingMarker, 81 DoNotRemovePartiallyOverlappingMarker,
87 RemovePartiallyOverlappingMarker 82 RemovePartiallyOverlappingMarker
88 }; 83 };
89 void removeMarkers(const EphemeralRange&, 84 void removeMarkers(const EphemeralRange&,
90 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(), 85 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(),
91 RemovePartiallyOverlappingMarkerOrNot = 86 RemovePartiallyOverlappingMarkerOrNot =
92 DoNotRemovePartiallyOverlappingMarker); 87 DoNotRemovePartiallyOverlappingMarker);
rlanday 2017/02/28 00:53:51 It appears that the RemovePartiallyOverlappingMark
Xiaocheng 2017/03/01 22:24:48 It's good if we can get rid of such a parameter.
93 void removeMarkers(Node*, 88 void removeMarkers(Node*,
94 unsigned startOffset, 89 int startOffset,
rlanday 2017/02/28 00:53:51 I thought about switching all the instances of uns
Xiaocheng 2017/03/01 22:24:48 Let's discuss in crbug.com/696831
95 int length, 90 int length,
96 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(), 91 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers(),
97 RemovePartiallyOverlappingMarkerOrNot = 92 RemovePartiallyOverlappingMarkerOrNot =
98 DoNotRemovePartiallyOverlappingMarker); 93 DoNotRemovePartiallyOverlappingMarker);
99 94
100 void removeMarkers( 95 void removeMarkers(
101 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 96 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
102 void removeMarkers( 97 void removeMarkers(
103 Node*, 98 Node*,
104 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 99 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
105 void removeMarkers(const MarkerRemoverPredicate& shouldRemoveMarker); 100 void removeSpellingMarkersForWords(const Vector<String>& words);
106 void repaintMarkers( 101 void repaintMarkers(
107 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 102 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
108 void shiftMarkers(Node*, unsigned startOffset, int delta); 103 void shiftMarkers(Node*, unsigned startOffset, int delta);
109 // Returns true if markers within a range are found. 104 // Returns true if markers within a range are found.
110 bool setMarkersActive(const EphemeralRange&, bool); 105 bool setTextMatchMarkersActive(const EphemeralRange&, bool);
111 // Returns true if markers within a range defined by a node, |startOffset| and 106 // Returns true if markers within a range defined by a node, |startOffset| and
112 // |endOffset| are found. 107 // |endOffset| are found.
113 bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool); 108 bool setTextMatchMarkersActive(Node*,
114 bool hasMarkers(Node* node) const { return m_markers.contains(node); } 109 unsigned startOffset,
110 unsigned endOffset,
111 bool);
112 bool hasMarkers(Node*) const;
115 113
116 DocumentMarkerVector markersFor( 114 DocumentMarkerVector markersFor(
117 Node*, 115 Node*,
118 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers()); 116 DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
119 DocumentMarkerVector markersInRange(const EphemeralRange&, 117 DocumentMarkerVector markersInRange(const EphemeralRange&,
120 DocumentMarker::MarkerTypes); 118 DocumentMarker::MarkerTypes);
121 DocumentMarkerVector markers(); 119 DocumentMarkerVector markers();
122 Vector<IntRect> renderedRectsForMarkers(DocumentMarker::MarkerType); 120 Vector<IntRect> renderedRectsForTextMatchMarkers();
123 void updateMarkerRenderedRectIfNeeded(const Node&, RenderedDocumentMarker&); 121 void updateTextMatchMarkerRenderedRectIfNeeded(const Node&,
124 void invalidateRectsForAllMarkers(); 122 RenderedTextMatchMarker&);
125 void invalidateRectsForMarkersInNode(const Node&); 123 void invalidateRectsForAllTextMatchMarkers();
124 void invalidateRectsForTextMatchMarkersInNode(Node&);
126 125
127 DECLARE_TRACE(); 126 DECLARE_TRACE();
128 127
129 #ifndef NDEBUG 128 #ifndef NDEBUG
130 void showMarkers() const; 129 void showMarkers() const;
131 #endif 130 #endif
132 131
133 private: 132 private:
134 void addMarker(Node*, const DocumentMarker&); 133 template <typename MarkerListType>
134 using MarkerMap = HeapHashMap<WeakMember<Node>, Member<MarkerListType>>;
135 135
136 using MarkerList = HeapVector<Member<RenderedDocumentMarker>>; 136 MarkerMap<SpellingMarkerList> m_spelling;
137 using MarkerLists = 137 MarkerMap<GrammarMarkerList> m_grammar;
138 HeapVector<Member<MarkerList>, DocumentMarker::MarkerTypeIndexesCount>; 138 MarkerMap<TextMatchMarkerList> m_textMatches;
139 using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>; 139 MarkerMap<CompositionMarkerList> m_compositions;
140 void mergeOverlapping(MarkerList*, RenderedDocumentMarker*); 140
141 bool possiblyHasMarkers(DocumentMarker::MarkerTypes);
142 void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes);
143 void removeMarkers(TextIterator&, 141 void removeMarkers(TextIterator&,
144 DocumentMarker::MarkerTypes, 142 DocumentMarker::MarkerTypes,
145 RemovePartiallyOverlappingMarkerOrNot); 143 RemovePartiallyOverlappingMarkerOrNot);
146 144
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; 145 const Member<const Document> m_document;
152 }; 146 };
153 147
154 } // namespace blink 148 } // namespace blink
155 149
156 #ifndef NDEBUG 150 #ifndef NDEBUG
157 void showDocumentMarkers(const blink::DocumentMarkerController*); 151 void showDocumentMarkers(const blink::DocumentMarkerController*);
158 #endif 152 #endif
159 153
160 #endif // DocumentMarkerController_h 154 #endif // DocumentMarkerController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698