OLD | NEW |
| (Empty) |
1 /* | |
2 * This file is part of the DOM implementation for WebCore. | |
3 * | |
4 * Copyright (C) 2006 Apple Computer, Inc. | |
5 * | |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Library General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Library General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Library General Public License | |
17 * along with this library; see the file COPYING.LIB. If not, write to | |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
19 * Boston, MA 02110-1301, USA. | |
20 * | |
21 */ | |
22 | |
23 #ifndef DocumentMarker_h | |
24 #define DocumentMarker_h | |
25 | |
26 #include "core/CoreExport.h" | |
27 #include "platform/heap/Handle.h" | |
28 #include "wtf/VectorTraits.h" | |
29 #include "wtf/text/WTFString.h" | |
30 | |
31 namespace blink { | |
32 | |
33 class DocumentMarkerDetails; | |
34 | |
35 // A range of a node within a document that is "marked", such as the range of a
misspelled word. | |
36 // It optionally includes a description that could be displayed in the user inte
rface. | |
37 // It also optionally includes a flag specifying whether the match is active, wh
ich is ignored | |
38 // for all types other than type TextMatch. | |
39 class CORE_EXPORT DocumentMarker : public NoBaseWillBeGarbageCollected<DocumentM
arker> { | |
40 public: | |
41 enum MarkerTypeIndex { | |
42 SpellingMarkerIndex = 0, | |
43 GramarMarkerIndex, | |
44 TextMatchMarkerIndex, | |
45 InvisibleSpellcheckMarkerIndex, | |
46 MarkerTypeIndexesCount | |
47 }; | |
48 | |
49 enum MarkerType { | |
50 Spelling = 1 << SpellingMarkerIndex, | |
51 Grammar = 1 << GramarMarkerIndex, | |
52 TextMatch = 1 << TextMatchMarkerIndex, | |
53 InvisibleSpellcheck = 1 << InvisibleSpellcheckMarkerIndex | |
54 }; | |
55 | |
56 class MarkerTypes { | |
57 public: | |
58 // The constructor is intentionally implicit to allow conversion from th
e bit-wise sum of above types | |
59 MarkerTypes(unsigned mask) : m_mask(mask) { } | |
60 | |
61 bool contains(MarkerType type) const { return m_mask & type; } | |
62 bool intersects(const MarkerTypes& types) const { return (m_mask & types
.m_mask); } | |
63 bool operator==(const MarkerTypes& other) const { return m_mask == other
.m_mask; } | |
64 | |
65 void add(const MarkerTypes& types) { m_mask |= types.m_mask; } | |
66 void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; } | |
67 | |
68 private: | |
69 unsigned m_mask; | |
70 }; | |
71 | |
72 class AllMarkers : public MarkerTypes { | |
73 public: | |
74 AllMarkers() | |
75 : MarkerTypes(Spelling | Grammar | TextMatch | InvisibleSpellcheck) | |
76 { | |
77 } | |
78 }; | |
79 | |
80 class MisspellingMarkers : public MarkerTypes { | |
81 public: | |
82 MisspellingMarkers() | |
83 : MarkerTypes(Spelling | Grammar) | |
84 { | |
85 } | |
86 }; | |
87 | |
88 class SpellCheckClientMarkers : public MarkerTypes { | |
89 public: | |
90 SpellCheckClientMarkers() | |
91 : MarkerTypes(Spelling | Grammar | InvisibleSpellcheck) | |
92 { | |
93 } | |
94 }; | |
95 | |
96 DocumentMarker(MarkerType, unsigned startOffset, unsigned endOffset, const S
tring& description, uint32_t hash); | |
97 DocumentMarker(unsigned startOffset, unsigned endOffset, bool activeMatch); | |
98 DocumentMarker(const DocumentMarker&); | |
99 | |
100 MarkerType type() const { return m_type; } | |
101 unsigned startOffset() const { return m_startOffset; } | |
102 unsigned endOffset() const { return m_endOffset; } | |
103 uint32_t hash() const { return m_hash; } | |
104 | |
105 const String& description() const; | |
106 bool activeMatch() const; | |
107 DocumentMarkerDetails* details() const; | |
108 | |
109 void setActiveMatch(bool); | |
110 void clearDetails() { m_details.clear(); } | |
111 | |
112 // Offset modifications are done by DocumentMarkerController. | |
113 // Other classes should not call following setters. | |
114 void setStartOffset(unsigned offset) { m_startOffset = offset; } | |
115 void setEndOffset(unsigned offset) { m_endOffset = offset; } | |
116 void shiftOffsets(int delta); | |
117 | |
118 bool operator==(const DocumentMarker& o) const | |
119 { | |
120 return type() == o.type() && startOffset() == o.startOffset() && endOffs
et() == o.endOffset(); | |
121 } | |
122 | |
123 bool operator!=(const DocumentMarker& o) const | |
124 { | |
125 return !(*this == o); | |
126 } | |
127 | |
128 DECLARE_TRACE(); | |
129 | |
130 private: | |
131 MarkerType m_type; | |
132 unsigned m_startOffset; | |
133 unsigned m_endOffset; | |
134 RefPtrWillBeMember<DocumentMarkerDetails> m_details; | |
135 uint32_t m_hash; | |
136 }; | |
137 | |
138 using DocumentMarkerVector = WillBeHeapVector<RawPtrWillBeMember<DocumentMarker>
>; | |
139 | |
140 inline DocumentMarkerDetails* DocumentMarker::details() const | |
141 { | |
142 return m_details.get(); | |
143 } | |
144 | |
145 class DocumentMarkerDetails : public RefCountedWillBeGarbageCollectedFinalized<D
ocumentMarkerDetails> { | |
146 public: | |
147 DocumentMarkerDetails() { } | |
148 virtual ~DocumentMarkerDetails(); | |
149 virtual bool isDescription() const { return false; } | |
150 virtual bool isTextMatch() const { return false; } | |
151 | |
152 DEFINE_INLINE_VIRTUAL_TRACE() { } | |
153 }; | |
154 | |
155 } // namespace blink | |
156 | |
157 #endif // DocumentMarker_h | |
OLD | NEW |