diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index a0402e3f3e3..07ed6329808 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -302,6 +302,7 @@ mod bindings { "NODE_.*", "NS_FONT_.*", "NS_STYLE_.*", + "NS_MATHML_.*", "NS_RADIUS_.*", "BORDER_COLOR_.*", "BORDER_STYLE_.*", diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 74c78ef7efc..a189187b1ed 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -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, diff --git a/components/style/gecko_bindings/structs_debug.rs b/components/style/gecko_bindings/structs_debug.rs index 3d5a9efaed6..019b92cad9b 100644 --- a/components/style/gecko_bindings/structs_debug.rs +++ b/components/style/gecko_bindings/structs_debug.rs @@ -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; diff --git a/components/style/gecko_bindings/structs_release.rs b/components/style/gecko_bindings/structs_release.rs index 5ddf3bc99d9..61e77ea4d96 100644 --- a/components/style/gecko_bindings/structs_release.rs +++ b/components/style/gecko_bindings/structs_release.rs @@ -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; diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 4f066f46da5..29cfd49ad88 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -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() { } +<% + 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) { diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index a1a13ae8c6b..75458446839 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -1118,8 +1118,7 @@ ${helpers.single_keyword("font-variant-position", <%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(()) } + +// 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 { + debug_assert!(false, "Should be set directly by presentation attributes only."); + Err(()) + } + + +<%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(&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 { + if let Ok(i) = input.try(|i| i.expect_integer()) { + return Ok(SpecifiedValue::Relative(i)) + } + input.expect_ident_matching("auto")?; + Ok(SpecifiedValue::Auto) + } + + +${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)} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index c0d40c87a83..4f828475ac3 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -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,