Backed out 5 changesets (bug 1496486) for valgrind bustages. CLOSED TREE

Backed out changeset d2f1e35ee4b7 (bug 1496486)
Backed out changeset 7f843f4ee162 (bug 1496486)
Backed out changeset 2f629a60f12c (bug 1496486)
Backed out changeset 4dd15fa31474 (bug 1496486)
Backed out changeset e8d8e2f3f00b (bug 1496486)
This commit is contained in:
Narcis Beleuzu 2018-10-09 19:44:51 +03:00
parent 115b6f10ca
commit e7a8994c37
31 changed files with 1115 additions and 645 deletions

View File

@ -294,7 +294,7 @@ cbindgen = check_prog('CBINDGEN', add_rustup_path('cbindgen'), paths=toolchain_s
@checking('cbindgen version')
@imports(_from='textwrap', _import='dedent')
def cbindgen_version(cbindgen):
cbindgen_min_version = Version('0.6.4')
cbindgen_min_version = Version('0.6.2')
# cbindgen x.y.z
version = Version(check_cmd_output(cbindgen, '--version').strip().split(" ")[1])

View File

@ -275,16 +275,6 @@ public:
return FontStretch(kUltraExpanded);
}
// The style system represents percentages in the 0.0..1.0 range, and
// FontStretch does it in the 0.0..100.0 range.
//
// TODO(emilio): We should consider changing this class to deal with the same
// range as the style system.
static FontStretch FromStyle(float aStylePercentage)
{
return FontStretch(std::min(aStylePercentage * 100.0f, float(kMax)));
}
bool IsNormal() const { return mValue == kNormal; }
float Percentage() const { return ToFloat(); }

View File

@ -41,6 +41,12 @@
#define NS_FONT_SYNTHESIS_WEIGHT 0x1
#define NS_FONT_SYNTHESIS_STYLE 0x2
#define NS_FONT_DISPLAY_AUTO 0
#define NS_FONT_DISPLAY_BLOCK 1
#define NS_FONT_DISPLAY_SWAP 2
#define NS_FONT_DISPLAY_FALLBACK 3
#define NS_FONT_DISPLAY_OPTIONAL 4
#define NS_FONT_OPTICAL_SIZING_AUTO 0
#define NS_FONT_OPTICAL_SIZING_NONE 1

View File

@ -112,7 +112,7 @@ gfxUserFontEntry::gfxUserFontEntry(gfxUserFontSet* aFontSet,
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
: gfxFontEntry(NS_LITERAL_CSTRING("userfont")),
mUserFontLoadState(STATUS_NOT_LOADED),
@ -152,7 +152,7 @@ gfxUserFontEntry::Matches(const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
{
return Weight() == aWeight &&
@ -953,7 +953,7 @@ gfxUserFontSet::FindOrCreateUserFontEntry(
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
{
RefPtr<gfxUserFontEntry> entry;
@ -996,7 +996,7 @@ gfxUserFontSet::FindExistingUserFontEntry(
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
{
nsTArray<RefPtr<gfxFontEntry>>& fontList = aFamily->GetFontList();
@ -1042,7 +1042,7 @@ gfxUserFontSet::AddUserFontEntry(const nsCString& aFamilyName,
(aUserFontEntry->IsOblique() ? "oblique" : "normal")),
weightString.get(),
stretchString.get(),
static_cast<int>(aUserFontEntry->GetFontDisplay())));
aUserFontEntry->GetFontDisplay()));
}
}

View File

@ -17,7 +17,6 @@
#include "nsIScriptError.h"
#include "nsURIHashKey.h"
#include "mozilla/FontPropertyTypes.h"
#include "mozilla/ServoStyleConsts.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "gfxFontConstants.h"
@ -245,7 +244,7 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
mozilla::StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags) = 0;
// creates a font face for the specified family, or returns an existing
@ -260,7 +259,7 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
mozilla::StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags);
// add in a font face for which we have the gfxUserFontEntry already
@ -516,7 +515,7 @@ protected:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
mozilla::StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags);
// creates a new gfxUserFontFamily in mFontFamilies, or returns an existing
@ -567,7 +566,7 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
mozilla::StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags);
virtual ~gfxUserFontEntry();
@ -581,7 +580,7 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
mozilla::StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags);
gfxFont* CreateFontInstance(const gfxFontStyle* aFontStyle) override;
@ -618,7 +617,7 @@ public:
return mCharacterMap.get();
}
mozilla::StyleFontDisplay GetFontDisplay() const { return mFontDisplay; }
uint8_t GetFontDisplay() const { return mFontDisplay; }
// load the font - starts the loading of sources which continues until
// a valid font resource is found or all sources fail
@ -723,8 +722,8 @@ protected:
};
FontDataLoadingState mFontDataLoadingState;
bool mUnsupportedFormat;
mozilla::StyleFontDisplay mFontDisplay; // timing of userfont fallback
bool mUnsupportedFormat;
uint8_t mFontDisplay; // timing of userfont fallback
RefPtr<gfxFontEntry> mPlatformFontEntry;
nsTArray<gfxFontFaceSrc> mSrcList;

View File

@ -10125,6 +10125,100 @@ nsLayoutUtils::ComputeSystemFont(nsFont* aSystemFont, LookAndFeel::FontID aFontI
}
}
static inline void
AssertValidFontTag(const nsString& aString)
{
// To be valid as a font feature tag, a string MUST be:
MOZ_ASSERT(aString.Length() == 4 && // (1) exactly 4 chars long
NS_IsAscii(aString.BeginReading()) && // (2) entirely ASCII
isprint(aString[0]) && // (3) all printable chars
isprint(aString[1]) &&
isprint(aString[2]) &&
isprint(aString[3]));
}
/* static */ void
nsLayoutUtils::ComputeFontFeatures(const nsCSSValuePairList *aFeaturesList,
nsTArray<gfxFontFeature>& aFeatureSettings)
{
aFeatureSettings.Clear();
for (const nsCSSValuePairList* p = aFeaturesList; p; p = p->mNext) {
gfxFontFeature feat;
MOZ_ASSERT(aFeaturesList->mXValue.GetUnit() == eCSSUnit_String,
"unexpected value unit");
// tag is a 4-byte ASCII sequence
nsAutoString tag;
p->mXValue.GetStringValue(tag);
AssertValidFontTag(tag);
if (tag.Length() != 4) {
continue;
}
// parsing validates that these are ASCII chars
// tags are always big-endian
feat.mTag = (tag[0] << 24) | (tag[1] << 16) | (tag[2] << 8) | tag[3];
// value
NS_ASSERTION(p->mYValue.GetUnit() == eCSSUnit_Integer,
"should have found an integer unit");
feat.mValue = p->mYValue.GetIntValue();
aFeatureSettings.AppendElement(feat);
}
}
/* static */ void
nsLayoutUtils::ComputeFontVariations(const nsCSSValuePairList* aVariationsList,
nsTArray<gfxFontVariation>& aVariationSettings)
{
aVariationSettings.Clear();
for (const nsCSSValuePairList* p = aVariationsList; p; p = p->mNext) {
gfxFontVariation var;
MOZ_ASSERT(aVariationsList->mXValue.GetUnit() == eCSSUnit_String,
"unexpected value unit");
// tag is a 4-byte ASCII sequence
nsAutoString tag;
p->mXValue.GetStringValue(tag);
AssertValidFontTag(tag);
if (tag.Length() != 4) {
continue;
}
// parsing validates that these are ASCII chars
// tags are always big-endian
var.mTag = (tag[0] << 24) | (tag[1] << 16) | (tag[2] << 8) | tag[3];
// value
NS_ASSERTION(p->mYValue.GetUnit() == eCSSUnit_Number,
"should have found a number unit");
var.mValue = p->mYValue.GetFloatValue();
aVariationSettings.AppendElement(var);
}
}
/* static */ uint32_t
nsLayoutUtils::ParseFontLanguageOverride(const nsAString& aLangTag)
{
if (!aLangTag.Length() || aLangTag.Length() > 4) {
return NO_FONT_LANGUAGE_OVERRIDE;
}
uint32_t index, result = 0;
for (index = 0; index < aLangTag.Length(); ++index) {
char16_t ch = aLangTag[index];
if (!nsCRT::IsAscii(ch)) { // valid tags are pure ASCII
return NO_FONT_LANGUAGE_OVERRIDE;
}
result = (result << 8) + ch;
}
while (index++ < 4) {
result = (result << 8) + 0x20;
}
return result;
}
/* static */ bool
nsLayoutUtils::ShouldHandleMetaViewport(nsIDocument* aDocument)
{

View File

@ -223,7 +223,23 @@ void
FontFace::GetFamily(nsString& aResult)
{
mFontFaceSet->FlushUserFontSet();
GetDesc(eCSSFontDesc_Family, aResult);
// Serialize the same way as in nsCSSFontFaceStyleDecl::GetPropertyValue.
nsCSSValue value;
GetDesc(eCSSFontDesc_Family, value);
aResult.Truncate();
if (value.GetUnit() == eCSSUnit_Null) {
return;
}
nsDependentString family(value.GetStringBufferValue());
if (!family.IsEmpty()) {
// The string length can be zero when the author passed an invalid
// family name or an invalid descriptor to the JS FontFace constructor.
nsStyleUtil::AppendEscapedCSSString(family, aResult);
}
}
void
@ -279,6 +295,10 @@ void
FontFace::GetUnicodeRange(nsString& aResult)
{
mFontFaceSet->FlushUserFontSet();
// There is no eCSSProperty_unicode_range for us to pass in to GetDesc
// to get a serialized (possibly defaulted) value, but that function
// doesn't use the property ID for this descriptor anyway.
GetDesc(eCSSFontDesc_UnicodeRange, aResult);
}
@ -586,6 +606,13 @@ FontFace::SetDescriptors(const nsAString& aFamily,
return true;
}
void
FontFace::GetDesc(nsCSSFontDesc aDescID, nsCSSValue& aResult) const
{
aResult.Reset();
Servo_FontFaceRule_GetDescriptor(GetData(), aDescID, &aResult);
}
void
FontFace::GetDesc(nsCSSFontDesc aDescID, nsString& aResult) const
{
@ -639,91 +666,19 @@ FontFace::SetUserFontEntry(gfxUserFontEntry* aEntry)
}
}
Maybe<StyleComputedFontWeightRange>
FontFace::GetFontWeight() const
{
StyleComputedFontWeightRange range;
if (!Servo_FontFaceRule_GetFontWeight(GetData(), &range)) {
return Nothing();
}
return Some(range);
}
Maybe<StyleComputedFontStretchRange>
FontFace::GetFontStretch() const
{
StyleComputedFontStretchRange range;
if (!Servo_FontFaceRule_GetFontStretch(GetData(), &range)) {
return Nothing();
}
return Some(range);
}
Maybe<StyleComputedFontStyleDescriptor>
FontFace::GetFontStyle() const
{
StyleComputedFontStyleDescriptor descriptor;
if (!Servo_FontFaceRule_GetFontStyle(GetData(), &descriptor)) {
return Nothing();
}
return Some(descriptor);
}
Maybe<StyleFontDisplay>
FontFace::GetFontDisplay() const
{
StyleFontDisplay display;
if (!Servo_FontFaceRule_GetFontDisplay(GetData(), &display)) {
return Nothing();
}
return Some(display);
}
Maybe<StyleFontLanguageOverride>
FontFace::GetFontLanguageOverride() const
{
StyleFontLanguageOverride langOverride;
if (!Servo_FontFaceRule_GetFontLanguageOverride(GetData(), &langOverride)) {
return Nothing();
}
return Some(langOverride);
}
bool
FontFace::HasLocalSrc() const
FontFace::GetFamilyName(nsCString& aResult)
{
AutoTArray<StyleFontFaceSourceListComponent, 8> components;
GetSources(components);
for (auto& component : components) {
if (component.tag == StyleFontFaceSourceListComponent::Tag::Local) {
return true;
}
nsCSSValue value;
GetDesc(eCSSFontDesc_Family, value);
if (value.GetUnit() == eCSSUnit_String) {
nsString familyname;
value.GetStringValue(familyname);
AppendUTF16toUTF8(familyname, aResult);
}
return false;
}
void
FontFace::GetFontFeatureSettings(nsTArray<gfxFontFeature>& aFeatures) const
{
Servo_FontFaceRule_GetFeatureSettings(GetData(), &aFeatures);
}
void
FontFace::GetFontVariationSettings(nsTArray<gfxFontVariation>& aVariations) const
{
Servo_FontFaceRule_GetVariationSettings(GetData(), &aVariations);
}
void
FontFace::GetSources(nsTArray<StyleFontFaceSourceListComponent>& aSources) const
{
Servo_FontFaceRule_GetSources(GetData(), &aSources);
}
nsAtom*
FontFace::GetFamilyName() const
{
return Servo_FontFaceRule_GetFamilyName(GetData());
return !aResult.IsEmpty();
}
void
@ -840,15 +795,19 @@ FontFace::GetUnicodeRangeAsCharacterMap()
return mUnicodeRange;
}
size_t len;
const StyleUnicodeRange* rangesPtr =
Servo_FontFaceRule_GetUnicodeRanges(GetData(), &len);
nsCSSValue val;
GetDesc(eCSSFontDesc_UnicodeRange, val);
Span<const StyleUnicodeRange> ranges(rangesPtr, len);
if (!ranges.IsEmpty()) {
if (val.GetUnit() == eCSSUnit_Array) {
mUnicodeRange = new gfxCharacterMap();
for (auto& range : ranges) {
mUnicodeRange->SetRange(range.start, range.end);
const nsCSSValue::Array& sources = *val.GetArrayValue();
MOZ_ASSERT(sources.Count() % 2 == 0,
"odd number of entries in a unicode-range: array");
for (uint32_t i = 0; i < sources.Count(); i += 2) {
uint32_t min = sources[i].GetIntValue();
uint32_t max = sources[i+1].GetIntValue();
mUnicodeRange->SetRange(min, max);
}
} else {
mUnicodeRange = nullptr;

View File

@ -9,9 +9,6 @@
#include "mozilla/dom/FontFaceBinding.h"
#include "mozilla/FontPropertyTypes.h"
#include "mozilla/Maybe.h"
#include "mozilla/Pair.h"
#include "mozilla/ServoStyleConsts.h"
#include "gfxUserFontSet.h"
#include "nsAutoPtr.h"
#include "nsCSSPropertyID.h"
@ -58,7 +55,7 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
: gfxUserFontEntry(aFontSet, aFontFaceSrcList, aWeight, aStretch,
aStyle, aFeatureSettings, aVariationSettings,
@ -90,15 +87,7 @@ public:
RawServoFontFaceRule* GetRule() { return mRule; }
bool HasLocalSrc() const;
Maybe<StyleComputedFontWeightRange> GetFontWeight() const;
Maybe<StyleComputedFontStretchRange> GetFontStretch() const;
Maybe<StyleComputedFontStyleDescriptor> GetFontStyle() const;
Maybe<StyleFontDisplay> GetFontDisplay() const;
void GetFontFeatureSettings(nsTArray<gfxFontFeature>&) const;
void GetFontVariationSettings(nsTArray<gfxFontVariation>&) const;
void GetSources(nsTArray<StyleFontFaceSourceListComponent>&) const;
Maybe<StyleFontLanguageOverride> GetFontLanguageOverride() const;
void GetDesc(nsCSSFontDesc aDescID, nsCSSValue& aResult) const;
gfxUserFontEntry* CreateUserFontEntry();
gfxUserFontEntry* GetUserFontEntry() const { return mUserFontEntry; }
@ -117,9 +106,9 @@ public:
/**
* Gets the family name of the FontFace as a raw string (such as 'Times', as
* opposed to GetFamily, which returns a CSS-escaped string, such as
* '"Times"'). Returns null if a valid family name was not available.
* '"Times"'). Returns whether a valid family name was available.
*/
nsAtom* GetFamilyName() const;
bool GetFamilyName(nsCString& aResult);
/**
* Returns whether this object is CSS-connected, i.e. reflecting an

View File

@ -211,9 +211,9 @@ FontFaceSet::ParseFontShorthandForMatching(
FontSlantStyle& aStyle,
ErrorResult& aRv)
{
StyleComputedFontStyleDescriptor style;
float stretch;
float weight;
nsCSSValue style;
nsCSSValue stretch;
nsCSSValue weight;
// FIXME(emilio): This Servo -> nsCSSValue -> Gecko conversion is stupid,
// Servo understands the font types.
@ -224,23 +224,30 @@ FontFaceSet::ParseFontShorthandForMatching(
return;
}
switch (style.tag) {
case StyleComputedFontStyleDescriptor::Tag::Normal:
switch (style.GetUnit()) {
case eCSSUnit_Normal:
aStyle = FontSlantStyle::Normal();
break;
case StyleComputedFontStyleDescriptor::Tag::Italic:
case eCSSUnit_Enumerated:
MOZ_ASSERT(style.GetIntValue() == NS_FONT_STYLE_ITALIC);
aStyle = FontSlantStyle::Italic();
break;
case StyleComputedFontStyleDescriptor::Tag::Oblique:
MOZ_ASSERT(style.oblique._0 == style.oblique._1,
"We use ComputedFontStyleDescriptor just for convenience, "
"the two values should always match");
aStyle = FontSlantStyle::Oblique(style.oblique._0);
case eCSSUnit_FontSlantStyle:
aStyle = style.GetFontSlantStyle();
break;
default:
MOZ_ASSERT_UNREACHABLE("Unknown unit for font-style");
}
aWeight = FontWeight(weight);
aStretch = FontStretch::FromStyle(stretch);
if (weight.GetUnit() == eCSSUnit_FontWeight) {
aWeight = weight.GetFontWeight();
} else {
MOZ_ASSERT(weight.GetUnit() == eCSSUnit_Enumerated);
aWeight = FontWeight(weight.GetIntValue());
}
MOZ_ASSERT(stretch.GetUnit() == eCSSUnit_FontStretch);
aStretch = stretch.GetFontStretch();
}
static bool
@ -826,6 +833,18 @@ FontFaceSet::UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules)
return modified;
}
static bool
HasLocalSrc(const nsCSSValue::Array *aSrcArr)
{
size_t numSrc = aSrcArr->Count();
for (size_t i = 0; i < numSrc; i++) {
if (aSrcArr->Item(i).GetUnit() == eCSSUnit_Local_Font) {
return true;
}
}
return false;
}
void
FontFaceSet::IncrementGeneration(bool aIsRebuild)
{
@ -837,21 +856,20 @@ void
FontFaceSet::InsertNonRuleFontFace(FontFace* aFontFace,
bool& aFontSetModified)
{
nsAtom* fontFamily = aFontFace->GetFamilyName();
if (!fontFamily) {
nsAutoCString fontfamily;
if (!aFontFace->GetFamilyName(fontfamily)) {
// If there is no family name, this rule cannot contribute a
// usable font, so there is no point in processing it further.
return;
}
nsAtomCString family(fontFamily);
// Just create a new font entry if we haven't got one already.
if (!aFontFace->GetUserFontEntry()) {
// XXX Should we be checking mUserFontSet->mLocalRulesUsed like
// InsertRuleFontFace does?
RefPtr<gfxUserFontEntry> entry =
FindOrCreateUserFontEntryFromFontFace(family, aFontFace, SheetType::Doc);
FindOrCreateUserFontEntryFromFontFace(fontfamily, aFontFace,
SheetType::Doc);
if (!entry) {
return;
}
@ -859,7 +877,7 @@ FontFaceSet::InsertNonRuleFontFace(FontFace* aFontFace,
}
aFontSetModified = true;
mUserFontSet->AddUserFontEntry(family, aFontFace->GetUserFontEntry());
mUserFontSet->AddUserFontEntry(fontfamily, aFontFace->GetUserFontEntry());
}
void
@ -867,8 +885,8 @@ FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
nsTArray<FontFaceRecord>& aOldRecords,
bool& aFontSetModified)
{
nsAtom* fontFamily = aFontFace->GetFamilyName();
if (!fontFamily) {
nsAutoCString fontfamily;
if (!aFontFace->GetFamilyName(fontfamily)) {
// If there is no family name, this rule cannot contribute a
// usable font, so there is no point in processing it further.
return;
@ -877,8 +895,6 @@ FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
bool remove = false;
size_t removeIndex;
nsAtomCString family(fontFamily);
// This is a rule backed FontFace. First, we check in aOldRecords; if
// the FontFace for the rule exists there, just move it to the new record
// list, and put the entry into the appropriate family.
@ -890,8 +906,12 @@ FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
// if local rules were used, don't use the old font entry
// for rules containing src local usage
if (mUserFontSet->mLocalRulesUsed && mUserFontSet->mRebuildLocalRules) {
if (aFontFace->HasLocalSrc()) {
if (mUserFontSet->mLocalRulesUsed &&
mUserFontSet->mRebuildLocalRules) {
nsCSSValue val;
aFontFace->GetDesc(eCSSFontDesc_Src, val);
nsCSSUnit unit = val.GetUnit();
if (unit == eCSSUnit_Array && HasLocalSrc(val.GetArrayValue())) {
// Remove the old record, but wait to see if we successfully create a
// new user font entry below.
remove = true;
@ -903,7 +923,7 @@ FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
gfxUserFontEntry* entry = rec.mFontFace->GetUserFontEntry();
MOZ_ASSERT(entry, "FontFace should have a gfxUserFontEntry by now");
mUserFontSet->AddUserFontEntry(family, entry);
mUserFontSet->AddUserFontEntry(fontfamily, entry);
MOZ_ASSERT(!HasRuleFontFace(rec.mFontFace),
"FontFace should not occur in mRuleFaces twice");
@ -921,7 +941,7 @@ FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
// this is a new rule:
RefPtr<gfxUserFontEntry> entry =
FindOrCreateUserFontEntryFromFontFace(family, aFontFace, aSheetType);
FindOrCreateUserFontEntryFromFontFace(fontfamily, aFontFace, aSheetType);
if (!entry) {
return;
@ -959,71 +979,117 @@ FontFaceSet::InsertRuleFontFace(FontFace* aFontFace, SheetType aSheetType,
// on the family, gfxUserFontFamily::AddFontEntry(), which AddUserFontEntry
// calls, will automatically remove the earlier occurrence of the same
// userfont entry.
mUserFontSet->AddUserFontEntry(family, entry);
mUserFontSet->AddUserFontEntry(fontfamily, entry);
}
/* static */ already_AddRefed<gfxUserFontEntry>
FontFaceSet::FindOrCreateUserFontEntryFromFontFace(FontFace* aFontFace)
{
nsAtom* fontFamily = aFontFace->GetFamilyName();
if (!fontFamily) {
nsAutoCString fontfamily;
if (!aFontFace->GetFamilyName(fontfamily)) {
// If there is no family name, this rule cannot contribute a
// usable font, so there is no point in processing it further.
return nullptr;
}
return FindOrCreateUserFontEntryFromFontFace(nsAtomCString(fontFamily), aFontFace,
return FindOrCreateUserFontEntryFromFontFace(fontfamily, aFontFace,
SheetType::Doc);
}
static FontWeight
GetWeightForDescriptor(const nsCSSValue& aVal)
{
switch (aVal.GetUnit()) {
case eCSSUnit_FontWeight:
return aVal.GetFontWeight();
case eCSSUnit_Enumerated:
return FontWeight(aVal.GetIntValue());
case eCSSUnit_Normal:
case eCSSUnit_Null:
return FontWeight::Normal();
default:
MOZ_ASSERT_UNREACHABLE("Unknown font-weight descriptor value");
return FontWeight::Normal();
}
}
static WeightRange
GetWeightRangeForDescriptor(const Maybe<StyleComputedFontWeightRange>& aVal,
GetWeightRangeForDescriptor(const nsCSSValue& aVal,
gfxFontEntry::RangeFlags& aRangeFlags)
{
if (!aVal) {
if (aVal.GetUnit() == eCSSUnit_Null) {
aRangeFlags |= gfxFontEntry::RangeFlags::eAutoWeight;
return WeightRange(FontWeight::Normal());
}
return WeightRange(FontWeight(aVal->_0), FontWeight(aVal->_1));
if (aVal.GetUnit() == eCSSUnit_Pair) {
return WeightRange(GetWeightForDescriptor(aVal.GetPairValue().mXValue),
GetWeightForDescriptor(aVal.GetPairValue().mYValue));
}
return WeightRange(GetWeightForDescriptor(aVal));
}
static FontSlantStyle
GetStyleForDescriptor(const nsCSSValue& aVal)
{
switch (aVal.GetUnit()) {
case eCSSUnit_Normal:
case eCSSUnit_Null:
return FontSlantStyle::Normal();
case eCSSUnit_Enumerated:
MOZ_ASSERT(aVal.GetIntValue() == NS_FONT_STYLE_ITALIC);
return FontSlantStyle::Italic();
case eCSSUnit_FontSlantStyle:
return aVal.GetFontSlantStyle();
default:
MOZ_ASSERT_UNREACHABLE("Unknown font-style descriptor value");
return FontSlantStyle::Normal();
}
}
static SlantStyleRange
GetStyleRangeForDescriptor(const Maybe<StyleComputedFontStyleDescriptor>& aVal,
GetStyleRangeForDescriptor(const nsCSSValue& aVal,
gfxFontEntry::RangeFlags& aRangeFlags)
{
if (!aVal) {
if (aVal.GetUnit() == eCSSUnit_Null) {
aRangeFlags |= gfxFontEntry::RangeFlags::eAutoSlantStyle;
return SlantStyleRange(FontSlantStyle::Normal());
}
auto& val = *aVal;
switch (val.tag) {
case StyleComputedFontStyleDescriptor::Tag::Normal:
return SlantStyleRange(FontSlantStyle::Normal());
case StyleComputedFontStyleDescriptor::Tag::Italic:
return SlantStyleRange(FontSlantStyle::Italic());
case StyleComputedFontStyleDescriptor::Tag::Oblique:
return SlantStyleRange(FontSlantStyle::Oblique(val.oblique._0),
FontSlantStyle::Oblique(val.oblique._1));
if (aVal.GetUnit() == eCSSUnit_Pair) {
return SlantStyleRange(GetStyleForDescriptor(aVal.GetPairValue().mXValue),
GetStyleForDescriptor(aVal.GetPairValue().mYValue));
}
return SlantStyleRange(GetStyleForDescriptor(aVal));
}
static FontStretch
GetStretchForDescriptor(const nsCSSValue& aVal)
{
switch (aVal.GetUnit()) {
case eCSSUnit_Null:
return FontStretch::Normal();
case eCSSUnit_FontStretch:
return aVal.GetFontStretch();
default:
MOZ_ASSERT_UNREACHABLE("Unknown font-style descriptor value");
return FontStretch::Normal();
}
MOZ_ASSERT_UNREACHABLE("How?");
return SlantStyleRange(FontSlantStyle::Normal());
}
static StretchRange
GetStretchRangeForDescriptor(const Maybe<StyleComputedFontStretchRange>& aVal,
GetStretchRangeForDescriptor(const nsCSSValue& aVal,
gfxFontEntry::RangeFlags& aRangeFlags)
{
if (!aVal) {
if (aVal.GetUnit() == eCSSUnit_Null) {
aRangeFlags |= gfxFontEntry::RangeFlags::eAutoStretch;
return StretchRange(FontStretch::Normal());
}
return StretchRange(FontStretch::FromStyle(aVal->_0),
FontStretch::FromStyle(aVal->_1));
if (aVal.GetUnit() == eCSSUnit_Pair) {
return StretchRange(GetStretchForDescriptor(aVal.GetPairValue().mXValue),
GetStretchForDescriptor(aVal.GetPairValue().mYValue));
}
return StretchRange(GetStretchForDescriptor(aVal));
}
// TODO(emilio): Should this take an nsAtom* aFamilyName instead?
//
// All callers have one handy.
/* static */ already_AddRefed<gfxUserFontEntry>
FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsACString& aFamilyName,
FontFace* aFontFace,
@ -1031,39 +1097,74 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsACString& aFamilyName
{
FontFaceSet* set = aFontFace->GetPrimaryFontFaceSet();
nsCSSValue val;
nsCSSUnit unit;
uint32_t languageOverride = NO_FONT_LANGUAGE_OVERRIDE;
StyleFontDisplay fontDisplay = StyleFontDisplay::Auto;
uint8_t fontDisplay = NS_FONT_DISPLAY_AUTO;
gfxFontEntry::RangeFlags rangeFlags = gfxFontEntry::RangeFlags::eNoFlags;
// set up weight
WeightRange weight =
GetWeightRangeForDescriptor(aFontFace->GetFontWeight(), rangeFlags);
aFontFace->GetDesc(eCSSFontDesc_Weight, val);
WeightRange weight = GetWeightRangeForDescriptor(val, rangeFlags);
// set up stretch
StretchRange stretch =
GetStretchRangeForDescriptor(aFontFace->GetFontStretch(), rangeFlags);
aFontFace->GetDesc(eCSSFontDesc_Stretch, val);
StretchRange stretch = GetStretchRangeForDescriptor(val, rangeFlags);
// set up font style
SlantStyleRange italicStyle =
GetStyleRangeForDescriptor(aFontFace->GetFontStyle(), rangeFlags);
aFontFace->GetDesc(eCSSFontDesc_Style, val);
SlantStyleRange italicStyle = GetStyleRangeForDescriptor(val, rangeFlags);
// set up font display
if (Maybe<StyleFontDisplay> display = aFontFace->GetFontDisplay()) {
fontDisplay = *display;
aFontFace->GetDesc(eCSSFontDesc_Display, val);
unit = val.GetUnit();
if (unit == eCSSUnit_Enumerated) {
fontDisplay = val.GetIntValue();
} else {
NS_ASSERTION(unit == eCSSUnit_Null,
"@font-face style has unexpected unit");
}
// set up font features
nsTArray<gfxFontFeature> featureSettings;
aFontFace->GetFontFeatureSettings(featureSettings);
aFontFace->GetDesc(eCSSFontDesc_FontFeatureSettings, val);
unit = val.GetUnit();
if (unit == eCSSUnit_Normal) {
// empty list of features
} else if (unit == eCSSUnit_PairList || unit == eCSSUnit_PairListDep) {
nsLayoutUtils::ComputeFontFeatures(val.GetPairListValue(), featureSettings);
} else {
NS_ASSERTION(unit == eCSSUnit_Null,
"@font-face font-feature-settings has unexpected unit");
}
// set up font variations
nsTArray<gfxFontVariation> variationSettings;
aFontFace->GetFontVariationSettings(variationSettings);
aFontFace->GetDesc(eCSSFontDesc_FontVariationSettings, val);
unit = val.GetUnit();
if (unit == eCSSUnit_Normal) {
// empty list of variations
} else if (unit == eCSSUnit_PairList || unit == eCSSUnit_PairListDep) {
nsLayoutUtils::ComputeFontVariations(val.GetPairListValue(), variationSettings);
} else {
NS_ASSERTION(unit == eCSSUnit_Null,
"@font-face font-variation-settings has unexpected unit");
}
// set up font language override
if (Maybe<StyleFontLanguageOverride> descriptor = aFontFace->GetFontLanguageOverride()) {
languageOverride = descriptor->_0;
aFontFace->GetDesc(eCSSFontDesc_FontLanguageOverride, val);
unit = val.GetUnit();
if (unit == eCSSUnit_Normal) {
// empty feature string
} else if (unit == eCSSUnit_String) {
nsString stringValue;
val.GetStringValue(stringValue);
languageOverride = nsLayoutUtils::ParseFontLanguageOverride(stringValue);
} else {
NS_ASSERTION(unit == eCSSUnit_Null,
"@font-face font-language-override has unexpected unit");
}
// set up unicode-range
@ -1081,27 +1182,38 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsACString& aFamilyName
face->mBuffer = aFontFace->CreateBufferSource();
face->mReferrerPolicy = mozilla::net::RP_Unset;
} else {
AutoTArray<StyleFontFaceSourceListComponent, 8> sourceListComponents;
aFontFace->GetSources(sourceListComponents);
size_t len = sourceListComponents.Length();
for (size_t i = 0; i < len; ++i) {
gfxFontFaceSrc* face = srcArray.AppendElement();
const auto& component = sourceListComponents[i];
switch (component.tag) {
case StyleFontFaceSourceListComponent::Tag::Local: {
nsAtom* atom = component.local._0;
face->mLocalName.Append(nsAtomCString(atom));
aFontFace->GetDesc(eCSSFontDesc_Src, val);
unit = val.GetUnit();
if (unit == eCSSUnit_Array) {
// Hold a strong reference because content of val is going away
// in the loop below.
RefPtr<nsCSSValue::Array> srcArr = val.GetArrayValue();
size_t numSrc = srcArr->Count();
for (size_t i = 0; i < numSrc; i++) {
val = srcArr->Item(i);
unit = val.GetUnit();
gfxFontFaceSrc* face = srcArray.AppendElements(1);
if (!face)
return nullptr;
switch (unit) {
case eCSSUnit_Local_Font: {
nsAutoString localName;
val.GetStringValue(localName);
face->mLocalName.Append(NS_ConvertUTF16toUTF8(localName));
face->mSourceType = gfxFontFaceSrc::eSourceType_Local;
face->mURI = nullptr;
face->mFormatFlags = 0;
face->mReferrerPolicy = mozilla::net::RP_Unset;
break;
}
case StyleFontFaceSourceListComponent::Tag::Url: {
case eCSSUnit_URL: {
face->mSourceType = gfxFontFaceSrc::eSourceType_URL;
const URLValue* url = component.url._0;
nsIURI* uri = url->GetURI();
nsIURI* uri = val.GetURLValue();
face->mURI = uri ? new gfxFontSrcURI(uri) : nullptr;
URLValue* url = val.GetURLStructValue();
face->mReferrer = url->mExtraData->GetReferrer();
face->mReferrerPolicy = url->mExtraData->GetReferrerPolicy();
face->mOriginPrincipal =
@ -1118,16 +1230,12 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsACString& aFamilyName
face->mLocalName.Truncate();
face->mFormatFlags = 0;
while (i + 1 < len) {
const auto& maybeFontFormat = sourceListComponents[i + 1];
if (maybeFontFormat.tag != StyleFontFaceSourceListComponent::Tag::FormatHint) {
while (i + 1 < numSrc) {
val = srcArr->Item(i + 1);
if (val.GetUnit() != eCSSUnit_Font_Format)
break;
}
nsDependentCSubstring valueString(
reinterpret_cast<const char*>(maybeFontFormat.format_hint.utf8_bytes),
maybeFontFormat.format_hint.length);
nsDependentString valueString(val.GetStringBufferValue());
if (valueString.LowerCaseEqualsASCII("woff")) {
face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_WOFF;
} else if (Preferences::GetBool(GFX_PREF_WOFF2_ENABLED) &&
@ -1171,10 +1279,14 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsACString& aFamilyName
}
break;
}
case StyleFontFaceSourceListComponent::Tag::FormatHint:
MOZ_ASSERT_UNREACHABLE("Should always come after a URL source, and be consumed already");
default:
NS_ASSERTION(unit == eCSSUnit_Local_Font || unit == eCSSUnit_URL,
"strange unit type in font-face src array");
break;
}
}
} else {
NS_ASSERTION(unit == eCSSUnit_Null, "@font-face src has unexpected unit");
}
}
@ -1940,7 +2052,7 @@ FontFaceSet::UserFontSet::CreateUserFontEntry(
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
{
RefPtr<gfxUserFontEntry> entry =

View File

@ -105,7 +105,7 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
StyleFontDisplay aFontDisplay,
uint8_t aFontDisplay,
RangeFlags aRangeFlags) override;
private:

View File

@ -376,35 +376,9 @@ SERVO_BINDING_FUNC(Servo_FontFaceRule_IndexGetter, nsCSSFontDesc,
RawServoFontFaceRuleBorrowed rule, uint32_t index)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetDeclCssText, void,
RawServoFontFaceRuleBorrowed rule, nsAString* result)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetFontWeight, bool,
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetDescriptor, void,
RawServoFontFaceRuleBorrowed rule,
mozilla::StyleComputedFontWeightRange* out)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetFontDisplay, bool,
RawServoFontFaceRuleBorrowed rule,
mozilla::StyleFontDisplay* out)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetFontStyle, bool,
RawServoFontFaceRuleBorrowed rule,
mozilla::StyleComputedFontStyleDescriptor* out)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetFontStretch, bool,
RawServoFontFaceRuleBorrowed rule,
mozilla::StyleComputedFontStretchRange* out)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetFontLanguageOverride, bool,
RawServoFontFaceRuleBorrowed rule,
mozilla::StyleFontLanguageOverride* out)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetFamilyName, nsAtom*,
RawServoFontFaceRuleBorrowed rule)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetUnicodeRanges, const mozilla::StyleUnicodeRange*,
RawServoFontFaceRuleBorrowed rule,
size_t* out_len)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetSources, void,
RawServoFontFaceRuleBorrowed rule,
nsTArray<mozilla::StyleFontFaceSourceListComponent>* components)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetVariationSettings, void,
RawServoFontFaceRuleBorrowed rule,
nsTArray<mozilla::gfx::FontVariation>* out)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetFeatureSettings, void,
RawServoFontFaceRuleBorrowed rule,
nsTArray<gfxFontFeature>* out)
nsCSSFontDesc desc, nsCSSValueBorrowedMut result)
SERVO_BINDING_FUNC(Servo_FontFaceRule_GetDescriptorCssText, void,
RawServoFontFaceRuleBorrowed rule,
nsCSSFontDesc desc, nsAString* result)
@ -907,11 +881,9 @@ SERVO_BINDING_FUNC(Servo_ParseFontShorthandForMatching, bool,
const nsAString* value,
RawGeckoURLExtraData* data,
RefPtr<SharedFontList>* family,
// We use ComputedFontStyleDescriptor just for convenience,
// but the two values of Oblique are the same.
mozilla::StyleComputedFontStyleDescriptor* style,
float* stretch,
float* weight);
nsCSSValueBorrowedMut style,
nsCSSValueBorrowedMut stretch,
nsCSSValueBorrowedMut weight);
SERVO_BINDING_FUNC(Servo_ResolveLogicalProperty,
nsCSSPropertyID,

View File

@ -2229,7 +2229,7 @@ Gecko_CSSValue_SetPixelLength(nsCSSValueBorrowedMut aCSSValue, float aLen)
void
Gecko_CSSValue_SetCalc(nsCSSValueBorrowedMut aCSSValue, nsStyleCoord::CalcValue aCalc)
{
aCSSValue->SetCalcValue(aCalc);
aCSSValue->SetCalcValue(&aCalc);
}
nsStyleCoord::CalcValue
@ -2280,6 +2280,13 @@ Gecko_CSSValue_SetArray(nsCSSValueBorrowedMut aCSSValue, int32_t aLength)
aCSSValue->SetArrayValue(array, eCSSUnit_Array);
}
void
Gecko_CSSValue_SetURL(nsCSSValueBorrowedMut aCSSValue, URLValue* aURL)
{
MOZ_ASSERT(aCSSValue->GetUnit() == eCSSUnit_Null);
aCSSValue->SetURLValue(aURL);
}
void
Gecko_CSSValue_SetInt(nsCSSValueBorrowedMut aCSSValue,
int32_t aInteger, nsCSSUnit aUnit)
@ -2358,6 +2365,29 @@ Gecko_CSSValue_Drop(nsCSSValueBorrowedMut aCSSValue)
aCSSValue->~nsCSSValue();
}
void
Gecko_CSSValue_SetFontStretch(nsCSSValueBorrowedMut aCSSValue,
float stretch)
{
aCSSValue->SetFontStretch(
FontStretch(std::min(stretch * 100.0f, float(FontStretch::kMax))));
}
// FIXME(emilio): This function should probably have `Oblique` in its name.
void
Gecko_CSSValue_SetFontSlantStyle(nsCSSValueBorrowedMut aCSSValue,
float aAngle)
{
aCSSValue->SetFontSlantStyle(mozilla::FontSlantStyle::Oblique(aAngle));
}
void
Gecko_CSSValue_SetFontWeight(nsCSSValueBorrowedMut aCSSValue,
float weight)
{
aCSSValue->SetFontWeight(mozilla::FontWeight(weight));
}
void
Gecko_nsStyleFont_SetLang(nsStyleFont* aFont, nsAtom* aAtom)
{

View File

@ -582,6 +582,9 @@ void Gecko_CSSValue_SetKeyword(nsCSSValueBorrowedMut css_value, nsCSSKeyword key
void Gecko_CSSValue_SetPercentage(nsCSSValueBorrowedMut css_value, float percent);
void Gecko_CSSValue_SetPixelLength(nsCSSValueBorrowedMut aCSSValue, float aLen);
void Gecko_CSSValue_SetCalc(nsCSSValueBorrowedMut css_value, nsStyleCoord::CalcValue calc);
void Gecko_CSSValue_SetFontStretch(nsCSSValueBorrowedMut css_value, float stretch);
void Gecko_CSSValue_SetFontSlantStyle(nsCSSValueBorrowedMut css_value, float style);
void Gecko_CSSValue_SetFontWeight(nsCSSValueBorrowedMut css_value, float weight);
void Gecko_CSSValue_SetFunction(nsCSSValueBorrowedMut css_value, int32_t len);
void Gecko_CSSValue_SetString(nsCSSValueBorrowedMut css_value,
const uint8_t* string, uint32_t len, nsCSSUnit unit);
@ -590,6 +593,7 @@ void Gecko_CSSValue_SetStringFromAtom(nsCSSValueBorrowedMut css_value,
// Take an addrefed nsAtom and set it to the nsCSSValue
void Gecko_CSSValue_SetAtomIdent(nsCSSValueBorrowedMut css_value, nsAtom* atom);
void Gecko_CSSValue_SetArray(nsCSSValueBorrowedMut css_value, int32_t len);
void Gecko_CSSValue_SetURL(nsCSSValueBorrowedMut css_value, mozilla::css::URLValue* uri);
void Gecko_CSSValue_SetInt(nsCSSValueBorrowedMut css_value, int32_t integer, nsCSSUnit unit);
void Gecko_CSSValue_SetFloat(nsCSSValueBorrowedMut css_value, float value, nsCSSUnit unit);
void Gecko_CSSValue_SetPair(nsCSSValueBorrowedMut css_value,

View File

@ -263,15 +263,6 @@ whitelist-types = [
"mozilla::gfx::Float",
"mozilla::gfx::FontVariation",
"mozilla::StyleImageLayerAttachment",
"mozilla::StyleComputedFontStretchRange",
"mozilla::StyleComputedFontStyleDescriptor",
"mozilla::StyleComputedFontWeightRange",
"mozilla::StyleFontDisplay",
"mozilla::StyleUnicodeRange",
"mozilla::StyleFontLanguageOverride",
"mozilla::StyleFontFaceSourceListComponent",
"gfxFontFeature",
"gfxFontVariation",
".*ThreadSafe.*Holder",
"AnonymousContent",
"AudioContext",
@ -287,7 +278,9 @@ whitelist-types = [
"GeckoParserExtraData",
"GeckoFontMetrics",
"gfxAlternateValue",
"gfxFontFeature",
"gfxFontFeatureValueSet",
"gfxFontVariation",
"GridNamedArea",
"mozilla::HalfCorner",
"Image",
@ -496,15 +489,6 @@ structs-types = [
"mozilla::StyleMotion",
"mozilla::UniquePtr",
"mozilla::StyleDisplayMode",
"mozilla::StyleComputedFontStretchRange",
"mozilla::StyleComputedFontStyleDescriptor",
"mozilla::StyleComputedFontWeightRange",
"mozilla::StyleFontDisplay",
"mozilla::StyleUnicodeRange",
"mozilla::StyleFontLanguageOverride",
"mozilla::StyleFontFaceSourceListComponent",
"gfxFontFeature",
"mozilla::gfx::FontVariation",
"ServoRawOffsetArc",
"DeclarationBlockMutationClosure",
"nsAttrValue",

View File

@ -70,9 +70,9 @@ ServoCSSParser::ParseTransformIntoMatrix(const nsAString& aValue,
ServoCSSParser::ParseFontShorthandForMatching(const nsAString& aValue,
URLExtraData* aUrl,
RefPtr<SharedFontList>& aList,
StyleComputedFontStyleDescriptor& aStyle,
float& aStretch,
float& aWeight)
nsCSSValue& aStyle,
nsCSSValue& aStretch,
nsCSSValue& aWeight)
{
return Servo_ParseFontShorthandForMatching(&aValue, aUrl, &aList,
&aStyle, &aStretch, &aWeight);

View File

@ -130,9 +130,9 @@ public:
static bool ParseFontShorthandForMatching(const nsAString& aValue,
URLExtraData* aUrl,
RefPtr<SharedFontList>& aList,
StyleComputedFontStyleDescriptor& aStyle,
float& aStretch,
float& aWeight);
nsCSSValue& aStyle,
nsCSSValue& aStretch,
nsCSSValue& aWeight);
/**
* Get a URLExtraData from |nsIDocument|.

View File

@ -81,6 +81,20 @@ nsCSSValue::nsCSSValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
mValue.mArray->AddRef();
}
nsCSSValue::nsCSSValue(mozilla::css::URLValue* aValue)
: mUnit(eCSSUnit_URL)
{
mValue.mURL = aValue;
mValue.mURL->AddRef();
}
nsCSSValue::nsCSSValue(mozilla::css::GridTemplateAreasValue* aValue)
: mUnit(eCSSUnit_GridTemplateAreas)
{
mValue.mGridTemplateAreas = aValue;
mValue.mGridTemplateAreas->AddRef();
}
nsCSSValue::nsCSSValue(SharedFontList* aValue)
: mUnit(eCSSUnit_FontFamilyList)
{
@ -88,6 +102,24 @@ nsCSSValue::nsCSSValue(SharedFontList* aValue)
mValue.mFontFamilyList->AddRef();
}
nsCSSValue::nsCSSValue(FontStretch aStretch)
: mUnit(eCSSUnit_FontStretch)
{
mValue.mFontStretch = aStretch;
}
nsCSSValue::nsCSSValue(FontSlantStyle aStyle)
: mUnit(eCSSUnit_FontSlantStyle)
{
mValue.mFontSlantStyle = aStyle;
}
nsCSSValue::nsCSSValue(FontWeight aWeight)
: mUnit(eCSSUnit_FontWeight)
{
mValue.mFontWeight = aWeight;
}
nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
: mUnit(aCopy.mUnit)
{
@ -109,6 +141,10 @@ nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
mValue.mArray = aCopy.mValue.mArray;
mValue.mArray->AddRef();
}
else if (eCSSUnit_URL == mUnit) {
mValue.mURL = aCopy.mValue.mURL;
mValue.mURL->AddRef();
}
else if (eCSSUnit_Pair == mUnit) {
mValue.mPair = aCopy.mValue.mPair;
mValue.mPair->AddRef();
@ -131,10 +167,23 @@ nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
else if (eCSSUnit_PairListDep == mUnit) {
mValue.mPairListDependent = aCopy.mValue.mPairListDependent;
}
else if (eCSSUnit_GridTemplateAreas == mUnit) {
mValue.mGridTemplateAreas = aCopy.mValue.mGridTemplateAreas;
mValue.mGridTemplateAreas->AddRef();
}
else if (eCSSUnit_FontFamilyList == mUnit) {
mValue.mFontFamilyList = aCopy.mValue.mFontFamilyList;
mValue.mFontFamilyList->AddRef();
}
else if (eCSSUnit_FontStretch == mUnit) {
mValue.mFontStretch = aCopy.mValue.mFontStretch;
}
else if (eCSSUnit_FontSlantStyle == mUnit) {
mValue.mFontSlantStyle = aCopy.mValue.mFontSlantStyle;
}
else if (eCSSUnit_FontWeight == mUnit) {
mValue.mFontWeight = aCopy.mValue.mFontWeight;
}
else if (eCSSUnit_AtomIdent == mUnit) {
mValue.mAtom = aCopy.mValue.mAtom;
mValue.mAtom->AddRef();
@ -188,6 +237,9 @@ bool nsCSSValue::operator==(const nsCSSValue& aOther) const
else if (UnitHasArrayValue()) {
return *mValue.mArray == *aOther.mValue.mArray;
}
else if (eCSSUnit_URL == mUnit) {
return mValue.mURL->Equals(*aOther.mValue.mURL);
}
else if (eCSSUnit_Pair == mUnit) {
return *mValue.mPair == *aOther.mValue.mPair;
}
@ -201,10 +253,22 @@ bool nsCSSValue::operator==(const nsCSSValue& aOther) const
return nsCSSValuePairList::Equal(mValue.mPairList,
aOther.mValue.mPairList);
}
else if (eCSSUnit_GridTemplateAreas == mUnit) {
return *mValue.mGridTemplateAreas == *aOther.mValue.mGridTemplateAreas;
}
else if (eCSSUnit_FontFamilyList == mUnit) {
return mValue.mFontFamilyList->mNames ==
aOther.mValue.mFontFamilyList->mNames;
}
else if (eCSSUnit_FontStretch == mUnit) {
return mValue.mFontStretch == aOther.mValue.mFontStretch;
}
else if (eCSSUnit_FontSlantStyle == mUnit) {
return mValue.mFontSlantStyle == aOther.mValue.mFontSlantStyle;
}
else if (eCSSUnit_FontWeight == mUnit) {
return mValue.mFontWeight == aOther.mValue.mFontWeight;
}
else if (eCSSUnit_AtomIdent == mUnit) {
return mValue.mAtom == aOther.mValue.mAtom;
}
@ -286,6 +350,8 @@ void nsCSSValue::DoReset()
mValue.mString->Release();
} else if (UnitHasArrayValue()) {
DO_RELEASE(mArray);
} else if (eCSSUnit_URL == mUnit) {
DO_RELEASE(mURL);
} else if (eCSSUnit_Pair == mUnit) {
DO_RELEASE(mPair);
} else if (eCSSUnit_List == mUnit) {
@ -294,6 +360,8 @@ void nsCSSValue::DoReset()
DO_RELEASE(mSharedList);
} else if (eCSSUnit_PairList == mUnit) {
DO_RELEASE(mPairList);
} else if (eCSSUnit_GridTemplateAreas == mUnit) {
DO_RELEASE(mGridTemplateAreas);
} else if (eCSSUnit_FontFamilyList == mUnit) {
DO_RELEASE(mFontFamilyList);
} else if (eCSSUnit_AtomIdent == mUnit) {
@ -369,6 +437,50 @@ void nsCSSValue::SetArrayValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
mValue.mArray->AddRef();
}
void nsCSSValue::SetURLValue(mozilla::css::URLValue* aValue)
{
Reset();
mUnit = eCSSUnit_URL;
mValue.mURL = aValue;
mValue.mURL->AddRef();
}
void nsCSSValue::SetGridTemplateAreas(mozilla::css::GridTemplateAreasValue* aValue)
{
Reset();
mUnit = eCSSUnit_GridTemplateAreas;
mValue.mGridTemplateAreas = aValue;
mValue.mGridTemplateAreas->AddRef();
}
void nsCSSValue::SetFontFamilyListValue(already_AddRefed<SharedFontList> aValue)
{
Reset();
mUnit = eCSSUnit_FontFamilyList;
mValue.mFontFamilyList = aValue.take();
}
void nsCSSValue::SetFontStretch(FontStretch aStretch)
{
Reset();
mUnit = eCSSUnit_FontStretch;
mValue.mFontStretch = aStretch;
}
void nsCSSValue::SetFontSlantStyle(FontSlantStyle aStyle)
{
Reset();
mUnit = eCSSUnit_FontSlantStyle;
mValue.mFontSlantStyle = aStyle;
}
void nsCSSValue::SetFontWeight(FontWeight aWeight)
{
Reset();
mUnit = eCSSUnit_FontWeight;
mValue.mFontWeight = aWeight;
}
void nsCSSValue::SetPairValue(const nsCSSValuePair* aValue)
{
// pairs should not be used for null/inherit/initial values
@ -423,6 +535,27 @@ void nsCSSValue::SetSharedListValue(nsCSSValueSharedList* aList)
mValue.mSharedList->AddRef();
}
void nsCSSValue::SetDependentListValue(nsCSSValueList* aList)
{
Reset();
if (aList) {
mUnit = eCSSUnit_ListDep;
mValue.mListDependent = aList;
}
}
void
nsCSSValue::AdoptListValue(UniquePtr<nsCSSValueList> aValue)
{
// We have to copy the first element since for owned lists the first
// element should be an nsCSSValueList_heap object.
SetListValue();
mValue.mList->mValue = std::move(aValue->mValue);
mValue.mList->mNext = aValue->mNext;
aValue->mNext = nullptr;
aValue.reset();
}
nsCSSValuePairList* nsCSSValue::SetPairListValue()
{
Reset();
@ -432,22 +565,98 @@ nsCSSValuePairList* nsCSSValue::SetPairListValue()
return mValue.mPairList;
}
void nsCSSValue::SetDependentPairListValue(nsCSSValuePairList* aList)
{
Reset();
if (aList) {
mUnit = eCSSUnit_PairListDep;
mValue.mPairListDependent = aList;
}
}
void
nsCSSValue::AdoptPairListValue(UniquePtr<nsCSSValuePairList> aValue)
{
// We have to copy the first element, since for owned pair lists, the first
// element should be an nsCSSValuePairList_heap object.
SetPairListValue();
mValue.mPairList->mXValue = std::move(aValue->mXValue);
mValue.mPairList->mYValue = std::move(aValue->mYValue);
mValue.mPairList->mNext = aValue->mNext;
aValue->mNext = nullptr;
aValue.reset();
}
void nsCSSValue::SetAutoValue()
{
Reset();
mUnit = eCSSUnit_Auto;
}
void nsCSSValue::SetInheritValue()
{
Reset();
mUnit = eCSSUnit_Inherit;
}
void nsCSSValue::SetInitialValue()
{
Reset();
mUnit = eCSSUnit_Initial;
}
void nsCSSValue::SetUnsetValue()
{
Reset();
mUnit = eCSSUnit_Unset;
}
void nsCSSValue::SetNoneValue()
{
Reset();
mUnit = eCSSUnit_None;
}
void nsCSSValue::SetCalcValue(const nsStyleCoord::CalcValue& aCalc)
void nsCSSValue::SetAllValue()
{
Reset();
mUnit = eCSSUnit_All;
}
void nsCSSValue::SetNormalValue()
{
Reset();
mUnit = eCSSUnit_Normal;
}
void nsCSSValue::SetSystemFontValue()
{
Reset();
mUnit = eCSSUnit_System_Font;
}
void nsCSSValue::SetDummyValue()
{
Reset();
mUnit = eCSSUnit_Dummy;
}
void nsCSSValue::SetDummyInheritValue()
{
Reset();
mUnit = eCSSUnit_DummyInherit;
}
void nsCSSValue::SetCalcValue(const nsStyleCoord::CalcValue* aCalc)
{
RefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(1);
if (!aCalc.mHasPercent) {
arr->Item(0).SetIntegerCoordValue(aCalc.mLength);
if (!aCalc->mHasPercent) {
arr->Item(0).SetIntegerCoordValue(aCalc->mLength);
} else {
nsCSSValue::Array* arr2 = nsCSSValue::Array::Create(2);
nsCSSValue::Array *arr2 = nsCSSValue::Array::Create(2);
arr->Item(0).SetArrayValue(arr2, eCSSUnit_Calc_Plus);
arr2->Item(0).SetIntegerCoordValue(aCalc.mLength);
arr2->Item(1).SetPercentValue(aCalc.mPercent);
arr2->Item(0).SetIntegerCoordValue(aCalc->mLength);
arr2->Item(1).SetPercentValue(aCalc->mPercent);
}
SetArrayValue(arr, eCSSUnit_Calc);
@ -456,7 +665,8 @@ void nsCSSValue::SetCalcValue(const nsStyleCoord::CalcValue& aCalc)
nsStyleCoord::CalcValue
nsCSSValue::GetCalcValue() const
{
MOZ_ASSERT(mUnit == eCSSUnit_Calc, "The unit should be eCSSUnit_Calc");
MOZ_ASSERT(mUnit == eCSSUnit_Calc,
"The unit should be eCSSUnit_Calc");
const nsCSSValue::Array* array = GetArrayValue();
MOZ_ASSERT(array->Count() == 1,
@ -492,6 +702,31 @@ nsCSSValue::GetCalcValue() const
return result;
}
nsCSSValue::Array*
nsCSSValue::InitFunction(nsCSSKeyword aFunctionId, uint32_t aNumArgs)
{
RefPtr<nsCSSValue::Array> func = Array::Create(aNumArgs + 1);
func->Item(0).SetIntValue(aFunctionId, eCSSUnit_Enumerated);
SetArrayValue(func, eCSSUnit_Function);
return func;
}
bool
nsCSSValue::EqualsFunction(nsCSSKeyword aFunctionId) const
{
if (mUnit != eCSSUnit_Function) {
return false;
}
nsCSSValue::Array* func = mValue.mArray;
MOZ_ASSERT(func && func->Count() >= 1 &&
func->Item(0).GetUnit() == eCSSUnit_Enumerated,
"illegally structured function value");
nsCSSKeyword thisFunctionId = func->Item(0).GetKeywordValue();
return thisFunctionId == aFunctionId;
}
// static
already_AddRefed<nsStringBuffer>
nsCSSValue::BufferFromString(const nsString& aValue)
@ -518,6 +753,16 @@ nsCSSValue::BufferFromString(const nsString& aValue)
return buffer.forget();
}
void
nsCSSValue::AtomizeIdentValue()
{
MOZ_ASSERT(mUnit == eCSSUnit_Ident);
RefPtr<nsAtom> atom = NS_Atomize(GetStringBufferValue());
Reset();
mUnit = eCSSUnit_AtomIdent;
mValue.mAtom = atom.forget().take();
}
/* static */ void
nsCSSValue::AppendAlignJustifyValueToString(int32_t aValue, nsAString& aResult)
{
@ -578,6 +823,8 @@ nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
case eCSSUnit_String:
case eCSSUnit_Ident:
case eCSSUnit_Attr:
case eCSSUnit_Local_Font:
case eCSSUnit_Font_Format:
case eCSSUnit_Element:
n += mValue.mString->SizeOfIncludingThisIfUnshared(aMallocSizeOf);
break;
@ -598,6 +845,11 @@ nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
case eCSSUnit_Calc_Divided:
break;
// URL
case eCSSUnit_URL:
n += mValue.mURL->SizeOfIncludingThis(aMallocSizeOf);
break;
// Pair
case eCSSUnit_Pair:
n += mValue.mPair->SizeOfIncludingThis(aMallocSizeOf);
@ -627,6 +879,11 @@ nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
case eCSSUnit_PairListDep:
break;
// GridTemplateAreas
case eCSSUnit_GridTemplateAreas:
n += mValue.mGridTemplateAreas->SizeOfIncludingThis(aMallocSizeOf);
break;
case eCSSUnit_FontFamilyList:
// The SharedFontList is a refcounted object, but is unique per
// declaration. We don't measure the references from computed
@ -641,6 +898,9 @@ nsCSSValue::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
// Int: nothing extra to measure.
case eCSSUnit_Integer:
case eCSSUnit_Enumerated:
case eCSSUnit_FontStretch:
case eCSSUnit_FontSlantStyle:
case eCSSUnit_FontWeight:
break;
// Float: nothing extra to measure.

View File

@ -336,7 +336,9 @@ enum nsCSSUnit {
eCSSUnit_String = 11, // (char16_t*) a string value
eCSSUnit_Ident = 12, // (char16_t*) a string value
eCSSUnit_Attr = 14, // (char16_t*) a attr(string) value
eCSSUnit_Element = 15, // (char16_t*) an element id
eCSSUnit_Local_Font = 15, // (char16_t*) a local font name
eCSSUnit_Font_Format = 16, // (char16_t*) a font format name
eCSSUnit_Element = 17, // (char16_t*) an element id
eCSSUnit_Array = 20, // (nsCSSValue::Array*) a list of values
eCSSUnit_Counter = 21, // (nsCSSValue::Array*) a counter(string,[string]) value
@ -366,6 +368,10 @@ enum nsCSSUnit {
eCSSUnit_Calc_Times_R = 34, // (nsCSSValue::Array*) val * num within calc
eCSSUnit_Calc_Divided = 35, // (nsCSSValue::Array*) / within calc
eCSSUnit_URL = 40, // (nsCSSValue::URL*) value
eCSSUnit_GridTemplateAreas = 44, // (GridTemplateAreasValue*)
// for grid-template-areas
eCSSUnit_Pair = 50, // (nsCSSValuePair*) pair of values
eCSSUnit_List = 53, // (nsCSSValueList*) list of values
eCSSUnit_ListDep = 54, // (nsCSSValueList*) same as List
@ -425,6 +431,11 @@ enum nsCSSUnit {
// Flexible fraction (CSS Grid)
eCSSUnit_FlexFraction = 4000, // (float) Fraction of free space
// Font property types
eCSSUnit_FontWeight = 5000, // An encoded font-weight
eCSSUnit_FontStretch = 5001, // An encoded font-stretch
eCSSUnit_FontSlantStyle = 5002, // An encoded font-style
};
struct nsCSSValuePair;
@ -440,6 +451,8 @@ public:
struct Array;
friend struct Array;
friend struct mozilla::css::URLValueData;
friend struct mozilla::css::ImageValue;
// for valueless units only (null, auto, inherit, none, all, normal)
@ -453,7 +466,13 @@ public:
nsCSSValue(float aValue, nsCSSUnit aUnit);
nsCSSValue(const nsString& aValue, nsCSSUnit aUnit);
nsCSSValue(Array* aArray, nsCSSUnit aUnit);
explicit nsCSSValue(mozilla::css::URLValue* aValue);
explicit nsCSSValue(mozilla::css::ImageValue* aValue);
explicit nsCSSValue(mozilla::css::GridTemplateAreasValue* aValue);
explicit nsCSSValue(mozilla::SharedFontList* aValue);
explicit nsCSSValue(mozilla::FontStretch aStretch);
explicit nsCSSValue(mozilla::FontSlantStyle aStyle);
explicit nsCSSValue(mozilla::FontWeight aWeight);
nsCSSValue(const nsCSSValue& aCopy);
nsCSSValue(nsCSSValue&& aOther)
: mUnit(aOther.mUnit)
@ -586,6 +605,12 @@ public:
return mValue.mArray;
}
nsIURI* GetURLValue() const
{
MOZ_ASSERT(mUnit == eCSSUnit_URL, "not a URL value");
return mValue.mURL->GetURI();
}
nsCSSValueSharedList* GetSharedListValue() const
{
MOZ_ASSERT(mUnit == eCSSUnit_SharedList, "not a shared list value");
@ -601,6 +626,24 @@ public:
return mozilla::WrapNotNull(mValue.mFontFamilyList);
}
mozilla::FontStretch GetFontStretch() const
{
MOZ_ASSERT(mUnit == eCSSUnit_FontStretch, "not a font stretch value");
return mValue.mFontStretch;
}
mozilla::FontSlantStyle GetFontSlantStyle() const
{
MOZ_ASSERT(mUnit == eCSSUnit_FontSlantStyle, "not a font style value");
return mValue.mFontSlantStyle;
}
mozilla::FontWeight GetFontWeight() const
{
MOZ_ASSERT(mUnit == eCSSUnit_FontWeight, "not a font weight value");
return mValue.mFontWeight;
}
// bodies of these are below
inline nsCSSValuePair& GetPairValue();
inline const nsCSSValuePair& GetPairValue() const;
@ -611,6 +654,21 @@ public:
inline nsCSSValuePairList* GetPairListValue();
inline const nsCSSValuePairList* GetPairListValue() const;
mozilla::css::URLValue* GetURLStructValue() const
{
// Not allowing this for Image values, because if the caller takes
// a ref to them they won't be able to delete them properly.
MOZ_ASSERT(mUnit == eCSSUnit_URL, "not a URL value");
return mValue.mURL;
}
mozilla::css::GridTemplateAreasValue* GetGridTemplateAreas() const
{
MOZ_ASSERT(mUnit == eCSSUnit_GridTemplateAreas,
"not a grid-template-areas value");
return mValue.mGridTemplateAreas;
}
// Not making this inline because that would force us to include
// imgIRequest.h, which leads to REQUIRES hell, since this header is included
// all over.
@ -653,20 +711,50 @@ public:
// converts the nscoord to pixels
void SetIntegerCoordValue(nscoord aCoord);
void SetArrayValue(nsCSSValue::Array* aArray, nsCSSUnit aUnit);
void SetURLValue(mozilla::css::URLValue* aURI);
void SetGridTemplateAreas(mozilla::css::GridTemplateAreasValue* aValue);
void SetFontFamilyListValue(already_AddRefed<mozilla::SharedFontList> aFontListValue);
void SetFontStretch(mozilla::FontStretch aStretch);
void SetFontSlantStyle(mozilla::FontSlantStyle aStyle);
void SetFontWeight(mozilla::FontWeight aWeight);
void SetPairValue(const nsCSSValuePair* aPair);
void SetPairValue(const nsCSSValue& xValue, const nsCSSValue& yValue);
void SetSharedListValue(nsCSSValueSharedList* aList);
void SetDependentListValue(nsCSSValueList* aList);
void SetDependentPairListValue(nsCSSValuePairList* aList);
void SetAutoValue();
void SetInheritValue();
void SetInitialValue();
void SetUnsetValue();
void SetNoneValue();
void SetAllValue();
void SetNormalValue();
void SetSystemFontValue();
void SetDummyValue();
void SetDummyInheritValue();
// Converts an nsStyleCoord::CalcValue back into a CSSValue
void SetCalcValue(const nsStyleCoord::CalcValue* aCalc);
nsStyleCoord::CalcValue GetCalcValue() const;
void SetCalcValue(const nsStyleCoord::CalcValue&);
// These are a little different - they allocate storage for you and
// return a handle.
nsCSSValueList* SetListValue();
nsCSSValuePairList* SetPairListValue();
// These take ownership of the passed-in resource.
void AdoptListValue(mozilla::UniquePtr<nsCSSValueList> aValue);
void AdoptPairListValue(mozilla::UniquePtr<nsCSSValuePairList> aValue);
void StartImageLoad(nsIDocument* aDocument,
mozilla::CORSMode aCORSMode) const; // Only pretend const
// Initializes as a function value with the specified function id.
Array* InitFunction(nsCSSKeyword aFunctionId, uint32_t aNumArgs);
// Checks if this is a function value with the specified function id.
bool EqualsFunction(nsCSSKeyword aFunctionId) const;
// Returns an already addrefed buffer. Guaranteed to return non-null.
// (Will abort on allocation failure.)
static already_AddRefed<nsStringBuffer>
@ -695,6 +783,8 @@ protected:
nsStringBuffer* MOZ_OWNING_REF mString;
nsAtom* MOZ_OWNING_REF mAtom;
Array* MOZ_OWNING_REF mArray;
mozilla::css::URLValue* MOZ_OWNING_REF mURL;
mozilla::css::GridTemplateAreasValue* MOZ_OWNING_REF mGridTemplateAreas;
nsCSSValuePair_heap* MOZ_OWNING_REF mPair;
nsCSSValueList_heap* MOZ_OWNING_REF mList;
nsCSSValueList* mListDependent;
@ -702,6 +792,9 @@ protected:
nsCSSValuePairList_heap* MOZ_OWNING_REF mPairList;
nsCSSValuePairList* mPairListDependent;
mozilla::SharedFontList* MOZ_OWNING_REF mFontFamilyList;
mozilla::FontStretch mFontStretch;
mozilla::FontSlantStyle mFontSlantStyle;
mozilla::FontWeight mFontWeight;
} mValue;
};

View File

@ -80,9 +80,9 @@ void
nsFontFaceLoader::StartedLoading(nsIStreamLoader* aStreamLoader)
{
int32_t loadTimeout;
StyleFontDisplay fontDisplay = GetFontDisplay();
if (fontDisplay == StyleFontDisplay::Auto ||
fontDisplay == StyleFontDisplay::Block) {
uint8_t fontDisplay = GetFontDisplay();
if (fontDisplay == NS_FONT_DISPLAY_AUTO ||
fontDisplay == NS_FONT_DISPLAY_BLOCK) {
loadTimeout = GetFallbackDelay();
} else {
loadTimeout = GetShortFallbackDelay();
@ -113,7 +113,7 @@ nsFontFaceLoader::LoadTimerCallback(nsITimer* aTimer, void* aClosure)
}
gfxUserFontEntry* ufe = loader->mUserFontEntry.get();
StyleFontDisplay fontDisplay = loader->GetFontDisplay();
uint8_t fontDisplay = loader->GetFontDisplay();
// Depending upon the value of the font-display descriptor for the font,
// their may be one or two timeouts associated with each font. The LOADING_SLOWLY
@ -123,8 +123,8 @@ nsFontFaceLoader::LoadTimerCallback(nsITimer* aTimer, void* aClosure)
bool updateUserFontSet = true;
switch (fontDisplay) {
case StyleFontDisplay::Auto:
case StyleFontDisplay::Block:
case NS_FONT_DISPLAY_AUTO:
case NS_FONT_DISPLAY_BLOCK:
// If the entry is loading, check whether it's >75% done; if so,
// we allow another timeout period before showing a fallback font.
if (ufe->mFontDataLoadingState == gfxUserFontEntry::LOADING_STARTED) {
@ -156,10 +156,10 @@ nsFontFaceLoader::LoadTimerCallback(nsITimer* aTimer, void* aClosure)
ufe->mFontDataLoadingState = gfxUserFontEntry::LOADING_SLOWLY;
}
break;
case StyleFontDisplay::Swap:
case NS_FONT_DISPLAY_SWAP:
ufe->mFontDataLoadingState = gfxUserFontEntry::LOADING_SLOWLY;
break;
case StyleFontDisplay::Fallback: {
case NS_FONT_DISPLAY_FALLBACK: {
if (ufe->mFontDataLoadingState == gfxUserFontEntry::LOADING_STARTED) {
ufe->mFontDataLoadingState = gfxUserFontEntry::LOADING_SLOWLY;
} else {
@ -168,7 +168,7 @@ nsFontFaceLoader::LoadTimerCallback(nsITimer* aTimer, void* aClosure)
}
break;
}
case StyleFontDisplay::Optional:
case NS_FONT_DISPLAY_OPTIONAL:
ufe->mFontDataLoadingState = gfxUserFontEntry::LOADING_TIMED_OUT;
break;
@ -189,7 +189,7 @@ nsFontFaceLoader::LoadTimerCallback(nsITimer* aTimer, void* aClosure)
fontSet->IncrementGeneration();
ctx->UserFontSetUpdated(ufe);
LOG(("userfonts (%p) timeout reflow for pres context %p display %d\n",
loader, ctx, static_cast<int>(fontDisplay)));
loader, ctx, fontDisplay));
}
}
}
@ -221,7 +221,7 @@ nsFontFaceLoader::OnStreamComplete(nsIStreamLoader* aLoader,
uint32_t downloadTimeMS = uint32_t(downloadTime.ToMilliseconds());
Telemetry::Accumulate(Telemetry::WEBFONT_DOWNLOAD_TIME, downloadTimeMS);
if (GetFontDisplay() == StyleFontDisplay::Fallback) {
if (GetFontDisplay() == NS_FONT_DISPLAY_FALLBACK) {
uint32_t loadTimeout = GetFallbackDelay();
if (downloadTimeMS > loadTimeout &&
(mUserFontEntry->mFontDataLoadingState ==
@ -333,11 +333,12 @@ nsFontFaceLoader::Cancel()
mChannel->Cancel(NS_BINDING_ABORTED);
}
StyleFontDisplay
uint8_t
nsFontFaceLoader::GetFontDisplay()
{
if (!StaticPrefs::layout_css_font_display_enabled()) {
return StyleFontDisplay::Auto;
uint8_t fontDisplay = NS_FONT_DISPLAY_AUTO;
if (StaticPrefs::layout_css_font_display_enabled()) {
fontDisplay = mUserFontEntry->GetFontDisplay();
}
return mUserFontEntry->GetFontDisplay();
return fontDisplay;
}

View File

@ -51,7 +51,7 @@ protected:
virtual ~nsFontFaceLoader();
// helper method for determining the font-display value
mozilla::StyleFontDisplay GetFontDisplay();
uint8_t GetFontDisplay();
private:
RefPtr<gfxUserFontEntry> mUserFontEntry;

View File

@ -30,6 +30,6 @@ load_sheet(
"USER_SHEET");
is([...document.fonts].map(f => f.family).join(" "),
'TestAgent TestUser TestAuthor',
'"TestAgent" "TestUser" "TestAuthor"',
"@font-face rules are returned in correct cascade order");
</script>

View File

@ -999,7 +999,7 @@ function runTest() {
is(all.length, 1, "document.fonts should contain one FontFace (TEST 33)");
var face = all[0];
is(face.family, "something", "FontFace should have correct family value (TEST 33)");
is(face.family, "\"something\"", "FontFace should have correct family value (TEST 33)");
Object.keys(nonDefaultValues).forEach(function(aDesc) {
var ok_todo = aDesc == "variant" ? todo : ok;
ok_todo(face[aDesc] == nonDefaultValues[aDesc][1], "FontFace should have correct " + aDesc + " value (TEST 33)");

View File

@ -6,17 +6,7 @@ autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated usi
* 1. Get the latest cbindgen using `cargo install --force cbindgen`
* a. Alternatively, you can clone `https://github.com/eqrion/cbindgen` and use a tagged release
* 2. Run `rustup run nightly cbindgen toolkit/library/rust/ --lockfile Cargo.lock --crate style -o layout/style/ServoStyleConsts.h`
*/
class nsAtom;
namespace mozilla {
namespace css {
struct URLValue;
}
// Work-around weird cbindgen renaming.
typedef css::URLValue StyleURLValue;
typedef nsAtom StylensAtom;
}
"""
*/"""
include_guard = "mozilla_ServoStyleConsts_h"
include_version = true
braces = "SameLine"
@ -25,10 +15,6 @@ tab_width = 2
language = "C++"
namespaces = ["mozilla"]
[parse]
parse_deps = true
include = ["cssparser"]
[struct]
derive_eq = true
@ -39,16 +25,9 @@ derive_helper_methods = true
prefix = "Style"
include = [
"StyleAppearance",
"StyleComputedFontStretchRange",
"StyleComputedFontStyleDescriptor",
"StyleComputedFontWeightRange",
"StyleDisplay",
"StyleDisplayMode",
"StyleFillRule",
"StyleFontDisplay",
"StyleFontFaceSourceListComponent",
"StyleFontLanguageOverride",
"StylePathCommand",
"StyleUnicodeRange",
"StylePathCommand"
]
item_types = ["enums", "structs", "typedefs"]

View File

@ -24,7 +24,7 @@ use style_traits::values::SequenceWriter;
use values::computed::font::FamilyName;
use values::generics::font::FontStyle as GenericFontStyle;
use values::specified::Angle;
use values::specified::font::{AbsoluteFontWeight, FontStretch};
use values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch};
#[cfg(feature = "gecko")]
use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
use values::specified::font::SpecifiedFontStyle;
@ -45,19 +45,6 @@ impl OneOrMoreSeparated for Source {
type S = Comma;
}
/// A POD representation for Gecko. All pointers here are non-owned and as such
/// can't outlive the rule they came from, but we can't enforce that via C++.
///
/// All the strings are of course utf8.
#[cfg(feature = "gecko")]
#[repr(u8)]
#[allow(missing_docs)]
pub enum FontFaceSourceListComponent {
Url(*const ::gecko_bindings::structs::mozilla::css::URLValue),
Local(*mut ::gecko_bindings::structs::nsAtom),
FormatHint { length: usize, utf8_bytes: *const u8 },
}
/// A `UrlSource` represents a font-face source that has been specified with a
/// `url()` function.
///
@ -97,7 +84,6 @@ impl ToCss for UrlSource {
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
#[repr(u8)]
pub enum FontDisplay {
Auto,
Block,
@ -106,83 +92,41 @@ pub enum FontDisplay {
Optional,
}
macro_rules! impl_range {
($range:ident, $component:ident) => {
impl Parse for $range {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let first = $component::parse(context, input)?;
let second = input
.try(|input| $component::parse(context, input))
.unwrap_or_else(|_| first.clone());
Ok($range(first, second))
}
}
impl ToCss for $range {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
self.0.to_css(dest)?;
if self.0 != self.1 {
dest.write_str(" ")?;
self.1.to_css(dest)?;
}
Ok(())
}
}
}
}
/// The font-weight descriptor:
///
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-weight
#[derive(Clone, Debug, PartialEq)]
pub struct FontWeightRange(pub AbsoluteFontWeight, pub AbsoluteFontWeight);
impl_range!(FontWeightRange, AbsoluteFontWeight);
#[derive(Clone, Debug, PartialEq, ToCss)]
pub struct FontWeight(pub AbsoluteFontWeight, pub Option<AbsoluteFontWeight>);
/// The computed representation of the above so Gecko can read them easily.
///
/// This one is needed because cbindgen doesn't know how to generate
/// specified::Number.
#[repr(C)]
#[allow(missing_docs)]
pub struct ComputedFontWeightRange(f32, f32);
impl FontWeightRange {
/// Returns a computed font-stretch range.
pub fn compute(&self) -> ComputedFontWeightRange {
ComputedFontWeightRange(self.0.compute().0, self.1.compute().0)
impl Parse for FontWeight {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let first = AbsoluteFontWeight::parse(context, input)?;
let second = input
.try(|input| AbsoluteFontWeight::parse(context, input))
.ok();
Ok(FontWeight(first, second))
}
}
/// The font-stretch descriptor:
///
/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-stretch
#[derive(Clone, Debug, PartialEq,)]
pub struct FontStretchRange(pub FontStretch, pub FontStretch);
impl_range!(FontStretchRange, FontStretch);
#[derive(Clone, Debug, PartialEq, ToCss)]
pub struct FontStretch(pub SpecifiedFontStretch, pub Option<SpecifiedFontStretch>);
/// The computed representation of the above, so that
/// Gecko can read them easily.
#[repr(C)]
#[allow(missing_docs)]
pub struct ComputedFontStretchRange(f32, f32);
impl FontStretchRange {
/// Returns a computed font-stretch range.
pub fn compute(&self) -> ComputedFontStretchRange {
fn compute_stretch(s: &FontStretch) -> f32 {
match *s {
FontStretch::Keyword(ref kw) => kw.compute().0,
FontStretch::Stretch(ref p) => p.get(),
FontStretch::System(..) => unreachable!(),
}
}
ComputedFontStretchRange(compute_stretch(&self.0), compute_stretch(&self.1))
impl Parse for FontStretch {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let first = SpecifiedFontStretch::parse(context, input)?;
let second = input
.try(|input| SpecifiedFontStretch::parse(context, input))
.ok();
Ok(FontStretch(first, second))
}
}
@ -197,16 +141,6 @@ pub enum FontStyle {
Oblique(Angle, Angle),
}
/// The computed representation of the above, with angles in degrees, so that
/// Gecko can read them easily.
#[repr(u8)]
#[allow(missing_docs)]
pub enum ComputedFontStyleDescriptor {
Normal,
Italic,
Oblique(f32, f32),
}
impl Parse for FontStyle {
fn parse<'i, 't>(
context: &ParserContext,
@ -251,22 +185,6 @@ impl ToCss for FontStyle {
}
}
impl FontStyle {
/// Returns a computed font-style descriptor.
pub fn compute(&self) -> ComputedFontStyleDescriptor {
match *self {
FontStyle::Normal => ComputedFontStyleDescriptor::Normal,
FontStyle::Italic => ComputedFontStyleDescriptor::Italic,
FontStyle::Oblique(ref first, ref second) => {
ComputedFontStyleDescriptor::Oblique(
SpecifiedFontStyle::compute_angle_degrees(first),
SpecifiedFontStyle::compute_angle_degrees(second),
)
}
}
}
}
/// Parse the block inside a `@font-face` rule.
///
/// Note that the prelude parsing code lives in the `stylesheets` module.
@ -541,10 +459,10 @@ font_face_descriptors! {
"font-style" style / mStyle: FontStyle,
/// The weight of this font face.
"font-weight" weight / mWeight: FontWeightRange,
"font-weight" weight / mWeight: FontWeight,
/// The stretch of this font face.
"font-stretch" stretch / mStretch: FontStretchRange,
"font-stretch" stretch / mStretch: FontStretch,
/// The display of this font face.
"font-display" display / mDisplay: FontDisplay,

View File

@ -4,9 +4,201 @@
//! Bindings for CSS Rule objects
use byteorder::{BigEndian, WriteBytesExt};
use counter_style::{self, CounterBound};
use cssparser::UnicodeRange;
use font_face::{FontDisplay, FontWeight, FontStretch, FontStyle, Source};
use gecko_bindings::structs::{self, nsCSSValue};
use gecko_bindings::sugar::ns_css_value::ToNsCssValue;
use properties::longhands::font_language_override;
use std::str;
use values::computed::font::FamilyName;
use values::generics::font::FontTag;
use values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch};
use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
use values::specified::font::SpecifiedFontStyle;
impl<'a> ToNsCssValue for &'a FamilyName {
fn convert(self, nscssvalue: &mut nsCSSValue) {
nscssvalue.set_string_from_atom(&self.name)
}
}
impl<'a> ToNsCssValue for &'a SpecifiedFontStretch {
fn convert(self, nscssvalue: &mut nsCSSValue) {
let number = match *self {
SpecifiedFontStretch::Stretch(ref p) => p.get(),
SpecifiedFontStretch::Keyword(ref kw) => kw.compute().0,
SpecifiedFontStretch::System(..) => unreachable!(),
};
nscssvalue.set_font_stretch(number);
}
}
impl<'a> ToNsCssValue for &'a AbsoluteFontWeight {
fn convert(self, nscssvalue: &mut nsCSSValue) {
nscssvalue.set_font_weight(self.compute().0)
}
}
impl ToNsCssValue for FontTag {
fn convert(self, nscssvalue: &mut nsCSSValue) {
let mut raw = [0u8; 4];
(&mut raw[..]).write_u32::<BigEndian>(self.0).unwrap();
nscssvalue.set_string(str::from_utf8(&raw).unwrap());
}
}
impl<'a> ToNsCssValue for &'a SpecifiedFontFeatureSettings {
fn convert(self, nscssvalue: &mut nsCSSValue) {
if self.0.is_empty() {
nscssvalue.set_normal();
return;
}
nscssvalue.set_pair_list(self.0.iter().map(|entry| {
let mut index = nsCSSValue::null();
index.set_integer(entry.value.value());
(entry.tag.into(), index)
}))
}
}
impl<'a> ToNsCssValue for &'a SpecifiedFontVariationSettings {
fn convert(self, nscssvalue: &mut nsCSSValue) {
if self.0.is_empty() {
nscssvalue.set_normal();
return;
}
nscssvalue.set_pair_list(self.0.iter().map(|entry| {
let mut value = nsCSSValue::null();
value.set_number(entry.value.into());
(entry.tag.into(), value)
}))
}
}
macro_rules! descriptor_range_conversion {
($name:ident) => {
impl<'a> ToNsCssValue for &'a $name {
fn convert(self, nscssvalue: &mut nsCSSValue) {
let $name(ref first, ref second) = *self;
let second = match *second {
None => {
nscssvalue.set_from(first);
return;
},
Some(ref second) => second,
};
let mut a = nsCSSValue::null();
let mut b = nsCSSValue::null();
a.set_from(first);
b.set_from(second);
nscssvalue.set_pair(&a, &b);
}
}
};
}
descriptor_range_conversion!(FontWeight);
descriptor_range_conversion!(FontStretch);
impl<'a> ToNsCssValue for &'a FontStyle {
fn convert(self, nscssvalue: &mut nsCSSValue) {
match *self {
FontStyle::Normal => nscssvalue.set_normal(),
FontStyle::Italic => nscssvalue.set_enum(structs::NS_FONT_STYLE_ITALIC as i32),
FontStyle::Oblique(ref first, ref second) => {
let mut a = nsCSSValue::null();
let mut b = nsCSSValue::null();
a.set_font_style(SpecifiedFontStyle::compute_angle(first).degrees());
b.set_font_style(SpecifiedFontStyle::compute_angle(second).degrees());
nscssvalue.set_pair(&a, &b);
},
}
}
}
impl<'a> ToNsCssValue for &'a font_language_override::SpecifiedValue {
fn convert(self, nscssvalue: &mut nsCSSValue) {
match *self {
font_language_override::SpecifiedValue::Normal => nscssvalue.set_normal(),
font_language_override::SpecifiedValue::Override(ref lang) => {
nscssvalue.set_string(&*lang)
},
// This path is unreachable because the descriptor is only specified by the user.
font_language_override::SpecifiedValue::System(_) => unreachable!(),
}
}
}
impl<'a> ToNsCssValue for &'a Vec<Source> {
fn convert(self, nscssvalue: &mut nsCSSValue) {
let src_len = self.iter().fold(0, |acc, src| {
acc + match *src {
// Each format hint takes one position in the array of mSrc.
Source::Url(ref url) => url.format_hints.len() + 1,
Source::Local(_) => 1,
}
});
let mut target_srcs = nscssvalue
.set_array(src_len as i32)
.as_mut_slice()
.iter_mut();
macro_rules! next {
() => {
target_srcs
.next()
.expect("Length of target_srcs should be enough")
};
}
for src in self.iter() {
match *src {
Source::Url(ref url) => {
next!().set_url(&url.url);
for hint in url.format_hints.iter() {
next!().set_font_format(&hint);
}
},
Source::Local(ref family) => {
next!().set_local_font(&family.name);
},
}
}
debug_assert!(target_srcs.next().is_none(), "Should have filled all slots");
}
}
impl<'a> ToNsCssValue for &'a Vec<UnicodeRange> {
fn convert(self, nscssvalue: &mut nsCSSValue) {
let target_ranges = nscssvalue
.set_array((self.len() * 2) as i32)
.as_mut_slice()
.chunks_mut(2);
for (range, target) in self.iter().zip(target_ranges) {
target[0].set_integer(range.start as i32);
target[1].set_integer(range.end as i32);
}
}
}
impl<'a> ToNsCssValue for &'a FontDisplay {
fn convert(self, nscssvalue: &mut nsCSSValue) {
nscssvalue.set_enum(match *self {
FontDisplay::Auto => structs::NS_FONT_DISPLAY_AUTO,
FontDisplay::Block => structs::NS_FONT_DISPLAY_BLOCK,
FontDisplay::Swap => structs::NS_FONT_DISPLAY_SWAP,
FontDisplay::Fallback => structs::NS_FONT_DISPLAY_FALLBACK,
FontDisplay::Optional => structs::NS_FONT_DISPLAY_OPTIONAL,
} as i32)
}
}
impl<'a> ToNsCssValue for &'a counter_style::System {
fn convert(self, nscssvalue: &mut nsCSSValue) {

View File

@ -14,6 +14,7 @@ use std::mem;
use std::ops::{Index, IndexMut};
use std::slice;
use values::computed::{Angle, Length, LengthOrPercentage, Percentage};
use values::specified::url::SpecifiedUrl;
impl nsCSSValue {
/// Create a CSSValue with null unit, useful to be used as a return value.
@ -166,6 +167,31 @@ impl nsCSSValue {
unsafe { bindings::Gecko_CSSValue_SetAtomIdent(self, s.into_addrefed()) }
}
/// Set to a font format.
pub fn set_font_format(&mut self, s: &str) {
self.set_string_internal(s, nsCSSUnit::eCSSUnit_Font_Format);
}
/// Set to a local font value.
pub fn set_local_font(&mut self, s: &Atom) {
self.set_string_from_atom_internal(s, nsCSSUnit::eCSSUnit_Local_Font);
}
/// Set to a font stretch.
pub fn set_font_stretch(&mut self, s: f32) {
unsafe { bindings::Gecko_CSSValue_SetFontStretch(self, s) }
}
/// Set to a font style
pub fn set_font_style(&mut self, s: f32) {
unsafe { bindings::Gecko_CSSValue_SetFontSlantStyle(self, s) }
}
/// Set to a font weight
pub fn set_font_weight(&mut self, w: f32) {
unsafe { bindings::Gecko_CSSValue_SetFontWeight(self, w) }
}
fn set_int_internal(&mut self, value: i32, unit: nsCSSUnit) {
unsafe { bindings::Gecko_CSSValue_SetInt(self, value, unit) }
}
@ -185,6 +211,11 @@ impl nsCSSValue {
unsafe { bindings::Gecko_CSSValue_SetFloat(self, number, nsCSSUnit::eCSSUnit_Number) }
}
/// Set to a url value
pub fn set_url(&mut self, url: &SpecifiedUrl) {
unsafe { bindings::Gecko_CSSValue_SetURL(self, url.url_value.get()) }
}
/// Set to an array of given length
pub fn set_array(&mut self, len: i32) -> &mut nsCSSValue_Array {
unsafe { bindings::Gecko_CSSValue_SetArray(self, len) }

View File

@ -747,7 +747,6 @@ pub type FontVariationSettings = FontSettings<VariationValue<Number>>;
/// it and store it as a 32-bit integer
/// (see http://www.microsoft.com/typography/otspec/languagetags.htm).
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq)]
#[repr(C)]
pub struct FontLanguageOverride(pub u32);
impl FontLanguageOverride {

View File

@ -27,7 +27,6 @@ use values::generics::NonNegative;
ToAnimatedZero,
ToComputedValue,
)]
#[repr(C)]
pub struct Percentage(pub CSSFloat);
impl Percentage {

View File

@ -292,16 +292,14 @@ pub const FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES: f32 = 90.;
pub const FONT_STYLE_OBLIQUE_MIN_ANGLE_DEGREES: f32 = -90.;
impl SpecifiedFontStyle {
/// Gets a clamped angle in degrees from a specified Angle.
pub fn compute_angle_degrees(angle: &Angle) -> f32 {
angle
.degrees()
.max(FONT_STYLE_OBLIQUE_MIN_ANGLE_DEGREES)
.min(FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES)
}
fn compute_angle(angle: &Angle) -> ComputedAngle {
ComputedAngle::Deg(Self::compute_angle_degrees(angle))
/// Gets a clamped angle from a specified Angle.
pub fn compute_angle(angle: &Angle) -> ComputedAngle {
ComputedAngle::Deg(
angle
.degrees()
.max(FONT_STYLE_OBLIQUE_MIN_ANGLE_DEGREES)
.min(FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES),
)
}
/// Parse a suitable angle for font-style: oblique.
@ -382,7 +380,6 @@ impl Parse for FontStyle {
/// https://drafts.csswg.org/css-fonts-4/#font-stretch-prop
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
#[repr(u8)]
pub enum FontStretch {
Stretch(Percentage),
Keyword(FontStretchKeyword),
@ -2060,29 +2057,6 @@ impl FontLanguageOverride {
FontLanguageOverride::Normal
}
/// The ToComputedValue implementation for non-system-font
/// FontLanguageOverride, used for @font-face descriptors.
#[inline]
pub fn compute_non_system(&self) -> computed::FontLanguageOverride {
match *self {
FontLanguageOverride::Normal => computed::FontLanguageOverride(0),
FontLanguageOverride::Override(ref lang) => {
if lang.is_empty() || lang.len() > 4 {
return computed::FontLanguageOverride(0);
}
let mut bytes = [b' '; 4];
for (byte, lang_byte) in bytes.iter_mut().zip(lang.as_bytes()) {
if !lang_byte.is_ascii() {
return computed::FontLanguageOverride(0);
}
*byte = *lang_byte;
}
computed::FontLanguageOverride(BigEndian::read_u32(&bytes))
},
FontLanguageOverride::System(..) => unreachable!(),
}
}
system_font_methods!(FontLanguageOverride, font_language_override);
}
@ -2092,8 +2066,19 @@ impl ToComputedValue for FontLanguageOverride {
#[inline]
fn to_computed_value(&self, context: &Context) -> computed::FontLanguageOverride {
match *self {
FontLanguageOverride::Normal => computed::FontLanguageOverride(0),
FontLanguageOverride::Override(ref lang) => {
if lang.is_empty() || lang.len() > 4 || !lang.is_ascii() {
return computed::FontLanguageOverride(0);
}
let mut computed_lang = lang.to_string();
while computed_lang.len() < 4 {
computed_lang.push(' ');
}
let bytes = computed_lang.into_bytes();
computed::FontLanguageOverride(BigEndian::read_u32(&bytes))
},
FontLanguageOverride::System(_) => self.compute_system(context),
_ => self.compute_non_system(),
}
}
#[inline]

View File

@ -2481,160 +2481,38 @@ pub unsafe extern "C" fn Servo_FontFaceRule_GetDeclCssText(
})
}
macro_rules! simple_font_descriptor_getter {
($function_name:ident, $gecko_type:ident, $field:ident, $compute:ident) => {
#[no_mangle]
pub unsafe extern "C" fn $function_name(
rule: RawServoFontFaceRuleBorrowed,
out: *mut structs::$gecko_type,
) -> bool {
read_locked_arc(rule, |rule: &FontFaceRule| {
match rule.$field {
None => return false,
Some(ref f) => {
// FIXME(emilio): We should probably teach bindgen about
// cbindgen.toml and making it hide the types and use
// the rust ones instead. This would make transmute()
// calls unnecessary.
// unsafe: cbindgen guarantees the same representation.
*out = ::std::mem::transmute(f.$compute());
}
}
true
})
}
}
}
simple_font_descriptor_getter!(Servo_FontFaceRule_GetFontWeight, StyleComputedFontWeightRange, weight, compute);
simple_font_descriptor_getter!(Servo_FontFaceRule_GetFontStretch, StyleComputedFontStretchRange, stretch, compute);
simple_font_descriptor_getter!(Servo_FontFaceRule_GetFontStyle, StyleComputedFontStyleDescriptor, style, compute);
simple_font_descriptor_getter!(Servo_FontFaceRule_GetFontDisplay, StyleFontDisplay, display, clone);
simple_font_descriptor_getter!(Servo_FontFaceRule_GetFontLanguageOverride, StyleFontLanguageOverride, language_override, compute_non_system);
#[no_mangle]
pub unsafe extern "C" fn Servo_FontFaceRule_GetFamilyName(
pub unsafe extern "C" fn Servo_FontFaceRule_GetDescriptor(
rule: RawServoFontFaceRuleBorrowed,
) -> *mut nsAtom {
read_locked_arc(rule, |rule: &FontFaceRule| {
// TODO(emilio): font-family is a mandatory descriptor, can't we unwrap
// here, and remove the null-checks in Gecko?
rule.family.as_ref().map_or(ptr::null_mut(), |f| f.name.as_ptr())
})
}
#[no_mangle]
pub unsafe extern "C" fn Servo_FontFaceRule_GetUnicodeRanges(
rule: RawServoFontFaceRuleBorrowed,
out_len: *mut usize,
) -> *const structs::StyleUnicodeRange {
*out_len = 0;
read_locked_arc(rule, |rule: &FontFaceRule| {
let ranges = match rule.unicode_range {
Some(ref ranges) => ranges,
None => return ptr::null(),
};
*out_len = ranges.len();
ranges.as_ptr() as *const _
})
}
#[no_mangle]
pub unsafe extern "C" fn Servo_FontFaceRule_GetSources(
rule: RawServoFontFaceRuleBorrowed,
out: *mut nsTArray<structs::StyleFontFaceSourceListComponent>,
desc: nsCSSFontDesc,
result: nsCSSValueBorrowedMut,
) {
use style::font_face::{Source, FontFaceSourceListComponent};
let out = &mut *out;
read_locked_arc(rule, |rule: &FontFaceRule| {
let sources = match rule.sources {
Some(ref s) => s,
None => return,
};
let len = sources.iter().fold(0, |acc, src| {
acc + match *src {
// Each format hint takes one position in the array of mSrc.
Source::Url(ref url) => url.format_hints.len() + 1,
Source::Local(_) => 1,
}
});
out.set_len(len as u32);
let mut iter = out.iter_mut();
{
let mut set_next = |component: FontFaceSourceListComponent| {
// transmute: cbindgen ensures they have the same representation.
*iter.next().expect("miscalculated length") =
::std::mem::transmute(component);
};
for source in sources.iter() {
match *source {
Source::Url(ref url) => {
set_next(FontFaceSourceListComponent::Url(url.url.url_value.get()));
for hint in url.format_hints.iter() {
set_next(FontFaceSourceListComponent::FormatHint {
length: hint.len(),
utf8_bytes: hint.as_ptr(),
});
macro_rules! to_css_value {
(
valid: [$($v_enum_name:ident => $field:ident,)*]
invalid: [$($i_enum_name:ident,)*]
) => {
match desc {
$(
nsCSSFontDesc::$v_enum_name => {
if let Some(ref value) = rule.$field {
result.set_from(value);
}
}
}
Source::Local(ref name) => {
set_next(FontFaceSourceListComponent::Local(name.name.as_ptr()));
}
)*
$(
nsCSSFontDesc::$i_enum_name => {
debug_assert!(false, "not a valid font descriptor");
}
)*
}
}
}
assert!(iter.next().is_none(), "miscalculated");
apply_font_desc_list!(to_css_value)
})
}
#[no_mangle]
pub unsafe extern "C" fn Servo_FontFaceRule_GetVariationSettings(
rule: RawServoFontFaceRuleBorrowed,
variations: *mut nsTArray<structs::gfxFontVariation>,
) {
read_locked_arc(rule, |rule: &FontFaceRule| {
let source_variations = match rule.variation_settings {
Some(ref v) => v,
None => return,
};
(*variations).set_len(source_variations.0.len() as u32);
for (target, source) in (*variations).iter_mut().zip(source_variations.0.iter()) {
*target = structs::gfxFontVariation {
mTag: source.tag.0,
mValue: source.value.get(),
};
}
});
}
#[no_mangle]
pub unsafe extern "C" fn Servo_FontFaceRule_GetFeatureSettings(
rule: RawServoFontFaceRuleBorrowed,
features: *mut nsTArray<structs::gfxFontFeature>,
) {
read_locked_arc(rule, |rule: &FontFaceRule| {
let source_features = match rule.feature_settings {
Some(ref v) => v,
None => return,
};
(*features).set_len(source_features.0.len() as u32);
for (target, source) in (*features).iter_mut().zip(source_features.0.iter()) {
*target = structs::gfxFontFeature {
mTag: source.tag.0,
mValue: source.value.value() as u32,
};
}
});
}
#[no_mangle]
pub unsafe extern "C" fn Servo_FontFaceRule_GetDescriptorCssText(
rule: RawServoFontFaceRuleBorrowed,
@ -5761,24 +5639,22 @@ pub extern "C" fn Servo_ParseTransformIntoMatrix(
}
#[no_mangle]
pub unsafe extern "C" fn Servo_ParseFontShorthandForMatching(
pub extern "C" fn Servo_ParseFontShorthandForMatching(
value: *const nsAString,
data: *mut URLExtraData,
family: *mut structs::RefPtr<structs::SharedFontList>,
style: *mut structs::StyleComputedFontStyleDescriptor,
stretch: *mut f32,
weight: *mut f32,
style: nsCSSValueBorrowedMut,
stretch: nsCSSValueBorrowedMut,
weight: nsCSSValueBorrowedMut
) -> bool {
use style::font_face::ComputedFontStyleDescriptor;
use style::properties::shorthands::font;
use style::values::generics::font::FontStyle as GenericFontStyle;
use style::values::computed::font::FontWeight as ComputedFontWeight;
use style::values::specified::font::{FontFamily, FontWeight, FontStretch, FontStyle, SpecifiedFontStyle};
use style::values::specified::font::{FontFamily, FontWeight, FontStyle, SpecifiedFontStyle};
let string = (*value).to_string();
let string = unsafe { (*value).to_string() };
let mut input = ParserInput::new(&string);
let mut parser = Parser::new(&mut input);
let url_data = UrlExtraData::from_ptr_ref(&data);
let url_data = unsafe { UrlExtraData::from_ptr_ref(&data) };
let context = ParserContext::new(
Origin::Author,
url_data,
@ -5795,7 +5671,7 @@ pub unsafe extern "C" fn Servo_ParseFontShorthandForMatching(
};
// The system font is not acceptable, so we return false.
let family = &mut *family;
let family = unsafe { &mut *family };
match font.font_family {
FontFamily::Values(list) => family.set_move(list.0),
FontFamily::System(_) => return false,
@ -5805,29 +5681,27 @@ pub unsafe extern "C" fn Servo_ParseFontShorthandForMatching(
FontStyle::Specified(ref s) => s,
FontStyle::System(_) => return false,
};
*style = ::std::mem::transmute(match *specified_font_style {
GenericFontStyle::Normal => ComputedFontStyleDescriptor::Normal,
GenericFontStyle::Italic => ComputedFontStyleDescriptor::Italic,
match *specified_font_style {
GenericFontStyle::Normal => style.set_normal(),
GenericFontStyle::Italic => style.set_enum(structs::NS_FONT_STYLE_ITALIC as i32),
GenericFontStyle::Oblique(ref angle) => {
let angle = SpecifiedFontStyle::compute_angle_degrees(angle);
ComputedFontStyleDescriptor::Oblique(angle, angle)
style.set_font_style(SpecifiedFontStyle::compute_angle(angle).degrees())
}
});
}
*stretch = match font.font_stretch {
FontStretch::Keyword(ref k) => k.compute().0,
FontStretch::Stretch(ref p) => p.get(),
FontStretch::System(_) => return false,
};
if font.font_stretch.get_system().is_some() {
return false;
}
stretch.set_from(&font.font_stretch);
*weight = match font.font_weight {
FontWeight::Absolute(w) => w.compute().0,
match font.font_weight {
FontWeight::Absolute(w) => weight.set_font_weight(w.compute().0),
// Resolve relative font weights against the initial of font-weight
// (normal, which is equivalent to 400).
FontWeight::Bolder => ComputedFontWeight::normal().bolder().0,
FontWeight::Lighter => ComputedFontWeight::normal().lighter().0,
FontWeight::Bolder => weight.set_enum(structs::NS_FONT_WEIGHT_BOLD as i32),
FontWeight::Lighter => weight.set_enum(structs::NS_FONT_WEIGHT_THIN as i32),
FontWeight::System(_) => return false,
};
}
true
}

View File

@ -3,7 +3,7 @@ set -x -e -v
# If you update this, make sure to update the minimum version in rust.configure
# as well.
CBINDGEN_VERSION=v0.6.4
CBINDGEN_VERSION=v0.6.2
TARGET="$1"
case "$(uname -s)" in