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};
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))
}
}

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))]
#[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<MathDepth, ParseError<'i>> {
// 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))
}
}