зеркало из https://github.com/mozilla/gecko-dev.git
Bug 176602. Make typeaheadfind beep less annoying, and implement boolean pref accessibility.typeaheadfind.enablesound. Pref is turned off by default in Linux for now, sound needs testing and work there (see bug 179138 and bug 110385). r=kyle, sr=bz
This commit is contained in:
Родитель
f7a906ce38
Коммит
266790cc84
|
@ -1,2 +1,5 @@
|
|||
en-US.jar:
|
||||
locale/en-US/navigator/typeaheadfind.properties (locale/en-US/typeaheadfind.properties)
|
||||
|
||||
toolkit.jar:
|
||||
content/global/notfound.wav (content/notfound.wav)
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
#include "nsIWebBrowserChrome.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeOwner.h"
|
||||
#include "nsIEditorDocShell.h"
|
||||
|
@ -88,7 +91,6 @@
|
|||
#include "nsIWebNavigation.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
|
@ -148,7 +150,9 @@ nsTypeAheadFind::nsTypeAheadFind():
|
|||
mIsFirstVisiblePreferred(PR_FALSE), mIsIMETypeAheadActive(PR_FALSE),
|
||||
mIsBackspaceProtectOn(PR_FALSE),
|
||||
mBadKeysSinceMatch(0), mLastBadChar(0),
|
||||
mRepeatingMode(eRepeatingNone), mTimeoutLength(0)
|
||||
mRepeatingMode(eRepeatingNone), mTimeoutLength(0),
|
||||
mSoundInterface(nsnull), mIsSoundInitialized(PR_FALSE),
|
||||
mIsSoundEnabledPref(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
||||
|
@ -319,6 +323,10 @@ nsTypeAheadFind::PrefsReset(const char* aPrefName, void* instance_data)
|
|||
prefs->GetBoolPref("accessibility.typeaheadfind.startlinksonly",
|
||||
&typeAheadFind->mStartLinksOnlyPref);
|
||||
|
||||
prefs->GetBoolPref("accessibility.typeaheadfind.enablesound",
|
||||
&typeAheadFind->mIsSoundEnabledPref);
|
||||
typeAheadFind->mSoundInterface = nsnull; // will get as needed
|
||||
|
||||
prefs->GetIntPref("accessibility.typeaheadfind.timeout",
|
||||
&typeAheadFind->mTimeoutLength);
|
||||
|
||||
|
@ -353,6 +361,7 @@ nsTypeAheadFind::Observe(nsISupports *aSubject, const char *aTopic,
|
|||
}
|
||||
else if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
Shutdown();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (!nsCRT::strcmp(aTopic,"nsWebBrowserFind_FindAgain")) {
|
||||
// A find next command wants to be executed.
|
||||
|
@ -516,6 +525,26 @@ nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
// Deal with nsISound impl quirks in Windows
|
||||
if (!mIsSoundInitialized && mIsSoundEnabledPref) {
|
||||
// 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
|
||||
// by waiting for the first keystroke, we still get the startup time benefits
|
||||
mIsSoundInitialized = PR_TRUE;
|
||||
mSoundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
||||
if (mSoundInterface) {
|
||||
mSoundInterface->PlaySystemSound("");
|
||||
}
|
||||
}
|
||||
|
||||
// After each keystroke, destroy sound object to free up memory
|
||||
// allocated for error sound, otherwise Windows' nsISound impl
|
||||
// holds onto the last played sound.
|
||||
mSoundInterface = nsnull;
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIContent> targetContent;
|
||||
nsCOMPtr<nsIPresShell> targetPresShell;
|
||||
GetTargetIfTypeAheadOkay(aEvent, getter_AddRefs(targetContent),
|
||||
|
@ -567,7 +596,9 @@ nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
|
|||
aEvent->PreventDefault();
|
||||
CancelFind();
|
||||
}
|
||||
if (mFocusedDocSelection) {
|
||||
mFocusedDocSelection->CollapseToStart();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -895,13 +926,13 @@ nsTypeAheadFind::HandleChar(PRUnichar aChar)
|
|||
mRepeatingMode = eRepeatingNone;
|
||||
|
||||
++mBadKeysSinceMatch;
|
||||
// Error beep (don't been when backspace is pressed, they're
|
||||
|
||||
// Error sound (don't fire when backspace is pressed, they're
|
||||
// trying to correct the mistake!)
|
||||
nsCOMPtr<nsISound> soundInterface =
|
||||
do_CreateInstance("@mozilla.org/sound;1");
|
||||
if (soundInterface) {
|
||||
soundInterface->Beep();
|
||||
if (mIsSoundEnabledPref) {
|
||||
PlayNotFoundSound();
|
||||
}
|
||||
|
||||
// Remove bad character from buffer, so we can continue typing from
|
||||
// last matched character
|
||||
if (length >= 1) {
|
||||
|
@ -944,6 +975,24 @@ nsTypeAheadFind::SaveFind()
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
nsTypeAheadFind::PlayNotFoundSound()
|
||||
{
|
||||
if (!mSoundInterface) {
|
||||
mSoundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
||||
}
|
||||
if (mSoundInterface) {
|
||||
mIsSoundInitialized = PR_TRUE;
|
||||
nsCOMPtr<nsIURI> soundURI;
|
||||
NS_NewURI(getter_AddRefs(soundURI), NS_LITERAL_CSTRING(TYPEAHEADFIND_NOTFOUND_WAV_URL));
|
||||
nsCOMPtr<nsIURL> soundURL(do_QueryInterface(soundURI));
|
||||
if (soundURL) {
|
||||
mSoundInterface->Play(soundURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTypeAheadFind::HandleText(nsIDOMEvent* aTextEvent)
|
||||
{
|
||||
|
|
|
@ -62,9 +62,12 @@
|
|||
#include "nsITypeAheadFind.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsISound.h"
|
||||
|
||||
#define TYPEAHEADFIND_BUNDLE_URL \
|
||||
"chrome://navigator/locale/typeaheadfind.properties"
|
||||
#define TYPEAHEADFIND_NOTFOUND_WAV_URL \
|
||||
"chrome://global/content/notfound.wav"
|
||||
|
||||
enum {
|
||||
eRepeatingNone,
|
||||
|
@ -131,6 +134,7 @@ protected:
|
|||
nsresult HandleChar(PRUnichar aChar);
|
||||
PRBool HandleBackspace();
|
||||
void SaveFind();
|
||||
void PlayNotFoundSound();
|
||||
void GetTopContentPresShell(nsIDocShellTreeItem *aTreeItem,
|
||||
nsIPresShell **aPresShell);
|
||||
nsresult GetWebBrowserFind(nsIDOMWindow *aDOMWin,
|
||||
|
@ -209,6 +213,12 @@ protected:
|
|||
PRInt32 mRepeatingMode;
|
||||
PRInt32 mTimeoutLength; // time in ms before find is automatically cancelled
|
||||
|
||||
// Sound is played asynchronously on some platforms.
|
||||
// If we destroy mSoundInterface before sound has played, it won't play
|
||||
nsCOMPtr<nsISound> mSoundInterface;
|
||||
PRBool mIsSoundInitialized;
|
||||
PRBool mIsSoundEnabledPref;
|
||||
|
||||
static PRInt32 sAccelKey; // magic value of -1 indicates unitialized state
|
||||
|
||||
// where selection was when user started the find
|
||||
|
|
|
@ -138,7 +138,8 @@ pref("accessibility.accesskeycausesactivation", true);
|
|||
pref("accessibility.typeaheadfind", true);
|
||||
pref("accessibility.typeaheadfind.linksonly", true);
|
||||
pref("accessibility.typeaheadfind.startlinksonly", false);
|
||||
pref("accessibility.typeaheadfind.timeout", 5000);
|
||||
pref("accessibility.typeaheadfind.timeout", 4000);
|
||||
pref("accessibility.typeaheadfind.enablesound", true);
|
||||
|
||||
// Dialog modality issues
|
||||
pref("browser.prefWindowModal", true);
|
||||
|
|
|
@ -72,6 +72,10 @@ 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);
|
||||
|
||||
// override double-click word selection behavior.
|
||||
pref("layout.word_select.stop_at_punctuation", false);
|
||||
|
||||
|
|
|
@ -112,6 +112,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
|||
{
|
||||
// print a load error on bad status
|
||||
if (NS_FAILED(aStatus)) {
|
||||
#ifdef DEBUG
|
||||
if (aLoader) {
|
||||
nsCOMPtr<nsIRequest> request;
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
|
@ -124,12 +125,12 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
|||
if (uri) {
|
||||
nsCAutoString uriSpec;
|
||||
uri->GetSpec(uriSpec);
|
||||
#ifdef DEBUG
|
||||
printf("Failed to load %s\n", uriSpec.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
PurgeLastSound();
|
||||
|
|
Загрузка…
Ссылка в новой задаче