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

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

Issue 2780313002: [WIP] Refactor DocumentMarker (Closed)
Patch Set: Rebase Created 3 years, 8 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 * This file is part of the DOM implementation for WebCore. 2 * This file is part of the DOM implementation for WebCore.
3 * 3 *
4 * Copyright (C) 2006 Apple Computer, Inc. 4 * Copyright (C) 2006 Apple Computer, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 13 matching lines...) Expand all
24 #define DocumentMarker_h 24 #define DocumentMarker_h
25 25
26 #include "core/CoreExport.h" 26 #include "core/CoreExport.h"
27 #include "platform/graphics/Color.h" 27 #include "platform/graphics/Color.h"
28 #include "platform/heap/Handle.h" 28 #include "platform/heap/Handle.h"
29 #include "wtf/VectorTraits.h" 29 #include "wtf/VectorTraits.h"
30 #include "wtf/text/WTFString.h" 30 #include "wtf/text/WTFString.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 class DocumentMarkerDetails;
35
36 // A range of a node within a document that is "marked", such as the range of a 34 // A range of a node within a document that is "marked", such as the range of a
37 // misspelled word. It optionally includes a description that could be displayed 35 // misspelled word. It optionally includes a description that could be displayed
38 // in the user interface. It also optionally includes a flag specifying whether 36 // in the user interface. It also optionally includes a flag specifying whether
39 // the match is active, which is ignored for all types other than type 37 // the match is active, which is ignored for all types other than type
40 // TextMatch. 38 // TextMatch.
41 class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> { 39 class CORE_EXPORT DocumentMarker
40 : public GarbageCollectedFinalized<DocumentMarker> {
42 public: 41 public:
43 enum MarkerTypeIndex { 42 enum MarkerTypeIndex {
44 SpellingMarkerIndex = 0, 43 SpellingMarkerIndex = 0,
45 GrammarMarkerIndex, 44 GrammarMarkerIndex,
46 TextMatchMarkerIndex, 45 TextMatchMarkerIndex,
47 CompositionMarkerIndex, 46 CompositionMarkerIndex,
48 MarkerTypeIndexesCount 47 MarkerTypeIndexesCount
49 }; 48 };
50 49
51 enum MarkerType { 50 enum MarkerType {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 class MisspellingMarkers : public MarkerTypes { 126 class MisspellingMarkers : public MarkerTypes {
128 public: 127 public:
129 MisspellingMarkers() : MarkerTypes(Spelling | Grammar) {} 128 MisspellingMarkers() : MarkerTypes(Spelling | Grammar) {}
130 }; 129 };
131 130
132 class SpellCheckClientMarkers : public MarkerTypes { 131 class SpellCheckClientMarkers : public MarkerTypes {
133 public: 132 public:
134 SpellCheckClientMarkers() : MarkerTypes(Spelling | Grammar) {} 133 SpellCheckClientMarkers() : MarkerTypes(Spelling | Grammar) {}
135 }; 134 };
136 135
137 virtual DocumentMarker* clone() const; 136 virtual ~DocumentMarker();
138 137
139 DocumentMarker(MarkerType, 138 virtual DocumentMarker* clone() const = 0;
140 unsigned startOffset,
141 unsigned endOffset,
142 const String& description);
143 DocumentMarker(unsigned startOffset,
144 unsigned endOffset,
145 Color underlineColor,
146 bool thick,
147 Color backgroundColor);
148 139
149 MarkerType type() const { return m_type; } 140 virtual MarkerType type() const = 0;
150 unsigned startOffset() const { return m_startOffset; } 141 unsigned startOffset() const { return m_startOffset; }
151 unsigned endOffset() const { return m_endOffset; } 142 unsigned endOffset() const { return m_endOffset; }
152 143
153 const String& description() const; 144 virtual const String& description() const;
Xiaocheng 2017/03/29 23:40:11 These functions only make sense in subclasses. Can
154 bool activeMatch() const; 145 virtual bool activeMatch() const;
155 Color underlineColor() const; 146 virtual Color underlineColor() const;
156 bool thick() const; 147 virtual bool thick() const;
157 Color backgroundColor() const; 148 virtual Color backgroundColor() const;
158 DocumentMarkerDetails* details() const;
159
160 void setActiveMatch(bool);
161 void clearDetails() { m_details.clear(); }
162 149
163 struct ShiftMarkerResult { 150 struct ShiftMarkerResult {
164 unsigned newStartOffset; 151 unsigned newStartOffset;
165 unsigned newEndOffset; 152 unsigned newEndOffset;
166 bool shouldRemoveMarker; 153 bool shouldRemoveMarker;
167 }; 154 };
168 155
169 ShiftMarkerResult getShiftedMarkerPosition(unsigned offset, 156 ShiftMarkerResult getShiftedMarkerPosition(unsigned offset,
170 unsigned oldLength, 157 unsigned oldLength,
171 unsigned newLength) const; 158 unsigned newLength) const;
172 159
173 // Offset modifications are done by DocumentMarkerController and subclasses of 160 // Offset modifications are done by DocumentMarkerController and subclasses of
174 // DocumentMarkerList. Other classes should not call following setters. 161 // DocumentMarkerList. Other classes should not call following setters.
175 void setStartOffset(unsigned offset) { m_startOffset = offset; } 162 void setStartOffset(unsigned offset) { m_startOffset = offset; }
176 void setEndOffset(unsigned offset) { m_endOffset = offset; } 163 void setEndOffset(unsigned offset) { m_endOffset = offset; }
177 void shiftOffsets(int delta); 164 void shiftOffsets(int delta);
178 165
179 bool operator==(const DocumentMarker& o) const { 166 bool operator==(const DocumentMarker& other) const;
Xiaocheng 2017/03/29 23:40:11 These comparison methods seem not used at all. Co
180 return type() == o.type() && startOffset() == o.startOffset() && 167
181 endOffset() == o.endOffset(); 168 bool operator!=(const DocumentMarker& other) const {
169 return !(*this == other);
182 } 170 }
183 171
184 bool operator!=(const DocumentMarker& o) const { return !(*this == o); } 172 DEFINE_INLINE_VIRTUAL_TRACE() {}
185
186 DECLARE_TRACE();
187 173
188 protected: 174 protected:
189 DocumentMarker(const DocumentMarker&); 175 DocumentMarker(const DocumentMarker&);
190 DocumentMarker(unsigned startOffset, unsigned endOffset, bool activeMatch); 176 DocumentMarker(unsigned startOffset, unsigned endOffset);
191 177
192 private: 178 private:
193 MarkerType m_type;
194 unsigned m_startOffset; 179 unsigned m_startOffset;
195 unsigned m_endOffset; 180 unsigned m_endOffset;
196 Member<DocumentMarkerDetails> m_details;
197 }; 181 };
198 182
199 using DocumentMarkerVector = HeapVector<Member<DocumentMarker>>; 183 using DocumentMarkerVector = HeapVector<Member<DocumentMarker>>;
200 184
201 inline DocumentMarkerDetails* DocumentMarker::details() const {
202 return m_details.get();
203 }
204
205 class DocumentMarkerDetails
206 : public GarbageCollectedFinalized<DocumentMarkerDetails> {
207 public:
208 DocumentMarkerDetails() {}
209 virtual ~DocumentMarkerDetails();
210 virtual bool isDescription() const { return false; }
211 virtual bool isTextMatch() const { return false; }
212 virtual bool isComposition() const { return false; }
213
214 DEFINE_INLINE_VIRTUAL_TRACE() {}
215 };
216
217 } // namespace blink 185 } // namespace blink
218 186
219 #endif // DocumentMarker_h 187 #endif // DocumentMarker_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698