style: Move contain outside of mako

This commit is contained in:
lizhixun 2018-01-03 22:20:54 -08:00
parent 9187c9a093
commit 4c23f09934
5 changed files with 102 additions and 98 deletions

View file

@ -9,8 +9,9 @@ use cssparser::Parser;
use parser::{Parse, ParserContext};
#[cfg(feature = "servo")]
use properties::{longhands, PropertyDeclaration};
use selectors::parser::SelectorParseErrorKind;
use std::fmt;
use style_traits::{ParseError, ToCss};
use style_traits::{ParseError, ToCss, StyleParseErrorKind};
use values::CustomIdent;
use values::KeyframesName;
#[cfg(feature = "servo")]
@ -492,3 +493,92 @@ pub fn assert_touch_action_matches() {
NS_STYLE_TOUCH_ACTION_MANIPULATION => TouchAction::TOUCH_ACTION_MANIPULATION,
}
}
bitflags! {
#[derive(MallocSizeOf, ToComputedValue)]
/// Constants for contain: https://drafts.csswg.org/css-contain/#contain-property
pub struct Contain: u8 {
/// `layout` variant, turns on layout containment
const LAYOUT = 0x01;
/// `style` variant, turns on style containment
const STYLE = 0x02;
/// `paint` variant, turns on paint containment
const PAINT = 0x04;
/// `strict` variant, turns on all types of containment
const STRICT = 0x8;
/// variant with all the bits that contain: strict turns on
const STRICT_BITS = Contain::LAYOUT.bits | Contain::STYLE.bits | Contain::PAINT.bits;
}
}
impl ToCss for Contain {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.is_empty() {
return dest.write_str("none")
}
if self.contains(Contain::STRICT) {
return dest.write_str("strict")
}
let mut has_any = false;
macro_rules! maybe_write_value {
($ident:path => $str:expr) => {
if self.contains($ident) {
if has_any {
dest.write_str(" ")?;
}
has_any = true;
dest.write_str($str)?;
}
}
}
maybe_write_value!(Contain::LAYOUT => "layout");
maybe_write_value!(Contain::STYLE => "style");
maybe_write_value!(Contain::PAINT => "paint");
debug_assert!(has_any);
Ok(())
}
}
impl Parse for Contain {
/// none | strict | content | [ size || layout || style || paint ]
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>
) -> Result<Contain, ParseError<'i>> {
let mut result = Contain::empty();
while let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
let flag = match_ignore_ascii_case! { &name,
"layout" => Some(Contain::LAYOUT),
"style" => Some(Contain::STYLE),
"paint" => Some(Contain::PAINT),
"strict" => {
if result.is_empty() {
return Ok(Contain::STRICT | Contain::STRICT_BITS)
}
None
},
"none" => {
if result.is_empty() {
return Ok(result)
}
None
},
_ => None
};
let flag = match flag {
Some(flag) if !result.contains(flag) => flag,
_ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name)))
};
result.insert(flag);
}
if !result.is_empty() {
Ok(result)
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
}

View file

@ -34,7 +34,7 @@ pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVa
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, FontVariantEastAsian};
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior};
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::effects::{BoxShadow, Filter, SimpleShadow};