-
-
Save nikhilm/4067312 to your computer and use it in GitHub Desktop.
fire event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nsresult | |
XHRSampleListener::FireOnResultEvent(const nsAString &response) | |
{ | |
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread"); | |
nsresult rv; | |
nsCOMPtr<nsIDOMEvent> event; | |
rv = NS_NewDOMEvent(getter_AddRefs(event), nullptr, nullptr); | |
NS_ENSURE_SUCCESS(rv, rv); | |
rv = event->InitEvent(NS_LITERAL_STRING("result"), false, false); | |
NS_ENSURE_SUCCESS(rv, rv); | |
rv = event->SetTrusted(true); | |
NS_ENSURE_SUCCESS(rv, rv); | |
nsCOMPtr<nsIDOMWindow> aWindow; | |
nsCOMPtr<nsIDOMDocument> aDoc; | |
nsCOMPtr<nsIDOMEventTarget> tWindow; | |
nsIFocusManager* fm = nsFocusManager::GetFocusManager(); | |
if(!fm) return NS_ERROR_FAILURE; | |
rv = fm->GetFocusedWindow(getter_AddRefs(aWindow)); | |
NS_ENSURE_SUCCESS(rv, rv); | |
tWindow = do_QueryInterface(aWindow); | |
rv = aWindow->GetDocument(getter_AddRefs(aDoc)); | |
NS_ENSURE_SUCCESS(rv, rv); | |
nsString uri; | |
rv = aDoc->GetDocumentURI(uri); | |
NS_ENSURE_SUCCESS(rv, rv); | |
//NS_ASSERTION(0, nsPrintfCString("URI: %s\n", NS_ConvertUTF16toUTF8(uri).get()).get()); | |
nsCOMPtr<nsIDOMEventTarget> root; | |
rv = aWindow->GetWindowRoot(getter_AddRefs(root)); | |
NS_ENSURE_SUCCESS(rv, rv); | |
bool ret; | |
rv = root->DispatchEvent(event, &ret); | |
NS_ASSERTION(ret, "dispatch"); | |
return rv; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var recognition = new SpeechRecognition(); | |
function boo(event) { | |
alert("HI"); | |
if (event.results.length > 0) { | |
var result = event.results[0]; | |
for (var i = 0; i < result.length; ++i) { | |
var text = result[i].transcript; | |
select.options[i] = new Option(text, text); | |
} | |
} | |
} | |
recognition.onresult = boo; | |
window.onresult = boo; | |
</script> | |
<select id="select"></select> | |
<button onclick="recognition.start()">Click to Speak</button> | |
<button onclick="recognition.stop()">Stop!</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment