style: Remove StyleFontSize enum from nsStyleConsts.h.

Differential Revision: https://phabricator.services.mozilla.com/D77511
This commit is contained in:
Philipp Zech 2020-06-17 11:08:44 +00:00 committed by Emilio Cobos Álvarez
parent 60f4fedcbf
commit 5af0d7ca7c
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
6 changed files with 56 additions and 79 deletions

View file

@ -511,9 +511,11 @@ pub enum KeywordSize {
XXLarge,
#[css(keyword = "xxx-large")]
XXXLarge,
#[css(skip)]
None,
}
impl KeywordSize {
impl FontSizeKeyword {
/// Convert to an HTML <font size> value
#[inline]
pub fn html_size(self) -> u8 {
@ -521,9 +523,9 @@ impl KeywordSize {
}
}
impl Default for KeywordSize {
impl Default for FontSizeKeyword {
fn default() -> Self {
KeywordSize::Medium
FontSizeKeyword::Medium
}
}
@ -546,7 +548,7 @@ impl Default for KeywordSize {
/// Additional information for keyword-derived font sizes.
pub struct KeywordInfo {
/// The keyword used
pub kw: KeywordSize,
pub kw: FontSizeKeyword,
/// A factor to be multiplied by the computed size of the keyword
#[css(skip)]
pub factor: f32,
@ -559,10 +561,15 @@ pub struct KeywordInfo {
impl KeywordInfo {
/// KeywordInfo value for font-size: medium
pub fn medium() -> Self {
Self::new(KeywordSize::Medium)
Self::new(FontSizeKeyword::Medium)
}
fn new(kw: KeywordSize) -> Self {
/// KeywordInfo value for font-size: none
pub fn none() -> Self {
Self::new(FontSizeKeyword::None)
}
fn new(kw: FontSizeKeyword) -> Self {
KeywordInfo {
kw,
factor: 1.,
@ -573,6 +580,7 @@ impl KeywordInfo {
/// Computes the final size for this font-size keyword, accounting for
/// text-zoom.
fn to_computed_value(&self, context: &Context) -> CSSPixelLength {
debug_assert_ne!(self.kw, FontSizeKeyword::None);
let base = context.maybe_zoom_text(self.kw.to_length(context).0);
base * self.factor + context.maybe_zoom_text(self.offset)
}
@ -580,6 +588,9 @@ impl KeywordInfo {
/// Given a parent keyword info (self), apply an additional factor/offset to
/// it.
fn compose(self, factor: f32) -> Self {
if self.kw == FontSizeKeyword::None {
return self;
}
KeywordInfo {
kw: self.kw,
factor: self.factor * factor,
@ -590,7 +601,7 @@ impl KeywordInfo {
impl SpecifiedValueInfo for KeywordInfo {
fn collect_completion_keywords(f: KeywordsCollectFn) {
<KeywordSize as SpecifiedValueInfo>::collect_completion_keywords(f);
<FontSizeKeyword as SpecifiedValueInfo>::collect_completion_keywords(f);
}
}
@ -766,21 +777,21 @@ const LARGER_FONT_SIZE_RATIO: f32 = 1.2;
/// The default font size.
pub const FONT_MEDIUM_PX: i32 = 16;
impl KeywordSize {
impl FontSizeKeyword {
#[inline]
#[cfg(feature = "servo")]
fn to_length(&self, _: &Context) -> NonNegativeLength {
let medium = Length::new(FONT_MEDIUM_PX as f32);
// https://drafts.csswg.org/css-fonts-3/#font-size-prop
NonNegative(match *self {
KeywordSize::XXSmall => medium * 3.0 / 5.0,
KeywordSize::XSmall => medium * 3.0 / 4.0,
KeywordSize::Small => medium * 8.0 / 9.0,
KeywordSize::Medium => medium,
KeywordSize::Large => medium * 6.0 / 5.0,
KeywordSize::XLarge => medium * 3.0 / 2.0,
KeywordSize::XXLarge => medium * 2.0,
KeywordSize::XXXLarge => medium * 3.0,
FontSizeKeyword::XXSmall => medium * 3.0 / 5.0,
FontSizeKeyword::XSmall => medium * 3.0 / 4.0,
FontSizeKeyword::Small => medium * 8.0 / 9.0,
FontSizeKeyword::Medium => medium,
FontSizeKeyword::Large => medium * 6.0 / 5.0,
FontSizeKeyword::XLarge => medium * 3.0 / 2.0,
FontSizeKeyword::XXLarge => medium * 2.0,
FontSizeKeyword::XXXLarge => medium * 3.0,
})
}
@ -861,14 +872,14 @@ impl FontSize {
pub fn from_html_size(size: u8) -> Self {
FontSize::Keyword(KeywordInfo::new(match size {
// If value is less than 1, let it be 1.
0 | 1 => KeywordSize::XSmall,
2 => KeywordSize::Small,
3 => KeywordSize::Medium,
4 => KeywordSize::Large,
5 => KeywordSize::XLarge,
6 => KeywordSize::XXLarge,
0 | 1 => FontSizeKeyword::XSmall,
2 => FontSizeKeyword::Small,
3 => FontSizeKeyword::Medium,
4 => FontSizeKeyword::Large,
5 => FontSizeKeyword::XLarge,
6 => FontSizeKeyword::XXLarge,
// If value is greater than 7, let it be 7.
_ => KeywordSize::XXXLarge,
_ => FontSizeKeyword::XXXLarge,
}))
}
@ -886,9 +897,9 @@ impl FontSize {
.get_parent_font()
.clone_font_size()
.keyword_info
.map(|i| i.compose(factor))
.compose(factor)
};
let mut info = None;
let mut info = KeywordInfo::none();
let size = match *self {
FontSize::Length(LengthPercentage::Length(NoCalcLength::FontRelative(value))) => {
if let FontRelativeLength::Em(em) = value {
@ -917,7 +928,7 @@ impl FontSize {
},
FontSize::Keyword(i) => {
// As a specified keyword, this is keyword derived
info = Some(i);
info = i;
i.to_computed_value(context).clamp_to_non_negative()
},
FontSize::Smaller => {
@ -991,7 +1002,7 @@ impl FontSize {
return Ok(FontSize::Length(lp));
}
if let Ok(kw) = input.try(KeywordSize::parse) {
if let Ok(kw) = input.try(FontSizeKeyword::parse) {
return Ok(FontSize::Keyword(KeywordInfo::new(kw)));
}

View file

@ -50,7 +50,7 @@ pub use self::effects::{BoxShadow, Filter, SimpleShadow};
pub use self::flex::FlexBasis;
pub use self::font::{FontFamily, FontLanguageOverride, FontStyle};
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis};
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis, FontSizeKeyword};
pub use self::font::{FontVariantAlternates, FontWeight};
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};