diff --git a/gfx/thebes/gfxMacPlatformFontList.h b/gfx/thebes/gfxMacPlatformFontList.h index 1729e8df9113..9c26b5ccbf6c 100644 --- a/gfx/thebes/gfxMacPlatformFontList.h +++ b/gfx/thebes/gfxMacPlatformFontList.h @@ -6,6 +6,8 @@ #ifndef gfxMacPlatformFontList_H_ #define gfxMacPlatformFontList_H_ +#include + #include "mozilla/MemoryReporting.h" #include "nsDataHashtable.h" #include "nsRefPtrHashtable.h" @@ -14,8 +16,6 @@ #include "gfxPlatform.h" #include "gfxPlatformMac.h" -#include - #include "nsUnicharUtils.h" #include "nsTArray.h" @@ -101,7 +101,11 @@ private: // special case font faces treated as font families (set via prefs) void InitSingleFaceList(); - static void ATSNotification(ATSFontNotificationInfoRef aInfo, void* aUserArg); + static void RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center, + void *observer, + CFStringRef name, + const void *object, + CFDictionaryRef userInfo); // search fonts system-wide for a given character, null otherwise virtual gfxFontEntry* GlobalFontFallback(const uint32_t aCh, @@ -112,9 +116,6 @@ private: virtual bool UsesSystemFallback() { return true; } - // keep track of ATS generation to prevent unneeded updates when loading downloaded fonts - uint32_t mATSGeneration; - enum { kATSGenerationInitial = -1 }; diff --git a/gfx/thebes/gfxMacPlatformFontList.mm b/gfx/thebes/gfxMacPlatformFontList.mm index b37359f68cad..b03556e6c619 100644 --- a/gfx/thebes/gfxMacPlatformFontList.mm +++ b/gfx/thebes/gfxMacPlatformFontList.mm @@ -43,7 +43,6 @@ #endif #include "prlog.h" -#include #include #import @@ -646,12 +645,15 @@ gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(gfxPlatformFontList *aPlatformF #pragma mark- gfxMacPlatformFontList::gfxMacPlatformFontList() : - gfxPlatformFontList(false), mATSGeneration(uint32_t(kATSGenerationInitial)), + gfxPlatformFontList(false), mDefaultFont(nullptr) { - ::ATSFontNotificationSubscribe(ATSNotification, - kATSFontNotifyOptionDefault, - (void*)this, nullptr); + ::CFNotificationCenterAddObserver(::CFNotificationCenterGetLocalCenter(), + this, + RegisteredFontsChangedNotificationCallback, + kCTFontManagerRegisteredFontsChangedNotification, + 0, + CFNotificationSuspensionBehaviorDeliverImmediately); // cache this in a static variable so that MacOSFontFamily objects // don't have to repeatedly look it up @@ -670,19 +672,8 @@ gfxMacPlatformFontList::InitFontList() { nsAutoreleasePool localPool; - ATSGeneration currentGeneration = ::ATSGetGeneration(); - - // need to ignore notifications after adding each font - if (mATSGeneration == currentGeneration) - return NS_OK; - Telemetry::AutoTimer timer; - mATSGeneration = currentGeneration; -#ifdef PR_LOGGING - LOG_FONTLIST(("(fontlist) updating to generation: %d", mATSGeneration)); -#endif - // reset font lists gfxPlatformFontList::InitFontList(); @@ -777,11 +768,18 @@ gfxMacPlatformFontList::GetStandardFamilyName(const nsAString& aFontName, nsAStr } void -gfxMacPlatformFontList::ATSNotification(ATSFontNotificationInfoRef aInfo, - void* aUserArg) +gfxMacPlatformFontList::RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center, + void *observer, + CFStringRef name, + const void *object, + CFDictionaryRef userInfo) { + if (!::CFEqual(name, kCTFontManagerRegisteredFontsChangedNotification)) { + return; + } + // xxx - should be carefully pruning the list of fonts, not rebuilding it from scratch - static_cast(aUserArg)->UpdateFontList(); + static_cast(observer)->UpdateFontList(); // modify a preference that will trigger reflow everywhere static const char kPrefName[] = "font.internaluseonly.changed";