This source file includes following definitions.
- description
- isDescription
- create
- toDocumentMarkerDescription
- activeMatch
- isTextMatch
- instanceFor
- toDocumentMarkerTextMatch
- m_hash
- m_hash
- m_hash
- m_hash
- m_hash
- m_hash
- shiftOffsets
- setActiveMatch
- description
- activeMatch
#include "config.h"
#include "core/dom/DocumentMarker.h"
namespace WebCore {
DocumentMarkerDetails::~DocumentMarkerDetails()
{
}
class DocumentMarkerDescription FINAL : public DocumentMarkerDetails {
public:
static PassRefPtr<DocumentMarkerDescription> create(const String&);
const String& description() const { return m_description; }
virtual bool isDescription() const OVERRIDE { return true; }
private:
DocumentMarkerDescription(const String& description)
: m_description(description)
{
}
String m_description;
};
PassRefPtr<DocumentMarkerDescription> DocumentMarkerDescription::create(const String& description)
{
return adoptRef(new DocumentMarkerDescription(description));
}
inline DocumentMarkerDescription* toDocumentMarkerDescription(DocumentMarkerDetails* details)
{
if (details && details->isDescription())
return static_cast<DocumentMarkerDescription*>(details);
return 0;
}
class DocumentMarkerTextMatch FINAL : public DocumentMarkerDetails {
public:
static PassRefPtr<DocumentMarkerTextMatch> instanceFor(bool);
bool activeMatch() const { return m_match; }
virtual bool isTextMatch() const OVERRIDE { return true; }
private:
explicit DocumentMarkerTextMatch(bool match)
: m_match(match)
{
}
bool m_match;
};
PassRefPtr<DocumentMarkerTextMatch> DocumentMarkerTextMatch::instanceFor(bool match)
{
DEFINE_STATIC_REF(DocumentMarkerTextMatch, trueInstance, (adoptRef(new DocumentMarkerTextMatch(true))));
DEFINE_STATIC_REF(DocumentMarkerTextMatch, falseInstance, (adoptRef(new DocumentMarkerTextMatch(false))));
return match ? trueInstance : falseInstance;
}
inline DocumentMarkerTextMatch* toDocumentMarkerTextMatch(DocumentMarkerDetails* details)
{
if (details && details->isTextMatch())
return static_cast<DocumentMarkerTextMatch*>(details);
return 0;
}
DocumentMarker::DocumentMarker()
: m_type(Spelling)
, m_startOffset(0)
, m_endOffset(0)
, m_hash(0)
{
}
DocumentMarker::DocumentMarker(MarkerType type, unsigned startOffset, unsigned endOffset)
: m_type(type)
, m_startOffset(startOffset)
, m_endOffset(endOffset)
, m_hash(0)
{
}
DocumentMarker::DocumentMarker(MarkerType type, unsigned startOffset, unsigned endOffset, const String& description)
: m_type(type)
, m_startOffset(startOffset)
, m_endOffset(endOffset)
, m_details(description.isEmpty() ? nullptr : DocumentMarkerDescription::create(description))
, m_hash(0)
{
}
DocumentMarker::DocumentMarker(MarkerType type, unsigned startOffset, unsigned endOffset, const String& description, uint32_t hash)
: m_type(type)
, m_startOffset(startOffset)
, m_endOffset(endOffset)
, m_details(description.isEmpty() ? nullptr : DocumentMarkerDescription::create(description))
, m_hash(hash)
{
}
DocumentMarker::DocumentMarker(unsigned startOffset, unsigned endOffset, bool activeMatch)
: m_type(DocumentMarker::TextMatch)
, m_startOffset(startOffset)
, m_endOffset(endOffset)
, m_details(DocumentMarkerTextMatch::instanceFor(activeMatch))
, m_hash(0)
{
}
DocumentMarker::DocumentMarker(MarkerType type, unsigned startOffset, unsigned endOffset, PassRefPtr<DocumentMarkerDetails> details)
: m_type(type)
, m_startOffset(startOffset)
, m_endOffset(endOffset)
, m_details(details)
, m_hash(0)
{
}
void DocumentMarker::shiftOffsets(int delta)
{
m_startOffset += delta;
m_endOffset += delta;
}
void DocumentMarker::setActiveMatch(bool active)
{
m_details = DocumentMarkerTextMatch::instanceFor(active);
}
const String& DocumentMarker::description() const
{
if (DocumentMarkerDescription* details = toDocumentMarkerDescription(m_details.get()))
return details->description();
return emptyString();
}
bool DocumentMarker::activeMatch() const
{
if (DocumentMarkerTextMatch* details = toDocumentMarkerTextMatch(m_details.get()))
return details->activeMatch();
return false;
}
}