#pragma once
#include "Element.h"
#include "SimpleRange.h"
#include "TextChecking.h"
#include "Timer.h"
#include <wtf/Deque.h>
namespace WebCore {
class SpellChecker;
class TextCheckerClient;
class SpellCheckRequest final : public TextCheckingRequest {
public:
static RefPtr<SpellCheckRequest> create(OptionSet<TextCheckingType>, TextCheckingProcessType, const SimpleRange& checkingRange, const SimpleRange& automaticReplacementRange, const SimpleRange& paragraphRange);
virtual ~SpellCheckRequest();
const SimpleRange& checkingRange() const { return m_checkingRange; }
const SimpleRange& paragraphRange() const { return m_paragraphRange; }
const SimpleRange& automaticReplacementRange() const { return m_automaticReplacementRange; }
Element* rootEditableElement() const { return m_rootEditableElement.get(); }
void setCheckerAndIdentifier(SpellChecker*, TextCheckingRequestIdentifier);
void requesterDestroyed();
bool isStarted() const { return m_checker; }
const TextCheckingRequestData& data() const final;
private:
void didSucceed(const Vector<TextCheckingResult>&) final;
void didCancel() final;
SpellCheckRequest(const SimpleRange& checkingRange, const SimpleRange& automaticReplacementRange, const SimpleRange& paragraphRange, const String&, OptionSet<TextCheckingType>, TextCheckingProcessType);
SpellChecker* m_checker { nullptr };
SimpleRange m_checkingRange;
SimpleRange m_automaticReplacementRange;
SimpleRange m_paragraphRange;
RefPtr<Element> m_rootEditableElement;
TextCheckingRequestData m_requestData;
};
class SpellChecker {
WTF_MAKE_FAST_ALLOCATED;
public:
friend class SpellCheckRequest;
explicit SpellChecker(Document&);
~SpellChecker();
bool isAsynchronousEnabled() const;
bool isCheckable(const SimpleRange&) const;
void requestCheckingFor(Ref<SpellCheckRequest>&&);
TextCheckingRequestIdentifier lastRequestIdentifier() const { return m_lastRequestIdentifier; }
TextCheckingRequestIdentifier lastProcessedIdentifier() const { return m_lastProcessedIdentifier; }
private:
bool canCheckAsynchronously(const SimpleRange&) const;
TextCheckerClient* client() const;
void timerFiredToProcessQueuedRequest();
void invokeRequest(Ref<SpellCheckRequest>&&);
void enqueueRequest(Ref<SpellCheckRequest>&&);
void didCheckSucceed(TextCheckingRequestIdentifier, const Vector<TextCheckingResult>&);
void didCheckCancel(TextCheckingRequestIdentifier);
void didCheck(TextCheckingRequestIdentifier, const Vector<TextCheckingResult>&);
Document& m_document;
TextCheckingRequestIdentifier m_lastRequestIdentifier;
TextCheckingRequestIdentifier m_lastProcessedIdentifier;
Timer m_timerToProcessQueuedRequest;
RefPtr<SpellCheckRequest> m_processingRequest;
Deque<Ref<SpellCheckRequest>> m_requestQueue;
};
}