2 * This file is part of the DOM implementation for WebCore.
4 * Copyright (C) 2006 Apple Computer, Inc.
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.
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.
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.
23 #ifndef DocumentMarker_h
24 #define DocumentMarker_h
26 #include "platform/heap/Handle.h"
27 #include "wtf/VectorTraits.h"
28 #include "wtf/text/WTFString.h"
32 class DocumentMarkerDetails;
34 // A range of a node within a document that is "marked", such as the range of a misspelled word.
35 // It optionally includes a description that could be displayed in the user interface.
36 // It also optionally includes a flag specifying whether the match is active, which is ignored
37 // for all types other than type TextMatch.
38 class DocumentMarker : public NoBaseWillBeGarbageCollected<DocumentMarker> {
40 enum MarkerTypeIndex {
41 SpellingMarkerIndex = 0,
44 InvisibleSpellcheckMarkerIndex,
45 MarkerTypeIndexesCount
49 Spelling = 1 << SpellingMarkerIndex,
50 Grammar = 1 << GramarMarkerIndex,
51 TextMatch = 1 << TextMatchMarkerIndex,
52 InvisibleSpellcheck = 1 << InvisibleSpellcheckMarkerIndex
57 // The constructor is intentionally implicit to allow conversion from the bit-wise sum of above types
58 MarkerTypes(unsigned mask) : m_mask(mask) { }
60 bool contains(MarkerType type) const { return m_mask & type; }
61 bool intersects(const MarkerTypes& types) const { return (m_mask & types.m_mask); }
62 bool operator==(const MarkerTypes& other) const { return m_mask == other.m_mask; }
64 void add(const MarkerTypes& types) { m_mask |= types.m_mask; }
65 void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; }
71 class AllMarkers : public MarkerTypes {
74 : MarkerTypes(Spelling | Grammar | TextMatch | InvisibleSpellcheck)
79 class MisspellingMarkers : public MarkerTypes {
82 : MarkerTypes(Spelling | Grammar)
87 class SpellCheckClientMarkers : public MarkerTypes {
89 SpellCheckClientMarkers()
90 : MarkerTypes(Spelling | Grammar | InvisibleSpellcheck)
96 DocumentMarker(MarkerType, unsigned startOffset, unsigned endOffset, const String& description, uint32_t hash);
97 DocumentMarker(unsigned startOffset, unsigned endOffset, bool activeMatch);
98 DocumentMarker(MarkerType, unsigned startOffset, unsigned endOffset, PassRefPtrWillBeRawPtr<DocumentMarkerDetails>);
99 DocumentMarker(const DocumentMarker&);
101 MarkerType type() const { return m_type; }
102 unsigned startOffset() const { return m_startOffset; }
103 unsigned endOffset() const { return m_endOffset; }
104 uint32_t hash() const { return m_hash; }
106 const String& description() const;
107 bool activeMatch() const;
108 DocumentMarkerDetails* details() const;
110 void setActiveMatch(bool);
111 void clearDetails() { m_details.clear(); }
113 // Offset modifications are done by DocumentMarkerController.
114 // Other classes should not call following setters.
115 void setStartOffset(unsigned offset) { m_startOffset = offset; }
116 void setEndOffset(unsigned offset) { m_endOffset = offset; }
117 void shiftOffsets(int delta);
119 bool operator==(const DocumentMarker& o) const
121 return type() == o.type() && startOffset() == o.startOffset() && endOffset() == o.endOffset();
124 bool operator!=(const DocumentMarker& o) const
126 return !(*this == o);
129 void trace(Visitor*);
133 unsigned m_startOffset;
134 unsigned m_endOffset;
135 RefPtrWillBeMember<DocumentMarkerDetails> m_details;
139 using DocumentMarkerVector = WillBeHeapVector<RawPtrWillBeMember<DocumentMarker>>;
141 inline DocumentMarkerDetails* DocumentMarker::details() const
143 return m_details.get();
146 class DocumentMarkerDetails : public RefCountedWillBeGarbageCollectedFinalized<DocumentMarkerDetails>
149 DocumentMarkerDetails() { }
150 virtual ~DocumentMarkerDetails();
151 virtual bool isDescription() const { return false; }
152 virtual bool isTextMatch() const { return false; }
154 virtual void trace(Visitor*) { }
159 #endif // DocumentMarker_h