From 6e842c373c107301d2dba17de38003f62c0486ca Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 10 Apr 2017 15:28:48 +0800 Subject: [PATCH] stylo: Support mathsize, width, and scriptminsize presentation attributes in MathML --- components/style/gecko_bindings/bindings.rs | 6 +++ .../style/properties/longhand/font.mako.rs | 34 +++++++++++++++++ components/style/values/specified/length.rs | 21 ++++++---- ports/geckolib/glue.rs | 38 ++++++++++++++++++- 4 files changed, 91 insertions(+), 8 deletions(-) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index a189187b1ed..720bd416970 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_SetLengthValue(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID, + value: f32, unit: nsCSSUnit); +} extern "C" { pub fn Servo_DeclarationBlock_SetNumberValue(declarations: RawServoDeclarationBlockBorrowed, diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index cfd36cad6b8..1e5cc783bd3 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -459,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; @@ -1283,3 +1289,31 @@ ${helpers.single_keyword("-moz-math-variant", 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/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 313078d74b2..34c67e28cae 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1413,6 +1413,41 @@ 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, @@ -1439,7 +1474,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(declarations: 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); @@ -1451,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);