From 1889b530c2363225ef677351752aa431cf1d5d32 Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Tue, 3 Dec 2002 23:51:10 +0000 Subject: [PATCH] 179784: go back to beep by default for typeahead find "not found", since the nsSound solution doesn't work well on linux or mac. r=aaronl sr=sfraser --- .../typeaheadfind/src/nsTypeAheadFind.cpp | 30 ++++++++++++------- .../typeaheadfind/src/nsTypeAheadFind.h | 3 +- modules/libpref/src/init/all.js | 2 +- modules/libpref/src/mac/macprefs.js | 2 ++ modules/libpref/src/unix/unix.js | 5 ++-- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp index 44c38e87c028..56281512d4be 100644 --- a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp +++ b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp @@ -153,8 +153,7 @@ nsTypeAheadFind::nsTypeAheadFind(): mIsBackspaceProtectOn(PR_FALSE), mBadKeysSinceMatch(0), mLastBadChar(0), mRepeatingMode(eRepeatingNone), mTimeoutLength(0), - mSoundInterface(nsnull), mIsSoundInitialized(PR_FALSE), - mIsSoundEnabledPref(PR_FALSE) + mSoundInterface(nsnull), mIsSoundInitialized(PR_FALSE) { NS_INIT_ISUPPORTS(); @@ -315,9 +314,10 @@ nsTypeAheadFind::PrefsReset() prefBranch->GetBoolPref("accessibility.typeaheadfind.startlinksonly", &mStartLinksOnlyPref); - prefBranch->GetBoolPref("accessibility.typeaheadfind.enablesound", - &mIsSoundEnabledPref); - mSoundInterface = nsnull; // will get as needed + nsXPIDLCString soundStr; + prefBranch->GetCharPref("accessibility.typeaheadfind.soundURL", + getter_Copies(soundStr)); + mNotFoundSoundURL = soundStr; prefBranch->GetIntPref("accessibility.typeaheadfind.timeout", &mTimeoutLength); @@ -522,7 +522,7 @@ nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent) #ifdef XP_WIN // Deal with nsISound impl quirks in Windows - if (!mIsSoundInitialized && mIsSoundEnabledPref) { + if (!mIsSoundInitialized) { // Don't play a sound, just make sure sound system is initialized // This makes sure system sound library (winmm.dll) is loaded so that // there's no lag before the first sound is played @@ -924,9 +924,7 @@ nsTypeAheadFind::HandleChar(PRUnichar aChar) // Error sound (don't fire when backspace is pressed, they're // trying to correct the mistake!) - if (mIsSoundEnabledPref) { - PlayNotFoundSound(); - } + PlayNotFoundSound(); // Remove bad character from buffer, so we can continue typing from // last matched character @@ -973,13 +971,25 @@ nsTypeAheadFind::SaveFind() void nsTypeAheadFind::PlayNotFoundSound() { + if (mNotFoundSoundURL.IsEmpty()) // no sound + return; if (!mSoundInterface) { mSoundInterface = do_CreateInstance("@mozilla.org/sound;1"); } if (mSoundInterface) { mIsSoundInitialized = PR_TRUE; + + if (mNotFoundSoundURL.Equals("beep")) { + mSoundInterface->Beep(); + return; + } + nsCOMPtr soundURI; - NS_NewURI(getter_AddRefs(soundURI), NS_LITERAL_CSTRING(TYPEAHEADFIND_NOTFOUND_WAV_URL)); + if (mNotFoundSoundURL.Equals("default")) + NS_NewURI(getter_AddRefs(soundURI), + NS_LITERAL_CSTRING(TYPEAHEADFIND_NOTFOUND_WAV_URL)); + else + NS_NewURI(getter_AddRefs(soundURI), mNotFoundSoundURL); nsCOMPtr soundURL(do_QueryInterface(soundURI)); if (soundURL) { mSoundInterface->Play(soundURL); diff --git a/extensions/typeaheadfind/src/nsTypeAheadFind.h b/extensions/typeaheadfind/src/nsTypeAheadFind.h index 81bbd1b96767..79af942258c2 100644 --- a/extensions/typeaheadfind/src/nsTypeAheadFind.h +++ b/extensions/typeaheadfind/src/nsTypeAheadFind.h @@ -186,6 +186,8 @@ protected: nsString mFindNextBuffer; nsString mIMEString; + nsCString mNotFoundSoundURL; + // PRBool's are used instead of PRPackedBool's where the address of the // boolean variable is getting passed into a method. For example: // GetBoolPref("accessibility.typeaheadfind.linksonly", &mLinksOnlyPref); @@ -217,7 +219,6 @@ protected: // If we destroy mSoundInterface before sound has played, it won't play nsCOMPtr mSoundInterface; PRBool mIsSoundInitialized; - PRBool mIsSoundEnabledPref; static PRInt32 sAccelKey; // magic value of -1 indicates unitialized state diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 180a0390b42a..32637e3cfb3f 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -139,7 +139,7 @@ pref("accessibility.typeaheadfind", true); pref("accessibility.typeaheadfind.linksonly", true); pref("accessibility.typeaheadfind.startlinksonly", false); pref("accessibility.typeaheadfind.timeout", 4000); -pref("accessibility.typeaheadfind.enablesound", true); +pref("accessibility.typeaheadfind.soundURL", "default"); // Dialog modality issues pref("browser.prefWindowModal", true); diff --git a/modules/libpref/src/mac/macprefs.js b/modules/libpref/src/mac/macprefs.js index e8defd8468bc..649265650362 100644 --- a/modules/libpref/src/mac/macprefs.js +++ b/modules/libpref/src/mac/macprefs.js @@ -184,6 +184,8 @@ pref("font.size.fixed.zh-TW", 16); // 1 focuses text controls, 2 focuses other form elements, 4 adds links. pref("accessibility.tabfocus", 1); +pref("accessibility.typeaheadfind.soundURL", "beep"); + // Override the Windows settings: no menu key, meta accelerator key. ctrl for general access key in HTML/XUL // Use 17 for Ctrl, 18 for Option, 224 for Cmd, 0 for none pref("ui.key.menuAccessKey", 0); diff --git a/modules/libpref/src/unix/unix.js b/modules/libpref/src/unix/unix.js index 7962191cb03e..8e8846ecaef1 100644 --- a/modules/libpref/src/unix/unix.js +++ b/modules/libpref/src/unix/unix.js @@ -72,9 +72,8 @@ pref("browser.urlbar.clickSelectsAll", false); // Leave this at the default, 7, to match mozilla1.0-era user expectations. // pref("accessibility.tabfocus", 1); -// Keep sound pref'd off in Linux, at least until nsISound becomes -// asynchronous (bug 110385) -pref("accessibility.typeaheadfind.enablesound", false); +// Beep instead of playing sound in Linux, at least until nsISound is fixed: +pref("accessibility.typeaheadfind.soundURL", "beep"); // override double-click word selection behavior. pref("layout.word_select.stop_at_punctuation", false);