Backed out changeset 4c66c0ddf562 (bug 1178738)

This commit is contained in:
Sebastian Hengst 2016-06-02 20:32:46 +02:00
Родитель af455b44c1
Коммит 4263412d7e
9 изменённых файлов: 24 добавлений и 53 удалений

Просмотреть файл

@ -35,7 +35,6 @@ public:
: mTask(aTask) : mTask(aTask)
, mSpeechSynthesizer(aSynth) , mSpeechSynthesizer(aSynth)
, mOffsets(aOffsets) , mOffsets(aOffsets)
, mCanceled(false)
{ {
mStartingTime = TimeStamp::Now(); mStartingTime = TimeStamp::Now();
} }
@ -62,7 +61,6 @@ private:
TimeStamp mStartingTime; TimeStamp mStartingTime;
uint32_t mCurrentIndex; uint32_t mCurrentIndex;
nsTArray<size_t> mOffsets; nsTArray<size_t> mOffsets;
bool mCanceled;
}; };
NS_IMPL_CYCLE_COLLECTION(SpeechTaskCallback, mTask); NS_IMPL_CYCLE_COLLECTION(SpeechTaskCallback, mTask);
@ -80,7 +78,6 @@ SpeechTaskCallback::OnCancel()
{ {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
mCanceled = true;
[mSpeechSynthesizer stopSpeaking]; [mSpeechSynthesizer stopSpeaking];
return NS_OK; return NS_OK;
@ -166,12 +163,7 @@ SpeechTaskCallback::OnError(uint32_t aIndex)
void void
SpeechTaskCallback::OnDidFinishSpeaking() SpeechTaskCallback::OnDidFinishSpeaking()
{ {
if (mCanceled) {
mTask->DispatchError(GetTimeDurationFromStart(), mCurrentIndex,
uint32_t(dom::SpeechSynthesisErrorCode::Interrupted));
} else {
mTask->DispatchEnd(GetTimeDurationFromStart(), mCurrentIndex); mTask->DispatchEnd(GetTimeDurationFromStart(), mCurrentIndex);
}
// no longer needed // no longer needed
[mSpeechSynthesizer setDelegate:nil]; [mSpeechSynthesizer setDelegate:nil];
mTask = nullptr; mTask = nullptr;

Просмотреть файл

@ -411,7 +411,7 @@ nsSpeechTask::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex)
DestroyAudioChannelAgent(); DestroyAudioChannelAgent();
MOZ_ASSERT(mUtterance); MOZ_ASSERT(mUtterance);
if(NS_WARN_IF(mUtterance->mState != SpeechSynthesisUtterance::STATE_SPEAKING)) { if(NS_WARN_IF(mUtterance->mState == SpeechSynthesisUtterance::STATE_ENDED)) {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
@ -426,10 +426,14 @@ nsSpeechTask::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex)
mSpeechSynthesis->OnEnd(this); mSpeechSynthesis->OnEnd(this);
} }
if (utterance->mState == SpeechSynthesisUtterance::STATE_PENDING) {
utterance->mState = SpeechSynthesisUtterance::STATE_NONE;
} else {
utterance->mState = SpeechSynthesisUtterance::STATE_ENDED; utterance->mState = SpeechSynthesisUtterance::STATE_ENDED;
utterance->DispatchSpeechSynthesisEvent(NS_LITERAL_STRING("end"), utterance->DispatchSpeechSynthesisEvent(NS_LITERAL_STRING("end"),
aCharIndex, aElapsedTime, aCharIndex, aElapsedTime,
EmptyString()); EmptyString());
}
return NS_OK; return NS_OK;
} }
@ -509,12 +513,6 @@ nsSpeechTask::DispatchError(float aElapsedTime, uint32_t aCharIndex, uint32_t aE
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return DispatchErrorInner(aElapsedTime, aCharIndex, aError);
}
nsresult
nsSpeechTask::DispatchErrorInner(float aElapsedTime, uint32_t aCharIndex, uint32_t aError)
{
if (!mPreCanceled) { if (!mPreCanceled) {
nsSynthVoiceRegistry::GetInstance()->SpeakNext(); nsSynthVoiceRegistry::GetInstance()->SpeakNext();
} }
@ -534,12 +532,9 @@ nsSpeechTask::DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex, uint32_
mSpeechSynthesis->OnEnd(this); mSpeechSynthesis->OnEnd(this);
} }
RefPtr<SpeechSynthesisUtterance> utterance = mUtterance; mUtterance->mState = SpeechSynthesisUtterance::STATE_ENDED;
utterance->mState = (utterance->mState == SpeechSynthesisUtterance::STATE_SPEAKING) ? mUtterance->DispatchSpeechSynthesisErrorEvent(aCharIndex, aElapsedTime,
SpeechSynthesisUtterance::STATE_ENDED : SpeechSynthesisUtterance::STATE_NONE;
utterance->DispatchSpeechSynthesisErrorEvent(aCharIndex, aElapsedTime,
SpeechSynthesisErrorCode(aError)); SpeechSynthesisErrorCode(aError));
return NS_OK; return NS_OK;
} }
@ -665,8 +660,7 @@ nsSpeechTask::Cancel()
} }
if (!mIndirectAudio) { if (!mIndirectAudio) {
DispatchErrorInner(GetCurrentTime(), GetCurrentCharOffset(), DispatchEndInner(GetCurrentTime(), GetCurrentCharOffset());
uint32_t(SpeechSynthesisErrorCode::Interrupted));
} }
} }

Просмотреть файл

@ -109,8 +109,6 @@ private:
nsresult DispatchEndInner(float aElapsedTime, uint32_t aCharIndex); nsresult DispatchEndInner(float aElapsedTime, uint32_t aCharIndex);
nsresult DispatchErrorInner(float aElapsedTime, uint32_t aCharIndex, uint32_t aError);
void CreateAudioChannelAgent(); void CreateAudioChannelAgent();
void DestroyAudioChannelAgent(); void DestroyAudioChannelAgent();

Просмотреть файл

@ -8,7 +8,6 @@
#include "mozilla/dom/nsSpeechTask.h" #include "mozilla/dom/nsSpeechTask.h"
#include "mozilla/dom/nsSynthVoiceRegistry.h" #include "mozilla/dom/nsSynthVoiceRegistry.h"
#include "mozilla/dom/SpeechSynthesisErrorEvent.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "nsEscape.h" #include "nsEscape.h"
#include "nsISupports.h" #include "nsISupports.h"
@ -252,11 +251,6 @@ SpeechDispatcherCallback::OnSpeechEvent(SPDNotificationType state)
break; break;
case SPD_EVENT_CANCEL: case SPD_EVENT_CANCEL:
mTask->DispatchError((TimeStamp::Now() - mStartTime).ToSeconds(), 0,
uint32_t(SpeechSynthesisErrorCode::Interrupted));
remove = true;
break;
case SPD_EVENT_END: case SPD_EVENT_END:
mTask->DispatchEnd((TimeStamp::Now() - mStartTime).ToSeconds(), 0); mTask->DispatchEnd((TimeStamp::Now() - mStartTime).ToSeconds(), 0);
remove = true; remove = true;

Просмотреть файл

@ -41,7 +41,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1188099
var utterance5 = new win2.SpeechSynthesisUtterance("u5: hello, losers too"); var utterance5 = new win2.SpeechSynthesisUtterance("u5: hello, losers too");
utterance5.lang = 'it-IT-noend'; utterance5.lang = 'it-IT-noend';
var eventOrder = ['start1', 'end1', 'start2', 'error2']; var eventOrder = ['start1', 'end1', 'start2', 'end2'];
utterance1.addEventListener('start', function(e) { utterance1.addEventListener('start', function(e) {
is(eventOrder.shift(), 'start1', 'start1'); is(eventOrder.shift(), 'start1', 'start1');
testSynthState(win1, { speaking: true, pending: true }); testSynthState(win1, { speaking: true, pending: true });
@ -61,8 +61,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1188099
testSynthState(win2, { speaking: true, pending: false }); testSynthState(win2, { speaking: true, pending: false });
win1.speechSynthesis.cancel(); win1.speechSynthesis.cancel();
}); });
utterance2.addEventListener('error', function(e) { utterance2.addEventListener('end', function(e) {
is(eventOrder.shift(), 'error2', 'error2'); is(eventOrder.shift(), 'end2', 'end2');
testSynthState(win1, { speaking: false, pending: false }); testSynthState(win1, { speaking: false, pending: false });
testSynthState(win2, { speaking: false, pending: false }); testSynthState(win2, { speaking: false, pending: false });
SimpleTest.finish(); SimpleTest.finish();

Просмотреть файл

@ -50,7 +50,7 @@ function testFunc(done_cb) {
speechSynthesis.cancel(); speechSynthesis.cancel();
}); });
utterance.addEventListener('error', function(e) { utterance.addEventListener('end', function(e) {
ok(e.charIndex, 1, 'resume event charIndex matches service arguments'); ok(e.charIndex, 1, 'resume event charIndex matches service arguments');
ok(e.elapsedTime, 1.5, 'end event elapsedTime matches service arguments'); ok(e.elapsedTime, 1.5, 'end event elapsedTime matches service arguments');
test_no_events(); test_no_events();

Просмотреть файл

@ -27,7 +27,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1150315
/** Test for Bug 1150315 **/ /** Test for Bug 1150315 **/
function testFunc(done_cb) { function testFunc(done_cb) {
var gotErrorEvent = false; var gotEndEvent = false;
// A long utterance that we will interrupt. // A long utterance that we will interrupt.
var utterance = new SpeechSynthesisUtterance("Donec ac nunc feugiat, posuere " + var utterance = new SpeechSynthesisUtterance("Donec ac nunc feugiat, posuere " +
"mauris id, pharetra velit. Donec fermentum orci nunc, sit amet maximus" + "mauris id, pharetra velit. Donec fermentum orci nunc, sit amet maximus" +
@ -63,14 +63,13 @@ function testFunc(done_cb) {
speechSynthesis.cancel(); speechSynthesis.cancel();
speechSynthesis.speak(utterance3); speechSynthesis.speak(utterance3);
}); });
utterance2.addEventListener('error', function(e) { utterance2.addEventListener('end', function(e) {
gotErrorEvent = true; gotEndEvent = true;
is(e.error, "interrupted", "Error event is has right error.")
}); });
var utterance3 = new SpeechSynthesisUtterance("Hello, world 3!"); var utterance3 = new SpeechSynthesisUtterance("Hello, world 3!");
utterance3.addEventListener('start', function() { utterance3.addEventListener('start', function() {
ok(gotErrorEvent, "didn't get error event for previous utterance"); ok(gotEndEvent, "didn't get start event for this utterance");
}); });
utterance3.addEventListener('end', done_cb); utterance3.addEventListener('end', done_cb);

Просмотреть файл

@ -90,8 +90,7 @@ public:
NS_IMETHOD OnCancel() override NS_IMETHOD OnCancel() override
{ {
if (mTask) { if (mTask) {
mTask->DispatchError(1.5, 1, mTask->DispatchEnd(1.5, 1);
uint32_t(SpeechSynthesisErrorCode::Interrupted));
} }
return NS_OK; return NS_OK;

Просмотреть файл

@ -13,7 +13,6 @@
#include "mozilla/dom/nsSynthVoiceRegistry.h" #include "mozilla/dom/nsSynthVoiceRegistry.h"
#include "mozilla/dom/nsSpeechTask.h" #include "mozilla/dom/nsSpeechTask.h"
#include "mozilla/dom/SpeechSynthesisErrorEvent.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
namespace mozilla { namespace mozilla {
@ -132,13 +131,9 @@ SapiCallback::OnSpeechEvent(const SPEVENT& speechEvent)
break; break;
case SPEI_END_INPUT_STREAM: case SPEI_END_INPUT_STREAM:
if (mSpeakTextLen) { if (mSpeakTextLen) {
// mSpeakTextLen will be > 0 on any utterance except a cancel utterance.
mCurrentIndex = mSpeakTextLen; mCurrentIndex = mSpeakTextLen;
mTask->DispatchEnd(GetTickCount() - mStartingTime, mCurrentIndex);
} else {
mTask->DispatchError(GetTickCount() - mStartingTime, mCurrentIndex,
uint32_t(SpeechSynthesisErrorCode::Interrupted));
} }
mTask->DispatchEnd(GetTickCount() - mStartingTime, mCurrentIndex);
mTask = nullptr; mTask = nullptr;
break; break;
case SPEI_TTS_BOOKMARK: case SPEI_TTS_BOOKMARK: