Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Source/WebCore: Clean up the speech recognintion API
https://bugs.webkit.org/show_bug.cgi?id=112916

Reviewed by Adam Barth.

This patch cleans away deprecated parts, fixes so that stop() can be called more than once and adds
the missing emma attribute on SpeechRecognitionEvent (which is always null).

Patch covered by existing tests.

* Modules/speech/SpeechRecognition.cpp:
(WebCore::SpeechRecognition::stopFunction):
(WebCore::SpeechRecognition::abort):
(WebCore::SpeechRecognition::didEnd):
(WebCore::SpeechRecognition::SpeechRecognition):
* Modules/speech/SpeechRecognition.h:
(SpeechRecognition):
* Modules/speech/SpeechRecognitionEvent.cpp:
(WebCore::SpeechRecognitionEvent::createResult):
(WebCore::SpeechRecognitionEvent::createNoMatch):
(WebCore::SpeechRecognitionEvent::SpeechRecognitionEvent):
* Modules/speech/SpeechRecognitionEvent.h:
(WebCore):
(SpeechRecognitionEventInit):
(SpeechRecognitionEvent):
(WebCore::SpeechRecognitionEvent::emma):
* Modules/speech/SpeechRecognitionEvent.idl:

Source/WebKit/chromium: Clean up the speach recognintion API
https://bugs.webkit.org/show_bug.cgi?id=112916

Reviewed by Adam Barth.

* public/WebSpeechRecognizerClient.h:
* src/SpeechRecognitionClientProxy.cpp:
* src/SpeechRecognitionClientProxy.h:
(SpeechRecognitionClientProxy):

LayoutTests: Clean up the speech recognintion API
https://bugs.webkit.org/show_bug.cgi?id=112916

Reviewed by Adam Barth.

* fast/events/constructors/speech-recognition-event-constructor-expected.txt:
* fast/events/constructors/speech-recognition-event-constructor.html:


Canonical link: https://commits.webkit.org/131379@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@146601 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Tommy Widenflycht committed Mar 22, 2013
1 parent 7aee452 commit 5c158a0
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 76 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
2013-03-22 Tommy Widenflycht <tommyw@google.com>

Clean up the speech recognintion API
https://bugs.webkit.org/show_bug.cgi?id=112916

Reviewed by Adam Barth.

* fast/events/constructors/speech-recognition-event-constructor-expected.txt:
* fast/events/constructors/speech-recognition-event-constructor.html:

2013-03-22 Emil A Eklund <eae@chromium.org>

Floor cell widths in AutoTableLayout::recalcColumn
Expand Down
Expand Up @@ -5,9 +5,8 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE

PASS new webkitSpeechRecognitionEvent('eventType').bubbles is false
PASS new webkitSpeechRecognitionEvent('eventType').cancelable is false
PASS new webkitSpeechRecognitionEvent('eventType').result is null
PASS new webkitSpeechRecognitionEvent('eventType').results is null
PASS new webkitSpeechRecognitionEvent('eventType').resultIndex is 0
PASS new webkitSpeechRecognitionEvent('eventType').resultHistory is null
PASS new webkitSpeechRecognitionEvent('eventType', { bubbles: false }).bubbles is false
PASS new webkitSpeechRecognitionEvent('eventType', { bubbles: true }).bubbles is true
PASS new webkitSpeechRecognitionEvent('eventType', { cancelable: false }).cancelable is false
Expand Down
Expand Up @@ -13,9 +13,8 @@
// Test constructor without initializer.
shouldBe("new webkitSpeechRecognitionEvent('eventType').bubbles", "false");
shouldBe("new webkitSpeechRecognitionEvent('eventType').cancelable", "false");
shouldBe("new webkitSpeechRecognitionEvent('eventType').result", "null");
shouldBe("new webkitSpeechRecognitionEvent('eventType').results", "null");
shouldBe("new webkitSpeechRecognitionEvent('eventType').resultIndex", "0");
shouldBe("new webkitSpeechRecognitionEvent('eventType').resultHistory", "null");

// Test passing bubbles in the initializer.
shouldBe("new webkitSpeechRecognitionEvent('eventType', { bubbles: false }).bubbles", "false");
Expand Down
30 changes: 30 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,33 @@
2013-03-22 Tommy Widenflycht <tommyw@google.com>

Clean up the speech recognintion API
https://bugs.webkit.org/show_bug.cgi?id=112916

Reviewed by Adam Barth.

This patch cleans away deprecated parts, fixes so that stop() can be called more than once and adds
the missing emma attribute on SpeechRecognitionEvent (which is always null).

Patch covered by existing tests.

* Modules/speech/SpeechRecognition.cpp:
(WebCore::SpeechRecognition::stopFunction):
(WebCore::SpeechRecognition::abort):
(WebCore::SpeechRecognition::didEnd):
(WebCore::SpeechRecognition::SpeechRecognition):
* Modules/speech/SpeechRecognition.h:
(SpeechRecognition):
* Modules/speech/SpeechRecognitionEvent.cpp:
(WebCore::SpeechRecognitionEvent::createResult):
(WebCore::SpeechRecognitionEvent::createNoMatch):
(WebCore::SpeechRecognitionEvent::SpeechRecognitionEvent):
* Modules/speech/SpeechRecognitionEvent.h:
(WebCore):
(SpeechRecognitionEventInit):
(SpeechRecognitionEvent):
(WebCore::SpeechRecognitionEvent::emma):
* Modules/speech/SpeechRecognitionEvent.idl:

2013-03-22 Emil A Eklund <eae@chromium.org>

Floor cell widths in AutoTableLayout::recalcColumn
Expand Down
17 changes: 10 additions & 7 deletions Source/WebCore/Modules/speech/SpeechRecognition.cpp
Expand Up @@ -62,13 +62,19 @@ void SpeechRecognition::start(ExceptionCode& ec)
void SpeechRecognition::stopFunction()
{
ASSERT(m_controller);
m_controller->stop(this);
if (m_started && !m_stopping) {
m_stopping = true;
m_controller->stop(this);
}
}

void SpeechRecognition::abort()
{
ASSERT(m_controller);
m_controller->abort(this);
if (m_started && !m_stopping) {
m_stopping = true;
m_controller->abort(this);
}
}

void SpeechRecognition::didStartAudio()
Expand Down Expand Up @@ -101,11 +107,6 @@ void SpeechRecognition::didEndAudio()
dispatchEvent(Event::create(eventNames().audioendEvent, /*canBubble=*/false, /*cancelable=*/false));
}

void SpeechRecognition::didReceiveResult(PassRefPtr<SpeechRecognitionResult> result, unsigned long resultIndex, PassRefPtr<SpeechRecognitionResultList> resultHistory)
{
dispatchEvent(SpeechRecognitionEvent::createResult(result, resultIndex, resultHistory));
}

void SpeechRecognition::didReceiveResults(const Vector<RefPtr<SpeechRecognitionResult> >& newFinalResults, const Vector<RefPtr<SpeechRecognitionResult> >& currentInterimResults)
{
unsigned long resultIndex = m_finalResults.size();
Expand Down Expand Up @@ -139,6 +140,7 @@ void SpeechRecognition::didStart()
void SpeechRecognition::didEnd()
{
m_started = false;
m_stopping = false;
if (!m_stoppedByActiveDOMObject)
dispatchEvent(Event::create(eventNames().endEvent, /*canBubble=*/false, /*cancelable=*/false));
unsetPendingActivity(this);
Expand Down Expand Up @@ -170,6 +172,7 @@ SpeechRecognition::SpeechRecognition(ScriptExecutionContext* context)
, m_controller(0)
, m_stoppedByActiveDOMObject(false)
, m_started(false)
, m_stopping(false)
{
Document* document = toDocument(scriptExecutionContext());

Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/Modules/speech/SpeechRecognition.h
Expand Up @@ -74,8 +74,6 @@ class SpeechRecognition : public RefCounted<SpeechRecognition>, public ActiveDOM
void didEndSound();
void didEndAudio();
void didReceiveResults(const Vector<RefPtr<SpeechRecognitionResult> >& newFinalResults, const Vector<RefPtr<SpeechRecognitionResult> >& currentInterimResults);
// FIXME: Remove this once we start using didReceiveResults.
void didReceiveResult(PassRefPtr<SpeechRecognitionResult>, unsigned long resultIndex, PassRefPtr<SpeechRecognitionResultList> resultHistory);
void didReceiveNoMatch(PassRefPtr<SpeechRecognitionResult>);
void didReceiveError(PassRefPtr<SpeechRecognitionError>);
void didStart();
Expand Down Expand Up @@ -126,6 +124,7 @@ class SpeechRecognition : public RefCounted<SpeechRecognition>, public ActiveDOM
SpeechRecognitionController* m_controller;
bool m_stoppedByActiveDOMObject;
bool m_started;
bool m_stopping;
Vector<RefPtr<SpeechRecognitionResult> > m_finalResults;
};

Expand Down
30 changes: 11 additions & 19 deletions Source/WebCore/Modules/speech/SpeechRecognitionEvent.cpp
Expand Up @@ -46,19 +46,20 @@ PassRefPtr<SpeechRecognitionEvent> SpeechRecognitionEvent::create(const AtomicSt
return adoptRef(new SpeechRecognitionEvent(eventName, initializer));
}

PassRefPtr<SpeechRecognitionEvent> SpeechRecognitionEvent::createResult(PassRefPtr<SpeechRecognitionResult> result, short resultIndex, PassRefPtr<SpeechRecognitionResultList> resultHistory)
{
return adoptRef(new SpeechRecognitionEvent(eventNames().resultEvent, result, resultIndex, resultHistory));
}

PassRefPtr<SpeechRecognitionEvent> SpeechRecognitionEvent::createResult(unsigned long resultIndex, const Vector<RefPtr<SpeechRecognitionResult> >& results)
{
return adoptRef(new SpeechRecognitionEvent(eventNames().resultEvent, resultIndex, results));
return adoptRef(new SpeechRecognitionEvent(eventNames().resultEvent, resultIndex, SpeechRecognitionResultList::create(results)));
}

PassRefPtr<SpeechRecognitionEvent> SpeechRecognitionEvent::createNoMatch(PassRefPtr<SpeechRecognitionResult> result)
{
return adoptRef(new SpeechRecognitionEvent(eventNames().nomatchEvent, result, 0, 0));
if (result) {
Vector<RefPtr<SpeechRecognitionResult> > results;
results.append(result);
return adoptRef(new SpeechRecognitionEvent(eventNames().nomatchEvent, 0, SpeechRecognitionResultList::create(results)));
}

return adoptRef(new SpeechRecognitionEvent(eventNames().nomatchEvent, 0, 0));
}

const AtomicString& SpeechRecognitionEvent::interfaceName() const
Expand All @@ -74,23 +75,14 @@ SpeechRecognitionEvent::SpeechRecognitionEvent()
SpeechRecognitionEvent::SpeechRecognitionEvent(const AtomicString& eventName, const SpeechRecognitionEventInit& initializer)
: Event(eventName, initializer)
, m_resultIndex(initializer.resultIndex)
, m_result(initializer.result)
, m_resultHistory(initializer.resultHistory)
{
}

SpeechRecognitionEvent::SpeechRecognitionEvent(const AtomicString& eventName, PassRefPtr<SpeechRecognitionResult> result, short resultIndex, PassRefPtr<SpeechRecognitionResultList> resultHistory)
: Event(eventName, /*canBubble=*/false, /*cancelable=*/false)
, m_resultIndex(resultIndex)
, m_result(result)
, m_resultHistory(resultHistory)
, m_results(initializer.results)
{
}

SpeechRecognitionEvent::SpeechRecognitionEvent(const AtomicString& eventName, unsigned long resultIndex, const Vector<RefPtr<SpeechRecognitionResult> >& results)
SpeechRecognitionEvent::SpeechRecognitionEvent(const AtomicString& eventName, unsigned long resultIndex, PassRefPtr<SpeechRecognitionResultList> results)
: Event(eventName, /*canBubble=*/false, /*cancelable=*/false)
, m_resultIndex(resultIndex)
, m_results(SpeechRecognitionResultList::create(results))
, m_results(results)
{
}

Expand Down
25 changes: 3 additions & 22 deletions Source/WebCore/Modules/speech/SpeechRecognitionEvent.h
Expand Up @@ -29,24 +29,17 @@
#if ENABLE(SCRIPTED_SPEECH)

#include "Event.h"
#include "SpeechRecognitionError.h"
#include "SpeechRecognitionResult.h"
#include "SpeechRecognitionResultList.h"
#include <wtf/RefPtr.h>

namespace WebCore {

class SpeechRecognitionError;
class SpeechRecognitionResult;
class SpeechRecognitionResultList;
class Document;

struct SpeechRecognitionEventInit : public EventInit {
SpeechRecognitionEventInit();

// DEPRECATED
RefPtr<SpeechRecognitionResult> result;
RefPtr<SpeechRecognitionResultList> resultHistory;

unsigned long resultIndex;
RefPtr<SpeechRecognitionResultList> results;
};
Expand All @@ -57,35 +50,23 @@ class SpeechRecognitionEvent : public Event {
static PassRefPtr<SpeechRecognitionEvent> create(const AtomicString&, const SpeechRecognitionEventInit&);
virtual ~SpeechRecognitionEvent();

// DEPRECATED
static PassRefPtr<SpeechRecognitionEvent> createResult(PassRefPtr<SpeechRecognitionResult>, short resultIndex, PassRefPtr<SpeechRecognitionResultList> resultHistory);

static PassRefPtr<SpeechRecognitionEvent> createResult(unsigned long resultIndex, const Vector<RefPtr<SpeechRecognitionResult> >& results);
static PassRefPtr<SpeechRecognitionEvent> createNoMatch(PassRefPtr<SpeechRecognitionResult>);

unsigned long resultIndex() const { return m_resultIndex; }
SpeechRecognitionResultList* results() const { return m_results.get(); }

// DEPRECATED
SpeechRecognitionResult* result() const { return m_result.get(); }
SpeechRecognitionResultList* resultHistory() const { return m_resultHistory.get(); }
Document* emma() { return 0; }

// Event
virtual const AtomicString& interfaceName() const OVERRIDE;

private:
SpeechRecognitionEvent();
SpeechRecognitionEvent(const AtomicString&, const SpeechRecognitionEventInit&);
SpeechRecognitionEvent(const AtomicString& eventName, PassRefPtr<SpeechRecognitionResult>, short resultIndex, PassRefPtr<SpeechRecognitionResultList> resultHistory); // FIXME: Remove.
SpeechRecognitionEvent(const AtomicString& eventName, unsigned long resultIndex, const Vector<RefPtr<SpeechRecognitionResult> >& results);
explicit SpeechRecognitionEvent(PassRefPtr<SpeechRecognitionError>);
SpeechRecognitionEvent(const AtomicString& eventName, unsigned long resultIndex, PassRefPtr<SpeechRecognitionResultList> results);

unsigned long m_resultIndex;
RefPtr<SpeechRecognitionResultList> m_results;

// DEPRECATED
RefPtr<SpeechRecognitionResult> m_result;
RefPtr<SpeechRecognitionResultList> m_resultHistory;
};

} // namespace WebCore
Expand Down
7 changes: 2 additions & 5 deletions Source/WebCore/Modules/speech/SpeechRecognitionEvent.idl
Expand Up @@ -27,11 +27,8 @@
Conditional=SCRIPTED_SPEECH,
ConstructorTemplate=Event,
] interface SpeechRecognitionEvent : Event {
// DEPRECATED
[InitializedByEventConstructor] readonly attribute SpeechRecognitionResult result;
[InitializedByEventConstructor] readonly attribute SpeechRecognitionResultList resultHistory;

[InitializedByEventConstructor] readonly attribute unsigned long resultIndex;
[InitializedByEventConstructor] readonly attribute SpeechRecognitionResultList results;
// FIXME: Add the emma attribute.

readonly attribute Document emma;
};
12 changes: 12 additions & 0 deletions Source/WebKit/chromium/ChangeLog
@@ -1,3 +1,15 @@
2013-03-22 Tommy Widenflycht <tommyw@google.com>

Clean up the speach recognintion API
https://bugs.webkit.org/show_bug.cgi?id=112916

Reviewed by Adam Barth.

* public/WebSpeechRecognizerClient.h:
* src/SpeechRecognitionClientProxy.cpp:
* src/SpeechRecognitionClientProxy.h:
(SpeechRecognitionClientProxy):

2013-03-22 Hajime Morrita <morrita@google.com>

Custom Elements: "readyCallback" lifecycle callback should be called.
Expand Down
4 changes: 0 additions & 4 deletions Source/WebKit/chromium/public/WebSpeechRecognizerClient.h
Expand Up @@ -67,10 +67,6 @@ class WebSpeechRecognizerClient {
// This is expected to be called after didEndSound.
virtual void didEndAudio(const WebSpeechRecognitionHandle&) = 0;

// To be called when the speech recognizer returns a result.
// FIXME: Remove this when we have moved over to only use the function below.
virtual void didReceiveResult(const WebSpeechRecognitionHandle&, const WebSpeechRecognitionResult&, unsigned long resultIndex, const WebVector<WebSpeechRecognitionResult>& resultHistory) = 0;

// To be called when the speech recognizer provides new results.
// - newFinalResults contains zero or more final results that are new since
// the last time the function was called.
Expand Down
12 changes: 0 additions & 12 deletions Source/WebKit/chromium/src/SpeechRecognitionClientProxy.cpp
Expand Up @@ -101,18 +101,6 @@ void SpeechRecognitionClientProxy::didEndAudio(const WebSpeechRecognitionHandle&
recognition->didEndAudio();
}

void SpeechRecognitionClientProxy::didReceiveResult(const WebSpeechRecognitionHandle& handle, const WebSpeechRecognitionResult& result, unsigned long resultIndex, const WebVector<WebSpeechRecognitionResult>& resultHistory)
{
RefPtr<SpeechRecognition> recognition = PassRefPtr<SpeechRecognition>(handle);

Vector<RefPtr<SpeechRecognitionResult> > resultHistoryVector(resultHistory.size());
for (size_t i = 0; i < resultHistory.size(); ++i)
resultHistoryVector[i] = static_cast<PassRefPtr<SpeechRecognitionResult> >(resultHistory[i]);

recognition->didReceiveResult(result, resultIndex, SpeechRecognitionResultList::create(resultHistoryVector));

}

void SpeechRecognitionClientProxy::didReceiveResults(const WebSpeechRecognitionHandle& handle, const WebVector<WebSpeechRecognitionResult>& newFinalResults, const WebVector<WebSpeechRecognitionResult>& currentInterimResults)
{
RefPtr<SpeechRecognition> recognition = PassRefPtr<SpeechRecognition>(handle);
Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/chromium/src/SpeechRecognitionClientProxy.h
Expand Up @@ -55,7 +55,6 @@ class SpeechRecognitionClientProxy : public WebCore::SpeechRecognitionClient, pu
virtual void didStartSound(const WebSpeechRecognitionHandle&) OVERRIDE;
virtual void didEndSound(const WebSpeechRecognitionHandle&) OVERRIDE;
virtual void didEndAudio(const WebSpeechRecognitionHandle&) OVERRIDE;
virtual void didReceiveResult(const WebSpeechRecognitionHandle&, const WebSpeechRecognitionResult&, unsigned long resultIndex, const WebVector<WebSpeechRecognitionResult>& resultHistory) OVERRIDE;
virtual void didReceiveResults(const WebSpeechRecognitionHandle&, const WebVector<WebSpeechRecognitionResult>& newFinalResults, const WebVector<WebSpeechRecognitionResult>& currentInterimResults) OVERRIDE;
virtual void didReceiveNoMatch(const WebSpeechRecognitionHandle&, const WebSpeechRecognitionResult&) OVERRIDE;
virtual void didReceiveError(const WebSpeechRecognitionHandle&, const WebString& message, WebSpeechRecognizerClient::ErrorCode) OVERRIDE;
Expand Down

0 comments on commit 5c158a0

Please sign in to comment.