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

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

Issue 2780313002: [WIP] Refactor DocumentMarker (Closed)
Patch Set: Move accessor methods into derived classes 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 14 matching lines...) Expand all
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/Optional.h" 29 #include "wtf/Optional.h"
30 #include "wtf/VectorTraits.h" 30 #include "wtf/VectorTraits.h"
31 #include "wtf/text/WTFString.h" 31 #include "wtf/text/WTFString.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 class DocumentMarkerDetails;
36
37 // A range of a node within a document that is "marked", such as the range of a 35 // A range of a node within a document that is "marked", such as the range of a
38 // misspelled word. It optionally includes a description that could be displayed 36 // misspelled word. It optionally includes a description that could be displayed
39 // in the user interface. It also optionally includes a flag specifying whether 37 // in the user interface. It also optionally includes a flag specifying whether
40 // the match is active, which is ignored for all types other than type 38 // the match is active, which is ignored for all types other than type
41 // TextMatch. 39 // TextMatch.
42 class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> { 40 class CORE_EXPORT DocumentMarker
41 : public GarbageCollectedFinalized<DocumentMarker> {
43 public: 42 public:
44 enum MarkerTypeIndex { 43 enum MarkerTypeIndex {
45 SpellingMarkerIndex = 0, 44 SpellingMarkerIndex = 0,
46 GrammarMarkerIndex, 45 GrammarMarkerIndex,
47 TextMatchMarkerIndex, 46 TextMatchMarkerIndex,
48 CompositionMarkerIndex, 47 CompositionMarkerIndex,
49 MarkerTypeIndexesCount 48 MarkerTypeIndexesCount
50 }; 49 };
51 50
52 enum MarkerType { 51 enum MarkerType {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 class MisspellingMarkers : public MarkerTypes { 127 class MisspellingMarkers : public MarkerTypes {
129 public: 128 public:
130 MisspellingMarkers() : MarkerTypes(Spelling | Grammar) {} 129 MisspellingMarkers() : MarkerTypes(Spelling | Grammar) {}
131 }; 130 };
132 131
133 class SpellCheckClientMarkers : public MarkerTypes { 132 class SpellCheckClientMarkers : public MarkerTypes {
134 public: 133 public:
135 SpellCheckClientMarkers() : MarkerTypes(Spelling | Grammar) {} 134 SpellCheckClientMarkers() : MarkerTypes(Spelling | Grammar) {}
136 }; 135 };
137 136
138 virtual DocumentMarker* clone() const; 137 virtual ~DocumentMarker();
139 138
140 DocumentMarker(MarkerType, 139 virtual DocumentMarker* clone() const = 0;
141 unsigned startOffset,
142 unsigned endOffset,
143 const String& description);
144 DocumentMarker(unsigned startOffset,
145 unsigned endOffset,
146 Color underlineColor,
147 bool thick,
148 Color backgroundColor);
149 140
150 MarkerType type() const { return m_type; } 141 virtual MarkerType type() const = 0;
151 unsigned startOffset() const { return m_startOffset; } 142 unsigned startOffset() const { return m_startOffset; }
152 unsigned endOffset() const { return m_endOffset; } 143 unsigned endOffset() const { return m_endOffset; }
153 144
154 const String& description() const;
Xiaocheng 2017/03/31 02:01:01 Hmm... I didn't expect these accessors to be used
155 bool activeMatch() const;
156 Color underlineColor() const;
157 bool thick() const;
158 Color backgroundColor() const;
159 DocumentMarkerDetails* details() const;
160
161 void setActiveMatch(bool);
162 void clearDetails() { m_details.clear(); }
163
164 struct MarkerOffsets { 145 struct MarkerOffsets {
165 unsigned startOffset; 146 unsigned startOffset;
166 unsigned endOffset; 147 unsigned endOffset;
167 }; 148 };
168 149
169 Optional<MarkerOffsets> computeOffsetsAfterShift(unsigned offset, 150 Optional<MarkerOffsets> computeOffsetsAfterShift(unsigned offset,
170 unsigned oldLength, 151 unsigned oldLength,
171 unsigned newLength) const; 152 unsigned newLength) const;
172 153
173 // Offset modifications are done by DocumentMarkerController and subclasses of 154 // Offset modifications are done by DocumentMarkerController and subclasses of
174 // DocumentMarkerList. Other classes should not call following setters. 155 // DocumentMarkerList. Other classes should not call following setters.
175 void setStartOffset(unsigned offset) { m_startOffset = offset; } 156 void setStartOffset(unsigned offset) { m_startOffset = offset; }
176 void setEndOffset(unsigned offset) { m_endOffset = offset; } 157 void setEndOffset(unsigned offset) { m_endOffset = offset; }
177 void shiftOffsets(int delta); 158 void shiftOffsets(int delta);
178 159
179 DECLARE_TRACE(); 160 DEFINE_INLINE_VIRTUAL_TRACE() {}
180 161
181 protected: 162 protected:
182 DocumentMarker(const DocumentMarker&); 163 DocumentMarker(const DocumentMarker&);
183 DocumentMarker(unsigned startOffset, unsigned endOffset, bool activeMatch); 164 DocumentMarker(unsigned startOffset, unsigned endOffset);
184 165
185 private: 166 private:
186 MarkerType m_type;
187 unsigned m_startOffset; 167 unsigned m_startOffset;
188 unsigned m_endOffset; 168 unsigned m_endOffset;
189 Member<DocumentMarkerDetails> m_details;
190 }; 169 };
191 170
192 using DocumentMarkerVector = HeapVector<Member<DocumentMarker>>; 171 using DocumentMarkerVector = HeapVector<Member<DocumentMarker>>;
193 172
194 inline DocumentMarkerDetails* DocumentMarker::details() const {
195 return m_details.get();
196 }
197
198 class DocumentMarkerDetails
199 : public GarbageCollectedFinalized<DocumentMarkerDetails> {
200 public:
201 DocumentMarkerDetails() {}
202 virtual ~DocumentMarkerDetails();
203 virtual bool isDescription() const { return false; }
204 virtual bool isTextMatch() const { return false; }
205 virtual bool isComposition() const { return false; }
206
207 DEFINE_INLINE_VIRTUAL_TRACE() {}
208 };
209
210 } // namespace blink 173 } // namespace blink
211 174
212 #endif // DocumentMarker_h 175 #endif // DocumentMarker_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698