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 b7f556606b
commit 09b6048d53
6 changed files with 48 additions and 40 deletions

View File

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

View File

@ -54,11 +54,13 @@
#include "nsIDOMNSHTMLElement.h" #include "nsIDOMNSHTMLElement.h"
#include "nsIFrame.h" #include "nsIFrame.h"
#include "nsINameSpaceManager.h" #include "nsINameSpaceManager.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
/// the accessible library and cached methods /// the accessible library and cached methods
HINSTANCE nsAccessNodeWrap::gmAccLib = nsnull; HINSTANCE nsAccessNodeWrap::gmAccLib = nsnull;
HINSTANCE nsAccessNodeWrap::gmUserLib = nsnull; HINSTANCE nsAccessNodeWrap::gmUserLib = nsnull;
@ -711,12 +713,7 @@ void nsAccessNodeWrap::TurnOffNewTabSwitchingForJawsAndWE()
// Check to see if the pref for disallowing CtrlTab is already set. // Check to see if the pref for disallowing CtrlTab is already set.
// If so, bail out. // If so, bail out.
// If not, set it. // If not, set it.
nsCOMPtr<nsIPrefBranch> prefs (do_GetService(NS_PREFSERVICE_CONTRACTID)); if (Preferences::HasUserValue(CTRLTAB_DISALLOW_FOR_SCREEN_READERS_PREF)) {
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. // This pref has been set before. There is no default for it.
// Do nothing further, respect the setting that's there. // Do nothing further, respect the setting that's there.
// That way, if noone touches it, it'll stay on after toggled once. // That way, if noone touches it, it'll stay on after toggled once.
@ -725,8 +722,7 @@ void nsAccessNodeWrap::TurnOffNewTabSwitchingForJawsAndWE()
} }
// Value has never been set, set it. // Value has never been set, set it.
prefs->SetBoolPref(CTRLTAB_DISALLOW_FOR_SCREEN_READERS_PREF, PR_TRUE); Preferences::SetBool(CTRLTAB_DISALLOW_FOR_SCREEN_READERS_PREF, PR_TRUE);
}
} }
void nsAccessNodeWrap::DoATSpecificProcessing() void nsAccessNodeWrap::DoATSpecificProcessing()

View File

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

View File

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

View File

@ -188,6 +188,11 @@ public:
*/ */
static nsresult ClearUser(const char* aPref); 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. * Adds/Removes the observer for the root pref branch.
* The observer is referenced strongly if AddStrongObserver is used. On the * 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); 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 // static
nsresult nsresult
Preferences::AddStrongObserver(nsIObserver* aObserver, Preferences::AddStrongObserver(nsIObserver* aObserver,