2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef SpellChecker_h
27 #define SpellChecker_h
30 #include "PlatformString.h"
32 #include "TextChecking.h"
34 #include <wtf/Deque.h>
35 #include <wtf/RefCounted.h>
36 #include <wtf/RefPtr.h>
37 #include <wtf/Noncopyable.h>
38 #include <wtf/Vector.h>
44 class TextCheckerClient;
47 class SpellCheckRequest : public TextCheckingRequest {
49 SpellCheckRequest(PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange, const String&, TextCheckingTypeMask, TextCheckingProcessType);
50 virtual ~SpellCheckRequest();
52 static PassRefPtr<SpellCheckRequest> create(TextCheckingTypeMask, TextCheckingProcessType, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange);
54 PassRefPtr<Range> checkingRange() const { return m_checkingRange; }
55 PassRefPtr<Range> paragraphRange() const { return m_paragraphRange; }
56 PassRefPtr<Element> rootEditableElement() const { return m_rootEditableElement; }
58 void setCheckerAndSequence(SpellChecker*, int sequence);
59 void requesterDestroyed();
60 bool isStarted() const { return m_checker; }
62 virtual void didSucceed(const Vector<TextCheckingResult>&) OVERRIDE;
63 virtual void didCancel() OVERRIDE;
66 SpellChecker* m_checker;
67 RefPtr<Range> m_checkingRange;
68 RefPtr<Range> m_paragraphRange;
69 RefPtr<Element> m_rootEditableElement;
73 WTF_MAKE_NONCOPYABLE(SpellChecker);
75 friend class SpellCheckRequest;
77 explicit SpellChecker(Frame*);
80 bool isAsynchronousEnabled() const;
81 bool isCheckable(Range*) const;
83 void requestCheckingFor(PassRefPtr<SpellCheckRequest>);
85 int lastRequestSequence() const
87 return m_lastRequestSequence;
90 int lastProcessedSequence() const
92 return m_lastProcessedSequence;
96 typedef Deque<RefPtr<SpellCheckRequest> > RequestQueue;
98 bool canCheckAsynchronously(Range*) const;
99 TextCheckerClient* client() const;
100 void timerFiredToProcessQueuedRequest(Timer<SpellChecker>*);
101 void invokeRequest(PassRefPtr<SpellCheckRequest>);
102 void enqueueRequest(PassRefPtr<SpellCheckRequest>);
103 void didCheckSucceed(int sequence, const Vector<TextCheckingResult>&);
104 void didCheckCancel(int sequence);
105 void didCheck(int sequence, const Vector<TextCheckingResult>&);
108 int m_lastRequestSequence;
109 int m_lastProcessedSequence;
111 Timer<SpellChecker> m_timerToProcessQueuedRequest;
113 RefPtr<SpellCheckRequest> m_processingRequest;
114 RequestQueue m_requestQueue;
117 } // namespace WebCore
119 #endif // SpellChecker_h