From a16a23e56ffe7e3af3f6362adc1e3024c250e4b6 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 5 Jul 2018 13:36:07 -0700 Subject: [PATCH] Bug 1473631: Part 4 - Replace pref observers with callbacks in FocusManager. r=njn MozReview-Commit-ID: 533Qz2nIkmX --HG-- extra : rebase_source : 71e32db787b150b8ef3cee3163953c0adb893c92 --- dom/base/nsFocusManager.cpp | 50 +++++++++++++++++++++---------------- dom/base/nsFocusManager.h | 2 ++ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 7e38fbaf6ed5..d68ded7751f6 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -188,7 +188,9 @@ nsFocusManager::nsFocusManager() nsFocusManager::~nsFocusManager() { - Preferences::RemoveObservers(this, kObservedPrefs); + Preferences::UnregisterCallbacks( + PREF_CHANGE_METHOD(nsFocusManager::PrefChanged), + kObservedPrefs, this); nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { @@ -213,7 +215,9 @@ nsFocusManager::Init() sTestMode = Preferences::GetBool("focusmanager.testmode", false); - Preferences::AddWeakObservers(fm, kObservedPrefs); + Preferences::RegisterCallbacks( + PREF_CHANGE_METHOD(nsFocusManager::PrefChanged), + kObservedPrefs, fm); nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { @@ -230,30 +234,34 @@ nsFocusManager::Shutdown() NS_IF_RELEASE(sInstance); } +void +nsFocusManager::PrefChanged(const char* aPref) +{ + nsDependentCString pref(aPref); + if (pref.EqualsLiteral("accessibility.browsewithcaret")) { + UpdateCaretForCaretBrowsingMode(); + } + else if (pref.EqualsLiteral("accessibility.tabfocus_applies_to_xul")) { + nsIContent::sTabFocusModelAppliesToXUL = + Preferences::GetBool("accessibility.tabfocus_applies_to_xul", + nsIContent::sTabFocusModelAppliesToXUL); + } + else if (pref.EqualsLiteral("accessibility.mouse_focuses_formcontrol")) { + sMouseFocusesFormControl = + Preferences::GetBool("accessibility.mouse_focuses_formcontrol", + false); + } + else if (pref.EqualsLiteral("focusmanager.testmode")) { + sTestMode = Preferences::GetBool("focusmanager.testmode", false); + } +} + NS_IMETHODIMP nsFocusManager::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData) { - if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { - nsDependentString data(aData); - if (data.EqualsLiteral("accessibility.browsewithcaret")) { - UpdateCaretForCaretBrowsingMode(); - } - else if (data.EqualsLiteral("accessibility.tabfocus_applies_to_xul")) { - nsIContent::sTabFocusModelAppliesToXUL = - Preferences::GetBool("accessibility.tabfocus_applies_to_xul", - nsIContent::sTabFocusModelAppliesToXUL); - } - else if (data.EqualsLiteral("accessibility.mouse_focuses_formcontrol")) { - sMouseFocusesFormControl = - Preferences::GetBool("accessibility.mouse_focuses_formcontrol", - false); - } - else if (data.EqualsLiteral("focusmanager.testmode")) { - sTestMode = Preferences::GetBool("focusmanager.testmode", false); - } - } else if (!nsCRT::strcmp(aTopic, "xpcom-shutdown")) { + if (!nsCRT::strcmp(aTopic, "xpcom-shutdown")) { mActiveWindow = nullptr; mFocusedWindow = nullptr; mFocusedElement = nullptr; diff --git a/dom/base/nsFocusManager.h b/dom/base/nsFocusManager.h index 3efe2a2790b8..9d0600d5ebae 100644 --- a/dom/base/nsFocusManager.h +++ b/dom/base/nsFocusManager.h @@ -57,6 +57,8 @@ public: static nsresult Init(); static void Shutdown(); + void PrefChanged(const char* aPref); + /** * Retrieve the single focus manager. */