#ifndef SpellChecker_h
#define SpellChecker_h
#include "Element.h"
#include "Range.h"
#include "TextChecking.h"
#include "Timer.h"
#include <wtf/Deque.h>
#include <wtf/RefPtr.h>
#include <wtf/Noncopyable.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class Frame;
class Node;
class TextCheckerClient;
class SpellChecker;
class SpellCheckRequest : public TextCheckingRequest {
public:
static RefPtr<SpellCheckRequest> create(TextCheckingTypeMask, TextCheckingProcessType, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange);
virtual ~SpellCheckRequest();
PassRefPtr<Range> checkingRange() const { return m_checkingRange; }
PassRefPtr<Range> paragraphRange() const { return m_paragraphRange; }
PassRefPtr<Element> rootEditableElement() const { return m_rootEditableElement; }
void setCheckerAndSequence(SpellChecker*, int sequence);
void requesterDestroyed();
bool isStarted() const { return m_checker; }
const TextCheckingRequestData& data() const override;
void didSucceed(const Vector<TextCheckingResult>&) override;
void didCancel() override;
private:
SpellCheckRequest(PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange, const String&, TextCheckingTypeMask, TextCheckingProcessType);
SpellChecker* m_checker { nullptr };
RefPtr<Range> m_checkingRange;
RefPtr<Range> m_paragraphRange;
RefPtr<Element> m_rootEditableElement;
TextCheckingRequestData m_requestData;
};
class SpellChecker {
WTF_MAKE_NONCOPYABLE(SpellChecker); WTF_MAKE_FAST_ALLOCATED;
public:
friend class SpellCheckRequest;
explicit SpellChecker(Frame&);
~SpellChecker();
bool isAsynchronousEnabled() const;
bool isCheckable(Range*) const;
void requestCheckingFor(PassRefPtr<SpellCheckRequest>);
int lastRequestSequence() const
{
return m_lastRequestSequence;
}
int lastProcessedSequence() const
{
return m_lastProcessedSequence;
}
private:
typedef Deque<RefPtr<SpellCheckRequest>> RequestQueue;
bool canCheckAsynchronously(Range*) const;
TextCheckerClient* client() const;
void timerFiredToProcessQueuedRequest();
void invokeRequest(PassRefPtr<SpellCheckRequest>);
void enqueueRequest(PassRefPtr<SpellCheckRequest>);
void didCheckSucceed(int sequence, const Vector<TextCheckingResult>&);
void didCheckCancel(int sequence);
void didCheck(int sequence, const Vector<TextCheckingResult>&);
Frame& m_frame;
int m_lastRequestSequence;
int m_lastProcessedSequence;
Timer m_timerToProcessQueuedRequest;
RefPtr<SpellCheckRequest> m_processingRequest;
RequestQueue m_requestQueue;
};
}
#endif // SpellChecker_h