Commit bc97234a authored by satish@chromium.org's avatar satish@chromium.org

2010-10-21 Satish Sampath <satish@chromium.org>

        Reviewed by Jeremy Orlow.

        Allow embedder to pass on all the speech recognition results to the input element.
        https://bugs.webkit.org/show_bug.cgi?id=48068

        No new tests added as functionality has not changed, tests will be added in the next
        patch where these results are exposed as an attribute to scripts.

        * Android.mk: Added new source files.
        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.xcodeproj/project.pbxproj:
        * page/SpeechInput.cpp:
        (WebCore::SpeechInput::setRecognitionResult): Accept an array instead of a single string.
        * page/SpeechInput.h:
        * page/SpeechInputListener.h:
        * page/SpeechInputResult.cpp: Added, defines a class for managing a speech input result.
        (WebCore::SpeechInputResult::create):
        (WebCore::SpeechInputResult::SpeechInputResult):
        (WebCore::SpeechInputResult::confidence):
        (WebCore::SpeechInputResult::utterance):
        * page/SpeechInputResult.h: Added.
        * platform/mock/SpeechInputClientMock.cpp:
        (WebCore::SpeechInputClientMock::timerFired):
        * rendering/TextControlInnerElements.cpp:
        (WebCore::InputFieldSpeechButtonElement::setRecognitionResult):
        * rendering/TextControlInnerElements.h:
2010-10-21  Satish Sampath  <satish@chromium.org>

        Reviewed by Jeremy Orlow.

        Allow embedder to pass on all the speech recognition results to the input element.
        https://bugs.webkit.org/show_bug.cgi?id=48068

        * WebKit.gyp: Added new files
        * public/WebSpeechInputListener.h:
        * public/WebSpeechInputResult.h: Added, wrapper around WebCore::SpeechInputResult
        (WebKit::WebSpeechInputResult::WebSpeechInputResult):
        (WebKit::WebSpeechInputResult::~WebSpeechInputResult):
        * src/SpeechInputClientImpl.cpp:
        (WebKit::SpeechInputClientImpl::setRecognitionResult): Accepts an array instead of a single string.
        * src/SpeechInputClientImpl.h:
        * src/WebSpeechInputControllerMockImpl.cpp:
        (WebKit::WebSpeechInputControllerMockImpl::setRecognitionResult):
        * src/WebSpeechInputControllerMockImpl.h:
        * src/WebSpeechInputResult.cpp: Added.
        (WebKit::WebSpeechInputResult::reset):
        (WebKit::WebSpeechInputResult::WebSpeechInputResult):
        (WebKit::WebSpeechInputResult::set):
        (WebKit::WebSpeechInputResult::operator PassRefPtr<WebCore::SpeechInputResult>):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@70490 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 439da383
......@@ -425,6 +425,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
page/Settings.cpp \
page/SpatialNavigation.cpp \
page/SpeechInput.cpp \
page/SpeechInputResult.cpp \
page/SuspendableTimer.cpp \
page/Timing.cpp \
page/UserContentURLPattern.cpp \
......
2010-10-21 Satish Sampath <satish@chromium.org>
Reviewed by Jeremy Orlow.
Allow embedder to pass on all the speech recognition results to the input element.
https://bugs.webkit.org/show_bug.cgi?id=48068
No new tests added as functionality has not changed, tests will be added in the next
patch where these results are exposed as an attribute to scripts.
* Android.mk: Added new source files.
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.xcodeproj/project.pbxproj:
* page/SpeechInput.cpp:
(WebCore::SpeechInput::setRecognitionResult): Accept an array instead of a single string.
* page/SpeechInput.h:
* page/SpeechInputListener.h:
* page/SpeechInputResult.cpp: Added, defines a class for managing a speech input result.
(WebCore::SpeechInputResult::create):
(WebCore::SpeechInputResult::SpeechInputResult):
(WebCore::SpeechInputResult::confidence):
(WebCore::SpeechInputResult::utterance):
* page/SpeechInputResult.h: Added.
* platform/mock/SpeechInputClientMock.cpp:
(WebCore::SpeechInputClientMock::timerFired):
* rendering/TextControlInnerElements.cpp:
(WebCore::InputFieldSpeechButtonElement::setRecognitionResult):
* rendering/TextControlInnerElements.h:
2010-10-25 Jian Li <jianli@chromium.org>
Reviewed by David Levin.
......@@ -2126,6 +2126,8 @@ webcore_sources += \
WebCore/page/SpeechInput.cpp \
WebCore/page/SpeechInput.h \
WebCore/page/SpeechInputListener.h \
WebCore/page/SpeechInputResult.cpp \
WebCore/page/SpeechInputResult.h \
WebCore/page/SuspendableTimer.cpp \
WebCore/page/SuspendableTimer.h \
WebCore/page/Timing.cpp \
......
......@@ -2263,6 +2263,8 @@
'page/SpeechInput.h',
'page/SpeechInputClient.h',
'page/SpeechInputListener.h',
'page/SpeechInputResult.cpp',
'page/SpeechInputResult.h',
'page/SuspendableTimer.cpp',
'page/SuspendableTimer.h',
'page/Timing.cpp',
......
......@@ -1999,6 +1999,7 @@ HEADERS += \
page/SpeechInput.h \
page/SpeechInputClient.h \
page/SpeechInputListener.h \
page/SpeechInputResult.h \
page/WindowFeatures.h \
page/WorkerNavigator.h \
page/XSSAuditor.h \
......@@ -3103,6 +3104,7 @@ contains(DEFINES, ENABLE_SHARED_WORKERS=1) {
contains(DEFINES, ENABLE_INPUT_SPEECH=1) {
SOURCES += \
page/SpeechInput.cpp \
page/SpeechInputResult.cpp \
rendering/RenderInputSpeech.cpp
}
......
......@@ -1478,6 +1478,8 @@
75793ED30D0CE85B007FC0AC /* DOMMessageEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 75793ED00D0CE85B007FC0AC /* DOMMessageEvent.h */; };
75793ED40D0CE85B007FC0AC /* DOMMessageEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 75793ED10D0CE85B007FC0AC /* DOMMessageEvent.mm */; };
75793ED50D0CE85B007FC0AC /* DOMMessageEventInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */; };
758978EC127090D60076D5A9 /* SpeechInputResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 758978EA127090D60076D5A9 /* SpeechInputResult.cpp */; };
758978ED127090D60076D5A9 /* SpeechInputResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 758978EB127090D60076D5A9 /* SpeechInputResult.h */; };
7637C541112E7B74003D6CDC /* WebSocketHandshakeRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7637C540112E7B74003D6CDC /* WebSocketHandshakeRequest.cpp */; };
7637C543112E7B7E003D6CDC /* WebSocketHandshakeRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 7637C542112E7B7E003D6CDC /* WebSocketHandshakeRequest.h */; };
767F99BE11A1194A0080C51D /* WebSocketHandshakeResponse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 767F99BD11A1194A0080C51D /* WebSocketHandshakeResponse.cpp */; };
......@@ -7589,6 +7591,8 @@
75793ED00D0CE85B007FC0AC /* DOMMessageEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMMessageEvent.h; sourceTree = "<group>"; };
75793ED10D0CE85B007FC0AC /* DOMMessageEvent.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMMessageEvent.mm; sourceTree = "<group>"; };
75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMMessageEventInternal.h; sourceTree = "<group>"; };
758978EA127090D60076D5A9 /* SpeechInputResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpeechInputResult.cpp; sourceTree = "<group>"; };
758978EB127090D60076D5A9 /* SpeechInputResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpeechInputResult.h; sourceTree = "<group>"; };
7637C540112E7B74003D6CDC /* WebSocketHandshakeRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSocketHandshakeRequest.cpp; sourceTree = "<group>"; };
7637C542112E7B7E003D6CDC /* WebSocketHandshakeRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSocketHandshakeRequest.h; sourceTree = "<group>"; };
767F99BD11A1194A0080C51D /* WebSocketHandshakeResponse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSocketHandshakeResponse.cpp; sourceTree = "<group>"; };
......@@ -13216,6 +13220,8 @@
7578F90911DDF26900D933C5 /* SpeechInput.h */,
7578F90A11DDF26900D933C5 /* SpeechInputClient.h */,
7578F91E11E4E32800D933C5 /* SpeechInputListener.h */,
758978EA127090D60076D5A9 /* SpeechInputResult.cpp */,
758978EB127090D60076D5A9 /* SpeechInputResult.h */,
62C1217A11AB9E76003C462C /* SuspendableTimer.cpp */,
62C1217B11AB9E77003C462C /* SuspendableTimer.h */,
8AF4E55811DC5A63000ED3DE /* Timing.cpp */,
......@@ -21155,6 +21161,7 @@
089021AD126EF5E90092D5EA /* SVGAnimatedLengthList.h in Headers */,
8AB4BC77126FDB7100DEB727 /* IgnoreDestructiveWriteCountIncrementer.h in Headers */,
087B84961272CEC800A14417 /* SVGAnimatedAngle.h in Headers */,
758978ED127090D60076D5A9 /* SpeechInputResult.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -23708,6 +23715,7 @@
E18772F1126E2629003DD586 /* Language.cpp in Sources */,
7A1F2B52126C61B20006A7E6 /* InspectorClient.cpp in Sources */,
E13F01F11270E19000DFBA71 /* CookieStorageMac.mm in Sources */,
758978EC127090D60076D5A9 /* SpeechInputResult.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -85,7 +85,7 @@ void SpeechInput::didCompleteRecognition(int listenerId)
m_listeners.get(listenerId)->didCompleteRecognition(listenerId);
}
void SpeechInput::setRecognitionResult(int listenerId, const String& result)
void SpeechInput::setRecognitionResult(int listenerId, const SpeechInputResultArray& result)
{
// Don't assert if not present as the element might have been removed by the page while
// this event was on the way.
......
......@@ -68,7 +68,7 @@ public:
// SpeechInputListener methods.
virtual void didCompleteRecording(int);
virtual void didCompleteRecognition(int);
virtual void setRecognitionResult(int, const String&);
virtual void setRecognitionResult(int, const SpeechInputResultArray&);
private:
SpeechInputClient* m_client;
......
......@@ -33,10 +33,13 @@
#if ENABLE(INPUT_SPEECH)
#include "SpeechInputResult.h"
#include <wtf/Forward.h>
namespace WebCore {
typedef Vector<RefPtr<SpeechInputResult> > SpeechInputResultArray;
// Interface to be implemented by the element which invokes SpeechInput.
class SpeechInputListener {
public:
......@@ -53,7 +56,7 @@ public:
// This method can potentially get called multiple times if there are partial results
// available as the user keeps speaking. If the speech could not be recognized properly
// or if there was any other errors in the process, this method may never be called.
virtual void setRecognitionResult(int requestId, const String& result) = 0;
virtual void setRecognitionResult(int requestId, const SpeechInputResultArray&) = 0;
protected:
virtual ~SpeechInputListener() { }
......
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "SpeechInputResult.h"
#if ENABLE(INPUT_SPEECH)
namespace WebCore {
PassRefPtr<SpeechInputResult> SpeechInputResult::create(const String& utterance, double confidence)
{
return adoptRef(new SpeechInputResult(utterance, confidence));
}
SpeechInputResult::SpeechInputResult(const String& utterance, double confidence)
: m_utterance(utterance)
, m_confidence(confidence)
{
}
double SpeechInputResult::confidence() const
{
return m_confidence;
}
const String& SpeechInputResult::utterance() const
{
return m_utterance;
}
} // namespace WebCore
#endif // ENABLE(INPUT_SPEECH)
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SpeechInputResult_h
#define SpeechInputResult_h
#if ENABLE(INPUT_SPEECH)
#include "PlatformString.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
namespace WebCore {
// This class holds one speech recognition result including the text and other related
// fields, as received from the embedder.
class SpeechInputResult : public RefCounted<SpeechInputResult> {
public:
static PassRefPtr<SpeechInputResult> create(const String& utterance, double confidence);
double confidence() const;
const String& utterance() const;
private:
SpeechInputResult(const String& utterance, double confidence);
String m_utterance;
double m_confidence;
};
} // namespace WebCore
#endif // ENABLE(INPUT_SPEECH)
#endif // SpeechInputResult_h
......@@ -92,7 +92,9 @@ void SpeechInputClientMock::timerFired(WebCore::Timer<SpeechInputClientMock>*)
m_listener->didCompleteRecording(m_requestId);
m_timer.startOneShot(0);
} else {
m_listener->setRecognitionResult(m_requestId, m_recognitionResult);
SpeechInputResultArray results;
results.append(SpeechInputResult::create(m_recognitionResult, 1.0));
m_listener->setRecognitionResult(m_requestId, results);
m_listener->didCompleteRecognition(m_requestId);
m_requestId = 0;
}
......
......@@ -471,14 +471,16 @@ void InputFieldSpeechButtonElement::didCompleteRecognition(int)
setState(Idle);
}
void InputFieldSpeechButtonElement::setRecognitionResult(int, const String& result)
void InputFieldSpeechButtonElement::setRecognitionResult(int, const SpeechInputResultArray& results)
{
m_results = results;
HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
// The call to setValue() below dispatches an event, and an event handler in the page might
// remove the input element from DOM. To make sure it remains valid until we finish our work
// here, we take a temporary reference.
RefPtr<HTMLInputElement> holdRef(input);
input->setValue(result);
input->setValue(results.isEmpty() ? "" : results[0]->utterance());
input->dispatchWebkitSpeechChangeEvent();
renderer()->repaint();
}
......
......@@ -141,7 +141,7 @@ public:
// SpeechInputListener methods.
void didCompleteRecording(int);
void didCompleteRecognition(int);
void setRecognitionResult(int, const String& result);
void setRecognitionResult(int, const SpeechInputResultArray&);
private:
InputFieldSpeechButtonElement(HTMLElement*);
......@@ -151,6 +151,7 @@ private:
bool m_capturing;
SpeechInputState m_state;
int m_listenerId;
SpeechInputResultArray m_results;
};
#endif // ENABLE(INPUT_SPEECH)
......
2010-10-21 Satish Sampath <satish@chromium.org>
Reviewed by Jeremy Orlow.
Allow embedder to pass on all the speech recognition results to the input element.
https://bugs.webkit.org/show_bug.cgi?id=48068
* WebKit.gyp: Added new files
* public/WebSpeechInputListener.h:
* public/WebSpeechInputResult.h: Added, wrapper around WebCore::SpeechInputResult
(WebKit::WebSpeechInputResult::WebSpeechInputResult):
(WebKit::WebSpeechInputResult::~WebSpeechInputResult):
* src/SpeechInputClientImpl.cpp:
(WebKit::SpeechInputClientImpl::setRecognitionResult): Accepts an array instead of a single string.
* src/SpeechInputClientImpl.h:
* src/WebSpeechInputControllerMockImpl.cpp:
(WebKit::WebSpeechInputControllerMockImpl::setRecognitionResult):
* src/WebSpeechInputControllerMockImpl.h:
* src/WebSpeechInputResult.cpp: Added.
(WebKit::WebSpeechInputResult::reset):
(WebKit::WebSpeechInputResult::WebSpeechInputResult):
(WebKit::WebSpeechInputResult::set):
(WebKit::WebSpeechInputResult::operator PassRefPtr<WebCore::SpeechInputResult>):
2010-10-25 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r70451.
......
......@@ -257,6 +257,7 @@
'public/WebSpeechInputController.h',
'public/WebSpeechInputControllerMock.h',
'public/WebSpeechInputListener.h',
'public/WebSpeechInputResult.h',
'public/WebStorageArea.h',
'public/WebStorageEventDispatcher.h',
'public/WebStorageNamespace.h',
......@@ -518,6 +519,7 @@
'src/WebSharedWorkerImpl.h',
'src/WebSpeechInputControllerMockImpl.cpp',
'src/WebSpeechInputControllerMockImpl.h',
'src/WebSpeechInputResult.cpp',
'src/WebStorageAreaImpl.cpp',
'src/WebStorageAreaImpl.h',
'src/WebStorageEventDispatcherImpl.cpp',
......
......@@ -31,6 +31,8 @@
#ifndef WebSpeechInputListener_h
#define WebSpeechInputListener_h
#include "WebSpeechInputResult.h"
namespace WebKit {
class WebString;
......@@ -47,19 +49,28 @@ public:
// WebSpeechInputController::stopRecording() was called.
// Typically after this call the listener would update the UI to reflect that recognition is
// in progress.
virtual void didCompleteRecording(int) = 0;
virtual void didCompleteRecording(int) { WEBKIT_ASSERT_NOT_REACHED(); }
// Gives results from speech recognition, either partial or the final results.
// This method can potentially get called multiple times if there are partial results
// available as the user keeps speaking. If the speech could not be recognized properly
// or if there was any other errors in the process, this method may never be called.
virtual void setRecognitionResult(int, const WebString&) = 0;
virtual void setRecognitionResult(int, const WebSpeechInputResultArray&) { WEBKIT_ASSERT_NOT_REACHED(); }
// FIXME: Remove this once the chromium side is able to send multiple recognition results
// using the above call.
virtual void setRecognitionResult(int requestId, const WebString& result)
{
WebSpeechInputResultArray results(1U);
results[0].set(result, 1.0);
setRecognitionResult(requestId, results);
}
// Informs that speech recognition has completed. This gets invoked irrespective of whether
// recognition was succesful or not, whether setRecognitionResult() was invoked or not. The
// handler typically frees up any temporary resources allocated and waits for the next speech
// recognition request.
virtual void didCompleteRecognition(int) = 0;
virtual void didCompleteRecognition(int) { WEBKIT_ASSERT_NOT_REACHED(); }
protected:
~WebSpeechInputListener() { }
......
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WebSpeechInputResult_h
#define WebSpeechInputResult_h
#include "WebCommon.h"
#include "WebPrivatePtr.h"
#include "WebString.h"
#include "WebVector.h"
namespace WebCore {
class SpeechInputResult;
}
namespace WebKit {
// This class holds one speech recognition result including the text and other related
// fields, as received from the embedder.
class WebSpeechInputResult {
public:
WebSpeechInputResult() { }
~WebSpeechInputResult() { reset(); }
WEBKIT_API void set(const WebString& utterance, double confidence);
WEBKIT_API void reset();
#if WEBKIT_IMPLEMENTATION
WebSpeechInputResult(const WTF::PassRefPtr<WebCore::SpeechInputResult>&);
operator WTF::PassRefPtr<WebCore::SpeechInputResult>() const;
#endif
private:
WebPrivatePtr<WebCore::SpeechInputResult> m_private;
};
typedef WebVector<WebSpeechInputResult> WebSpeechInputResultArray;
} // namespace WebKit
#endif // WebSpeechInputResult_h
......@@ -86,10 +86,13 @@ void SpeechInputClientImpl::didCompleteRecognition(int requestId)
m_listener->didCompleteRecognition(requestId);
}
void SpeechInputClientImpl::setRecognitionResult(int requestId, const WebString& result)
void SpeechInputClientImpl::setRecognitionResult(int requestId, const WebSpeechInputResultArray& results)
{
ASSERT(m_listener);
m_listener->setRecognitionResult(requestId, result);
WebCore::SpeechInputResultArray webcoreResults(results.size());
for (size_t i = 0; i < results.size(); ++i)
webcoreResults[i] = results[i];
m_listener->setRecognitionResult(requestId, webcoreResults);
}
} // namespace WebKit
......
......@@ -60,7 +60,7 @@ public:
// WebSpeechInputListener methods.
void didCompleteRecording(int);
void setRecognitionResult(int, const WebString&);
void setRecognitionResult(int, const WebSpeechInputResultArray&);
void didCompleteRecognition(int);
private:
......
......@@ -70,7 +70,7 @@ void WebSpeechInputControllerMockImpl::didCompleteRecognition(int requestId)
m_listener->didCompleteRecognition(requestId);
}
void WebSpeechInputControllerMockImpl::setRecognitionResult(int requestId, const WTF::String& result)
void WebSpeechInputControllerMockImpl::setRecognitionResult(int requestId, const WebCore::SpeechInputResultArray& result)
{
m_listener->setRecognitionResult(requestId, result);
}
......
......@@ -54,7 +54,7 @@ public:
// WebCore::SpeechInputListener methods.
void didCompleteRecording(int requestId);
void didCompleteRecognition(int requestId);
void setRecognitionResult(int requestId, const WTF::String& result);
void setRecognitionResult(int requestId, const WebCore::SpeechInputResultArray& result);
// WebSpeechInputController methods.
bool startRecognition(int requestId, const WebRect& elementRect);
......
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "WebSpeechInputResult.h"
#include "SpeechInputResult.h"
#include <wtf/PassRefPtr.h>
namespace WebKit {
void WebSpeechInputResult::reset()
{
m_private.reset();
}
WebSpeechInputResult::WebSpeechInputResult(const PassRefPtr<WebCore::SpeechInputResult>& value)
: m_private(value)
{
}
void WebSpeechInputResult::set(const WebString& utterance, double confidence)
{
m_private = WebCore::SpeechInputResult::create(utterance, confidence);
}
WebSpeechInputResult::operator PassRefPtr<WebCore::SpeechInputResult>() const
{
return m_private.get();
}
} // namespace WebKit
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment