mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Factor out implemantations for {min,max} size properties as a macro.
This commit is contained in:
parent
57c27e5d35
commit
aba0db0943
2 changed files with 94 additions and 0 deletions
|
@ -1067,3 +1067,87 @@
|
|||
}
|
||||
}
|
||||
</%def>
|
||||
|
||||
// Define property that supports prefixed intrinsic size keyword values for gecko.
|
||||
// E.g. -moz-max-content, -moz-min-content, etc.
|
||||
<%def name="gecko_size_type(name, length_type, initial_value, logical, **kwargs)">
|
||||
<%call expr="longhand(name,
|
||||
predefined_type=length_type,
|
||||
logical=logical,
|
||||
**kwargs)">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
% if not logical:
|
||||
use values::specified::AllowQuirks;
|
||||
% endif
|
||||
use values::specified::${length_type};
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = ::values::computed::${length_type};
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(${length_type});
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::${length_type};
|
||||
${length_type}::${initial_value}
|
||||
}
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
% if logical:
|
||||
let ret = ${length_type}::parse(context, input);
|
||||
% else:
|
||||
let ret = ${length_type}::parse_quirky(context, input, AllowQuirks::Yes);
|
||||
% endif
|
||||
// Keyword values don't make sense in the block direction; don't parse them
|
||||
% if "block" in name:
|
||||
if let Ok(${length_type}::ExtremumLength(..)) = ret {
|
||||
return Err(())
|
||||
}
|
||||
% endif
|
||||
ret.map(SpecifiedValue)
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
% if not logical or "block" in name:
|
||||
use values::computed::${length_type};
|
||||
% endif
|
||||
let computed = self.0.to_computed_value(context);
|
||||
|
||||
// filter out keyword values in the block direction
|
||||
% if logical:
|
||||
% if "block" in name:
|
||||
if let ${length_type}::ExtremumLength(..) = computed {
|
||||
return get_initial_value()
|
||||
}
|
||||
% endif
|
||||
% else:
|
||||
if let ${length_type}::ExtremumLength(..) = computed {
|
||||
<% is_height = "true" if "height" in name else "false" %>
|
||||
if ${is_height} != context.style().writing_mode.is_vertical() {
|
||||
return get_initial_value()
|
||||
}
|
||||
}
|
||||
% endif
|
||||
computed
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
SpecifiedValue(ToComputedValue::from_computed_value(computed))
|
||||
}
|
||||
}
|
||||
</%call>
|
||||
</%def>
|
||||
|
||||
|
|
|
@ -252,6 +252,16 @@ ${helpers.predefined_type("flex-basis",
|
|||
}
|
||||
</%helpers:longhand>
|
||||
% endfor
|
||||
// min-width, min-height, min-block-size, min-inline-size,
|
||||
// max-width, max-height, max-block-size, max-inline-size
|
||||
${helpers.gecko_size_type("min-%s" % size, "MozLength", "auto()",
|
||||
logical,
|
||||
spec=spec % size,
|
||||
animation_value_type="ComputedValue")}
|
||||
${helpers.gecko_size_type("max-%s" % size, "MaxLength", "none()",
|
||||
logical,
|
||||
spec=spec % size,
|
||||
animation_value_type="ComputedValue")}
|
||||
% else:
|
||||
// servo versions (no keyword support)
|
||||
${helpers.predefined_type("min-%s" % size,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue