#pragma once
#include <wtf/OptionSet.h>
#include <wtf/RefCounted.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
enum class TextCheckingType : uint8_t {
None = 0,
Spelling = 1 << 0,
Grammar = 1 << 1,
Link = 1 << 2,
Quote = 1 << 3,
Dash = 1 << 4,
Replacement = 1 << 5,
Correction = 1 << 6,
ShowCorrectionPanel = 1 << 7,
};
#if PLATFORM(MAC)
typedef uint64_t NSTextCheckingTypes;
WEBCORE_EXPORT NSTextCheckingTypes nsTextCheckingTypes(OptionSet<TextCheckingType>);
#endif
enum TextCheckingProcessType {
TextCheckingProcessBatch,
TextCheckingProcessIncremental
};
struct GrammarDetail {
int location;
int length;
Vector<String> guesses;
String userDescription;
};
struct TextCheckingResult {
TextCheckingType type;
int location;
int length;
Vector<GrammarDetail> details;
String replacement;
};
const int unrequestedTextCheckingSequence = -1;
class TextCheckingRequestData {
friend class SpellCheckRequest; public:
TextCheckingRequestData() = default;
TextCheckingRequestData(int sequence, const String& text, OptionSet<TextCheckingType> checkingTypes, TextCheckingProcessType processType)
: m_text { text }
, m_sequence { sequence }
, m_processType { processType }
, m_checkingTypes { checkingTypes }
{
}
int sequence() const { return m_sequence; }
const String& text() const { return m_text; }
OptionSet<TextCheckingType> checkingTypes() const { return m_checkingTypes; }
TextCheckingProcessType processType() const { return m_processType; }
private:
String m_text;
int m_sequence { unrequestedTextCheckingSequence };
TextCheckingProcessType m_processType { TextCheckingProcessIncremental };
OptionSet<TextCheckingType> m_checkingTypes;
};
class TextCheckingRequest : public RefCounted<TextCheckingRequest> {
public:
virtual ~TextCheckingRequest() = default;
virtual const TextCheckingRequestData& data() const = 0;
virtual void didSucceed(const Vector<TextCheckingResult>&) = 0;
virtual void didCancel() = 0;
};
}