style: Implement CSS parsing for the math-depth property.

Differential Revision: https://phabricator.services.mozilla.com/D91500
This commit is contained in:
Frederic Wang 2020-09-28 10:42:49 +00:00 committed by Emilio Cobos Álvarez
parent 4dfcf583cf
commit 1a5f48ba43
2 changed files with 26 additions and 26 deletions

View file

@ -35,6 +35,7 @@ use style_traits::{CssWriter, ParseError, ToCss};
use to_shmem::{self, SharedMemoryBuilder, ToShmem}; use to_shmem::{self, SharedMemoryBuilder, ToShmem};
pub use crate::values::computed::Length as MozScriptMinSize; 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::{FontSynthesis, MozScriptSizeMultiplier};
pub use crate::values::specified::font::{XLang, XTextZoom}; pub use crate::values::specified::font::{XLang, XTextZoom};
@ -823,7 +824,7 @@ impl ToComputedValue for specified::MathDepth {
use std::{cmp, i8}; use std::{cmp, i8};
let int = match *self { let int = match *self {
specified::MathDepth::Auto => { specified::MathDepth::AutoAdd => {
let parent = cx.builder.get_parent_font().clone_math_depth() as i32; let parent = cx.builder.get_parent_font().clone_math_depth() as i32;
let style = cx.builder.get_parent_font().clone_math_style(); let style = cx.builder.get_parent_font().clone_math_style();
if style == MathStyleValue::Compact { if style == MathStyleValue::Compact {
@ -832,17 +833,18 @@ impl ToComputedValue for specified::MathDepth {
parent parent
} }
}, },
specified::MathDepth::Relative(rel) => { specified::MathDepth::Add(rel) => {
let parent = cx.builder.get_parent_font().clone_math_depth(); 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 cmp::min(int, i8::MAX as i32) as i8
} }
fn from_computed_value(other: &i8) -> Self { 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))
} }
} }

View file

@ -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))] #[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] #[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 { pub enum MathDepth {
/// Change `font-size` relatively. /// Increment math-depth if math-style is compact.
Relative(i32), AutoAdd,
/// Change `font-size` absolutely.
/// /// Add the function's argument to math-depth.
/// 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.
#[css(function)] #[css(function)]
MozAbsolute(i32), Add(Integer),
/// Change `font-size` automatically.
Auto, /// Set math-depth to the specified value.
Absolute(Integer),
} }
impl Parse for MathDepth { impl Parse for MathDepth {
fn parse<'i, 't>( fn parse<'i, 't>(
_: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<MathDepth, ParseError<'i>> { ) -> Result<MathDepth, ParseError<'i>> {
// We don't bother to handle calc here. if input.try_parse(|i| i.expect_ident_matching("auto-add")).is_ok() {
if let Ok(i) = input.try_parse(|i| i.expect_integer()) { return Ok(MathDepth::AutoAdd);
return Ok(MathDepth::Relative(i));
} }
input.expect_ident_matching("auto")?; if let Ok(math_depth_value) = input.try_parse(|input| Integer::parse(context, input)) {
Ok(MathDepth::Auto) 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))
} }
} }