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..720bd416970 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1871,6 +1871,18 @@ extern "C" { property: nsCSSPropertyID, value: f32); } +extern "C" { + pub fn Servo_DeclarationBlock_SetLengthValue(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID, + value: f32, unit: nsCSSUnit); +} +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..1e5cc783bd3 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -225,7 +225,8 @@ ${helpers.single_keyword("font-style", gecko_constant_prefix="NS_FONT_STYLE", gecko_ffi_name="mFont.style", spec="https://drafts.csswg.org/css-fonts/#propdef-font-style", - animation_type="none")} + animation_type="none", + needs_conversion=True)} ${helpers.single_keyword("font-variant", "normal small-caps", @@ -292,19 +293,24 @@ ${helpers.single_keyword("font-variant-caps", _ => Err(()) } }).or_else(|()| { - match try!(input.expect_integer()) { - 100 => Ok(SpecifiedValue::Weight100), - 200 => Ok(SpecifiedValue::Weight200), - 300 => Ok(SpecifiedValue::Weight300), - 400 => Ok(SpecifiedValue::Weight400), - 500 => Ok(SpecifiedValue::Weight500), - 600 => Ok(SpecifiedValue::Weight600), - 700 => Ok(SpecifiedValue::Weight700), - 800 => Ok(SpecifiedValue::Weight800), - 900 => Ok(SpecifiedValue::Weight900), + SpecifiedValue::from_int(input.expect_integer()?) + }) + } + + impl SpecifiedValue { + pub fn from_int(kw: i32) -> Result { + match kw { + % for weight in range(100, 901, 100): + ${weight} => Ok(SpecifiedValue::Weight${weight}), + % endfor _ => Err(()) } - }) + } + + pub fn from_gecko_keyword(kw: u32) -> Self { + Self::from_int(kw as i32).expect("Found unexpected value in style + struct for font-weight property") + } } /// Used in @font-face, where relative keywords are not allowed. @@ -453,6 +459,12 @@ ${helpers.single_keyword("font-variant-caps", Larger, } + impl From for SpecifiedValue { + fn from(other: specified::LengthOrPercentage) -> Self { + SpecifiedValue::Length(other) + } + } + pub mod computed_value { use app_units::Au; pub type T = Au; @@ -1118,8 +1130,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 +1164,156 @@ ${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)} + +<%helpers:longhand name="-moz-script-min-size" products="gecko" animation_type="none" + predefined_type="Length" gecko_ffi_name="mScriptMinSize" + spec="Internal (not web-exposed)" + internal="True" disable_when_testing="True"> + use app_units::Au; + use gecko_bindings::structs::NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT; + use values::HasViewportPercentage; + use values::computed::ComputedValueAsSpecified; + use values::specified::length::{AU_PER_PT, Length}; + + pub type SpecifiedValue = Length; + + pub mod computed_value { + pub type T = super::Au; + } + + #[inline] + pub fn get_initial_value() -> computed_value::T { + Au((NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT as f32 * AU_PER_PT) as i32) + } + + pub fn parse(_context: &ParserContext, _input: &mut Parser) -> Result { + debug_assert!(false, "Should be set directly by presentation attributes only."); + Err(()) + } + + diff --git a/components/style/properties/longhand/inherited_box.mako.rs b/components/style/properties/longhand/inherited_box.mako.rs index c5a121a794f..d8c286301d5 100644 --- a/components/style/properties/longhand/inherited_box.mako.rs +++ b/components/style/properties/longhand/inherited_box.mako.rs @@ -24,7 +24,8 @@ ${helpers.single_keyword("writing-mode", spec="https://drafts.csswg.org/css-writing-modes/#propdef-writing-mode")} ${helpers.single_keyword("direction", "ltr rtl", need_clone=True, animation_type="none", - spec="https://drafts.csswg.org/css-writing-modes/#propdef-direction")} + spec="https://drafts.csswg.org/css-writing-modes/#propdef-direction", + needs_conversion=True)} <%helpers:single_keyword_computed name="text-orientation" diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 1a509ea06a0..9426893f2fe 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -26,13 +26,20 @@ pub use super::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingSh pub use super::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword}; pub use super::image::{SizeKeyword, VerticalDirection}; -const AU_PER_PX: CSSFloat = 60.; -const AU_PER_IN: CSSFloat = AU_PER_PX * 96.; -const AU_PER_CM: CSSFloat = AU_PER_IN / 2.54; -const AU_PER_MM: CSSFloat = AU_PER_IN / 25.4; -const AU_PER_Q: CSSFloat = AU_PER_MM / 4.; -const AU_PER_PT: CSSFloat = AU_PER_IN / 72.; -const AU_PER_PC: CSSFloat = AU_PER_PT * 12.; +/// Number of app units per pixel +pub const AU_PER_PX: CSSFloat = 60.; +/// Number of app units per inch +pub const AU_PER_IN: CSSFloat = AU_PER_PX * 96.; +/// Number of app units per centimeter +pub const AU_PER_CM: CSSFloat = AU_PER_IN / 2.54; +/// Number of app units per millimeter +pub const AU_PER_MM: CSSFloat = AU_PER_IN / 25.4; +/// Number of app units per quarter +pub const AU_PER_Q: CSSFloat = AU_PER_MM / 4.; +/// Number of app units per point +pub const AU_PER_PT: CSSFloat = AU_PER_IN / 72.; +/// Number of app units per pica +pub const AU_PER_PC: CSSFloat = AU_PER_PT * 12.; /// Same as Gecko's AppUnitsToIntCSSPixels /// diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index c0d40c87a83..224be3da1b7 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1327,6 +1327,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(declarations: let prop = match_wrap_declared! { long, MozUserModify => longhands::_moz_user_modify::SpecifiedValue::from_gecko_keyword(value), // TextEmphasisPosition => FIXME implement text-emphasis-position + Direction => longhands::direction::SpecifiedValue::from_gecko_keyword(value), Display => longhands::display::SpecifiedValue::from_gecko_keyword(value), Float => longhands::float::SpecifiedValue::from_gecko_keyword(value), VerticalAlign => longhands::vertical_align::SpecifiedValue::from_gecko_keyword(value), @@ -1337,7 +1338,10 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(declarations: // We rely on Gecko passing in font-size values (0...7) here. longhands::font_size::SpecifiedValue::from_html_size(value as u8) }, + FontStyle => longhands::font_style::SpecifiedValue::from_gecko_keyword(value), + FontWeight => longhands::font_weight::SpecifiedValue::from_gecko_keyword(value), 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 +1359,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,13 +1413,68 @@ pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(declarations: }) } + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID, + value: f32, + unit: structs::nsCSSUnit) { + use style::properties::{PropertyDeclaration, LonghandId}; + use style::values::specified::length::{AbsoluteLength, FontRelativeLength}; + use style::values::specified::length::{LengthOrPercentage, NoCalcLength}; + + let long = get_longhand_from_id!(property); + let nocalc = match unit { + structs::nsCSSUnit::eCSSUnit_EM => NoCalcLength::FontRelative(FontRelativeLength::Em(value)), + structs::nsCSSUnit::eCSSUnit_XHeight => NoCalcLength::FontRelative(FontRelativeLength::Ex(value)), + structs::nsCSSUnit::eCSSUnit_Pixel => NoCalcLength::Absolute(AbsoluteLength::Px(value)), + structs::nsCSSUnit::eCSSUnit_Inch => NoCalcLength::Absolute(AbsoluteLength::In(value)), + structs::nsCSSUnit::eCSSUnit_Centimeter => NoCalcLength::Absolute(AbsoluteLength::Cm(value)), + structs::nsCSSUnit::eCSSUnit_Millimeter => NoCalcLength::Absolute(AbsoluteLength::Mm(value)), + structs::nsCSSUnit::eCSSUnit_Point => NoCalcLength::Absolute(AbsoluteLength::Pt(value)), + structs::nsCSSUnit::eCSSUnit_Pica => NoCalcLength::Absolute(AbsoluteLength::Pc(value)), + structs::nsCSSUnit::eCSSUnit_Quarter => NoCalcLength::Absolute(AbsoluteLength::Q(value)), + _ => unreachable!("Unknown unit {:?} passed to SetLengthValue", unit) + }; + + let prop = match_wrap_declared! { long, + Width => nocalc.into(), + FontSize => LengthOrPercentage::from(nocalc).into(), + MozScriptMinSize => nocalc.into(), + }; + write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| { + decls.push(prop, Importance::Normal); + }) +} + +#[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, property: nsCSSPropertyID, value: f32) { use style::properties::{PropertyDeclaration, LonghandId}; - use style::values::specified::length::Percentage; + use style::values::specified::length::{LengthOrPercentage, Percentage}; let long = get_longhand_from_id!(property); let pc = Percentage(value); @@ -1424,6 +1486,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(declarations: MarginRight => pc.into(), MarginBottom => pc.into(), MarginLeft => pc.into(), + FontSize => LengthOrPercentage::from(pc).into(), }; write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| { decls.push(prop, Importance::Normal); @@ -1521,6 +1584,33 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(declarations: } } +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(declarations: + RawServoDeclarationBlockBorrowed, + value: *const nsAString, + raw_extra_data: *mut URLExtraData) { + use style::properties::PropertyDeclaration; + use style::properties::longhands::background_image::SpecifiedValue as BackgroundImage; + use style::properties::longhands::background_image::single_value::SpecifiedValue as SingleBackgroundImage; + use style::values::specified::image::Image; + use style::values::specified::url::SpecifiedUrl; + + let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) }; + let string = unsafe { (*value).to_string() }; + let error_reporter = StdoutErrorReporter; + let context = ParserContext::new(Origin::Author, url_data, &error_reporter, Some(CssRuleType::Style)); + if let Ok(url) = SpecifiedUrl::parse_from_string(string.into(), &context) { + let decl = PropertyDeclaration::BackgroundImage(BackgroundImage( + vec![SingleBackgroundImage( + Some(Image::Url(url)) + )] + )); + write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| { + decls.push(decl, Importance::Normal); + }) + } +} + #[no_mangle] pub extern "C" fn Servo_DeclarationBlock_SetTextDecorationColorOverride(declarations: RawServoDeclarationBlockBorrowed) {