Bug 1667050 - Convert nsFocusManager::sInstance into a StaticRefPtr; r=NeilDeakin

Differential Revision: https://phabricator.services.mozilla.com/D91263
This commit is contained in:
Edgar Chen 2020-09-25 00:06:45 +00:00
Родитель 3fd329a969
Коммит 260bce2e82
2 изменённых файлов: 9 добавлений и 10 удалений

Просмотреть файл

@ -164,7 +164,7 @@ NS_IMPL_CYCLE_COLLECTION_WEAK(nsFocusManager, mActiveWindow,
mFirstBlurEvent, mFirstFocusEvent,
mWindowBeingLowered, mDelayedBlurFocusEvents)
nsFocusManager* nsFocusManager::sInstance = nullptr;
StaticRefPtr<nsFocusManager> nsFocusManager::sInstance;
bool nsFocusManager::sMouseFocusesFormControl = false;
bool nsFocusManager::sTestMode = false;
@ -189,9 +189,7 @@ nsFocusManager::~nsFocusManager() {
// static
nsresult nsFocusManager::Init() {
nsFocusManager* fm = new nsFocusManager();
NS_ADDREF(fm);
sInstance = fm;
sInstance = new nsFocusManager();
nsIContent::sTabFocusModelAppliesToXUL =
Preferences::GetBool("accessibility.tabfocus_applies_to_xul",
@ -203,18 +201,18 @@ nsresult nsFocusManager::Init() {
sTestMode = Preferences::GetBool("focusmanager.testmode", false);
Preferences::RegisterCallbacks(nsFocusManager::PrefChanged, kObservedPrefs,
fm);
sInstance.get());
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(fm, "xpcom-shutdown", true);
obs->AddObserver(sInstance, "xpcom-shutdown", true);
}
return NS_OK;
}
// static
void nsFocusManager::Shutdown() { NS_IF_RELEASE(sInstance); }
void nsFocusManager::Shutdown() { sInstance = nullptr; }
// static
void nsFocusManager::PrefChanged(const char* aPref, void* aSelf) {
@ -396,8 +394,8 @@ nsFocusManager::GetActiveBrowsingContext(BrowsingContext** aBrowsingContext) {
void nsFocusManager::FocusWindow(nsPIDOMWindowOuter* aWindow,
CallerType aCallerType) {
if (RefPtr<nsFocusManager> fm = sInstance) {
fm->SetFocusedWindowWithCallerType(aWindow, aCallerType);
if (sInstance) {
sInstance->SetFocusedWindowWithCallerType(aWindow, aCallerType);
}
}

Просмотреть файл

@ -16,6 +16,7 @@
#include "nsWeakReference.h"
#include "mozilla/Attributes.h"
#include "mozilla/RefPtr.h"
#include "mozilla/StaticPtr.h"
#define FOCUSMETHOD_MASK 0xF000
#define FOCUSMETHODANDRING_MASK 0xF0F000
@ -831,7 +832,7 @@ class nsFocusManager final : public nsIFocusManager,
static bool sTestMode;
// the single focus manager
static nsFocusManager* sInstance;
static mozilla::StaticRefPtr<nsFocusManager> sInstance;
};
nsresult NS_NewFocusManager(nsIFocusManager** aResult);