Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / speech / SpeechRecognition.h
1 /*
2  * Copyright (C) 2012 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  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * 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 THE COPYRIGHT HOLDERS ``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 THE COPYRIGHT OWNER 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 SpeechRecognition_h
27 #define SpeechRecognition_h
28
29 #include "bindings/v8/ScriptWrappable.h"
30 #include "core/dom/ActiveDOMObject.h"
31 #include "core/events/EventTarget.h"
32 #include "heap/Handle.h"
33 #include "modules/speech/SpeechGrammarList.h"
34 #include "modules/speech/SpeechRecognitionResult.h"
35 #include "wtf/Compiler.h"
36 #include "wtf/PassRefPtr.h"
37 #include "wtf/RefCounted.h"
38 #include "wtf/text/WTFString.h"
39
40 namespace WebCore {
41
42 class ExceptionState;
43 class ExecutionContext;
44 class SpeechRecognitionController;
45 class SpeechRecognitionError;
46
47 class SpeechRecognition FINAL : public RefCountedWillBeRefCountedGarbageCollected<SpeechRecognition>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithInlineData {
48     DECLARE_GC_INFO;
49     DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<SpeechRecognition>);
50 public:
51     static PassRefPtrWillBeRawPtr<SpeechRecognition> create(ExecutionContext*);
52     virtual ~SpeechRecognition();
53
54     // Attributes.
55     SpeechGrammarList* grammars() { return m_grammars.get(); }
56     void setGrammars(PassRefPtrWillBeRawPtr<SpeechGrammarList> grammars) { m_grammars = grammars; }
57     String lang() { return m_lang; }
58     void setLang(const String& lang) { m_lang = lang; }
59     bool continuous() { return m_continuous; }
60     void setContinuous(bool continuous) { m_continuous = continuous; }
61     bool interimResults() { return m_interimResults; }
62     void setInterimResults(bool interimResults) { m_interimResults = interimResults; }
63     unsigned long maxAlternatives() { return m_maxAlternatives; }
64     void setMaxAlternatives(unsigned long maxAlternatives) { m_maxAlternatives = maxAlternatives; }
65
66     // Callable by the user.
67     void start(ExceptionState&);
68     void stopFunction();
69     void abort();
70
71     // Called by the SpeechRecognitionClient.
72     void didStartAudio();
73     void didStartSound();
74     void didStartSpeech();
75     void didEndSpeech();
76     void didEndSound();
77     void didEndAudio();
78     void didReceiveResults(const Vector<RefPtr<SpeechRecognitionResult> >& newFinalResults, const Vector<RefPtr<SpeechRecognitionResult> >& currentInterimResults);
79     void didReceiveNoMatch(PassRefPtr<SpeechRecognitionResult>);
80     void didReceiveError(PassRefPtr<SpeechRecognitionError>);
81     void didStart();
82     void didEnd();
83
84     // EventTarget.
85     virtual const AtomicString& interfaceName() const OVERRIDE;
86     virtual ExecutionContext* executionContext() const OVERRIDE;
87
88     // ActiveDOMObject.
89     virtual void stop() OVERRIDE;
90
91     DEFINE_ATTRIBUTE_EVENT_LISTENER(audiostart);
92     DEFINE_ATTRIBUTE_EVENT_LISTENER(soundstart);
93     DEFINE_ATTRIBUTE_EVENT_LISTENER(speechstart);
94     DEFINE_ATTRIBUTE_EVENT_LISTENER(speechend);
95     DEFINE_ATTRIBUTE_EVENT_LISTENER(soundend);
96     DEFINE_ATTRIBUTE_EVENT_LISTENER(audioend);
97     DEFINE_ATTRIBUTE_EVENT_LISTENER(result);
98     DEFINE_ATTRIBUTE_EVENT_LISTENER(nomatch);
99     DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
100     DEFINE_ATTRIBUTE_EVENT_LISTENER(start);
101     DEFINE_ATTRIBUTE_EVENT_LISTENER(end);
102
103     void trace(Visitor*);
104
105 private:
106     friend class RefCounted<SpeechRecognition>;
107
108     explicit SpeechRecognition(ExecutionContext*);
109
110     RefPtrWillBeMember<SpeechGrammarList> m_grammars;
111     String m_lang;
112     bool m_continuous;
113     bool m_interimResults;
114     unsigned long m_maxAlternatives;
115
116     SpeechRecognitionController* m_controller;
117     bool m_stoppedByActiveDOMObject;
118     bool m_started;
119     bool m_stopping;
120     Vector<RefPtr<SpeechRecognitionResult> > m_finalResults;
121 };
122
123 } // namespace WebCore
124
125 #endif // SpeechRecognition_h