This source file includes following definitions.
- m_nextListenerId
- create
- registerListener
- unregisterListener
- didCompleteRecording
- didCompleteRecognition
- setRecognitionResult
- startRecognition
- stopRecording
- cancelRecognition
- supplementName
- provideSpeechInputTo
#include "config.h"
#include "core/speech/SpeechInput.h"
#if ENABLE(INPUT_SPEECH)
#include "core/speech/SpeechInputClient.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
SpeechInput::SpeechInput(PassOwnPtr<SpeechInputClient> client)
: m_client(client)
, m_nextListenerId(1)
{
m_client->setListener(this);
}
SpeechInput::~SpeechInput()
{
m_client->setListener(0);
}
PassOwnPtr<SpeechInput> SpeechInput::create(PassOwnPtr<SpeechInputClient> client)
{
return adoptPtr(new SpeechInput(client));
}
int SpeechInput::registerListener(SpeechInputListener* listener)
{
#if defined(DEBUG)
for (HashMap<int, SpeechInputListener*>::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it)
ASSERT(it->value != listener);
#endif
m_listeners.add(m_nextListenerId, listener);
return m_nextListenerId++;
}
void SpeechInput::unregisterListener(int listenerId)
{
if (m_listeners.contains(listenerId))
m_listeners.remove(listenerId);
}
void SpeechInput::didCompleteRecording(int listenerId)
{
if (m_listeners.contains(listenerId))
m_listeners.get(listenerId)->didCompleteRecording(listenerId);
}
void SpeechInput::didCompleteRecognition(int listenerId)
{
if (m_listeners.contains(listenerId))
m_listeners.get(listenerId)->didCompleteRecognition(listenerId);
}
void SpeechInput::setRecognitionResult(int listenerId, const SpeechInputResultArray& result)
{
if (m_listeners.contains(listenerId))
m_listeners.get(listenerId)->setRecognitionResult(listenerId, result);
}
bool SpeechInput::startRecognition(int listenerId, const IntRect& elementRect, const AtomicString& language, const String& grammar, SecurityOrigin* origin)
{
ASSERT(m_listeners.contains(listenerId));
return m_client->startRecognition(listenerId, elementRect, language, grammar, origin);
}
void SpeechInput::stopRecording(int listenerId)
{
ASSERT(m_listeners.contains(listenerId));
m_client->stopRecording(listenerId);
}
void SpeechInput::cancelRecognition(int listenerId)
{
ASSERT(m_listeners.contains(listenerId));
m_client->cancelRecognition(listenerId);
}
const char* SpeechInput::supplementName()
{
return "SpeechInput";
}
void provideSpeechInputTo(Page& page, PassOwnPtr<SpeechInputClient> client)
{
SpeechInput::provideTo(page, SpeechInput::supplementName(), SpeechInput::create(client));
}
}
#endif