mirror of
https://github.com/servo/servo.git
synced 2025-10-04 10:39:16 +01:00
Introduce a style::values::CustomIdent type
This commit is contained in:
parent
5daf92dd5a
commit
4993a80074
2 changed files with 32 additions and 1 deletions
|
@ -444,6 +444,7 @@ impl CSSWideKeyword {
|
||||||
/// to a CSSWideKeyword.
|
/// to a CSSWideKeyword.
|
||||||
pub fn from_ident<'i>(ident: &Cow<'i, str>) -> Option<Self> {
|
pub fn from_ident<'i>(ident: &Cow<'i, str>) -> Option<Self> {
|
||||||
match_ignore_ascii_case! { ident,
|
match_ignore_ascii_case! { ident,
|
||||||
|
// If modifying this set of keyword, also update values::CustomIdent::from_ident
|
||||||
"initial" => Some(CSSWideKeyword::Initial),
|
"initial" => Some(CSSWideKeyword::Initial),
|
||||||
"inherit" => Some(CSSWideKeyword::Inherit),
|
"inherit" => Some(CSSWideKeyword::Inherit),
|
||||||
"unset" => Some(CSSWideKeyword::Unset),
|
"unset" => Some(CSSWideKeyword::Unset),
|
||||||
|
|
|
@ -8,8 +8,11 @@
|
||||||
|
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
pub use cssparser::{RGBA, Parser};
|
use Atom;
|
||||||
|
pub use cssparser::{RGBA, Parser, serialize_identifier};
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
|
use std::ascii::AsciiExt;
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
|
@ -211,6 +214,33 @@ impl<A: ToComputedValue, B: ToComputedValue> ToComputedValue for Either<A, B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-values-4/#custom-idents
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
pub struct CustomIdent(pub Atom);
|
||||||
|
|
||||||
|
impl CustomIdent {
|
||||||
|
/// Parse an already-tokenizer identifier
|
||||||
|
pub fn from_ident(ident: Cow<str>, excluding: &[&str]) -> Result<Self, ()> {
|
||||||
|
match_ignore_ascii_case! { &ident,
|
||||||
|
"initial" | "inherit" | "unset" | "default" => return Err(()),
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
if excluding.iter().any(|s| ident.eq_ignore_ascii_case(s)) {
|
||||||
|
Err(())
|
||||||
|
} else {
|
||||||
|
Ok(CustomIdent(ident.into()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for CustomIdent {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
serialize_identifier(&self.0.to_string(), dest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// A type for possible values for min- and max- flavors of width,
|
// A type for possible values for min- and max- flavors of width,
|
||||||
// height, block-size, and inline-size.
|
// height, block-size, and inline-size.
|
||||||
define_css_keyword_enum!(ExtremumLength:
|
define_css_keyword_enum!(ExtremumLength:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue