mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #18451 - Manishearth:stylo-calc-fontsize, r=emilio
stylo: Add support for calcs in base size calculation This tracks an offset along with the ratio for the keyword font size data. The offset gets used when a calc is involved whilst inheriting font-size (it is the computed value of that calc ignoring em/percentage portions, which go into the ratio). If the family or language changes, the new font size can be computed by taking the keyword's size in the context of that family/language, multiplying it by the ratio, and adding the offset. r=emilio https://bugzilla.mozilla.org/show_bug.cgi?id=1380980 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18451) <!-- Reviewable:end -->
This commit is contained in:
commit
f91ea02bf7
7 changed files with 106 additions and 91 deletions
|
@ -5007,7 +5007,7 @@ pub mod root {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_ServoStyleContext() {
|
fn bindgen_test_layout_ServoStyleContext() {
|
||||||
assert_eq!(::std::mem::size_of::<ServoStyleContext>() , 272usize ,
|
assert_eq!(::std::mem::size_of::<ServoStyleContext>() , 280usize ,
|
||||||
concat ! (
|
concat ! (
|
||||||
"Size of: " , stringify ! ( ServoStyleContext ) ));
|
"Size of: " , stringify ! ( ServoStyleContext ) ));
|
||||||
assert_eq! (::std::mem::align_of::<ServoStyleContext>() , 8usize ,
|
assert_eq! (::std::mem::align_of::<ServoStyleContext>() , 8usize ,
|
||||||
|
@ -5030,14 +5030,14 @@ pub mod root {
|
||||||
assert_eq! (unsafe {
|
assert_eq! (unsafe {
|
||||||
& ( * ( 0 as * const ServoStyleContext ) ) .
|
& ( * ( 0 as * const ServoStyleContext ) ) .
|
||||||
mNextInheritingAnonBoxStyle as * const _ as usize } ,
|
mNextInheritingAnonBoxStyle as * const _ as usize } ,
|
||||||
256usize , concat ! (
|
264usize , concat ! (
|
||||||
"Alignment of field: " , stringify ! (
|
"Alignment of field: " , stringify ! (
|
||||||
ServoStyleContext ) , "::" , stringify ! (
|
ServoStyleContext ) , "::" , stringify ! (
|
||||||
mNextInheritingAnonBoxStyle ) ));
|
mNextInheritingAnonBoxStyle ) ));
|
||||||
assert_eq! (unsafe {
|
assert_eq! (unsafe {
|
||||||
& ( * ( 0 as * const ServoStyleContext ) ) .
|
& ( * ( 0 as * const ServoStyleContext ) ) .
|
||||||
mNextLazyPseudoStyle as * const _ as usize } ,
|
mNextLazyPseudoStyle as * const _ as usize } ,
|
||||||
264usize , concat ! (
|
272usize , concat ! (
|
||||||
"Alignment of field: " , stringify ! (
|
"Alignment of field: " , stringify ! (
|
||||||
ServoStyleContext ) , "::" , stringify ! (
|
ServoStyleContext ) , "::" , stringify ! (
|
||||||
mNextLazyPseudoStyle ) ));
|
mNextLazyPseudoStyle ) ));
|
||||||
|
@ -15914,7 +15914,7 @@ pub mod root {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_ServoComputedData() {
|
fn bindgen_test_layout_ServoComputedData() {
|
||||||
assert_eq!(::std::mem::size_of::<ServoComputedData>() , 224usize ,
|
assert_eq!(::std::mem::size_of::<ServoComputedData>() , 232usize ,
|
||||||
concat ! ( "Size of: " , stringify ! ( ServoComputedData )
|
concat ! ( "Size of: " , stringify ! ( ServoComputedData )
|
||||||
));
|
));
|
||||||
assert_eq! (::std::mem::align_of::<ServoComputedData>() , 8usize ,
|
assert_eq! (::std::mem::align_of::<ServoComputedData>() , 8usize ,
|
||||||
|
|
|
@ -4895,7 +4895,7 @@ pub mod root {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_ServoStyleContext() {
|
fn bindgen_test_layout_ServoStyleContext() {
|
||||||
assert_eq!(::std::mem::size_of::<ServoStyleContext>() , 264usize ,
|
assert_eq!(::std::mem::size_of::<ServoStyleContext>() , 272usize ,
|
||||||
concat ! (
|
concat ! (
|
||||||
"Size of: " , stringify ! ( ServoStyleContext ) ));
|
"Size of: " , stringify ! ( ServoStyleContext ) ));
|
||||||
assert_eq! (::std::mem::align_of::<ServoStyleContext>() , 8usize ,
|
assert_eq! (::std::mem::align_of::<ServoStyleContext>() , 8usize ,
|
||||||
|
@ -4918,14 +4918,14 @@ pub mod root {
|
||||||
assert_eq! (unsafe {
|
assert_eq! (unsafe {
|
||||||
& ( * ( 0 as * const ServoStyleContext ) ) .
|
& ( * ( 0 as * const ServoStyleContext ) ) .
|
||||||
mNextInheritingAnonBoxStyle as * const _ as usize } ,
|
mNextInheritingAnonBoxStyle as * const _ as usize } ,
|
||||||
248usize , concat ! (
|
256usize , concat ! (
|
||||||
"Alignment of field: " , stringify ! (
|
"Alignment of field: " , stringify ! (
|
||||||
ServoStyleContext ) , "::" , stringify ! (
|
ServoStyleContext ) , "::" , stringify ! (
|
||||||
mNextInheritingAnonBoxStyle ) ));
|
mNextInheritingAnonBoxStyle ) ));
|
||||||
assert_eq! (unsafe {
|
assert_eq! (unsafe {
|
||||||
& ( * ( 0 as * const ServoStyleContext ) ) .
|
& ( * ( 0 as * const ServoStyleContext ) ) .
|
||||||
mNextLazyPseudoStyle as * const _ as usize } ,
|
mNextLazyPseudoStyle as * const _ as usize } ,
|
||||||
256usize , concat ! (
|
264usize , concat ! (
|
||||||
"Alignment of field: " , stringify ! (
|
"Alignment of field: " , stringify ! (
|
||||||
ServoStyleContext ) , "::" , stringify ! (
|
ServoStyleContext ) , "::" , stringify ! (
|
||||||
mNextLazyPseudoStyle ) ));
|
mNextLazyPseudoStyle ) ));
|
||||||
|
@ -15706,7 +15706,7 @@ pub mod root {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_ServoComputedData() {
|
fn bindgen_test_layout_ServoComputedData() {
|
||||||
assert_eq!(::std::mem::size_of::<ServoComputedData>() , 224usize ,
|
assert_eq!(::std::mem::size_of::<ServoComputedData>() , 232usize ,
|
||||||
concat ! ( "Size of: " , stringify ! ( ServoComputedData )
|
concat ! ( "Size of: " , stringify ! ( ServoComputedData )
|
||||||
));
|
));
|
||||||
assert_eq! (::std::mem::align_of::<ServoComputedData>() , 8usize ,
|
assert_eq! (::std::mem::align_of::<ServoComputedData>() , 8usize ,
|
||||||
|
|
|
@ -53,7 +53,7 @@ use logical_geometry::WritingMode;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
use properties::animated_properties::TransitionProperty;
|
use properties::animated_properties::TransitionProperty;
|
||||||
use properties::computed_value_flags::ComputedValueFlags;
|
use properties::computed_value_flags::ComputedValueFlags;
|
||||||
use properties::{longhands, FontComputationData, Importance, LonghandId};
|
use properties::{default_font_size_keyword, longhands, FontComputationData, Importance, LonghandId};
|
||||||
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
|
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
|
||||||
use rule_tree::StrongRuleNode;
|
use rule_tree::StrongRuleNode;
|
||||||
use selector_parser::PseudoElement;
|
use selector_parser::PseudoElement;
|
||||||
|
@ -85,7 +85,7 @@ impl ComputedValues {
|
||||||
pseudo: Option<<&PseudoElement>,
|
pseudo: Option<<&PseudoElement>,
|
||||||
custom_properties: Option<Arc<CustomPropertiesMap>>,
|
custom_properties: Option<Arc<CustomPropertiesMap>>,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
font_size_keyword: FontComputationData,
|
||||||
flags: ComputedValueFlags,
|
flags: ComputedValueFlags,
|
||||||
rules: Option<StrongRuleNode>,
|
rules: Option<StrongRuleNode>,
|
||||||
visited_style: Option<Arc<ComputedValues>>,
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
|
@ -114,7 +114,7 @@ impl ComputedValues {
|
||||||
ComputedValuesInner::new(
|
ComputedValuesInner::new(
|
||||||
/* custom_properties = */ None,
|
/* custom_properties = */ None,
|
||||||
/* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
|
/* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
|
||||||
FontComputationData::default_font_size_keyword(),
|
default_font_size_keyword(),
|
||||||
ComputedValueFlags::empty(),
|
ComputedValueFlags::empty(),
|
||||||
/* rules = */ None,
|
/* rules = */ None,
|
||||||
/* visited_style = */ None,
|
/* visited_style = */ None,
|
||||||
|
@ -188,7 +188,7 @@ type ParentStyleContextInfo<'a> = Option< &'a ComputedValues>;
|
||||||
impl ComputedValuesInner {
|
impl ComputedValuesInner {
|
||||||
pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>,
|
pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
font_size_keyword: FontComputationData,
|
||||||
flags: ComputedValueFlags,
|
flags: ComputedValueFlags,
|
||||||
rules: Option<StrongRuleNode>,
|
rules: Option<StrongRuleNode>,
|
||||||
visited_style: Option<Arc<ComputedValues>>,
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
|
@ -199,7 +199,7 @@ impl ComputedValuesInner {
|
||||||
ComputedValuesInner {
|
ComputedValuesInner {
|
||||||
custom_properties: custom_properties,
|
custom_properties: custom_properties,
|
||||||
writing_mode: writing_mode,
|
writing_mode: writing_mode,
|
||||||
font_computation_data: FontComputationData::new(font_size_keyword),
|
font_computation_data: font_size_keyword,
|
||||||
rules: rules,
|
rules: rules,
|
||||||
visited_style: visited_style.map(|x| Arc::into_raw_offset(x)),
|
visited_style: visited_style.map(|x| Arc::into_raw_offset(x)),
|
||||||
flags: flags,
|
flags: flags,
|
||||||
|
|
|
@ -605,7 +605,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
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 {
|
||||||
SpecifiedValue::Length(ref lop) => lop.to_css(dest),
|
SpecifiedValue::Length(ref lop) => lop.to_css(dest),
|
||||||
SpecifiedValue::Keyword(kw, _) => kw.to_css(dest),
|
SpecifiedValue::Keyword(kw, _, _) => kw.to_css(dest),
|
||||||
SpecifiedValue::Smaller => dest.write_str("smaller"),
|
SpecifiedValue::Smaller => dest.write_str("smaller"),
|
||||||
SpecifiedValue::Larger => dest.write_str("larger"),
|
SpecifiedValue::Larger => dest.write_str("larger"),
|
||||||
SpecifiedValue::System(sys) => sys.to_css(dest),
|
SpecifiedValue::System(sys) => sys.to_css(dest),
|
||||||
|
@ -617,13 +617,17 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub enum SpecifiedValue {
|
pub enum SpecifiedValue {
|
||||||
Length(specified::LengthOrPercentage),
|
Length(specified::LengthOrPercentage),
|
||||||
/// A keyword value, along with a ratio.
|
/// A keyword value, along with a ratio and absolute offset.
|
||||||
/// The ratio in any specified keyword value
|
/// The ratio in any specified keyword value
|
||||||
/// will be 1, but we cascade keywordness even
|
/// will be 1 (with offset 0), but we cascade keywordness even
|
||||||
/// after font-relative (percent and em) values
|
/// after font-relative (percent and em) values
|
||||||
/// have been applied, which is where the keyword
|
/// have been applied, which is where the ratio
|
||||||
/// comes in. See bug 1355707
|
/// comes in. The offset comes in if we cascaded a calc value,
|
||||||
Keyword(KeywordSize, f32),
|
/// where the font-relative portion (em and percentage) will
|
||||||
|
/// go into the ratio, and the remaining units all computed together
|
||||||
|
/// will go into the offset.
|
||||||
|
/// See bug 1355707.
|
||||||
|
Keyword(KeywordSize, f32, NonNegativeAu),
|
||||||
Smaller,
|
Smaller,
|
||||||
Larger,
|
Larger,
|
||||||
System(SystemFont)
|
System(SystemFont)
|
||||||
|
@ -802,32 +806,45 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
6 => XXLarge,
|
6 => XXLarge,
|
||||||
// If value is greater than 7, let it be 7.
|
// If value is greater than 7, let it be 7.
|
||||||
_ => XXXLarge,
|
_ => XXXLarge,
|
||||||
}, 1.)
|
}, 1., Au(0).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If this value is specified as a ratio of the parent font (em units
|
/// If this value is specified as a ratio of the parent font (em units
|
||||||
/// or percent) return the ratio
|
/// or percent) return the ratio
|
||||||
pub fn as_font_ratio(&self) -> Option<f32> {
|
pub fn as_font_ratio(&self, context: &Context) -> Option<(f32, NonNegativeAu)> {
|
||||||
match *self {
|
match *self {
|
||||||
SpecifiedValue::Length(ref lop) => {
|
SpecifiedValue::Length(ref lop) => {
|
||||||
match *lop {
|
match *lop {
|
||||||
LengthOrPercentage::Percentage(pc) => {
|
LengthOrPercentage::Percentage(pc) => {
|
||||||
Some(pc.0)
|
Some((pc.0, Au(0).into()))
|
||||||
}
|
}
|
||||||
LengthOrPercentage::Length(ref nocalc) => {
|
LengthOrPercentage::Length(ref nocalc) => {
|
||||||
match *nocalc {
|
match *nocalc {
|
||||||
NoCalcLength::FontRelative(FontRelativeLength::Em(em)) => {
|
NoCalcLength::FontRelative(FontRelativeLength::Em(em)) => {
|
||||||
Some(em)
|
Some((em, Au(0).into()))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME(emilio): This looks super fishy!
|
LengthOrPercentage::Calc(ref calc) => {
|
||||||
LengthOrPercentage::Calc(..) => None,
|
if calc.em.is_none() && calc.percentage.is_none() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
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, %)
|
||||||
|
// This will mean that other font-relative units like ex and ch will be computed against
|
||||||
|
// the old font even when the font changes. There's no particular "right answer" for what
|
||||||
|
// to do here -- Gecko recascades as if the font had changed, we instead track the changes
|
||||||
|
// and reapply, which means that we carry over old computed ex/ch values whilst Gecko
|
||||||
|
// 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()))
|
||||||
|
.length_component().into();
|
||||||
|
Some((ratio, abs))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SpecifiedValue::Larger => Some(LARGER_FONT_SIZE_RATIO),
|
SpecifiedValue::Larger => Some((LARGER_FONT_SIZE_RATIO, Au(0).into())),
|
||||||
SpecifiedValue::Smaller => Some(1. / LARGER_FONT_SIZE_RATIO),
|
SpecifiedValue::Smaller => Some((1. / LARGER_FONT_SIZE_RATIO, Au(0).into())),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -862,8 +879,8 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
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()
|
||||||
}
|
}
|
||||||
SpecifiedValue::Keyword(ref key, fraction) => {
|
SpecifiedValue::Keyword(ref key, fraction, offset) => {
|
||||||
context.maybe_zoom_text(key.to_computed_value(context).scale_by(fraction))
|
context.maybe_zoom_text(key.to_computed_value(context).scale_by(fraction) + offset)
|
||||||
}
|
}
|
||||||
SpecifiedValue::Smaller => {
|
SpecifiedValue::Smaller => {
|
||||||
FontRelativeLength::Em(1. / LARGER_FONT_SIZE_RATIO)
|
FontRelativeLength::Em(1. / LARGER_FONT_SIZE_RATIO)
|
||||||
|
@ -891,7 +908,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
SpecifiedValue::Keyword(Medium, 1.)
|
SpecifiedValue::Keyword(Medium, 1., Au(0).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -928,7 +945,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.))
|
return Ok(SpecifiedValue::Keyword(kw, 1., Au(0).into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
|
@ -954,17 +971,18 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
pub fn cascade_specified_font_size(context: &mut Context,
|
pub fn cascade_specified_font_size(context: &mut Context,
|
||||||
specified_value: &SpecifiedValue,
|
specified_value: &SpecifiedValue,
|
||||||
mut computed: NonNegativeAu) {
|
mut computed: NonNegativeAu) {
|
||||||
if let SpecifiedValue::Keyword(kw, fraction) = *specified_value {
|
if let SpecifiedValue::Keyword(kw, fraction, offset) = *specified_value {
|
||||||
context.builder.font_size_keyword = Some((kw, fraction));
|
context.builder.font_size_keyword = Some((kw, fraction, offset));
|
||||||
} else if let Some(ratio) = specified_value.as_font_ratio() {
|
} else if let Some((ratio, abs)) = specified_value.as_font_ratio(context) {
|
||||||
// In case a font-size-relative value was applied to a keyword
|
// In case a font-size-relative value was applied to a keyword
|
||||||
// value, we must preserve this fact in case the generic font family
|
// value, we must preserve this fact in case the generic font family
|
||||||
// changes. relative values (em and %) applied to keywords must be
|
// changes. relative values (em and %) applied to keywords must be
|
||||||
// recomputed from the base size for the keyword and the relative size.
|
// recomputed from the base size for the keyword and the relative size.
|
||||||
//
|
//
|
||||||
// See bug 1355707
|
// See bug 1355707
|
||||||
if let Some((kw, fraction)) = context.builder.inherited_font_computation_data().font_size_keyword {
|
if let Some((kw, fraction, old_abs)) = *context.builder.inherited_font_computation_data() {
|
||||||
context.builder.font_size_keyword = Some((kw, fraction * ratio));
|
context.builder.font_size_keyword =
|
||||||
|
Some((kw, fraction * ratio, abs + old_abs.0.scale_by(ratio).into()));
|
||||||
} else {
|
} else {
|
||||||
context.builder.font_size_keyword = None;
|
context.builder.font_size_keyword = None;
|
||||||
}
|
}
|
||||||
|
@ -982,8 +1000,8 @@ ${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((kw, ratio)) = context.builder.font_size_keyword {
|
if let Some((kw, ratio, offset)) = context.builder.font_size_keyword {
|
||||||
computed = context.maybe_zoom_text(kw.to_computed_value(context).scale_by(ratio));
|
computed = context.maybe_zoom_text(kw.to_computed_value(context).scale_by(ratio) + offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
|
@ -1012,15 +1030,15 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
// If inheriting, we must recompute font-size in case of language
|
// If inheriting, we must recompute font-size in case of language
|
||||||
// changes using the font_size_keyword. We also need to do this to
|
// changes using the font_size_keyword. We also need to do this to
|
||||||
// handle mathml scriptlevel changes
|
// handle mathml scriptlevel changes
|
||||||
let kw_inherited_size = context.builder.font_size_keyword.map(|(kw, ratio)| {
|
let kw_inherited_size = context.builder.font_size_keyword.map(|(kw, ratio, offset)| {
|
||||||
context.maybe_zoom_text(SpecifiedValue::Keyword(kw, ratio).to_computed_value(context))
|
context.maybe_zoom_text(SpecifiedValue::Keyword(kw, ratio, offset).to_computed_value(context))
|
||||||
});
|
});
|
||||||
let parent_kw;
|
let parent_kw;
|
||||||
let device = context.builder.device;
|
let device = context.builder.device;
|
||||||
let mut font = context.builder.take_font();
|
let mut font = context.builder.take_font();
|
||||||
let used_kw = {
|
let used_kw = {
|
||||||
let parent_font = context.builder.get_parent_font();
|
let parent_font = context.builder.get_parent_font();
|
||||||
parent_kw = context.builder.inherited_font_computation_data().font_size_keyword;
|
parent_kw = *context.builder.inherited_font_computation_data();
|
||||||
|
|
||||||
font.inherit_font_size_from(parent_font, kw_inherited_size, device)
|
font.inherit_font_size_from(parent_font, kw_inherited_size, device)
|
||||||
};
|
};
|
||||||
|
@ -1047,7 +1065,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
let device = context.builder.device;
|
let device = context.builder.device;
|
||||||
context.builder.mutate_font().fixup_font_min_size(device);
|
context.builder.mutate_font().fixup_font_min_size(device);
|
||||||
% endif
|
% endif
|
||||||
context.builder.font_size_keyword = Some((Default::default(), 1.));
|
context.builder.font_size_keyword = Some((Default::default(), 1., Au(0).into()));
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
#[cfg(feature = "servo")] use app_units::Au;
|
use app_units::Au;
|
||||||
use servo_arc::{Arc, UniqueArc};
|
use servo_arc::{Arc, UniqueArc};
|
||||||
use smallbitvec::SmallBitVec;
|
use smallbitvec::SmallBitVec;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -94,43 +94,27 @@ pub trait MaybeBoxed<Out> {
|
||||||
|
|
||||||
/// This is where we store extra font data while
|
/// This is where we store extra font data while
|
||||||
/// while computing font sizes.
|
/// while computing font sizes.
|
||||||
#[derive(Clone, Debug)]
|
///
|
||||||
pub struct FontComputationData {
|
/// font-size keyword values (and font-size-relative values applied
|
||||||
/// font-size keyword values (and font-size-relative values applied
|
/// to keyword values) need to preserve their identity as originating
|
||||||
/// to keyword values) need to preserve their identity as originating
|
/// from keywords and relative font sizes. We store this information
|
||||||
/// from keywords and relative font sizes. We store this information
|
/// out of band in the ComputedValues. When None, the font size on the
|
||||||
/// out of band in the ComputedValues. When None, the font size on the
|
/// current struct was computed from a value that was not a keyword
|
||||||
/// current struct was computed from a value that was not a keyword
|
/// or a chain of font-size-relative values applying to successive parents
|
||||||
/// or a chain of font-size-relative values applying to successive parents
|
/// terminated by a keyword. When Some, this means the font-size was derived
|
||||||
/// terminated by a keyword. When Some, this means the font-size was derived
|
/// from a keyword value or a keyword value on some ancestor with only
|
||||||
/// from a keyword value or a keyword value on some ancestor with only
|
/// font-size-relative keywords and regular inheritance in between. The
|
||||||
/// font-size-relative keywords and regular inheritance in between. The
|
/// integer stores the final ratio of the chain of font size relative values.
|
||||||
/// integer stores the final ratio of the chain of font size relative values.
|
/// and is 1 when there was just a keyword and no relative values.
|
||||||
/// and is 1 when there was just a keyword and no relative values.
|
///
|
||||||
///
|
/// When this is Some, we compute font sizes by computing the keyword against
|
||||||
/// When this is Some, we compute font sizes by computing the keyword against
|
/// the generic font, and then multiplying it by the ratio (as well as adding any
|
||||||
/// the generic font, and then multiplying it by the ratio.
|
/// absolute offset from calcs)
|
||||||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>
|
pub type FontComputationData = Option<(longhands::font_size::KeywordSize, f32, NonNegativeAu)>;
|
||||||
}
|
|
||||||
|
|
||||||
|
/// Default value for FontComputationData
|
||||||
impl FontComputationData {
|
pub fn default_font_size_keyword() -> FontComputationData {
|
||||||
/// Assigns values for variables in struct FontComputationData
|
Some((Default::default(), 1., Au(0).into()))
|
||||||
pub fn new(font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>) -> Self {
|
|
||||||
FontComputationData {
|
|
||||||
font_size_keyword: font_size_keyword
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Assigns default values for variables in struct FontComputationData
|
|
||||||
pub fn default_font_size_keyword() -> Option<(longhands::font_size::KeywordSize, f32)> {
|
|
||||||
Some((Default::default(), 1.))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets a FontComputationData with the default values.
|
|
||||||
pub fn default_values() -> Self {
|
|
||||||
Self::new(Self::default_font_size_keyword())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> MaybeBoxed<T> for T {
|
impl<T> MaybeBoxed<T> for T {
|
||||||
|
@ -2007,7 +1991,7 @@ impl ComputedValues {
|
||||||
_: Option<<&PseudoElement>,
|
_: Option<<&PseudoElement>,
|
||||||
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
font_size_keyword: FontComputationData,
|
||||||
flags: ComputedValueFlags,
|
flags: ComputedValueFlags,
|
||||||
rules: Option<StrongRuleNode>,
|
rules: Option<StrongRuleNode>,
|
||||||
visited_style: Option<Arc<ComputedValues>>,
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
|
@ -2040,7 +2024,7 @@ impl ComputedValuesInner {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
font_size_keyword: FontComputationData,
|
||||||
flags: ComputedValueFlags,
|
flags: ComputedValueFlags,
|
||||||
rules: Option<StrongRuleNode>,
|
rules: Option<StrongRuleNode>,
|
||||||
visited_style: Option<Arc<ComputedValues>>,
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
|
@ -2051,7 +2035,7 @@ impl ComputedValuesInner {
|
||||||
ComputedValuesInner {
|
ComputedValuesInner {
|
||||||
custom_properties: custom_properties,
|
custom_properties: custom_properties,
|
||||||
writing_mode: writing_mode,
|
writing_mode: writing_mode,
|
||||||
font_computation_data: FontComputationData::new(font_size_keyword),
|
font_computation_data: font_size_keyword,
|
||||||
rules: rules,
|
rules: rules,
|
||||||
visited_style: visited_style,
|
visited_style: visited_style,
|
||||||
flags: flags,
|
flags: flags,
|
||||||
|
@ -2564,7 +2548,7 @@ pub struct StyleBuilder<'a> {
|
||||||
/// TODO(emilio): Make private.
|
/// TODO(emilio): Make private.
|
||||||
pub writing_mode: WritingMode,
|
pub writing_mode: WritingMode,
|
||||||
/// The keyword behind the current font-size property, if any.
|
/// The keyword behind the current font-size property, if any.
|
||||||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
pub font_size_keyword: FontComputationData,
|
||||||
/// Flags for the computed value.
|
/// Flags for the computed value.
|
||||||
pub flags: ComputedValueFlags,
|
pub flags: ComputedValueFlags,
|
||||||
/// The element's style if visited, only computed if there's a relevant link
|
/// The element's style if visited, only computed if there's a relevant link
|
||||||
|
@ -2587,7 +2571,7 @@ impl<'a> StyleBuilder<'a> {
|
||||||
rules: Option<StrongRuleNode>,
|
rules: Option<StrongRuleNode>,
|
||||||
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
font_size_keyword: FontComputationData,
|
||||||
flags: ComputedValueFlags,
|
flags: ComputedValueFlags,
|
||||||
visited_style: Option<Arc<ComputedValues>>,
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -2657,7 +2641,7 @@ impl<'a> StyleBuilder<'a> {
|
||||||
rules: None, // FIXME(emilio): Dubious...
|
rules: None, // FIXME(emilio): Dubious...
|
||||||
custom_properties: style_to_derive_from.custom_properties(),
|
custom_properties: style_to_derive_from.custom_properties(),
|
||||||
writing_mode: style_to_derive_from.writing_mode,
|
writing_mode: style_to_derive_from.writing_mode,
|
||||||
font_size_keyword: style_to_derive_from.font_computation_data.font_size_keyword,
|
font_size_keyword: style_to_derive_from.font_computation_data,
|
||||||
flags: style_to_derive_from.flags,
|
flags: style_to_derive_from.flags,
|
||||||
visited_style: style_to_derive_from.clone_visited_style(),
|
visited_style: style_to_derive_from.clone_visited_style(),
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
|
@ -2757,7 +2741,7 @@ impl<'a> StyleBuilder<'a> {
|
||||||
/* rules = */ None,
|
/* rules = */ None,
|
||||||
parent.custom_properties(),
|
parent.custom_properties(),
|
||||||
parent.writing_mode,
|
parent.writing_mode,
|
||||||
parent.font_computation_data.font_size_keyword,
|
parent.font_computation_data,
|
||||||
parent.flags,
|
parent.flags,
|
||||||
parent.clone_visited_style()
|
parent.clone_visited_style()
|
||||||
)
|
)
|
||||||
|
@ -2912,7 +2896,8 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
|
||||||
mod lazy_static_module {
|
mod lazy_static_module {
|
||||||
use logical_geometry::WritingMode;
|
use logical_geometry::WritingMode;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use super::{ComputedValues, ComputedValuesInner, longhands, style_structs, FontComputationData};
|
use super::{ComputedValues, ComputedValuesInner, longhands, style_structs};
|
||||||
|
use super::default_font_size_keyword;
|
||||||
use super::computed_value_flags::ComputedValueFlags;
|
use super::computed_value_flags::ComputedValueFlags;
|
||||||
|
|
||||||
/// The initial values for all style structs as defined by the specification.
|
/// The initial values for all style structs as defined by the specification.
|
||||||
|
@ -2931,7 +2916,7 @@ mod lazy_static_module {
|
||||||
% endfor
|
% endfor
|
||||||
custom_properties: None,
|
custom_properties: None,
|
||||||
writing_mode: WritingMode::empty(),
|
writing_mode: WritingMode::empty(),
|
||||||
font_computation_data: FontComputationData::default_values(),
|
font_computation_data: default_font_size_keyword(),
|
||||||
rules: None,
|
rules: None,
|
||||||
visited_style: None,
|
visited_style: None,
|
||||||
flags: ComputedValueFlags::empty(),
|
flags: ComputedValueFlags::empty(),
|
||||||
|
@ -3152,7 +3137,7 @@ where
|
||||||
Some(rules.clone()),
|
Some(rules.clone()),
|
||||||
custom_properties,
|
custom_properties,
|
||||||
WritingMode::empty(),
|
WritingMode::empty(),
|
||||||
inherited_style.font_computation_data.font_size_keyword,
|
inherited_style.font_computation_data,
|
||||||
ComputedValueFlags::empty(),
|
ComputedValueFlags::empty(),
|
||||||
visited_style,
|
visited_style,
|
||||||
),
|
),
|
||||||
|
|
|
@ -113,6 +113,12 @@ impl CalcLengthOrPercentage {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn length(&self) -> Au {
|
pub fn length(&self) -> Au {
|
||||||
debug_assert!(self.percentage.is_none());
|
debug_assert!(self.percentage.is_none());
|
||||||
|
self.length_component()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the length component of this `calc()`
|
||||||
|
#[inline]
|
||||||
|
pub fn length_component(&self) -> Au {
|
||||||
self.clamping_mode.clamp(self.length)
|
self.clamping_mode.clamp(self.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,7 @@ use properties;
|
||||||
use properties::{ComputedValues, StyleBuilder};
|
use properties::{ComputedValues, StyleBuilder};
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::f32;
|
use std::{f32, fmt, ops};
|
||||||
use std::fmt;
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
@ -563,6 +562,13 @@ impl NonNegativeAu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ops::Add<NonNegativeAu> for NonNegativeAu {
|
||||||
|
type Output = NonNegativeAu;
|
||||||
|
fn add(self, other: Self) -> Self {
|
||||||
|
(self.0 + other.0).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Au> for NonNegativeAu {
|
impl From<Au> for NonNegativeAu {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(au: Au) -> NonNegativeAu {
|
fn from(au: Au) -> NonNegativeAu {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue