#ifndef DocumentMarker_h
#define DocumentMarker_h
#include "wtf/Forward.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class DocumentMarkerDetails;
class DocumentMarker {
public:
enum MarkerTypeIndex {
SpellingMarkerIndex = 0,
GramarMarkerIndex,
TextMatchMarkerIndex,
InvisibleSpellcheckMarkerIndex,
MarkerTypeIndexesCount
};
enum MarkerType {
Spelling = 1 << SpellingMarkerIndex,
Grammar = 1 << GramarMarkerIndex,
TextMatch = 1 << TextMatchMarkerIndex,
InvisibleSpellcheck = 1 << InvisibleSpellcheckMarkerIndex
};
class MarkerTypes {
public:
MarkerTypes(unsigned mask) : m_mask(mask) { }
bool contains(MarkerType type) const { return m_mask & type; }
bool intersects(const MarkerTypes& types) const { return (m_mask & types.m_mask); }
bool operator==(const MarkerTypes& other) const { return m_mask == other.m_mask; }
void add(const MarkerTypes& types) { m_mask |= types.m_mask; }
void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; }
private:
unsigned m_mask;
};
class AllMarkers : public MarkerTypes {
public:
AllMarkers()
: MarkerTypes(Spelling | Grammar | TextMatch | InvisibleSpellcheck)
{
}
};
class MisspellingMarkers : public MarkerTypes {
public:
MisspellingMarkers()
: MarkerTypes(Spelling | Grammar)
{
}
};
class SpellCheckClientMarkers : public MarkerTypes {
public:
SpellCheckClientMarkers()
: MarkerTypes(Spelling | Grammar | InvisibleSpellcheck)
{
}
};
DocumentMarker();
DocumentMarker(MarkerType, unsigned startOffset, unsigned endOffset);
DocumentMarker(MarkerType, unsigned startOffset, unsigned endOffset, const String& description);
DocumentMarker(MarkerType, unsigned startOffset, unsigned endOffset, const String& description, uint32_t hash);
DocumentMarker(unsigned startOffset, unsigned endOffset, bool activeMatch);
DocumentMarker(MarkerType, unsigned startOffset, unsigned endOffset, PassRefPtr<DocumentMarkerDetails>);
MarkerType type() const { return m_type; }
unsigned startOffset() const { return m_startOffset; }
unsigned endOffset() const { return m_endOffset; }
uint32_t hash() const { return m_hash; }
const String& description() const;
bool activeMatch() const;
DocumentMarkerDetails* details() const;
void setActiveMatch(bool);
void clearDetails() { m_details.clear(); }
void setStartOffset(unsigned offset) { m_startOffset = offset; }
void setEndOffset(unsigned offset) { m_endOffset = offset; }
void shiftOffsets(int delta);
bool operator==(const DocumentMarker& o) const
{
return type() == o.type() && startOffset() == o.startOffset() && endOffset() == o.endOffset();
}
bool operator!=(const DocumentMarker& o) const
{
return !(*this == o);
}
private:
MarkerType m_type;
unsigned m_startOffset;
unsigned m_endOffset;
RefPtr<DocumentMarkerDetails> m_details;
uint32_t m_hash;
};
inline DocumentMarkerDetails* DocumentMarker::details() const
{
return m_details.get();
}
class DocumentMarkerDetails : public RefCounted<DocumentMarkerDetails>
{
public:
DocumentMarkerDetails() { }
virtual ~DocumentMarkerDetails();
virtual bool isDescription() const { return false; }
virtual bool isTextMatch() const { return false; }
};
}
#endif