Bug 1318618 - Support nsCString data type in gfxPrefs; r=dvander

MozReview-Commit-ID: w5051nuVR5

--HG--
extra : rebase_source : 3af34967b0c9c432c6b77014479be98bd0f54387
This commit is contained in:
Daosheng Mu 2016-11-23 09:38:02 +08:00
Родитель f33e5256c6
Коммит ab3dd3ce52
3 изменённых файлов: 41 добавлений и 0 удалений

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

@ -25,6 +25,7 @@ union GfxPrefValue {
int32_t;
uint32_t;
float;
nsCString;
};
struct GfxPrefSetting {

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

@ -158,6 +158,14 @@ void gfxPrefs::PrefAddVarCache(float* aVariable,
Preferences::AddFloatVarCache(aVariable, aPref, aDefault);
}
void gfxPrefs::PrefAddVarCache(std::string* aVariable,
const char* aPref,
std::string aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetCString(aPref, aVariable->c_str());
}
bool gfxPrefs::PrefGet(const char* aPref, bool aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -182,6 +190,16 @@ float gfxPrefs::PrefGet(const char* aPref, float aDefault)
return Preferences::GetFloat(aPref, aDefault);
}
std::string gfxPrefs::PrefGet(const char* aPref, std::string aDefault)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
nsAdoptingCString result;
Preferences::GetCString(aPref, &result);
return result.get();
}
void gfxPrefs::PrefSet(const char* aPref, bool aValue)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
@ -206,6 +224,12 @@ void gfxPrefs::PrefSet(const char* aPref, float aValue)
Preferences::SetFloat(aPref, aValue);
}
void gfxPrefs::PrefSet(const char* aPref, std::string aValue)
{
MOZ_ASSERT(IsPrefsServiceAvailable());
Preferences::SetCString(aPref, aValue.c_str());
}
static void
OnGfxPrefChanged(const char* aPrefname, void* aClosure)
{
@ -246,6 +270,11 @@ void gfxPrefs::CopyPrefValue(const float* aValue, GfxPrefValue* aOutValue)
*aOutValue = *aValue;
}
void gfxPrefs::CopyPrefValue(const std::string* aValue, GfxPrefValue* aOutValue)
{
*aOutValue = nsCString(aValue->c_str());
}
void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, bool* aOutValue)
{
*aOutValue = aValue->get_bool();
@ -265,3 +294,8 @@ void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, float* aOutValue)
{
*aOutValue = aValue->get_float();
}
void gfxPrefs::CopyPrefValue(const GfxPrefValue* aValue, std::string* aOutValue)
{
*aOutValue = aValue->get_nsCString().get();
}

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

@ -8,6 +8,7 @@
#include <cmath> // for M_PI
#include <stdint.h>
#include <string>
#include "mozilla/Assertions.h"
#include "mozilla/Function.h"
#include "mozilla/gfx/LoggingConstants.h"
@ -642,14 +643,17 @@ private:
static void PrefAddVarCache(int32_t*, const char*, int32_t);
static void PrefAddVarCache(uint32_t*, const char*, uint32_t);
static void PrefAddVarCache(float*, const char*, float);
static void PrefAddVarCache(std::string*, const char*, std::string);
static bool PrefGet(const char*, bool);
static int32_t PrefGet(const char*, int32_t);
static uint32_t PrefGet(const char*, uint32_t);
static float PrefGet(const char*, float);
static std::string PrefGet(const char*, std::string);
static void PrefSet(const char* aPref, bool aValue);
static void PrefSet(const char* aPref, int32_t aValue);
static void PrefSet(const char* aPref, uint32_t aValue);
static void PrefSet(const char* aPref, float aValue);
static void PrefSet(const char* aPref, std::string aValue);
static void WatchChanges(const char* aPrefname, Pref* aPref);
static void UnwatchChanges(const char* aPrefname, Pref* aPref);
// Creating these to avoid having to include PGPU.h in the .h
@ -657,10 +661,12 @@ private:
static void CopyPrefValue(const int32_t* aValue, GfxPrefValue* aOutValue);
static void CopyPrefValue(const uint32_t* aValue, GfxPrefValue* aOutValue);
static void CopyPrefValue(const float* aValue, GfxPrefValue* aOutValue);
static void CopyPrefValue(const std::string* aValue, GfxPrefValue* aOutValue);
static void CopyPrefValue(const GfxPrefValue* aValue, bool* aOutValue);
static void CopyPrefValue(const GfxPrefValue* aValue, int32_t* aOutValue);
static void CopyPrefValue(const GfxPrefValue* aValue, uint32_t* aOutValue);
static void CopyPrefValue(const GfxPrefValue* aValue, float* aOutValue);
static void CopyPrefValue(const GfxPrefValue* aValue, std::string* aOutValue);
static void AssertMainThread();