Bug 869762: Use Core Foundation notifications instead of ATS for font changes on OS X. r=jdaggett

This commit is contained in:
Josh Aas 2013-10-15 23:53:52 -05:00
Родитель 71902a7d0a
Коммит 08b001d8f0
2 изменённых файлов: 24 добавлений и 25 удалений

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

@ -6,6 +6,8 @@
#ifndef gfxMacPlatformFontList_H_ #ifndef gfxMacPlatformFontList_H_
#define gfxMacPlatformFontList_H_ #define gfxMacPlatformFontList_H_
#include <CoreFoundation/CoreFoundation.h>
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "nsDataHashtable.h" #include "nsDataHashtable.h"
#include "nsRefPtrHashtable.h" #include "nsRefPtrHashtable.h"
@ -14,8 +16,6 @@
#include "gfxPlatform.h" #include "gfxPlatform.h"
#include "gfxPlatformMac.h" #include "gfxPlatformMac.h"
#include <Carbon/Carbon.h>
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
#include "nsTArray.h" #include "nsTArray.h"
@ -101,7 +101,11 @@ private:
// special case font faces treated as font families (set via prefs) // special case font faces treated as font families (set via prefs)
void InitSingleFaceList(); 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 // search fonts system-wide for a given character, null otherwise
virtual gfxFontEntry* GlobalFontFallback(const uint32_t aCh, virtual gfxFontEntry* GlobalFontFallback(const uint32_t aCh,
@ -112,9 +116,6 @@ private:
virtual bool UsesSystemFallback() { return true; } virtual bool UsesSystemFallback() { return true; }
// keep track of ATS generation to prevent unneeded updates when loading downloaded fonts
uint32_t mATSGeneration;
enum { enum {
kATSGenerationInitial = -1 kATSGenerationInitial = -1
}; };

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

@ -43,7 +43,6 @@
#endif #endif
#include "prlog.h" #include "prlog.h"
#include <Carbon/Carbon.h>
#include <algorithm> #include <algorithm>
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
@ -646,12 +645,15 @@ gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(gfxPlatformFontList *aPlatformF
#pragma mark- #pragma mark-
gfxMacPlatformFontList::gfxMacPlatformFontList() : gfxMacPlatformFontList::gfxMacPlatformFontList() :
gfxPlatformFontList(false), mATSGeneration(uint32_t(kATSGenerationInitial)), gfxPlatformFontList(false),
mDefaultFont(nullptr) mDefaultFont(nullptr)
{ {
::ATSFontNotificationSubscribe(ATSNotification, ::CFNotificationCenterAddObserver(::CFNotificationCenterGetLocalCenter(),
kATSFontNotifyOptionDefault, this,
(void*)this, nullptr); RegisteredFontsChangedNotificationCallback,
kCTFontManagerRegisteredFontsChangedNotification,
0,
CFNotificationSuspensionBehaviorDeliverImmediately);
// cache this in a static variable so that MacOSFontFamily objects // cache this in a static variable so that MacOSFontFamily objects
// don't have to repeatedly look it up // don't have to repeatedly look it up
@ -670,19 +672,8 @@ gfxMacPlatformFontList::InitFontList()
{ {
nsAutoreleasePool localPool; nsAutoreleasePool localPool;
ATSGeneration currentGeneration = ::ATSGetGeneration();
// need to ignore notifications after adding each font
if (mATSGeneration == currentGeneration)
return NS_OK;
Telemetry::AutoTimer<Telemetry::MAC_INITFONTLIST_TOTAL> timer; Telemetry::AutoTimer<Telemetry::MAC_INITFONTLIST_TOTAL> timer;
mATSGeneration = currentGeneration;
#ifdef PR_LOGGING
LOG_FONTLIST(("(fontlist) updating to generation: %d", mATSGeneration));
#endif
// reset font lists // reset font lists
gfxPlatformFontList::InitFontList(); gfxPlatformFontList::InitFontList();
@ -777,11 +768,18 @@ gfxMacPlatformFontList::GetStandardFamilyName(const nsAString& aFontName, nsAStr
} }
void void
gfxMacPlatformFontList::ATSNotification(ATSFontNotificationInfoRef aInfo, gfxMacPlatformFontList::RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center,
void* aUserArg) 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 // xxx - should be carefully pruning the list of fonts, not rebuilding it from scratch
static_cast<gfxMacPlatformFontList*>(aUserArg)->UpdateFontList(); static_cast<gfxMacPlatformFontList*>(observer)->UpdateFontList();
// modify a preference that will trigger reflow everywhere // modify a preference that will trigger reflow everywhere
static const char kPrefName[] = "font.internaluseonly.changed"; static const char kPrefName[] = "font.internaluseonly.changed";