From 8eeeec9e7338d18dd4d13e2dd0eb7feb38526573 Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Thu, 9 Jan 2003 20:03:41 +0000 Subject: [PATCH] Bug 187301 - tab nav prefs not dynamically changeable, no prefs observer. r=akkana, sr=bryner. git-svn-id: svn://10.0.0.236/trunk@136084 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/src/nsEventStateManager.cpp | 74 +++++++++++++------ .../content/events/src/nsEventStateManager.h | 6 +- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 8df3b936638..d2de5d3bc05 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -113,6 +113,7 @@ #include "nsIInterfaceRequestorUtils.h" #include "nsUnicharUtils.h" #include "nsContentUtils.h" +#include "nsIPrefBranchInternal.h" #if defined (XP_MAC) || defined(XP_MACOSX) #include @@ -209,6 +210,13 @@ nsEventStateManager::Init() mPrefBranch->GetIntPref("ui.key.generalAccessKey", &nsEventStateManager::gGeneralAccesskeyModifier); } + + nsCOMPtr prefInternal(do_QueryInterface(mPrefBranch)); + NS_ASSERTION(prefInternal, "No pref branch internal"); + prefInternal->AddObserver("accessibility.tabfocus", this, PR_FALSE); + if (sTabFocusModel == eTabFocus_unset) { + ResetObservedPrefs(); + } } if (nsEventStateManager::sTextfieldSelectModel == eTextfieldSelect_unset) { @@ -264,6 +272,11 @@ nsEventStateManager::~nsEventStateManager() nsresult nsEventStateManager::Shutdown() { + nsCOMPtr prefInternal(do_QueryInterface(mPrefBranch)); + NS_ASSERTION(prefInternal, "No pref branch internal"); + + prefInternal->RemoveObserver("accessibility.tabfocus", this); + mPrefBranch = nsnull; m_haveShutdown = PR_TRUE; @@ -286,6 +299,37 @@ nsEventStateManager::getPrefBranch() return NS_OK; } +void nsEventStateManager::ResetObservedPrefs() +{ + // Tab focus mode is constant across all windows. + // It would be nicer if we could make sure this was called only + // once, each time the pref changed, instead of once per esm + + sTabFocusModel = eTabFocus_any; + nsresult rv = getPrefBranch(); + + // XXX todo: On the mac, only links tabbing should be configurable in Mozilla + // Whether other form controls are tabbable is a system setting + // that we should adhere to via look and feel. + // Something like this: + // sTabFocusModel &= eTabFocus_linksMask; + // nsCOMPtr lookNFeel(do_GetService(kLookAndFeelCID)); + // PRInt32 tabToNonTextControls = 0; + // lookNFeel->GetMetric(nsILookAndFeel::eMetric_TabToNonTextControls, + // tabToNonTextControls); + // if (tabToNonTextControls) + // sTabFocusModel |= eTabFocus_formElementsMask; + // else + // sTabFocusModel = eTabFocus_textControlsMask; // Only tab to text fields + // This assumes that when the setting says "only text controls" + // that links shouldn't be tabbable. + // Also, we currently ignore the pref for XUL dialogs + // but we should pay attention to the mac setting there + + if (NS_SUCCEEDED(rv)) + mPrefBranch->GetIntPref("accessibility.tabfocus", &sTabFocusModel); +} + NS_IMETHODIMP nsEventStateManager::Observe(nsISupports *aSubject, const char *aTopic, @@ -293,6 +337,8 @@ nsEventStateManager::Observe(nsISupports *aSubject, { if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) Shutdown(); + else if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) + ResetObservedPrefs(); return NS_OK; } @@ -3392,19 +3438,6 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* PRBool disabled = PR_TRUE; PRBool hidden = PR_FALSE; - // Tab focus mode is constant across all windows. - // It would be nicer if ESM had a prefs callback, - // so we could store this and change behavior when it changes. - // But until the pref is exposed, that doesn't matter. - if (sTabFocusModel == eTabFocus_unset) { - sTabFocusModel = (eTabFocus_textControlsMask - | eTabFocus_formElementsMask - | eTabFocus_linksMask); - nsresult rv = getPrefBranch(); - if (NS_SUCCEEDED(rv)) - mPrefBranch->GetIntPref("accessibility.tabfocus", &sTabFocusModel); - } - child->GetTag(*getter_AddRefs(tag)); if (child->IsContentOfType(nsIContent::eHTML)) { if (nsHTMLAtoms::input==tag) { @@ -3419,8 +3452,7 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* || type.EqualsIgnoreCase("autocomplete") || type.EqualsIgnoreCase("password")) { // It's a text field or password field - disabled = - disabled || !(sTabFocusModel & eTabFocus_textControlsMask); + disabled = PR_FALSE; } else if (type.EqualsIgnoreCase("hidden")) { hidden = PR_TRUE; @@ -3448,13 +3480,11 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* } else if (nsHTMLAtoms::textarea==tag) { // it's a textarea - disabled = !(sTabFocusModel & eTabFocus_textControlsMask); - if (!disabled) { - nsCOMPtr nextTextArea(do_QueryInterface(child)); - if (nextTextArea) { - nextTextArea->GetDisabled(&disabled); - nextTextArea->GetTabIndex(&tabIndex); - } + disabled = PR_FALSE; + nsCOMPtr nextTextArea(do_QueryInterface(child)); + if (nextTextArea) { + nextTextArea->GetDisabled(&disabled); + nextTextArea->GetTabIndex(&tabIndex); } } else if (nsHTMLAtoms::a==tag) { diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 99c95cf613e..a34d9955d07 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -74,9 +74,10 @@ class nsEventStateManager : public nsSupportsWeakReference, // Tab focus model bit field: enum nsTabFocusModel { eTabFocus_unset = 0, // unset, check preferences - eTabFocus_textControlsMask = (1<<0), // text elements + //eTabFocus_textControlsMask = (1<<0), // unused - textboxes always tabbable eTabFocus_formElementsMask = (1<<1), // non-text form elements - eTabFocus_linksMask = (1<<2) // links + eTabFocus_linksMask = (1<<2), // links + eTabFocus_any = 1 | (1<<1) | (1<<2), // everything that can be focused }; enum nsTextfieldSelectModel { @@ -212,6 +213,7 @@ protected: PRBool scrollPage, PRBool aUseTargetFrame); void ForceViewUpdate(nsIView* aView); nsresult getPrefBranch(); + void ResetObservedPrefs(); nsresult ChangeTextSize(PRInt32 change); // end mousewheel functions