Bug 660742 accessible should use mozilla::Preferences r=roc+davidb

This commit is contained in:
Masayuki Nakano 2011-06-02 10:05:12 +09:00
parent ec9c2d5c92
commit aa6ba96502
6 changed files with 48 additions and 40 deletions

View File

@ -89,8 +89,6 @@
#include "nsReadableUtils.h"
#include "prdtoa.h"
#include "nsIAtom.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIURI.h"
#include "nsArrayUtils.h"
#include "nsIMutableArray.h"
@ -106,6 +104,9 @@
#endif
#include "mozilla/unused.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
////////////////////////////////////////////////////////////////////////////////
@ -339,14 +340,9 @@ nsAccessible::Description(nsString& aDescription)
static PRInt32
GetAccessModifierMask(nsIContent* aContent)
{
nsCOMPtr<nsIPrefBranch> prefBranch =
do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefBranch)
return 0;
// use ui.key.generalAccessKey (unless it is -1)
PRInt32 accessKey;
nsresult rv = prefBranch->GetIntPref("ui.key.generalAccessKey", &accessKey);
PRInt32 accessKey = -1;
nsresult rv = Preferences::GetInt("ui.key.generalAccessKey", accessKey);
if (NS_SUCCEEDED(rv) && accessKey != -1) {
switch (accessKey) {
case nsIDOMKeyEvent::DOM_VK_SHIFT: return NS_MODIFIER_SHIFT;
@ -372,14 +368,13 @@ GetAccessModifierMask(nsIContent* aContent)
PRInt32 itemType, accessModifierMask = 0;
treeItem->GetItemType(&itemType);
switch (itemType) {
case nsIDocShellTreeItem::typeChrome:
rv = Preferences::GetInt("ui.key.chromeAccess", &accessModifierMask);
break;
case nsIDocShellTreeItem::typeChrome:
rv = prefBranch->GetIntPref("ui.key.chromeAccess", &accessModifierMask);
break;
case nsIDocShellTreeItem::typeContent:
rv = prefBranch->GetIntPref("ui.key.contentAccess", &accessModifierMask);
break;
case nsIDocShellTreeItem::typeContent:
rv = Preferences::GetInt("ui.key.contentAccess", &accessModifierMask);
break;
}
return NS_SUCCEEDED(rv) ? accessModifierMask : 0;

View File

@ -54,11 +54,13 @@
#include "nsIDOMNSHTMLElement.h"
#include "nsIFrame.h"
#include "nsINameSpaceManager.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsPIDOMWindow.h"
#include "nsIServiceManager.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
/// the accessible library and cached methods
HINSTANCE nsAccessNodeWrap::gmAccLib = nsnull;
HINSTANCE nsAccessNodeWrap::gmUserLib = nsnull;
@ -711,22 +713,16 @@ void nsAccessNodeWrap::TurnOffNewTabSwitchingForJawsAndWE()
// Check to see if the pref for disallowing CtrlTab is already set.
// If so, bail out.
// If not, set it.
nsCOMPtr<nsIPrefBranch> prefs (do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs) {
PRBool hasDisallowNewCtrlTabPref = PR_FALSE;
nsresult rv = prefs->PrefHasUserValue(CTRLTAB_DISALLOW_FOR_SCREEN_READERS_PREF,
&hasDisallowNewCtrlTabPref);
if (NS_SUCCEEDED(rv) && hasDisallowNewCtrlTabPref) {
// This pref has been set before. There is no default for it.
// Do nothing further, respect the setting that's there.
// That way, if noone touches it, it'll stay on after toggled once.
// If someone decided to turn it off, we respect that, too.
return;
}
// Value has never been set, set it.
prefs->SetBoolPref(CTRLTAB_DISALLOW_FOR_SCREEN_READERS_PREF, PR_TRUE);
if (Preferences::HasUserValue(CTRLTAB_DISALLOW_FOR_SCREEN_READERS_PREF)) {
// This pref has been set before. There is no default for it.
// Do nothing further, respect the setting that's there.
// That way, if noone touches it, it'll stay on after toggled once.
// If someone decided to turn it off, we respect that, too.
return;
}
// Value has never been set, set it.
Preferences::SetBool(CTRLTAB_DISALLOW_FOR_SCREEN_READERS_PREF, PR_TRUE);
}
void nsAccessNodeWrap::DoATSpecificProcessing()

View File

@ -58,7 +58,6 @@
#include "nsIScrollableFrame.h"
#include "nsINameSpaceManager.h"
#include "nsINodeInfo.h"
#include "nsIPrefService.h"
#include "nsRootAccessible.h"
#include "nsIServiceManager.h"
#include "nsTextFormatter.h"

View File

@ -50,8 +50,6 @@
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsIDOMXULMultSelectCntrlEl.h"
#include "nsIDOMKeyEvent.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManager.h"
#include "nsIPresShell.h"
#include "nsIContent.h"
@ -59,6 +57,10 @@
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
@ -410,10 +412,7 @@ nsXULMenuitemAccessible::GetKeyboardShortcut(nsAString& aAccessKey)
// No need to cache pref service, this happens rarely
if (gMenuAccesskeyModifier == -1) {
// Need to initialize cached global accesskey pref
gMenuAccesskeyModifier = 0;
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefBranch)
prefBranch->GetIntPref("ui.key.menuAccessKey", &gMenuAccesskeyModifier);
gMenuAccesskeyModifier = Preferences::GetInt("ui.key.menuAccessKey", 0);
}
nsAutoString propertyKey;

View File

@ -188,6 +188,11 @@ public:
*/
static nsresult ClearUser(const char* aPref);
/**
* Whether the pref has a user value or not.
*/
static PRBool HasUserValue(const char* aPref);
/**
* Adds/Removes the observer for the root pref branch.
* The observer is referenced strongly if AddStrongObserver is used. On the

View File

@ -1285,6 +1285,20 @@ Preferences::ClearUser(const char* aPref)
return sPreferences->mRootBranch->ClearUserPref(aPref);
}
// static
PRBool
Preferences::HasUserValue(const char* aPref)
{
NS_ENSURE_TRUE(InitStaticMembers(), PR_FALSE);
PRBool hasUserValue;
nsresult rv =
sPreferences->mRootBranch->PrefHasUserValue(aPref, &hasUserValue);
if (NS_FAILED(rv)) {
return PR_FALSE;
}
return hasUserValue;
}
// static
nsresult
Preferences::AddStrongObserver(nsIObserver* aObserver,