Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Speech JavaScript API: add SpeechRecognition.maxAlternatives attribute
https://bugs.webkit.org/show_bug.cgi?id=89459

Reviewed by Eric Seidel.

Source/WebCore:

Add the SpeechRecognition.maxAlternatives attribute.

Test: fast/speech/scripted/basics.html:

* Modules/speech/SpeechRecognition.cpp:
(WebCore::SpeechRecognition::start):
(WebCore::SpeechRecognition::SpeechRecognition):
* Modules/speech/SpeechRecognition.h:
(WebCore::SpeechRecognition::maxAlternatives):
(WebCore::SpeechRecognition::setMaxAlternatives):
(SpeechRecognition):
* Modules/speech/SpeechRecognition.idl:
* Modules/speech/SpeechRecognitionClient.h:
(SpeechRecognitionClient):
* Modules/speech/SpeechRecognitionController.h:
(WebCore::SpeechRecognitionController::start):
(SpeechRecognitionController):

Source/WebKit/chromium:

Plumbing for the maxAlternatives attribute.

* public/WebSpeechRecognitionParams.h:
(WebKit::WebSpeechRecognitionParams::WebSpeechRecognitionParams):
(WebKit::WebSpeechRecognitionParams::maxAlternatives):
(WebSpeechRecognitionParams):
* src/SpeechRecognitionClientProxy.cpp:
(WebKit::SpeechRecognitionClientProxy::start):
* src/SpeechRecognitionClientProxy.h:
(SpeechRecognitionClientProxy):

LayoutTests:

Update the basic test to check for presence of the maxAlternatives attribute.

* fast/speech/scripted/basics-expected.txt:
* fast/speech/scripted/basics.html:


Canonical link: https://commits.webkit.org/107419@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@120817 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
zmodem committed Jun 20, 2012
1 parent e6c653b commit b8046ce
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 7 deletions.
12 changes: 12 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
2012-06-20 Hans Wennborg <hans@chromium.org>

Speech JavaScript API: add SpeechRecognition.maxAlternatives attribute
https://bugs.webkit.org/show_bug.cgi?id=89459

Reviewed by Eric Seidel.

Update the basic test to check for presence of the maxAlternatives attribute.

* fast/speech/scripted/basics-expected.txt:
* fast/speech/scripted/basics.html:

2012-06-20 Takashi Sakamoto <tasak@google.com>

applyAuthorStyles makes rules declared in all enclosing shadow dom subtrees applicable.
Expand Down
4 changes: 4 additions & 0 deletions LayoutTests/fast/speech/scripted/basics-expected.txt
Expand Up @@ -11,6 +11,7 @@ PASS speechReco.grammars == null is false
PASS speechReco.grammars.length === 0 is true
PASS 'lang' in speechReco is true
PASS 'continuous' in speechReco is true
PASS 'maxAlternatives' in speechReco is true
PASS 'start' in speechReco is true
PASS 'stop' in speechReco is true
PASS 'abort' in speechReco is true
Expand All @@ -29,4 +30,7 @@ PASS 'onend' in speechReco is true
PASS 'addEventListener' in speechReco is true
PASS 'removeEventListener' in speechReco is true
PASS 'dispatchEvent' in speechReco is true
PASS speechReco.lang is ''
PASS speechReco.continuous is false
PASS speechReco.maxAlternatives is 1

7 changes: 7 additions & 0 deletions LayoutTests/fast/speech/scripted/basics.html
Expand Up @@ -20,6 +20,7 @@
shouldBeTrue("speechReco.grammars.length === 0");
shouldBeTrue("'lang' in speechReco");
shouldBeTrue("'continuous' in speechReco");
shouldBeTrue("'maxAlternatives' in speechReco");
shouldBeTrue("'start' in speechReco");
shouldBeTrue("'stop' in speechReco");
shouldBeTrue("'abort' in speechReco");
Expand All @@ -40,6 +41,12 @@
shouldBeTrue("'removeEventListener' in speechReco");
shouldBeTrue("'dispatchEvent' in speechReco");

// Check default values.
// FIXME: The spec should say what the default value for .grammars is.
shouldBe("speechReco.lang", "''");
shouldBe("speechReco.continuous", "false");
shouldBe("speechReco.maxAlternatives", "1");

finishJSTest();
}

Expand Down
25 changes: 25 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,28 @@
2012-06-20 Hans Wennborg <hans@chromium.org>

Speech JavaScript API: add SpeechRecognition.maxAlternatives attribute
https://bugs.webkit.org/show_bug.cgi?id=89459

Reviewed by Eric Seidel.

Add the SpeechRecognition.maxAlternatives attribute.

Test: fast/speech/scripted/basics.html:

* Modules/speech/SpeechRecognition.cpp:
(WebCore::SpeechRecognition::start):
(WebCore::SpeechRecognition::SpeechRecognition):
* Modules/speech/SpeechRecognition.h:
(WebCore::SpeechRecognition::maxAlternatives):
(WebCore::SpeechRecognition::setMaxAlternatives):
(SpeechRecognition):
* Modules/speech/SpeechRecognition.idl:
* Modules/speech/SpeechRecognitionClient.h:
(SpeechRecognitionClient):
* Modules/speech/SpeechRecognitionController.h:
(WebCore::SpeechRecognitionController::start):
(SpeechRecognitionController):

2012-06-20 Takashi Sakamoto <tasak@google.com>

applyAuthorStyles makes rules declared in all enclosing shadow dom subtrees applicable.
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/speech/SpeechRecognition.cpp
Expand Up @@ -47,7 +47,7 @@ PassRefPtr<SpeechRecognition> SpeechRecognition::create(ScriptExecutionContext*
void SpeechRecognition::start()
{
ASSERT(m_controller); // FIXME: Spec should say what to do if we are already started.
m_controller->start(this, m_grammars.get(), m_lang, m_continuous);
m_controller->start(this, m_grammars.get(), m_lang, m_continuous, m_maxAlternatives);
}

void SpeechRecognition::stopFunction()
Expand Down Expand Up @@ -137,6 +137,7 @@ SpeechRecognition::SpeechRecognition(ScriptExecutionContext* context)
: ActiveDOMObject(context, this)
, m_grammars(SpeechGrammarList::create()) // FIXME: The spec is not clear on the default value for the grammars attribute.
, m_continuous(false)
, m_maxAlternatives(1)
, m_controller(0)
{
ASSERT(scriptExecutionContext()->isDocument());
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/Modules/speech/SpeechRecognition.h
Expand Up @@ -58,6 +58,9 @@ class SpeechRecognition : public RefCounted<SpeechRecognition>, public ActiveDOM
bool continuous() { return m_continuous; }
void setContinuous(bool continuous) { m_continuous = continuous; }

unsigned long maxAlternatives() { return m_maxAlternatives; }
void setMaxAlternatives(unsigned long maxAlternatives) { m_maxAlternatives = maxAlternatives; }

// Callable by the user.
void start();
void stopFunction();
Expand Down Expand Up @@ -112,6 +115,7 @@ class SpeechRecognition : public RefCounted<SpeechRecognition>, public ActiveDOM
RefPtr<SpeechGrammarList> m_grammars;
String m_lang;
bool m_continuous;
unsigned long m_maxAlternatives;

EventTargetData m_eventTargetData;

Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Modules/speech/SpeechRecognition.idl
Expand Up @@ -34,6 +34,7 @@ module core {
attribute SpeechGrammarList grammars;
attribute DOMString lang;
attribute boolean continuous;
attribute unsigned long maxAlternatives;

void start();
[ImplementedAs=stopFunction] void stop();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/speech/SpeechRecognitionClient.h
Expand Up @@ -38,7 +38,7 @@ class SpeechRecognition;

class SpeechRecognitionClient {
public:
virtual void start(SpeechRecognition*, const SpeechGrammarList*, const String& lang, bool continuous) = 0;
virtual void start(SpeechRecognition*, const SpeechGrammarList*, const String& lang, bool continuous, unsigned long maxAlternatives) = 0;
virtual void stop(SpeechRecognition*) = 0;
virtual void abort(SpeechRecognition*) = 0;

Expand Down
6 changes: 5 additions & 1 deletion Source/WebCore/Modules/speech/SpeechRecognitionController.h
Expand Up @@ -38,7 +38,11 @@ class SpeechRecognitionController : public Supplement<Page> {
public:
virtual ~SpeechRecognitionController();

void start(SpeechRecognition* recognition, const SpeechGrammarList* grammars, const String& lang, bool continuous) { m_client->start(recognition, grammars, lang, continuous); }
void start(SpeechRecognition* recognition, const SpeechGrammarList* grammars, const String& lang, bool continuous, unsigned long maxAlternatives)
{
m_client->start(recognition, grammars, lang, continuous, maxAlternatives);
}

void stop(SpeechRecognition* recognition) { m_client->stop(recognition); }
void abort(SpeechRecognition* recognition) { m_client->abort(recognition); }

Expand Down
18 changes: 18 additions & 0 deletions Source/WebKit/chromium/ChangeLog
@@ -1,3 +1,21 @@
2012-06-20 Hans Wennborg <hans@chromium.org>

Speech JavaScript API: add SpeechRecognition.maxAlternatives attribute
https://bugs.webkit.org/show_bug.cgi?id=89459

Reviewed by Eric Seidel.

Plumbing for the maxAlternatives attribute.

* public/WebSpeechRecognitionParams.h:
(WebKit::WebSpeechRecognitionParams::WebSpeechRecognitionParams):
(WebKit::WebSpeechRecognitionParams::maxAlternatives):
(WebSpeechRecognitionParams):
* src/SpeechRecognitionClientProxy.cpp:
(WebKit::SpeechRecognitionClientProxy::start):
* src/SpeechRecognitionClientProxy.h:
(SpeechRecognitionClientProxy):

2012-06-20 Hironori Bono <hbono@chromium.org>

[chromium] Select the marker range when right-clicking on a marker.
Expand Down
5 changes: 4 additions & 1 deletion Source/WebKit/chromium/public/WebSpeechRecognitionParams.h
Expand Up @@ -37,23 +37,26 @@ class WebSpeechGrammar;

class WebSpeechRecognitionParams {
public:
WebSpeechRecognitionParams(const WebVector<WebSpeechGrammar>& grammars, const WebString& language, bool continuous, const WebSecurityOrigin& origin)
WebSpeechRecognitionParams(const WebVector<WebSpeechGrammar>& grammars, const WebString& language, bool continuous, unsigned long maxAlternatives, const WebSecurityOrigin& origin)
: m_grammars(grammars)
, m_language(language)
, m_continuous(continuous)
, m_maxAlternatives(maxAlternatives)
, m_origin(origin)
{
}

const WebVector<WebSpeechGrammar>& grammars() const { return m_grammars; }
const WebString& language() const { return m_language; }
bool continuous() const { return m_continuous; }
unsigned long maxAlternatives() const { return m_maxAlternatives; }
const WebSecurityOrigin& origin() const { return m_origin; }

private:
WebVector<WebSpeechGrammar> m_grammars;
WebString m_language;
bool m_continuous;
unsigned long m_maxAlternatives;
WebSecurityOrigin m_origin;
};

Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/chromium/src/SpeechRecognitionClientProxy.cpp
Expand Up @@ -55,13 +55,13 @@ PassOwnPtr<SpeechRecognitionClientProxy> SpeechRecognitionClientProxy::create(We
return adoptPtr(new SpeechRecognitionClientProxy(recognizer));
}

void SpeechRecognitionClientProxy::start(SpeechRecognition* recognition, const SpeechGrammarList* grammarList, const String& lang, bool continuous)
void SpeechRecognitionClientProxy::start(SpeechRecognition* recognition, const SpeechGrammarList* grammarList, const String& lang, bool continuous, unsigned long maxAlternatives)
{
WebVector<WebSpeechGrammar> webSpeechGrammars(static_cast<size_t>(grammarList->length()));
for (unsigned long i = 0; i < grammarList->length(); ++i)
webSpeechGrammars[i] = grammarList->item(i);

WebSpeechRecognitionParams params(webSpeechGrammars, lang, continuous, WebSecurityOrigin(recognition->scriptExecutionContext()->securityOrigin()));
WebSpeechRecognitionParams params(webSpeechGrammars, lang, continuous, maxAlternatives, WebSecurityOrigin(recognition->scriptExecutionContext()->securityOrigin()));
m_recognizer->start(WebSpeechRecognitionHandle(recognition), params, this);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/chromium/src/SpeechRecognitionClientProxy.h
Expand Up @@ -46,7 +46,7 @@ class SpeechRecognitionClientProxy : public WebCore::SpeechRecognitionClient, pu
static PassOwnPtr<SpeechRecognitionClientProxy> create(WebSpeechRecognizer*);

// WebCore::SpeechRecognitionClient:
virtual void start(WebCore::SpeechRecognition*, const WebCore::SpeechGrammarList*, const String& lang, bool continuous) OVERRIDE;
virtual void start(WebCore::SpeechRecognition*, const WebCore::SpeechGrammarList*, const String& lang, bool continuous, unsigned long maxAlternatives) OVERRIDE;
virtual void stop(WebCore::SpeechRecognition*) OVERRIDE;
virtual void abort(WebCore::SpeechRecognition*) OVERRIDE;

Expand Down

0 comments on commit b8046ce

Please sign in to comment.