Fix the incorrect behavior touch sound on single tap event.
[framework/web/webkit-efl.git] / Source / WebCore / editing / SpellChecker.h
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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. 
24  */
25
26 #ifndef SpellChecker_h
27 #define SpellChecker_h
28
29 #include "Element.h"
30 #include "PlatformString.h"
31 #include "Range.h"
32 #include "TextChecking.h"
33 #include "Timer.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>
39
40 namespace WebCore {
41
42 class Frame;
43 class Node;
44 class TextCheckerClient;
45 class SpellChecker;
46
47 class SpellCheckRequest : public TextCheckingRequest {
48 public:
49     SpellCheckRequest(PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange, const String&, TextCheckingTypeMask, TextCheckingProcessType);
50     virtual ~SpellCheckRequest();
51
52     static PassRefPtr<SpellCheckRequest> create(TextCheckingTypeMask, TextCheckingProcessType, PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange);
53
54     PassRefPtr<Range> checkingRange() const { return m_checkingRange; }
55     PassRefPtr<Range> paragraphRange() const { return m_paragraphRange; }
56     PassRefPtr<Element> rootEditableElement() const { return m_rootEditableElement; }
57
58     void setCheckerAndSequence(SpellChecker*, int sequence);
59     void requesterDestroyed();
60     bool isStarted() const { return m_checker; }
61
62     virtual void didSucceed(const Vector<TextCheckingResult>&) OVERRIDE;
63     virtual void didCancel() OVERRIDE;
64
65 private:
66     SpellChecker* m_checker;
67     RefPtr<Range> m_checkingRange;
68     RefPtr<Range> m_paragraphRange;
69     RefPtr<Element> m_rootEditableElement;
70 };
71
72 class SpellChecker {
73     WTF_MAKE_NONCOPYABLE(SpellChecker);
74 public:
75     friend class SpellCheckRequest;
76
77     explicit SpellChecker(Frame*);
78     ~SpellChecker();
79
80     bool isAsynchronousEnabled() const;
81     bool isCheckable(Range*) const;
82
83     void requestCheckingFor(PassRefPtr<SpellCheckRequest>);
84
85     int lastRequestSequence() const
86     {
87         return m_lastRequestSequence;
88     }
89
90     int lastProcessedSequence() const
91     {
92         return m_lastProcessedSequence;
93     }
94
95 private:
96     typedef Deque<RefPtr<SpellCheckRequest> > RequestQueue;
97
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>&);
106
107     Frame* m_frame;
108     int m_lastRequestSequence;
109     int m_lastProcessedSequence;
110
111     Timer<SpellChecker> m_timerToProcessQueuedRequest;
112
113     RefPtr<SpellCheckRequest> m_processingRequest;
114     RequestQueue m_requestQueue;
115 };
116
117 } // namespace WebCore
118
119 #endif // SpellChecker_h