From afd8f25b042a7bc761d170c8faebbaa041787da2 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Thu, 27 Nov 2008 11:50:35 +0900 Subject: [PATCH] Bug 463209 No sound when message box is opened (alert/confirm/prompt/etc...) r+sr=roc, ui-jboriss, a=beltzner --- .../public/nsPIPromptService.idl | 2 +- .../windowwatcher/src/nsPromptService.cpp | 23 +++++++++++++----- toolkit/content/commonDialog.js | 10 ++++++++ toolkit/content/selectDialog.js | 14 +++++++++-- widget/public/nsISound.idl | 18 ++++++++++++++ widget/src/beos/nsSound.cpp | 7 ++++-- widget/src/gtk2/nsSound.cpp | 6 +++-- widget/src/os2/nsSound.cpp | 16 ++++++++++--- widget/src/photon/nsSound.cpp | 9 ++++--- widget/src/qt/nsSound.cpp | 4 +++- widget/src/windows/nsSound.cpp | 24 +++++++++++++++---- 11 files changed, 108 insertions(+), 25 deletions(-) diff --git a/embedding/components/windowwatcher/public/nsPIPromptService.idl b/embedding/components/windowwatcher/public/nsPIPromptService.idl index 4c8c42d6b7b..baad22a6013 100644 --- a/embedding/components/windowwatcher/public/nsPIPromptService.idl +++ b/embedding/components/windowwatcher/public/nsPIPromptService.idl @@ -50,7 +50,7 @@ interface nsPIPromptService : nsISupports enum {eMsg=0, eCheckboxMsg=1, eIconClass=2, eTitleMessage=3, eEditfield1Msg=4, eEditfield2Msg=5, eEditfield1Value=6, eEditfield2Value=7, eButton0Text=8, eButton1Text=9, eButton2Text=10, eButton3Text=11, - eDialogTitle=12}; + eDialogTitle=12, eOpeningSound=13}; enum {eButtonPressed=0, eCheckboxState=1, eNumberButtons=2, eNumberEditfields=3, eEditField1Password=4, eDefaultButton=5, eDelayButtonEnable=6}; diff --git a/embedding/components/windowwatcher/src/nsPromptService.cpp b/embedding/components/windowwatcher/src/nsPromptService.cpp index 86b46639d42..e6fa35a0867 100644 --- a/embedding/components/windowwatcher/src/nsPromptService.cpp +++ b/embedding/components/windowwatcher/src/nsPromptService.cpp @@ -52,6 +52,7 @@ #include "nsString.h" #include "nsIStringBundle.h" #include "nsXPIDLString.h" +#include "nsISound.h" static const char kPromptURL[] = "chrome://global/content/commonDialog.xul"; static const char kSelectPromptURL[] = "chrome://global/content/selectDialog.xul"; @@ -139,6 +140,7 @@ nsPromptService::Alert(nsIDOMWindow *parent, nsString url; NS_ConvertASCIItoUTF16 styleClass(kAlertIconClass); block->SetString(eIconClass, styleClass.get()); + block->SetString(eOpeningSound, NS_SYSSOUND_WARNING_DIALOG.get()); rv = DoDialog(parent, block, kPromptURL); @@ -183,6 +185,7 @@ nsPromptService::AlertCheck(nsIDOMWindow *parent, block->SetString(eIconClass, styleClass.get()); block->SetString(eCheckboxMsg, checkMsg); block->SetInt(eCheckboxState, *checkValue); + block->SetString(eOpeningSound, NS_SYSSOUND_WARNING_DIALOG.get()); rv = DoDialog(parent, block, kPromptURL); if (NS_FAILED(rv)) @@ -228,7 +231,8 @@ nsPromptService::Confirm(nsIDOMWindow *parent, NS_ConvertASCIItoUTF16 styleClass(kQuestionIconClass); block->SetString(eIconClass, styleClass.get()); - + block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get()); + rv = DoDialog(parent, block, kPromptURL); if (NS_FAILED(rv)) return rv; @@ -277,6 +281,7 @@ nsPromptService::ConfirmCheck(nsIDOMWindow *parent, block->SetString(eIconClass, styleClass.get()); block->SetString(eCheckboxMsg, checkMsg); block->SetInt(eCheckboxState, *checkValue); + block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get()); rv = DoDialog(parent, block, kPromptURL); if (NS_FAILED(rv)) @@ -376,8 +381,9 @@ nsPromptService::ConfirmEx(nsIDOMWindow *parent, buttonFlags >>= 8; } block->SetInt(eNumberButtons, numberButtons); - + block->SetString(eIconClass, NS_ConvertASCIItoUTF16(kQuestionIconClass).get()); + block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get()); if (checkMsg && checkValue) { block->SetString(eCheckboxMsg, checkMsg); @@ -453,6 +459,7 @@ nsPromptService::Prompt(nsIDOMWindow *parent, block->SetString(eCheckboxMsg, checkMsg); block->SetInt(eCheckboxState, *checkValue); } + block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get()); rv = DoDialog(parent, block, kPromptURL); if (NS_FAILED(rv)) @@ -528,7 +535,8 @@ nsPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent, block->SetString(eCheckboxMsg, checkMsg); block->SetInt(eCheckboxState, *checkValue); } - + block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get()); + rv = DoDialog(parent, block, kPromptURL); if (NS_FAILED(rv)) return rv; @@ -607,6 +615,7 @@ NS_IMETHODIMP nsPromptService::PromptPassword(nsIDOMWindow *parent, block->SetString(eCheckboxMsg, checkMsg); block->SetInt(eCheckboxState, *checkValue); } + block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get()); rv = DoDialog(parent, block, kPromptURL); if (NS_FAILED(rv)) @@ -698,14 +707,15 @@ nsPromptService::Select(nsIDOMWindow *parent, const PRUnichar *dialogTitle, if (NS_FAILED(rv)) return rv; - block->SetNumberStrings(count + 2); + block->SetNumberStrings(count + 3); if (dialogTitle) block->SetString(0, dialogTitle); block->SetString(1, text); + block->SetString(2, NS_SYSSOUND_QUESTION_DIALOG.get()); block->SetInt(eSelection, count); - for (PRUint32 i = 2; i <= count+1; i++) { - nsAutoString temp(selectList[i-2]); + for (PRUint32 i = 3; i <= count+2; i++) { + nsAutoString temp(selectList[i-3]); const PRUnichar* text = temp.get(); block->SetString(i, text); } @@ -741,6 +751,7 @@ nsPromptService::ShowNonBlockingAlert(nsIDOMWindow *aParent, paramBlock->SetString(nsPIPromptService::eIconClass, NS_LITERAL_STRING("alert-icon").get()); paramBlock->SetString(nsPIPromptService::eDialogTitle, aDialogTitle); paramBlock->SetString(nsPIPromptService::eMsg, aText); + paramBlock->SetString(eOpeningSound, NS_SYSSOUND_WARNING_DIALOG.get()); nsCOMPtr dialog; mWatcher->OpenWindow(aParent, "chrome://global/content/commonDialog.xul", diff --git a/toolkit/content/commonDialog.js b/toolkit/content/commonDialog.js index 2f3cfa5304a..925593ef56b 100644 --- a/toolkit/content/commonDialog.js +++ b/toolkit/content/commonDialog.js @@ -195,6 +195,16 @@ function commonDialogOnLoad() } getAttention(); + + // play sound + try { + var sound = gCommonDialogParam.GetString(13); + if (sound) { + var soundService = Components.classes["@mozilla.org/sound;1"]. + createInstance(Components.interfaces.nsISound); + soundService.playSystemSound(sound); + } + } catch (e) { } } var gDelayExpired = false; diff --git a/toolkit/content/selectDialog.js b/toolkit/content/selectDialog.js index 346b13b2da2..04f60df213b 100644 --- a/toolkit/content/selectDialog.js +++ b/toolkit/content/selectDialog.js @@ -81,12 +81,12 @@ function selectDialogOnLoad() { numItems = param.GetInt( 2 ); var i; - for ( i = 2; i <= numItems+1; i++ ) { + for ( i = 3; i <= numItems+2; i++ ) { var newString = param.GetString( i ); if (newString == "") { newString = "<>"; } - elements[i-2] = AppendStringToListbox(list, newString); + elements[i-3] = AppendStringToListbox(list, newString); } list.selectItem(elements[0]); list.focus(); @@ -98,6 +98,16 @@ function selectDialogOnLoad() { moveToAlertPosition(); param.SetInt(0, 1 ); centerWindowOnScreen(); + + // play sound + try { + var sound = param.GetString(2); + if (sound) { + var soundService = Components.classes["@mozilla.org/sound;1"]. + createInstance(Components.interfaces.nsISound); + soundService.playSystemSound(sound); + } + } catch (e) { } } function commonDialogOnOK() { diff --git a/widget/public/nsISound.idl b/widget/public/nsISound.idl index fd373c19acc..85357c9f646 100644 --- a/widget/public/nsISound.idl +++ b/widget/public/nsISound.idl @@ -57,3 +57,21 @@ interface nsISound : nsISupports */ void init(); }; + +%{C++ + +#include "nsString.h" + +#define NS_SYSSOUND_PREFIX NS_LITERAL_STRING("_moz_") +#define NS_SYSSOUND_MAIL_BEEP NS_LITERAL_STRING("_moz_mailbeep") +#define NS_SYSSOUND_ERROR_DIALOG NS_LITERAL_STRING("_moz_errordialog") +#define NS_SYSSOUND_INFO_DIALOG NS_LITERAL_STRING("_moz_infodialog") +#define NS_SYSSOUND_QUESTION_DIALOG NS_LITERAL_STRING("_moz_questiondialog") +#define NS_SYSSOUND_WARNING_DIALOG NS_LITERAL_STRING("_moz_warningdialog") + +static PRBool NS_IsMozAliasSound(const nsAString &aSoundAlias) +{ + return StringBeginsWith(aSoundAlias, NS_SYSSOUND_PREFIX); +} + +%} diff --git a/widget/src/beos/nsSound.cpp b/widget/src/beos/nsSound.cpp index c853e1b9adf..98a8fb5ee8a 100644 --- a/widget/src/beos/nsSound.cpp +++ b/widget/src/beos/nsSound.cpp @@ -153,8 +153,11 @@ NS_METHOD nsSound::Play(nsIURL *aURL) NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) { nsresult rv = NS_ERROR_FAILURE; - if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) - return Beep(); + if (NS_IsMozAliasSound(aSoundAlias)) { + if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP)) + return Beep(); + return NS_OK; + } nsCOMPtr fileURI; // create a nsILocalFile and then a nsIFileURL from that nsCOMPtr soundFile; diff --git a/widget/src/gtk2/nsSound.cpp b/widget/src/gtk2/nsSound.cpp index a7486b9834c..fe5cd05dd06 100644 --- a/widget/src/gtk2/nsSound.cpp +++ b/widget/src/gtk2/nsSound.cpp @@ -366,8 +366,10 @@ NS_METHOD nsSound::Play(nsIURL *aURL) NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) { - if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) { - return Beep(); + if (NS_IsMozAliasSound(aSoundAlias)) { + if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP)) + return Beep(); + return NS_OK; } nsresult rv; diff --git a/widget/src/os2/nsSound.cpp b/widget/src/os2/nsSound.cpp index b61e9da9dcf..4633e8c8e6f 100644 --- a/widget/src/os2/nsSound.cpp +++ b/widget/src/os2/nsSound.cpp @@ -480,12 +480,22 @@ NS_IMETHODIMP nsSound::Init() NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) { - // We don't have a default mail sound on OS/2, so just beep. - // Also just beep if MMPM isn't installed. - if (aSoundAlias.EqualsLiteral("_moz_mailbeep") || (!sMMPMInstalled)) { + // Just beep if MMPM isn't installed. + if (!sMMPMInstalled) { Beep(); return NS_OK; } + + if (NS_IsMozAliasSound(aSoundAlias)) { + // We don't have a default mail sound on OS/2, so just beep. + if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP)) + Beep(); + // XXX Should we call Beep() for NS_SYSSOUND_INFO_DIALOG, + // NS_SYSSOUND_QUESTION_DIALOG and NS_SYSSOUND_WARNING_DIALOG? + // And also should we call WinAlarm(HWND_DESKTOP, WA_ERROR) for + // NS_SYSSOUND_ERROR_DIALOG? + return NS_OK; + } nsCAutoString nativeSoundAlias; NS_CopyUnicodeToNative(aSoundAlias, nativeSoundAlias); diff --git a/widget/src/photon/nsSound.cpp b/widget/src/photon/nsSound.cpp index e53d58952ae..d5ebd96dc02 100644 --- a/widget/src/photon/nsSound.cpp +++ b/widget/src/photon/nsSound.cpp @@ -117,9 +117,12 @@ printf( "\n\n\nnsSound::PlaySystemSound aSoundAlias=%s\n\n", const char *soundfile; - if( utf8SoundAlias.Equals("_moz_mailbeep") ) - soundfile = "/usr/share/mozilla/gotmail.wav"; - else { + if( NS_IsMozAliasSound(aSoundAlias) ) { + if ( aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP) ) + soundfile = "/usr/share/mozilla/gotmail.wav"; + else + return NS_OK; + } else { /* the aSoundAlias is the fullpath to the soundfile */ if( !access( utf8SoundAlias.get(), F_OK ) ) soundfile = utf8SoundAlias.get(); diff --git a/widget/src/qt/nsSound.cpp b/widget/src/qt/nsSound.cpp index bbcfb2fa64a..e38678c4002 100644 --- a/widget/src/qt/nsSound.cpp +++ b/widget/src/qt/nsSound.cpp @@ -377,8 +377,10 @@ NS_METHOD nsSound::Play(nsIURL *aURL) NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) { - if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) { + if (NS_IsMozAliasSound(aSoundAlias)) { + if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP)) return Beep(); + return NS_OK; } nsresult rv; diff --git a/widget/src/windows/nsSound.cpp b/widget/src/windows/nsSound.cpp index bf2c762cc09..a2fe51a572d 100644 --- a/widget/src/windows/nsSound.cpp +++ b/widget/src/windows/nsSound.cpp @@ -164,13 +164,27 @@ NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) { PurgeLastSound(); - if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) { - ::PlaySoundW(L"MailBeep", nsnull, SND_ALIAS | SND_ASYNC); - } - else { - ::PlaySoundW(PromiseFlatString(aSoundAlias).get(), nsnull, SND_ALIAS | SND_ASYNC); + if (!NS_IsMozAliasSound(aSoundAlias)) { + ::PlaySoundW(PromiseFlatString(aSoundAlias).get(), nsnull, + SND_ALIAS | SND_ASYNC); + return NS_OK; } + const wchar_t *sound = nsnull; + if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP)) + sound = L"MailBeep"; + else if (aSoundAlias.Equals(NS_SYSSOUND_ERROR_DIALOG)) + sound = L"SystemHand"; + else if (aSoundAlias.Equals(NS_SYSSOUND_INFO_DIALOG)) + sound = L"SystemAsterisk"; + else if (aSoundAlias.Equals(NS_SYSSOUND_QUESTION_DIALOG)) + sound = L"SystemQuestion"; + else if (aSoundAlias.Equals(NS_SYSSOUND_WARNING_DIALOG)) + sound = L"SystemExclamation"; + + if (sound) + ::PlaySoundW(sound, nsnull, SND_ALIAS | SND_ASYNC); + return NS_OK; }