Title: [144244] trunk
Revision
144244
Author
[email protected]
Date
2013-02-27 14:55:18 -0800 (Wed, 27 Feb 2013)

Log Message

WebSpeech: support speech cancel
https://bugs.webkit.org/show_bug.cgi?id=107349

Reviewed by Beth Dakin.

Source/WebCore: 

Add the ability to cancel speech utterances and make it work with Mac
and the mock speech synthesizer.

Test: platform/mac/fast/speechsynthesis/speech-synthesis-cancel.html

* Modules/speech/SpeechSynthesis.cpp:
(WebCore::SpeechSynthesis::pending):
(WebCore::SpeechSynthesis::cancel):
(WebCore::SpeechSynthesis::handleSpeakingCompleted):
* platform/PlatformSpeechSynthesizer.h:
(PlatformSpeechSynthesizer):
* platform/mac/PlatformSpeechSynthesizerMac.mm:
(-[WebSpeechSynthesisWrapper cancel]):
(WebCore::PlatformSpeechSynthesizer::cancel):
(WebCore):
* platform/mock/PlatformSpeechSynthesizerMock.cpp:
(WebCore::PlatformSpeechSynthesizerMock::cancel):
(WebCore):
(WebCore::PlatformSpeechSynthesizerMock::speak):
* platform/mock/PlatformSpeechSynthesizerMock.h:
(PlatformSpeechSynthesizerMock):

LayoutTests: 

* platform/mac/fast/speechsynthesis/speech-synthesis-cancel-expected.txt: Added.
* platform/mac/fast/speechsynthesis/speech-synthesis-cancel.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (144243 => 144244)


--- trunk/LayoutTests/ChangeLog	2013-02-27 22:53:43 UTC (rev 144243)
+++ trunk/LayoutTests/ChangeLog	2013-02-27 22:55:18 UTC (rev 144244)
@@ -1,3 +1,13 @@
+2013-02-27  Chris Fleizach  <[email protected]>
+
+        WebSpeech: support speech cancel
+        https://bugs.webkit.org/show_bug.cgi?id=107349
+
+        Reviewed by Beth Dakin.
+
+        * platform/mac/fast/speechsynthesis/speech-synthesis-cancel-expected.txt: Added.
+        * platform/mac/fast/speechsynthesis/speech-synthesis-cancel.html: Added.
+
 2013-02-27  Kenneth Russell  <[email protected]>
 
         Insufficient validation when uploading depth textures to WebGL

Added: trunk/LayoutTests/platform/mac/fast/speechsynthesis/speech-synthesis-cancel-expected.txt (0 => 144244)


--- trunk/LayoutTests/platform/mac/fast/speechsynthesis/speech-synthesis-cancel-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/speechsynthesis/speech-synthesis-cancel-expected.txt	2013-02-27 22:55:18 UTC (rev 144244)
@@ -0,0 +1,13 @@
+This tests that cancelling a speech job fires the right events.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Speech started
+PASS speechSynthesis.pending is true
+Speech error received because we cancelled and speech should no longer be pending.
+PASS speechSynthesis.pending is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/platform/mac/fast/speechsynthesis/speech-synthesis-cancel.html (0 => 144244)


--- trunk/LayoutTests/platform/mac/fast/speechsynthesis/speech-synthesis-cancel.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/speechsynthesis/speech-synthesis-cancel.html	2013-02-27 22:55:18 UTC (rev 144244)
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body id="body">
+
+<div id="console"></div>
+
+<script>
+
+    description("This tests that cancelling a speech job fires the right events.");
+
+    if (window.testRunner)
+        testRunner.waitUntilDone();
+
+    if (window.internals)
+        window.internals.enableMockSpeechSynthesizer();
+
+    window.jsTestIsAsync = true;
+
+    var u = new SpeechSynthesisUtterance("this is a test");
+    u._onstart_ = function(event) {
+       debug("Speech started");
+    }
+
+    u._onerror_ = function(event) {
+       debug("Speech error received because we cancelled and speech should no longer be pending.");
+       shouldBeFalse("speechSynthesis.pending");
+       finishJSTest();
+    }
+
+    // Queue the first job which will start speaking immediately.
+    speechSynthesis.speak(u);
+
+    // Make a few more jobs, so that when we cancel, it will clear the entire queue.
+    var u2 = new SpeechSynthesisUtterance("this is a second test");
+    speechSynthesis.speak(u2);
+
+    // Make a few more jobs, so that when we cancel, it will clear the entire queue.
+    var u3 = new SpeechSynthesisUtterance("this is a third test");
+    speechSynthesis.speak(u3);
+
+    // While we have two jobs, speech synthesis should report that it's pending.
+    shouldBeTrue("speechSynthesis.pending");
+
+    // Cancel speaking.
+    setTimeout("speechSynthesis.cancel()", "1"); 
+
+</script>
+
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (144243 => 144244)


--- trunk/Source/WebCore/ChangeLog	2013-02-27 22:53:43 UTC (rev 144243)
+++ trunk/Source/WebCore/ChangeLog	2013-02-27 22:55:18 UTC (rev 144244)
@@ -1,3 +1,32 @@
+2013-02-27  Chris Fleizach  <[email protected]>
+
+        WebSpeech: support speech cancel
+        https://bugs.webkit.org/show_bug.cgi?id=107349
+
+        Reviewed by Beth Dakin.
+
+        Add the ability to cancel speech utterances and make it work with Mac
+        and the mock speech synthesizer.
+
+        Test: platform/mac/fast/speechsynthesis/speech-synthesis-cancel.html
+
+        * Modules/speech/SpeechSynthesis.cpp:
+        (WebCore::SpeechSynthesis::pending):
+        (WebCore::SpeechSynthesis::cancel):
+        (WebCore::SpeechSynthesis::handleSpeakingCompleted):
+        * platform/PlatformSpeechSynthesizer.h:
+        (PlatformSpeechSynthesizer):
+        * platform/mac/PlatformSpeechSynthesizerMac.mm:
+        (-[WebSpeechSynthesisWrapper cancel]):
+        (WebCore::PlatformSpeechSynthesizer::cancel):
+        (WebCore):
+        * platform/mock/PlatformSpeechSynthesizerMock.cpp:
+        (WebCore::PlatformSpeechSynthesizerMock::cancel):
+        (WebCore):
+        (WebCore::PlatformSpeechSynthesizerMock::speak):
+        * platform/mock/PlatformSpeechSynthesizerMock.h:
+        (PlatformSpeechSynthesizerMock):
+
 2013-02-27  Min Qin  <[email protected]>
 
         Unlock partially decoded images after passing them to the ImageDecodingStore

Modified: trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp (144243 => 144244)


--- trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp	2013-02-27 22:53:43 UTC (rev 144243)
+++ trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp	2013-02-27 22:55:18 UTC (rev 144244)
@@ -111,6 +111,9 @@
 
 void SpeechSynthesis::cancel()
 {
+    // Remove all the items from the utterance queue.
+    m_utteranceQueue.clear();
+    m_platformSpeechSynthesizer->cancel();
 }
 
 void SpeechSynthesis::pause()
@@ -137,14 +140,16 @@
 
     fireEvent(errorOccurred ? eventNames().errorEvent : eventNames().endEvent, utterance, 0, String());
 
-    RefPtr<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.first();
-    ASSERT(firstUtterance == utterance);
-    if (firstUtterance == utterance)
-        m_utteranceQueue.removeFirst();
-
-    // Start the next job if there is one pending.
-    if (!m_utteranceQueue.isEmpty())
-        startSpeakingImmediately(m_utteranceQueue.first().get());
+    if (m_utteranceQueue.size()) {
+        RefPtr<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.first();
+        ASSERT(firstUtterance == utterance);
+        if (firstUtterance == utterance)
+            m_utteranceQueue.removeFirst();
+        
+        // Start the next job if there is one pending.
+        if (!m_utteranceQueue.isEmpty())
+            startSpeakingImmediately(m_utteranceQueue.first().get());
+    }
 }
 
 void SpeechSynthesis::didStartSpeaking(const PlatformSpeechSynthesisUtterance* utterance)

Modified: trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h (144243 => 144244)


--- trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h	2013-02-27 22:53:43 UTC (rev 144243)
+++ trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h	2013-02-27 22:55:18 UTC (rev 144244)
@@ -64,6 +64,7 @@
     virtual void speak(const PlatformSpeechSynthesisUtterance&);
     virtual void pause();
     virtual void resume();
+    virtual void cancel();
     
     PlatformSpeechSynthesizerClient* client() const { return m_speechSynthesizerClient; }
     

Modified: trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm (144243 => 144244)


--- trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm	2013-02-27 22:53:43 UTC (rev 144243)
+++ trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm	2013-02-27 22:55:18 UTC (rev 144244)
@@ -137,6 +137,11 @@
     m_synthesizerObject->client()->didResumeSpeaking(m_utterance);
 }
 
+- (void)cancel
+{
+    [m_synthesizer stopSpeakingAtBoundary:NSSpeechImmediateBoundary];
+}
+
 - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)finishedSpeaking
 {
     ASSERT(m_utterance);
@@ -196,6 +201,11 @@
     [m_platformSpeechWrapper.get() speakUtterance:&utterance];
 }
 
+void PlatformSpeechSynthesizer::cancel()
+{
+    [m_platformSpeechWrapper.get() cancel];
+}
+    
 } // namespace WebCore
 
 #endif // ENABLE(SPEECH_SYNTHESIS)

Modified: trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp (144243 => 144244)


--- trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp	2013-02-27 22:53:43 UTC (rev 144243)
+++ trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp	2013-02-27 22:55:18 UTC (rev 144244)
@@ -69,6 +69,13 @@
     // Give the fake speech job some time so that pause and other functions have time to be called.
     m_speakingFinishedTimer.startOneShot(.1);
 }
+    
+void PlatformSpeechSynthesizerMock::cancel()
+{
+    m_speakingFinishedTimer.stop();
+    client()->speakingErrorOccurred(m_utterance);
+    m_utterance = 0;
+}
 
 void PlatformSpeechSynthesizerMock::pause()
 {

Modified: trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h (144243 => 144244)


--- trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h	2013-02-27 22:53:43 UTC (rev 144243)
+++ trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h	2013-02-27 22:55:18 UTC (rev 144244)
@@ -42,6 +42,7 @@
     virtual void speak(const PlatformSpeechSynthesisUtterance&);
     virtual void pause();
     virtual void resume();
+    virtual void cancel();
     
 private:
     explicit PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient*);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to