/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
usecrate::font_face::{FontFaceSourceFormatKeyword, FontFaceSourceTechFlags}; usecrate::parser::ParserContext; usecrate::properties::{PropertyDeclaration, PropertyId, SourcePropertyDeclaration}; usecrate::selector_parser::{SelectorImpl, SelectorParser}; usecrate::shared_lock::{DeepCloneWithLock, Locked}; usecrate::shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; usecrate::str::CssStringWriter; usecrate::stylesheets::{CssRuleType, CssRules}; use cssparser::parse_important; use cssparser::{Delimiter, Parser, SourceLocation, Token}; use cssparser::{ParseError as CssParseError, ParserInput}; #[cfg(feature = "gecko")] use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; use selectors::parser::{Selector, SelectorParseErrorKind}; use servo_arc::Arc; use std::fmt::{self, Write}; use std::str; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
/// An [`@supports`][supports] rule. /// /// [supports]: https://drafts.csswg.org/css-conditional-3/#at-supports #[derive(Debug, ToShmem)] pubstruct SupportsRule { /// The parsed condition pub condition: SupportsCondition, /// Child rules pub rules: Arc<Locked<CssRules>>, /// The result of evaluating the condition pub enabled: bool, /// The line and column of the rule's source code. pub source_location: SourceLocation,
}
impl SupportsRule { /// Measure heap usage. #[cfg(feature = "gecko")] pubfn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize { // Measurement of other fields may be added later. self.rules.unconditional_shallow_size_of(ops) + self.rules.read_with(guard).size_of(guard, ops)
}
}
letmut conditions = Vec::with_capacity(2);
conditions.push(in_parens); loop {
conditions.push(SupportsCondition::parse_in_parens(input)?); if input
.try_parse(|input| input.expect_ident_matching(keyword))
.is_err()
{ // Did not find the expected keyword. // If we found some other token, it will be rejected by // `Parser::parse_entirely` somewhere up the stack. return Ok(wrapper(conditions));
}
}
}
/// Parses an `@import` condition as per /// https://drafts.csswg.org/css-cascade-5/#typedef-import-conditions pubfn parse_for_import<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
input.expect_function_matching("supports")?;
input.parse_nested_block(parse_condition_or_declaration)
}
/// <https://drafts.csswg.org/css-conditional-3/#supports_condition_in_parens> fn parse_in_parens<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { // Whitespace is normally taken care of in `Parser::next`, but we want to not include it in // `pos` for the SupportsCondition::FutureSyntax cases.
input.skip_whitespace(); let pos = input.position(); let location = input.current_source_location(); match *input.next()? {
Token::ParenthesisBlock => { let nested = input
.try_parse(|input| input.parse_nested_block(parse_condition_or_declaration)); iflet Ok(nested) = nested { return Ok(Self::Parenthesized(Box::new(nested)));
}
},
Token::Function(ref ident) => { let ident = ident.clone(); let nested = input.try_parse(|input| {
input.parse_nested_block(|input| {
SupportsCondition::parse_functional(&ident, input)
})
}); if nested.is_ok() { return nested;
}
}, ref t => return Err(location.new_unexpected_token_error(t.clone())),
}
input.parse_nested_block(consume_any_value)?;
Ok(SupportsCondition::FutureSyntax(
input.slice_from(pos).to_owned(),
))
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.