mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Remove StyleFontSize enum from nsStyleConsts.h.
Differential Revision: https://phabricator.services.mozilla.com/D77511
This commit is contained in:
parent
60f4fedcbf
commit
5af0d7ca7c
6 changed files with 56 additions and 79 deletions
|
@ -854,12 +854,13 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
|
||||
let new_size = {
|
||||
let font = self.context.builder.get_font();
|
||||
let new_size = match font.clone_font_size().keyword_info {
|
||||
Some(info) => {
|
||||
let info = font.clone_font_size().keyword_info;
|
||||
let new_size = match info.kw {
|
||||
specified::FontSizeKeyword::None => return,
|
||||
_ => {
|
||||
self.context.for_non_inherited_property = None;
|
||||
specified::FontSize::Keyword(info).to_computed_value(self.context)
|
||||
}
|
||||
None => return,
|
||||
};
|
||||
|
||||
if font.gecko().mScriptUnconstrainedSize == Au::from(new_size.size()).0 {
|
||||
|
|
|
@ -942,62 +942,26 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn set_font_size(&mut self, v: FontSize) {
|
||||
use crate::values::specified::font::KeywordSize;
|
||||
|
||||
let size = Au::from(v.size());
|
||||
self.gecko.mScriptUnconstrainedSize = size.0;
|
||||
|
||||
// These two may be changed from Cascade::fixup_font_stuff.
|
||||
self.gecko.mSize = size.0;
|
||||
self.gecko.mFont.size = size.0;
|
||||
|
||||
if let Some(info) = v.keyword_info {
|
||||
self.gecko.mFontSizeKeyword = match info.kw {
|
||||
KeywordSize::XXSmall => structs::StyleFontSize::Xxsmall,
|
||||
KeywordSize::XSmall => structs::StyleFontSize::Xsmall,
|
||||
KeywordSize::Small => structs::StyleFontSize::Small,
|
||||
KeywordSize::Medium => structs::StyleFontSize::Medium,
|
||||
KeywordSize::Large => structs::StyleFontSize::Large,
|
||||
KeywordSize::XLarge => structs::StyleFontSize::Xxlarge,
|
||||
KeywordSize::XXLarge => structs::StyleFontSize::Xxlarge,
|
||||
KeywordSize::XXXLarge => structs::StyleFontSize::Xxxlarge,
|
||||
};
|
||||
self.gecko.mFontSizeFactor = info.factor;
|
||||
self.gecko.mFontSizeOffset = info.offset.to_i32_au();
|
||||
} else {
|
||||
self.gecko.mFontSizeKeyword = structs::StyleFontSize::NoKeyword;
|
||||
self.gecko.mFontSizeFactor = 1.;
|
||||
self.gecko.mFontSizeOffset = 0;
|
||||
}
|
||||
self.gecko.mFontSizeKeyword = v.keyword_info.kw;
|
||||
self.gecko.mFontSizeFactor = v.keyword_info.factor;
|
||||
self.gecko.mFontSizeOffset = v.keyword_info.offset.to_i32_au();
|
||||
}
|
||||
|
||||
pub fn clone_font_size(&self) -> FontSize {
|
||||
use crate::values::specified::font::{KeywordInfo, KeywordSize};
|
||||
let size = Au(self.gecko.mSize).into();
|
||||
let kw = match self.gecko.mFontSizeKeyword {
|
||||
structs::StyleFontSize::Xxsmall => KeywordSize::XXSmall,
|
||||
structs::StyleFontSize::Xsmall => KeywordSize::XSmall,
|
||||
structs::StyleFontSize::Small => KeywordSize::Small,
|
||||
structs::StyleFontSize::Medium => KeywordSize::Medium,
|
||||
structs::StyleFontSize::Large => KeywordSize::Large,
|
||||
structs::StyleFontSize::Xlarge => KeywordSize::XLarge,
|
||||
structs::StyleFontSize::Xxlarge => KeywordSize::XXLarge,
|
||||
structs::StyleFontSize::Xxxlarge => KeywordSize::XXXLarge,
|
||||
structs::StyleFontSize::NoKeyword => {
|
||||
return FontSize {
|
||||
size,
|
||||
keyword_info: None,
|
||||
}
|
||||
}
|
||||
_ => unreachable!("mFontSizeKeyword should be an absolute keyword or NO_KEYWORD")
|
||||
};
|
||||
use crate::values::specified::font::KeywordInfo;
|
||||
FontSize {
|
||||
size,
|
||||
keyword_info: Some(KeywordInfo {
|
||||
kw,
|
||||
size: Au(self.gecko.mSize).into(),
|
||||
keyword_info: KeywordInfo {
|
||||
kw: self.gecko.mFontSizeKeyword,
|
||||
factor: self.gecko.mFontSizeFactor,
|
||||
offset: Au(self.gecko.mFontSizeOffset).into()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -362,6 +362,7 @@ ${helpers.predefined_type(
|
|||
use crate::gecko_bindings::structs::{LookAndFeel_FontID, nsFont};
|
||||
use std::mem;
|
||||
use crate::values::computed::Percentage;
|
||||
use crate::values::specified::font::KeywordInfo;
|
||||
use crate::values::computed::font::{FontFamily, FontSize, FontStretch, FontStyle, FontFamilyList};
|
||||
use crate::values::generics::NonNegative;
|
||||
|
||||
|
@ -397,7 +398,7 @@ ${helpers.predefined_type(
|
|||
},
|
||||
font_size: FontSize {
|
||||
size: NonNegative(cx.maybe_zoom_text(Au(system.size).into())),
|
||||
keyword_info: None
|
||||
keyword_info: KeywordInfo::none()
|
||||
},
|
||||
font_weight,
|
||||
font_stretch,
|
||||
|
|
|
@ -101,7 +101,7 @@ pub struct FontSize {
|
|||
pub size: NonNegativeLength,
|
||||
/// If derived from a keyword, the keyword and additional transformations applied to it
|
||||
#[css(skip)]
|
||||
pub keyword_info: Option<KeywordInfo>,
|
||||
pub keyword_info: KeywordInfo,
|
||||
}
|
||||
|
||||
impl FontWeight {
|
||||
|
@ -170,7 +170,7 @@ impl FontSize {
|
|||
pub fn medium() -> Self {
|
||||
Self {
|
||||
size: NonNegative(Length::new(specified::FONT_MEDIUM_PX as CSSFloat)),
|
||||
keyword_info: Some(KeywordInfo::medium()),
|
||||
keyword_info: KeywordInfo::medium(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ impl ToAnimatedValue for FontSize {
|
|||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
FontSize {
|
||||
size: NonNegative(animated.clamp_to_non_negative()),
|
||||
keyword_info: None,
|
||||
keyword_info: KeywordInfo::none(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue