From 1a5f48ba433655fe06077cd69df2746a5ef9d88d Mon Sep 17 00:00:00 2001 From: Frederic Wang Date: Mon, 28 Sep 2020 10:42:49 +0000 Subject: [PATCH] style: Implement CSS parsing for the math-depth property. Differential Revision: https://phabricator.services.mozilla.com/D91500 --- components/style/values/computed/font.rs | 12 ++++--- components/style/values/specified/font.rs | 40 +++++++++++------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index a04a74abf4f..e0d6f689c31 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -35,6 +35,7 @@ use style_traits::{CssWriter, ParseError, ToCss}; use to_shmem::{self, SharedMemoryBuilder, ToShmem}; pub use crate::values::computed::Length as MozScriptMinSize; +pub use crate::values::specified::Integer as SpecifiedInteger; pub use crate::values::specified::font::{FontSynthesis, MozScriptSizeMultiplier}; pub use crate::values::specified::font::{XLang, XTextZoom}; @@ -823,7 +824,7 @@ impl ToComputedValue for specified::MathDepth { use std::{cmp, i8}; let int = match *self { - specified::MathDepth::Auto => { + specified::MathDepth::AutoAdd => { let parent = cx.builder.get_parent_font().clone_math_depth() as i32; let style = cx.builder.get_parent_font().clone_math_style(); if style == MathStyleValue::Compact { @@ -832,17 +833,18 @@ impl ToComputedValue for specified::MathDepth { parent } }, - specified::MathDepth::Relative(rel) => { + specified::MathDepth::Add(rel) => { let parent = cx.builder.get_parent_font().clone_math_depth(); - parent as i32 + rel + parent as i32 + rel.to_computed_value(cx) }, - specified::MathDepth::MozAbsolute(abs) => abs, + specified::MathDepth::Absolute(abs) => abs.to_computed_value(cx), }; cmp::min(int, i8::MAX as i32) as i8 } fn from_computed_value(other: &i8) -> Self { - specified::MathDepth::MozAbsolute(*other as i32) + let computed_value = *other as i32; + specified::MathDepth::Absolute(SpecifiedInteger::from_computed_value(&computed_value)) } } diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 825c05da0ce..175b0681750 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -2304,38 +2304,36 @@ impl Parse for MozScriptMinSize { } } +/// A value for the `math-depth` property. +/// https://mathml-refresh.github.io/mathml-core/#the-math-script-level-property #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, Copy, Debug, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] -/// Changes the scriptlevel in effect for the children. -/// Ref: https://wiki.mozilla.org/MathML:mstyle -/// -/// The main effect of scriptlevel is to control the font size. -/// https://www.w3.org/TR/MathML3/chapter3.html#presm.scriptlevel pub enum MathDepth { - /// Change `font-size` relatively. - Relative(i32), - /// Change `font-size` absolutely. - /// - /// Should only be serialized by presentation attributes, so even though - /// serialization for this would look the same as for the `Relative` - /// variant, it is unexposed, so no big deal. + /// Increment math-depth if math-style is compact. + AutoAdd, + + /// Add the function's argument to math-depth. #[css(function)] - MozAbsolute(i32), - /// Change `font-size` automatically. - Auto, + Add(Integer), + + /// Set math-depth to the specified value. + Absolute(Integer), } impl Parse for MathDepth { fn parse<'i, 't>( - _: &ParserContext, + context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - // We don't bother to handle calc here. - if let Ok(i) = input.try_parse(|i| i.expect_integer()) { - return Ok(MathDepth::Relative(i)); + if input.try_parse(|i| i.expect_ident_matching("auto-add")).is_ok() { + return Ok(MathDepth::AutoAdd); } - input.expect_ident_matching("auto")?; - Ok(MathDepth::Auto) + if let Ok(math_depth_value) = input.try_parse(|input| Integer::parse(context, input)) { + return Ok(MathDepth::Absolute(math_depth_value)); + } + input.expect_function_matching("add")?; + let math_depth_delta_value = input.parse_nested_block(|input| Integer::parse(context, input))?; + Ok(MathDepth::Add(math_depth_delta_value)) } }