Bug 184657 - GFX should use the newer nsIPrefService APIs instead of nsIPref. r=roc. sr=vladimir

This commit is contained in:
Makoto Kato 2009-04-04 18:43:42 +09:00
parent e79293b2c0
commit ac4e7cb6a8
7 changed files with 96 additions and 64 deletions

View File

@ -38,7 +38,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsIServiceManager.h"
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsCRT.h"
#include "nsThebesDeviceContext.h"
@ -178,8 +178,8 @@ nsThebesDeviceContext::SetDPI()
// If it's positive, we use it as the logical resolution
nsresult rv;
PRInt32 prefDPI;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && prefs) {
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
rv = prefs->GetIntPref("layout.css.dpi", &prefDPI);
if (NS_FAILED(rv)) {
prefDPI = -1;

View File

@ -122,6 +122,8 @@ public:
PRBool GetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> > *array);
void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> >& array);
void ClearPrefFonts() { mPrefFonts.Clear(); }
typedef nsDataHashtable<nsStringHashKey, nsRefPtr<FontFamily> > FontTable;
#ifdef MOZ_FT2_FONTS

View File

@ -37,7 +37,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsServiceManagerUtils.h"
#include "nsReadableUtils.h"
#include "nsExpirationTracker.h"
@ -937,8 +937,7 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
const PRUnichar kDoubleQuote = PRUnichar('\"');
const PRUnichar kComma = PRUnichar(',');
nsCOMPtr<nsIPref> prefs;
prefs = do_GetService(NS_PREF_CONTRACTID);
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
nsPromiseFlatString families(aFamilies);
const PRUnichar *p, *p_end;
@ -947,6 +946,7 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
nsAutoString family;
nsCAutoString lcFamily;
nsAutoString genericFamily;
nsXPIDLCString value;
nsCAutoString lang(aLangGroup);
if (lang.IsEmpty())
lang.Assign("x-unicode"); // XXX or should use "x-user-def"?
@ -1003,11 +1003,10 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
// prefs file always uses (must use) UTF-8 so that we can use
// |GetCharPref| and treat the result as a UTF-8 string.
nsXPIDLString value;
nsresult rv = prefs->CopyUnicharPref(prefName.get(), getter_Copies(value));
nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
if (NS_SUCCEEDED(rv)) {
CopyASCIItoUTF16(lcFamily, genericFamily);
family = value;
CopyUTF8toUTF16(value, family);
}
} else {
generic = PR_FALSE;
@ -1047,10 +1046,10 @@ gfxFontGroup::ForEachFontInternal(const nsAString& aFamilies,
prefName.Append(lcFamily);
prefName.AppendLiteral(".");
prefName.Append(aLangGroup);
nsXPIDLString value;
nsresult rv = prefs->CopyUnicharPref(prefName.get(), getter_Copies(value));
nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
if (NS_SUCCEEDED(rv)) {
ForEachFontInternal(value, lang, PR_FALSE, aResolveFontName,
ForEachFontInternal(NS_ConvertUTF8toUTF16(value),
lang, PR_FALSE, aResolveFontName,
fc, closure);
}
}

View File

@ -58,7 +58,6 @@
#include "gfxTextRunWordCache.h"
#include "gfxUserFontSet.h"
#include "nsIPref.h"
#include "nsServiceManagerUtils.h"
#include "nsTArray.h"
@ -344,45 +343,43 @@ AppendGenericFontFromPref(nsString& aFonts, const char *aLangGroup, const char *
{
nsresult rv;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs)
return;
nsCAutoString prefName;
nsXPIDLString nameValue, nameListValue;
nsXPIDLCString nameValue, nameListValue;
nsXPIDLString genericName;
nsCAutoString genericDotLang;
if (aGenericName) {
genericName = NS_ConvertASCIItoUTF16(aGenericName);
genericDotLang.Assign(aGenericName);
} else {
prefName.AssignLiteral("font.default.");
prefName.Append(aLangGroup);
prefs->CopyUnicharPref(prefName.get(), getter_Copies(genericName));
prefs->GetCharPref(prefName.get(), getter_Copies(genericDotLang));
}
nsCAutoString genericDotLang;
genericDotLang.Assign(NS_ConvertUTF16toUTF8(genericName));
genericDotLang.AppendLiteral(".");
genericDotLang.Append(aLangGroup);
// fetch font.name.xxx value
prefName.AssignLiteral("font.name.");
prefName.Append(genericDotLang);
rv = prefs->CopyUnicharPref(prefName.get(), getter_Copies(nameValue));
rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameValue));
if (NS_SUCCEEDED(rv)) {
if (!aFonts.IsEmpty())
aFonts.AppendLiteral(", ");
aFonts.Append(nameValue);
aFonts.Append(NS_ConvertUTF8toUTF16(nameValue));
}
// fetch font.name-list.xxx value
prefName.AssignLiteral("font.name-list.");
prefName.Append(genericDotLang);
rv = prefs->CopyUnicharPref(prefName.get(), getter_Copies(nameListValue));
rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameListValue));
if (NS_SUCCEEDED(rv) && !nameListValue.Equals(nameValue)) {
if (!aFonts.IsEmpty())
aFonts.AppendLiteral(", ");
aFonts.Append(nameListValue);
aFonts.Append(NS_ConvertUTF8toUTF16(nameListValue));
}
}
@ -401,7 +398,7 @@ PRBool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangAr
{
nsresult rv;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs)
return PR_FALSE;
@ -412,33 +409,31 @@ PRBool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangAr
const char *langGroup = GetPrefLangName(prefLang);
nsCAutoString prefName;
nsXPIDLString nameValue, nameListValue;
nsXPIDLString genericName;
prefName.AssignLiteral("font.default.");
prefName.Append(langGroup);
prefs->CopyUnicharPref(prefName.get(), getter_Copies(genericName));
nsXPIDLCString nameValue, nameListValue;
nsCAutoString genericDotLang;
genericDotLang.Assign(NS_ConvertUTF16toUTF8(genericName));
prefName.AssignLiteral("font.default.");
prefName.Append(langGroup);
prefs->GetCharPref(prefName.get(), getter_Copies(genericDotLang));
genericDotLang.AppendLiteral(".");
genericDotLang.Append(langGroup);
// fetch font.name.xxx value
prefName.AssignLiteral("font.name.");
prefName.Append(genericDotLang);
rv = prefs->CopyUnicharPref(prefName.get(), getter_Copies(nameValue));
rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameValue));
if (NS_SUCCEEDED(rv)) {
if (!aCallback(prefLang, nameValue, aClosure))
if (!aCallback(prefLang, NS_ConvertUTF8toUTF16(nameValue), aClosure))
return PR_FALSE;
}
// fetch font.name-list.xxx value
prefName.AssignLiteral("font.name-list.");
prefName.Append(genericDotLang);
rv = prefs->CopyUnicharPref(prefName.get(), getter_Copies(nameListValue));
rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameListValue));
if (NS_SUCCEEDED(rv) && !nameListValue.Equals(nameValue)) {
if (!aCallback(prefLang, nameListValue, aClosure))
if (!aCallback(prefLang, NS_ConvertUTF8toUTF16(nameListValue), aClosure))
return PR_FALSE;
}
}

View File

@ -213,6 +213,8 @@ public:
PRBool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName);
void UpdateFontList() { InitFontList(); }
void ClearPrefFonts() { mPrefFonts.Clear(); }
void GetFontFamilyList(nsTArray<nsRefPtr<MacOSFamilyEntry> >& aFamilyArray);
MacOSFontEntry* FindFontForChar(const PRUint32 aCh, gfxFont *aPrevFont);
@ -272,7 +274,6 @@ private:
void GenerateFontListKey(const nsAString& aKeyName, nsAString& aResult);
static void ATSNotification(ATSFontNotificationInfoRef aInfo, void* aUserArg);
static int PrefChangedCallback(const char *aPrefName, void *closure);
static PLDHashOperator
HashEnumFuncForFamilies(nsStringHashKey::KeyType aKey,

View File

@ -47,7 +47,8 @@
#include "gfxAtsuiFonts.h"
#include "gfxUserFontSet.h"
#include "nsIPref.h" // for pref changes callback notification
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h" // for pref changes callback notification
#include "nsServiceManagerUtils.h"
#include "nsTArray.h"
@ -106,6 +107,26 @@ static NSString* GetNSStringForString(const nsAString& aSrc)
static PRLogModuleInfo *gFontInfoLog = PR_NewLogModule("fontInfoLog");
class gfxQuartzFontCachePrefObserver : public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
};
NS_IMPL_ISUPPORTS1(gfxQuartzFontCachePrefObserver, nsIObserver)
NS_IMETHODIMP
gfxQuartzFontCachePrefObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
NS_ASSERTION(!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID), "invalid topic");
// XXX this could be made to only clear out the cache for the prefs that were changed
// but it probably isn't that big a deal.
gfxQuartzFontCache::SharedFontCache()->ClearPrefFonts();
return NS_OK;
}
void
gfxQuartzFontCache::GenerateFontListKey(const nsAString& aKeyName, nsAString& aResult)
{
@ -695,11 +716,17 @@ gfxQuartzFontCache::gfxQuartzFontCache()
(void*)this, nsnull);
// pref changes notification setup
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
pref->RegisterCallback("font.", PrefChangedCallback, this);
pref->RegisterCallback("font.name-list.", PrefChangedCallback, this);
pref->RegisterCallback("intl.accept_languages", PrefChangedCallback, this); // hmmmm...
gfxQuartzFontCachePrefObserver *observer = new gfxQuartzFontCachePrefObserver();
if (observer) {
nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (pref) {
pref->AddObserver("font.", observer, PR_FALSE);
pref->AddObserver("font.name-list.", observer, PR_FALSE);
pref->AddObserver("intl.accept_languages", observer, PR_FALSE); // hmmmm...
} else {
delete observer;
}
}
}
const PRUint32 kNonNormalTraits = NSItalicFontMask | NSBoldFontMask | NSNarrowFontMask | NSExpandedFontMask | NSCondensedFontMask | NSCompressedFontMask;
@ -1088,16 +1115,6 @@ gfxQuartzFontCache::ATSNotification(ATSFontNotificationInfoRef aInfo,
qfc->UpdateFontList();
}
int PR_CALLBACK
gfxQuartzFontCache::PrefChangedCallback(const char *aPrefName, void *closure)
{
// XXX this could be made to only clear out the cache for the prefs that were changed
// but it probably isn't that big a deal.
gfxQuartzFontCache *qfc = static_cast<gfxQuartzFontCache *>(closure);
qfc->mPrefFonts.Clear();
return 0;
}
MacOSFontEntry*
gfxQuartzFontCache::GetDefaultFont(const gfxFontStyle* aStyle, PRBool& aNeedsBold)
{

View File

@ -45,7 +45,8 @@
#include "nsUnicharUtils.h"
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsServiceManagerUtils.h"
#include "nsTArray.h"
@ -89,14 +90,24 @@ BuildKeyNameFromFontName(nsAString &aName)
ToLowerCase(aName);
}
int
gfxWindowsPlatform::PrefChangedCallback(const char *aPrefName, void *closure)
class gfxWindowsPlatformPrefObserver : public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
};
NS_IMPL_ISUPPORTS1(gfxWindowsPlatformPrefObserver, nsIObserver)
NS_IMETHODIMP
gfxWindowsPlatformPrefObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
NS_ASSERTION(!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID), "invalid topic");
// XXX this could be made to only clear out the cache for the prefs that were changed
// but it probably isn't that big a deal.
gfxWindowsPlatform *plat = static_cast<gfxWindowsPlatform *>(closure);
plat->mPrefFonts.Clear();
return 0;
gfxWindowsPlatform::GetPlatform()->ClearPrefFonts();
return NS_OK;
}
gfxWindowsPlatform::gfxWindowsPlatform()
@ -115,11 +126,18 @@ gfxWindowsPlatform::gfxWindowsPlatform()
UpdateFontList();
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
pref->RegisterCallback("font.", PrefChangedCallback, this);
pref->RegisterCallback("font.name-list.", PrefChangedCallback, this);
pref->RegisterCallback("intl.accept_languages", PrefChangedCallback, this);
// don't bother unregistering. We'll get shutdown after the pref service
gfxWindowsPlatformPrefObserver *observer = new gfxWindowsPlatformPrefObserver();
if (observer) {
nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (pref) {
pref->AddObserver("font.", observer, PR_FALSE);
pref->AddObserver("font.name-list.", observer, PR_FALSE);
pref->AddObserver("intl.accept_languages", observer, PR_FALSE);
// don't bother unregistering. We'll get shutdown after the pref service
} else {
delete observer;
}
}
}
gfxWindowsPlatform::~gfxWindowsPlatform()