mirror of
https://github.com/servo/servo.git
synced 2025-08-15 18:35:33 +01:00
Improve properties.mako.rs file structure, take 2
This is a new attempt of #10586, after Simon Sapin's great cleanups in #10749 has landed. I have adjusted the changes to the new structure that was introduced, and also only done a few of the longhand ones. Will certainly continue on this as soon as we have a basic agreement that this style is reasonable.
This commit is contained in:
parent
a6fc440125
commit
d0489f1160
10 changed files with 358 additions and 305 deletions
58
components/style/properties/longhand/position.mako.rs
Normal file
58
components/style/properties/longhand/position.mako.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
<%page args="data, helpers" />
|
||||
|
||||
<% data.new_style_struct("Position", inherited=False, gecko_ffi_name="nsStylePosition") %>
|
||||
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
${helpers.predefined_type(side, "LengthOrPercentageOrAuto",
|
||||
"computed::LengthOrPercentageOrAuto::Auto")}
|
||||
% endfor
|
||||
|
||||
<%helpers:longhand name="z-index">
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
pub type SpecifiedValue = computed_value::T;
|
||||
pub mod computed_value {
|
||||
use cssparser::ToCss;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Clone, Eq, Copy, Debug, HeapSizeOf)]
|
||||
pub enum T {
|
||||
Auto,
|
||||
Number(i32),
|
||||
}
|
||||
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
T::Auto => dest.write_str("auto"),
|
||||
T::Number(number) => write!(dest, "{}", number),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl T {
|
||||
pub fn number_or_zero(self) -> i32 {
|
||||
match self {
|
||||
T::Auto => 0,
|
||||
T::Number(value) => value,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::Auto
|
||||
}
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
|
||||
Ok(computed_value::T::Auto)
|
||||
} else {
|
||||
specified::parse_integer(input).map(computed_value::T::Number)
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
Loading…
Add table
Add a link
Reference in a new issue