mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
stylo: Clean up keyword values
This commit is contained in:
parent
df9d7cd941
commit
cd6f68c545
4 changed files with 48 additions and 34 deletions
|
@ -2164,7 +2164,7 @@ fn static_assert() {
|
||||||
use values::specified::font::KeywordSize;
|
use values::specified::font::KeywordSize;
|
||||||
self.gecko.mSize = v.size().0;
|
self.gecko.mSize = v.size().0;
|
||||||
self.gecko.mScriptUnconstrainedSize = v.size().0;
|
self.gecko.mScriptUnconstrainedSize = v.size().0;
|
||||||
if let Some(info) = v.info {
|
if let Some(info) = v.keyword_info {
|
||||||
self.gecko.mFontSizeKeyword = match info.kw {
|
self.gecko.mFontSizeKeyword = match info.kw {
|
||||||
KeywordSize::XXSmall => structs::NS_STYLE_FONT_SIZE_XXSMALL,
|
KeywordSize::XXSmall => structs::NS_STYLE_FONT_SIZE_XXSMALL,
|
||||||
KeywordSize::XSmall => structs::NS_STYLE_FONT_SIZE_XSMALL,
|
KeywordSize::XSmall => structs::NS_STYLE_FONT_SIZE_XSMALL,
|
||||||
|
@ -2385,14 +2385,14 @@ fn static_assert() {
|
||||||
structs::NS_STYLE_FONT_SIZE_NO_KEYWORD => {
|
structs::NS_STYLE_FONT_SIZE_NO_KEYWORD => {
|
||||||
return longhands::font_size::computed_value::T {
|
return longhands::font_size::computed_value::T {
|
||||||
size: size,
|
size: size,
|
||||||
info: None,
|
keyword_info: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!("mFontSizeKeyword should be an absolute keyword or NO_KEYWORD")
|
_ => unreachable!("mFontSizeKeyword should be an absolute keyword or NO_KEYWORD")
|
||||||
};
|
};
|
||||||
longhands::font_size::computed_value::T {
|
longhands::font_size::computed_value::T {
|
||||||
size: size,
|
size: size,
|
||||||
info: Some(KeywordInfo {
|
keyword_info: Some(KeywordInfo {
|
||||||
kw: kw,
|
kw: kw,
|
||||||
factor: self.gecko.mFontSizeFactor,
|
factor: self.gecko.mFontSizeFactor,
|
||||||
offset: Au(self.gecko.mFontSizeOffset).into()
|
offset: Au(self.gecko.mFontSizeOffset).into()
|
||||||
|
|
|
@ -603,6 +603,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
use values::specified::AllowQuirks;
|
use values::specified::AllowQuirks;
|
||||||
use values::specified::length::FontBaseSize;
|
use values::specified::length::FontBaseSize;
|
||||||
use values::specified::font::{FONT_MEDIUM_PX, KeywordSize};
|
use values::specified::font::{FONT_MEDIUM_PX, KeywordSize};
|
||||||
|
use values::computed::font::{KeywordInfo};
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::computed::font;
|
use values::computed::font;
|
||||||
|
@ -616,17 +617,13 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
computed_value::T {
|
computed_value::T {
|
||||||
size: Au::from_px(FONT_MEDIUM_PX).into(),
|
size: Au::from_px(FONT_MEDIUM_PX).into(),
|
||||||
info: Some(::values::computed::font::KeywordInfo {
|
keyword_info: Some(KeywordInfo::medium())
|
||||||
kw: KeywordSize::Medium,
|
|
||||||
factor: 1.,
|
|
||||||
offset: Au(0).into(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
SpecifiedValue::Keyword(KeywordSize::Medium, 1., Au(0).into())
|
SpecifiedValue::Keyword(KeywordInfo::medium())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -647,7 +644,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(kw) = input.try(KeywordSize::parse) {
|
if let Ok(kw) = input.try(KeywordSize::parse) {
|
||||||
return Ok(SpecifiedValue::Keyword(kw, 1., Au(0).into()))
|
return Ok(SpecifiedValue::Keyword(kw.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
|
@ -670,7 +667,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
context.builder.get_parent_font().gecko().mLanguage.raw::<nsIAtom>() ||
|
context.builder.get_parent_font().gecko().mLanguage.raw::<nsIAtom>() ||
|
||||||
context.builder.get_font().gecko().mGenericID !=
|
context.builder.get_font().gecko().mGenericID !=
|
||||||
context.builder.get_parent_font().gecko().mGenericID {
|
context.builder.get_parent_font().gecko().mGenericID {
|
||||||
if let Some(info) = computed.info {
|
if let Some(info) = computed.keyword_info {
|
||||||
computed.size = context.maybe_zoom_text(info.kw.to_computed_value(context)
|
computed.size = context.maybe_zoom_text(info.kw.to_computed_value(context)
|
||||||
.scale_by(info.factor) + info.offset)
|
.scale_by(info.factor) + info.offset)
|
||||||
}
|
}
|
||||||
|
@ -703,8 +700,8 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
// handle mathml scriptlevel changes
|
// handle mathml scriptlevel changes
|
||||||
let kw_inherited_size = context.builder.get_parent_font()
|
let kw_inherited_size = context.builder.get_parent_font()
|
||||||
.clone_font_size()
|
.clone_font_size()
|
||||||
.info.map(|info| {
|
.keyword_info.map(|info| {
|
||||||
context.maybe_zoom_text(SpecifiedValue::Keyword(info.kw, info.factor, info.offset)
|
context.maybe_zoom_text(SpecifiedValue::Keyword(info)
|
||||||
.to_computed_value(context).size)
|
.to_computed_value(context).size)
|
||||||
});
|
});
|
||||||
let mut font = context.builder.take_font();
|
let mut font = context.builder.take_font();
|
||||||
|
@ -2205,7 +2202,10 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
let weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
let weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
||||||
let ret = ComputedSystemFont {
|
let ret = ComputedSystemFont {
|
||||||
font_family: longhands::font_family::computed_value::T(family),
|
font_family: longhands::font_family::computed_value::T(family),
|
||||||
font_size: longhands::font_size::computed_value::T { size: Au(system.size).into(), info: None },
|
font_size: longhands::font_size::computed_value::T {
|
||||||
|
size: Au(system.size).into(),
|
||||||
|
keyword_info: None
|
||||||
|
},
|
||||||
font_weight: weight,
|
font_weight: weight,
|
||||||
font_size_adjust: longhands::font_size_adjust::computed_value
|
font_size_adjust: longhands::font_size_adjust::computed_value
|
||||||
::T::from_gecko_adjust(system.sizeAdjust),
|
::T::from_gecko_adjust(system.sizeAdjust),
|
||||||
|
|
|
@ -10,8 +10,8 @@ use style_traits::ToCss;
|
||||||
use values::computed::NonNegativeLength;
|
use values::computed::NonNegativeLength;
|
||||||
use values::specified::font as specified;
|
use values::specified::font as specified;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Animate, ComputeSquaredDistance, ToAnimatedValue, ToAnimatedZero)]
|
||||||
#[derive(ToAnimatedValue, Animate, ToAnimatedZero, ComputeSquaredDistance)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
/// The computed value of font-size
|
/// The computed value of font-size
|
||||||
|
@ -19,11 +19,11 @@ pub struct FontSize {
|
||||||
/// The size.
|
/// The size.
|
||||||
pub size: NonNegativeLength,
|
pub size: NonNegativeLength,
|
||||||
/// If derived from a keyword, the keyword and additional transformations applied to it
|
/// If derived from a keyword, the keyword and additional transformations applied to it
|
||||||
pub info: Option<KeywordInfo>,
|
pub keyword_info: Option<KeywordInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Animate, ComputeSquaredDistance, ToAnimatedValue, ToAnimatedZero)]
|
||||||
#[derive(ToAnimatedValue, Animate, ToAnimatedZero, ComputeSquaredDistance)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
/// Additional information for keyword-derived font sizes.
|
/// Additional information for keyword-derived font sizes.
|
||||||
|
@ -45,6 +45,21 @@ impl KeywordInfo {
|
||||||
offset: self.offset.scale_by(factor) + offset,
|
offset: self.offset.scale_by(factor) + offset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// KeywordInfo value for font-size: medium
|
||||||
|
pub fn medium() -> Self {
|
||||||
|
specified::KeywordSize::Medium.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<specified::KeywordSize> for KeywordInfo {
|
||||||
|
fn from(x: specified::KeywordSize) -> Self {
|
||||||
|
KeywordInfo {
|
||||||
|
kw: x,
|
||||||
|
factor: 1.,
|
||||||
|
offset: Au(0).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FontSize {
|
impl FontSize {
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub enum FontSize {
|
||||||
/// go into the ratio, and the remaining units all computed together
|
/// go into the ratio, and the remaining units all computed together
|
||||||
/// will go into the offset.
|
/// will go into the offset.
|
||||||
/// See bug 1355707.
|
/// See bug 1355707.
|
||||||
Keyword(KeywordSize, f32, NonNegativeLength),
|
Keyword(computed::KeywordInfo),
|
||||||
/// font-size: smaller
|
/// font-size: smaller
|
||||||
Smaller,
|
Smaller,
|
||||||
/// font-size: larger
|
/// font-size: larger
|
||||||
|
@ -45,7 +45,7 @@ impl ToCss for FontSize {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
match *self {
|
match *self {
|
||||||
FontSize::Length(ref lop) => lop.to_css(dest),
|
FontSize::Length(ref lop) => lop.to_css(dest),
|
||||||
FontSize::Keyword(kw, _, _) => kw.to_css(dest),
|
FontSize::Keyword(info) => info.kw.to_css(dest),
|
||||||
FontSize::Smaller => dest.write_str("smaller"),
|
FontSize::Smaller => dest.write_str("smaller"),
|
||||||
FontSize::Larger => dest.write_str("larger"),
|
FontSize::Larger => dest.write_str("larger"),
|
||||||
FontSize::System(sys) => sys.to_css(dest),
|
FontSize::System(sys) => sys.to_css(dest),
|
||||||
|
@ -60,8 +60,8 @@ impl From<LengthOrPercentage> for FontSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CSS font keywords
|
/// CSS font keywords
|
||||||
|
#[derive(Animate, ComputeSquaredDistance, ToAnimatedValue, ToAnimatedZero)]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
#[derive(ToAnimatedValue, Animate, ToAnimatedZero, ComputeSquaredDistance)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
@ -226,7 +226,7 @@ impl FontSize {
|
||||||
6 => KeywordSize::XXLarge,
|
6 => KeywordSize::XXLarge,
|
||||||
// If value is greater than 7, let it be 7.
|
// If value is greater than 7, let it be 7.
|
||||||
_ => KeywordSize::XXXLarge,
|
_ => KeywordSize::XXXLarge,
|
||||||
}, 1., Au(0).into())
|
}.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute it against a given base font size
|
/// Compute it against a given base font size
|
||||||
|
@ -239,7 +239,7 @@ impl FontSize {
|
||||||
|
|
||||||
let compose_keyword = |factor| {
|
let compose_keyword = |factor| {
|
||||||
context.style().get_parent_font()
|
context.style().get_parent_font()
|
||||||
.clone_font_size().info
|
.clone_font_size().keyword_info
|
||||||
.map(|i| i.compose(factor, Au(0).into()))
|
.map(|i| i.compose(factor, Au(0).into()))
|
||||||
};
|
};
|
||||||
let mut info = None;
|
let mut info = None;
|
||||||
|
@ -274,7 +274,7 @@ impl FontSize {
|
||||||
let parent = context.style().get_parent_font().clone_font_size();
|
let parent = context.style().get_parent_font().clone_font_size();
|
||||||
// if we contain em/% units and the parent was keyword derived, this is too
|
// if we contain em/% units and the parent was keyword derived, this is too
|
||||||
// Extract the ratio/offset and compose it
|
// Extract the ratio/offset and compose it
|
||||||
if (calc.em.is_some() || calc.percentage.is_some()) && parent.info.is_some() {
|
if (calc.em.is_some() || calc.percentage.is_some()) && parent.keyword_info.is_some() {
|
||||||
let ratio = calc.em.unwrap_or(0.) + calc.percentage.map_or(0., |pc| pc.0);
|
let ratio = calc.em.unwrap_or(0.) + calc.percentage.map_or(0., |pc| pc.0);
|
||||||
// Compute it, but shave off the font-relative part (em, %)
|
// Compute it, but shave off the font-relative part (em, %)
|
||||||
// This will mean that other font-relative units like ex and ch will be computed against
|
// This will mean that other font-relative units like ex and ch will be computed against
|
||||||
|
@ -284,19 +284,15 @@ impl FontSize {
|
||||||
// recomputes new ones. This is enough of an edge case to not really matter.
|
// recomputes new ones. This is enough of an edge case to not really matter.
|
||||||
let abs = calc.to_computed_value_zoomed(context, FontBaseSize::Custom(Au(0).into()))
|
let abs = calc.to_computed_value_zoomed(context, FontBaseSize::Custom(Au(0).into()))
|
||||||
.length_component().into();
|
.length_component().into();
|
||||||
info = parent.info.map(|i| i.compose(ratio, abs));
|
info = parent.keyword_info.map(|i| i.compose(ratio, abs));
|
||||||
}
|
}
|
||||||
let calc = calc.to_computed_value_zoomed(context, base_size);
|
let calc = calc.to_computed_value_zoomed(context, base_size);
|
||||||
calc.to_used_value(Some(base_size.resolve(context))).unwrap().into()
|
calc.to_used_value(Some(base_size.resolve(context))).unwrap().into()
|
||||||
}
|
}
|
||||||
FontSize::Keyword(key, fraction, offset) => {
|
FontSize::Keyword(i) => {
|
||||||
// As a specified keyword, this is keyword derived
|
// As a specified keyword, this is keyword derived
|
||||||
info = Some(computed::KeywordInfo {
|
info = Some(i);
|
||||||
kw: key,
|
context.maybe_zoom_text(i.kw.to_computed_value(context).scale_by(i.factor) + i.offset)
|
||||||
factor: fraction,
|
|
||||||
offset: offset,
|
|
||||||
});
|
|
||||||
context.maybe_zoom_text(key.to_computed_value(context).scale_by(fraction) + offset)
|
|
||||||
}
|
}
|
||||||
FontSize::Smaller => {
|
FontSize::Smaller => {
|
||||||
info = compose_keyword(1. / LARGER_FONT_SIZE_RATIO);
|
info = compose_keyword(1. / LARGER_FONT_SIZE_RATIO);
|
||||||
|
@ -318,7 +314,10 @@ impl FontSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
computed::FontSize { size, info }
|
computed::FontSize {
|
||||||
|
size: size,
|
||||||
|
keyword_info: info,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue