Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: Source/modules/speech/SpeechSynthesis.cpp

Issue 27477002: Add support for onvoiceschanged event. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@platform_speech_chromium
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 16 matching lines...) Expand all
27 #include "modules/speech/SpeechSynthesis.h" 27 #include "modules/speech/SpeechSynthesis.h"
28 28
29 #include "core/platform/PlatformSpeechSynthesisVoice.h" 29 #include "core/platform/PlatformSpeechSynthesisVoice.h"
30 #include "core/platform/PlatformSpeechSynthesizer.h" 30 #include "core/platform/PlatformSpeechSynthesizer.h"
31 #include "modules/speech/SpeechSynthesisEvent.h" 31 #include "modules/speech/SpeechSynthesisEvent.h"
32 #include "modules/speech/SpeechSynthesisUtterance.h" 32 #include "modules/speech/SpeechSynthesisUtterance.h"
33 #include "wtf/CurrentTime.h" 33 #include "wtf/CurrentTime.h"
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 PassRefPtr<SpeechSynthesis> SpeechSynthesis::create() 37 PassRefPtr<SpeechSynthesis> SpeechSynthesis::create(ExecutionContext* context)
38 { 38 {
39 return adoptRef(new SpeechSynthesis()); 39 return adoptRef(new SpeechSynthesis(context));
40 } 40 }
41 41
42 SpeechSynthesis::SpeechSynthesis() 42 SpeechSynthesis::SpeechSynthesis(ExecutionContext* context)
43 : m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this)) 43 : ContextLifecycleObserver(context)
44 , m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this))
44 , m_currentSpeechUtterance(0) 45 , m_currentSpeechUtterance(0)
45 , m_isPaused(false) 46 , m_isPaused(false)
46 { 47 {
47 ScriptWrappable::init(this); 48 ScriptWrappable::init(this);
48 } 49 }
49 50
50 void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesize r> synthesizer) 51 void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesize r> synthesizer)
51 { 52 {
52 m_platformSpeechSynthesizer = synthesizer; 53 m_platformSpeechSynthesizer = synthesizer;
53 } 54 }
54 55
56 ExecutionContext* SpeechSynthesis::executionContext() const
57 {
58 return ContextLifecycleObserver::executionContext();
59 }
60
55 void SpeechSynthesis::voicesDidChange() 61 void SpeechSynthesis::voicesDidChange()
abarth-chromium 2013/10/16 19:25:06 When can this function be called? Why don't we ne
dmazzoni 2013/10/16 22:09:06 Good question. This function is only called from
abarth-chromium 2013/10/17 02:00:53 I should write a design doc that explains how all
dmazzoni 2013/10/17 15:28:59 Got it, that makes sense. I made the same change
56 { 62 {
57 m_voiceList.clear(); 63 m_voiceList.clear();
64 dispatchEvent(Event::create(EventTypeNames::voiceschanged));
eseidel 2013/10/16 06:44:53 This will cause synchronous event dispatch, right?
dmazzoni 2013/10/16 07:08:00 That's only a problem if the user is triggering th
58 } 65 }
59 66
60 const Vector<RefPtr<SpeechSynthesisVoice> >& SpeechSynthesis::getVoices() 67 const Vector<RefPtr<SpeechSynthesisVoice> >& SpeechSynthesis::getVoices()
61 { 68 {
62 if (m_voiceList.size()) 69 if (m_voiceList.size())
63 return m_voiceList; 70 return m_voiceList;
64 71
65 // If the voiceList is empty, that's the cue to get the voices from the plat form again. 72 // If the voiceList is empty, that's the cue to get the voices from the plat form again.
66 const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_plat formSpeechSynthesizer->voiceList(); 73 const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_plat formSpeechSynthesizer->voiceList();
67 size_t voiceCount = platformVoices.size(); 74 size_t voiceCount = platformVoices.size();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 if (utterance->client()) 208 if (utterance->client())
202 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance ->client()), false); 209 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance ->client()), false);
203 } 210 }
204 211
205 void SpeechSynthesis::speakingErrorOccurred(PassRefPtr<PlatformSpeechSynthesisUt terance> utterance) 212 void SpeechSynthesis::speakingErrorOccurred(PassRefPtr<PlatformSpeechSynthesisUt terance> utterance)
206 { 213 {
207 if (utterance->client()) 214 if (utterance->client())
208 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance ->client()), true); 215 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance ->client()), true);
209 } 216 }
210 217
218 const AtomicString& SpeechSynthesis::interfaceName() const
219 {
220 return EventTargetNames::SpeechSynthesisUtterance;
221 }
222
211 } // namespace WebCore 223 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698