Skip to content

Commit

Permalink
Bug 1681691 - Add metrics override descriptors to webidl. r=emilio
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkthame committed Mar 23, 2021
1 parent 03752c9 commit a7442dc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dom/webidl/FontFace.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ dictionary FontFaceDescriptors {
UTF8String featureSettings = "normal";
UTF8String variationSettings = "normal";
UTF8String display = "auto";
UTF8String ascentOverride = "normal";
UTF8String descentOverride = "normal";
UTF8String lineGapOverride = "normal";
};

enum FontFaceLoadStatus { "unloaded", "loading", "loaded", "error" };
Expand All @@ -44,6 +47,9 @@ interface FontFace {
[SetterThrows] attribute UTF8String featureSettings;
[SetterThrows, Pref="layout.css.font-variations.enabled"] attribute UTF8String variationSettings;
[SetterThrows, Pref="layout.css.font-display.enabled"] attribute UTF8String display;
[SetterThrows, Pref="layout.css.font-metrics-overrides.enabled"] attribute UTF8String ascentOverride;
[SetterThrows, Pref="layout.css.font-metrics-overrides.enabled"] attribute UTF8String descentOverride;
[SetterThrows, Pref="layout.css.font-metrics-overrides.enabled"] attribute UTF8String lineGapOverride;

readonly attribute FontFaceLoadStatus status;

Expand Down
37 changes: 36 additions & 1 deletion layout/style/FontFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,36 @@ void FontFace::SetDisplay(const nsACString& aValue, ErrorResult& aRv) {
}
}

void FontFace::GetAscentOverride(nsACString& aResult) {
GetDesc(eCSSFontDesc_AscentOverride, aResult);
}

void FontFace::SetAscentOverride(const nsACString& aValue, ErrorResult& aRv) {
if (SetDescriptor(eCSSFontDesc_AscentOverride, aValue, aRv)) {
DescriptorUpdated();
}
}

void FontFace::GetDescentOverride(nsACString& aResult) {
GetDesc(eCSSFontDesc_DescentOverride, aResult);
}

void FontFace::SetDescentOverride(const nsACString& aValue, ErrorResult& aRv) {
if (SetDescriptor(eCSSFontDesc_DescentOverride, aValue, aRv)) {
DescriptorUpdated();
}
}

void FontFace::GetLineGapOverride(nsACString& aResult) {
GetDesc(eCSSFontDesc_LineGapOverride, aResult);
}

void FontFace::SetLineGapOverride(const nsACString& aValue, ErrorResult& aRv) {
if (SetDescriptor(eCSSFontDesc_LineGapOverride, aValue, aRv)) {
DescriptorUpdated();
}
}

void FontFace::DescriptorUpdated() {
// If we haven't yet initialized mUserFontEntry, no need to do anything here;
// we'll respect the updated descriptor when the time comes to create it.
Expand Down Expand Up @@ -531,7 +561,12 @@ bool FontFace::SetDescriptors(const nsACString& aFamily,
(StaticPrefs::layout_css_font_variations_enabled() &&
!setDesc(eCSSFontDesc_FontVariationSettings,
aDescriptors.mVariationSettings)) ||
!setDesc(eCSSFontDesc_Display, aDescriptors.mDisplay)) {
!setDesc(eCSSFontDesc_Display, aDescriptors.mDisplay) ||
(StaticPrefs::layout_css_font_metrics_overrides_enabled() &&
(!setDesc(eCSSFontDesc_AscentOverride, aDescriptors.mAscentOverride) ||
!setDesc(eCSSFontDesc_DescentOverride, aDescriptors.mDescentOverride) ||
!setDesc(eCSSFontDesc_LineGapOverride,
aDescriptors.mLineGapOverride)))) {
// XXX Handle font-variant once we support it (bug 1055385).

// If any of the descriptors failed to parse, none of them should be set
Expand Down
6 changes: 6 additions & 0 deletions layout/style/FontFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ class FontFace final : public nsISupports, public nsWrapperCache {
void SetVariationSettings(const nsACString& aValue, ErrorResult& aRv);
void GetDisplay(nsACString& aResult);
void SetDisplay(const nsACString& aValue, ErrorResult& aRv);
void GetAscentOverride(nsACString& aResult);
void SetAscentOverride(const nsACString& aValue, ErrorResult& aRv);
void GetDescentOverride(nsACString& aResult);
void SetDescentOverride(const nsACString& aValue, ErrorResult& aRv);
void GetLineGapOverride(nsACString& aResult);
void SetLineGapOverride(const nsACString& aValue, ErrorResult& aRv);

FontFaceLoadStatus Status();
Promise* Load(ErrorResult& aRv);
Expand Down

0 comments on commit a7442dc

Please sign in to comment.