stylo: Support -moz-script-size-multiplier, -moz-script-level, -moz-math-display

This commit is contained in:
Manish Goregaokar 2017-04-10 15:28:48 +08:00 committed by Manish Goregaokar
parent 4c851925fb
commit 2e22a006db
7 changed files with 221 additions and 3 deletions

View file

@ -302,6 +302,7 @@ mod bindings {
"NODE_.*",
"NS_FONT_.*",
"NS_STYLE_.*",
"NS_MATHML_.*",
"NS_RADIUS_.*",
"BORDER_COLOR_.*",
"BORDER_STYLE_.*",

View file

@ -1871,6 +1871,12 @@ extern "C" {
property: nsCSSPropertyID,
value: f32);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetNumberValue(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
value: f32);
}
extern "C" {
pub fn Servo_DeclarationBlock_SetPercentValue(declarations:
RawServoDeclarationBlockBorrowed,

View file

@ -540,6 +540,35 @@ pub mod root {
pub const NS_STYLE_GRID_TEMPLATE_SUBGRID: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_GRID_REPEAT_AUTO_FILL: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_GRID_REPEAT_AUTO_FIT: ::std::os::raw::c_uint = 1;
pub const NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER: f32 = 0.71;
pub const NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT: ::std::os::raw::c_uint =
8;
pub const NS_MATHML_MATHVARIANT_NONE: ::std::os::raw::c_uint = 0;
pub const NS_MATHML_MATHVARIANT_NORMAL: ::std::os::raw::c_uint = 1;
pub const NS_MATHML_MATHVARIANT_BOLD: ::std::os::raw::c_uint = 2;
pub const NS_MATHML_MATHVARIANT_ITALIC: ::std::os::raw::c_uint = 3;
pub const NS_MATHML_MATHVARIANT_BOLD_ITALIC: ::std::os::raw::c_uint = 4;
pub const NS_MATHML_MATHVARIANT_SCRIPT: ::std::os::raw::c_uint = 5;
pub const NS_MATHML_MATHVARIANT_BOLD_SCRIPT: ::std::os::raw::c_uint = 6;
pub const NS_MATHML_MATHVARIANT_FRAKTUR: ::std::os::raw::c_uint = 7;
pub const NS_MATHML_MATHVARIANT_DOUBLE_STRUCK: ::std::os::raw::c_uint = 8;
pub const NS_MATHML_MATHVARIANT_BOLD_FRAKTUR: ::std::os::raw::c_uint = 9;
pub const NS_MATHML_MATHVARIANT_SANS_SERIF: ::std::os::raw::c_uint = 10;
pub const NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF: ::std::os::raw::c_uint =
11;
pub const NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC: ::std::os::raw::c_uint
=
12;
pub const NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC:
::std::os::raw::c_uint =
13;
pub const NS_MATHML_MATHVARIANT_MONOSPACE: ::std::os::raw::c_uint = 14;
pub const NS_MATHML_MATHVARIANT_INITIAL: ::std::os::raw::c_uint = 15;
pub const NS_MATHML_MATHVARIANT_TAILED: ::std::os::raw::c_uint = 16;
pub const NS_MATHML_MATHVARIANT_LOOPED: ::std::os::raw::c_uint = 17;
pub const NS_MATHML_MATHVARIANT_STRETCHED: ::std::os::raw::c_uint = 18;
pub const NS_MATHML_DISPLAYSTYLE_INLINE: ::std::os::raw::c_uint = 0;
pub const NS_MATHML_DISPLAYSTYLE_BLOCK: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WIDTH_MAX_CONTENT: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_WIDTH_MIN_CONTENT: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WIDTH_FIT_CONTENT: ::std::os::raw::c_uint = 2;

View file

@ -540,6 +540,35 @@ pub mod root {
pub const NS_STYLE_GRID_TEMPLATE_SUBGRID: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_GRID_REPEAT_AUTO_FILL: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_GRID_REPEAT_AUTO_FIT: ::std::os::raw::c_uint = 1;
pub const NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER: f32 = 0.71;
pub const NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT: ::std::os::raw::c_uint =
8;
pub const NS_MATHML_MATHVARIANT_NONE: ::std::os::raw::c_uint = 0;
pub const NS_MATHML_MATHVARIANT_NORMAL: ::std::os::raw::c_uint = 1;
pub const NS_MATHML_MATHVARIANT_BOLD: ::std::os::raw::c_uint = 2;
pub const NS_MATHML_MATHVARIANT_ITALIC: ::std::os::raw::c_uint = 3;
pub const NS_MATHML_MATHVARIANT_BOLD_ITALIC: ::std::os::raw::c_uint = 4;
pub const NS_MATHML_MATHVARIANT_SCRIPT: ::std::os::raw::c_uint = 5;
pub const NS_MATHML_MATHVARIANT_BOLD_SCRIPT: ::std::os::raw::c_uint = 6;
pub const NS_MATHML_MATHVARIANT_FRAKTUR: ::std::os::raw::c_uint = 7;
pub const NS_MATHML_MATHVARIANT_DOUBLE_STRUCK: ::std::os::raw::c_uint = 8;
pub const NS_MATHML_MATHVARIANT_BOLD_FRAKTUR: ::std::os::raw::c_uint = 9;
pub const NS_MATHML_MATHVARIANT_SANS_SERIF: ::std::os::raw::c_uint = 10;
pub const NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF: ::std::os::raw::c_uint =
11;
pub const NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC: ::std::os::raw::c_uint
=
12;
pub const NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC:
::std::os::raw::c_uint =
13;
pub const NS_MATHML_MATHVARIANT_MONOSPACE: ::std::os::raw::c_uint = 14;
pub const NS_MATHML_MATHVARIANT_INITIAL: ::std::os::raw::c_uint = 15;
pub const NS_MATHML_MATHVARIANT_TAILED: ::std::os::raw::c_uint = 16;
pub const NS_MATHML_MATHVARIANT_LOOPED: ::std::os::raw::c_uint = 17;
pub const NS_MATHML_MATHVARIANT_STRETCHED: ::std::os::raw::c_uint = 18;
pub const NS_MATHML_DISPLAYSTYLE_INLINE: ::std::os::raw::c_uint = 0;
pub const NS_MATHML_DISPLAYSTYLE_BLOCK: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WIDTH_MAX_CONTENT: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_WIDTH_MIN_CONTENT: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WIDTH_FIT_CONTENT: ::std::os::raw::c_uint = 2;

View file

@ -664,6 +664,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
"MaxLength": impl_style_coord,
"MinLength": impl_style_coord,
"Number": impl_simple,
"Integer": impl_simple,
"Opacity": impl_simple,
"CSSColor": impl_color,
"SVGPaint": impl_svg_paint,
@ -1259,8 +1260,12 @@ fn static_assert() {
}
</%self:impl_trait>
<%
skip_font_longhands = """font-family font-size font-size-adjust font-weight
font-synthesis -x-lang font-language-override"""
%>
<%self:impl_trait style_struct_name="Font"
skip_longhands="font-family font-size font-size-adjust font-weight font-synthesis -x-lang font-language-override"
skip_longhands="${skip_font_longhands}"
skip_additionals="*">
pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {

View file

@ -1118,8 +1118,7 @@ ${helpers.single_keyword("font-variant-position",
</%helpers:longhand>
<%helpers:longhand name="-x-lang" products="gecko" animation_type="none" internal="True"
spec="Internal (not web-exposed)"
internal="True">
spec="Internal (not web-exposed)">
use values::HasViewportPercentage;
use values::computed::ComputedValueAsSpecified;
pub use self::computed_value::T as SpecifiedValue;
@ -1153,3 +1152,128 @@ ${helpers.single_keyword("font-variant-position",
Err(())
}
</%helpers:longhand>
// MathML properties
<%helpers:longhand name="-moz-script-size-multiplier" products="gecko" animation_type="none"
predefined_type="Number" gecko_ffi_name="mScriptSizeMultiplier"
spec="Internal (not web-exposed)"
internal="True" disable_when_testing="True">
use values::HasViewportPercentage;
use values::computed::ComputedValueAsSpecified;
pub use self::computed_value::T as SpecifiedValue;
impl ComputedValueAsSpecified for SpecifiedValue {}
no_viewport_percentage!(SpecifiedValue);
pub mod computed_value {
pub type T = f32;
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
::gecko_bindings::structs::NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER
}
pub fn parse(_context: &ParserContext, _input: &mut Parser) -> Result<SpecifiedValue, ()> {
debug_assert!(false, "Should be set directly by presentation attributes only.");
Err(())
}
</%helpers:longhand>
<%helpers:longhand name="-moz-script-level" products="gecko" animation_type="none"
predefined_type="Integer" gecko_ffi_name="mScriptLevel"
spec="Internal (not web-exposed)"
internal="True" disable_when_testing="True" need_clone="True">
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
no_viewport_percentage!(SpecifiedValue);
pub mod computed_value {
pub type T = i8;
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
0
}
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum SpecifiedValue {
Relative(i32),
Absolute(i32),
Auto
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::Auto => dest.write_str("auto"),
SpecifiedValue::Relative(rel) => write!(dest, "{}", rel),
// can only be specified by pres attrs; should not
// serialize to anything else
SpecifiedValue::Absolute(_) => Ok(()),
}
}
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
fn to_computed_value(&self, cx: &Context) -> i8 {
use properties::longhands::_moz_math_display::SpecifiedValue as DisplayValue;
use std::{cmp, i8};
let int = match *self {
SpecifiedValue::Auto => {
let parent = cx.inherited_style().get_font().clone__moz_script_level() as i32;
let display = cx.inherited_style().get_font().clone__moz_math_display();
if display == DisplayValue::inline {
parent + 1
} else {
parent
}
}
SpecifiedValue::Relative(rel) => {
let parent = cx.inherited_style().get_font().clone__moz_script_level();
parent as i32 + rel
}
SpecifiedValue::Absolute(abs) => abs,
};
cmp::min(int, i8::MAX as i32) as i8
}
fn from_computed_value(other: &computed_value::T) -> Self {
SpecifiedValue::Absolute(*other as i32)
}
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if let Ok(i) = input.try(|i| i.expect_integer()) {
return Ok(SpecifiedValue::Relative(i))
}
input.expect_ident_matching("auto")?;
Ok(SpecifiedValue::Auto)
}
</%helpers:longhand>
${helpers.single_keyword("-moz-math-display",
"inline block",
gecko_constant_prefix="NS_MATHML_DISPLAYSTYLE",
gecko_ffi_name="mMathDisplay",
products="gecko",
spec="Internal (not web-exposed)",
animation_type="none",
need_clone="True")}
${helpers.single_keyword("-moz-math-variant",
"""normal bold italic bold-italic script bold-script
fraktur double-struck bold-fraktur sans-serif
bold-sans-serif sans-serif-italic sans-serif-bold-italic
monospace initial tailed looped stretched""",
gecko_constant_prefix="NS_MATHML_MATHVARIANT",
gecko_ffi_name="mMathVariant",
products="gecko",
spec="Internal (not web-exposed)",
animation_type="none",
needs_conversion=True)}

View file

@ -1338,6 +1338,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(declarations:
longhands::font_size::SpecifiedValue::from_html_size(value as u8)
},
ListStyleType => longhands::list_style_type::SpecifiedValue::from_gecko_keyword(value),
MozMathVariant => longhands::_moz_math_variant::SpecifiedValue::from_gecko_keyword(value),
WhiteSpace => longhands::white_space::SpecifiedValue::from_gecko_keyword(value),
CaptionSide => longhands::caption_side::SpecifiedValue::from_gecko_keyword(value),
BorderTopStyle => BorderStyle::from_gecko_keyword(value),
@ -1355,11 +1356,14 @@ pub extern "C" fn Servo_DeclarationBlock_SetIntValue(declarations: RawServoDecla
property: nsCSSPropertyID,
value: i32) {
use style::properties::{PropertyDeclaration, LonghandId};
use style::properties::longhands::_moz_script_level::SpecifiedValue as MozScriptLevel;
use style::properties::longhands::_x_span::computed_value::T as Span;
let long = get_longhand_from_id!(property);
let prop = match_wrap_declared! { long,
XSpan => Span(value),
// Gecko uses Integer values to signal that it is relative
MozScriptLevel => MozScriptLevel::Relative(value),
};
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
decls.push(prop, Importance::Normal);
@ -1406,6 +1410,26 @@ pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(declarations:
})
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetNumberValue(declarations:
RawServoDeclarationBlockBorrowed,
property: nsCSSPropertyID,
value: f32) {
use style::properties::{PropertyDeclaration, LonghandId};
use style::properties::longhands::_moz_script_level::SpecifiedValue as MozScriptLevel;
let long = get_longhand_from_id!(property);
let prop = match_wrap_declared! { long,
MozScriptSizeMultiplier => value,
// Gecko uses Number values to signal that it is absolute
MozScriptLevel => MozScriptLevel::Absolute(value as i32),
};
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
decls.push(prop, Importance::Normal);
})
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(declarations:
RawServoDeclarationBlockBorrowed,