/* 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::media_queries::MediaList; usecrate::parser::{Parse, ParserContext}; usecrate::shared_lock::{
DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard,
}; usecrate::str::CssStringWriter; usecrate::stylesheets::{
layer_rule::LayerName, supports_rule::SupportsCondition, CssRule, CssRuleType,
StylesheetInDocument,
}; usecrate::values::CssUrl; use cssparser::{Parser, SourceLocation}; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; use to_shmem::{SharedMemoryBuilder, ToShmem};
/// A sheet that is held from an import rule. #[cfg(feature = "gecko")] #[derive(Debug)] pubenum ImportSheet { /// A bonafide stylesheet.
Sheet(crate::gecko::data::GeckoStyleSheet),
/// An @import created while parsing off-main-thread, whose Gecko sheet has /// yet to be created and attached.
Pending,
/// An @import created with a false <supports-condition>, so will never be fetched.
Refused,
}
#[cfg(feature = "gecko")] impl ImportSheet { /// Creates a new ImportSheet from a GeckoStyleSheet. pubfn new(sheet: crate::gecko::data::GeckoStyleSheet) -> Self {
ImportSheet::Sheet(sheet)
}
/// Creates a pending ImportSheet for a load that has not started yet. pubfn new_pending() -> Self {
ImportSheet::Pending
}
/// Creates a refused ImportSheet for a load that will not happen. pubfn new_refused() -> Self {
ImportSheet::Refused
}
/// Returns a reference to the GeckoStyleSheet in this ImportSheet, if it /// exists. pubfn as_sheet(&self) -> Option<&crate::gecko::data::GeckoStyleSheet> { match *self {
ImportSheet::Sheet(ref s) => {
debug_assert!(!s.hack_is_null()); if s.hack_is_null() { return None;
}
Some(s)
},
ImportSheet::Refused | ImportSheet::Pending => None,
}
}
/// Returns the media list for this import rule. pubfn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> { self.as_sheet().and_then(|s| s.media(guard))
}
/// Returns the rule list for this import rule. pubfn rules<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'</span>a [CssRule] { matchself.as_sheet() {
Some(s) => s.rules(guard),
None => &[],
}
}
}
/// A sheet that is held from an import rule. #[cfg(feature = "servo")] #[derive(Debug)] pubenum ImportSheet { /// A bonafide stylesheet.
Sheet(::servo_arc::Arc<crate::stylesheets::Stylesheet>),
/// An @import created with a false <supports-condition>, so will never be fetched.
Refused,
}
#[cfg(feature = "servo")] impl ImportSheet { /// Creates a new ImportSheet from a stylesheet. pubfn new(sheet: ::servo_arc::Arc<crate::stylesheets::Stylesheet>) -> Self {
ImportSheet::Sheet(sheet)
}
/// Creates a refused ImportSheet for a load that will not happen. pubfn new_refused() -> Self {
ImportSheet::Refused
}
/// Returns a reference to the stylesheet in this ImportSheet, if it exists. pubfn as_sheet(&self) -> Option<&::servo_arc::Arc<crate::stylesheets::Stylesheet>> { match *self {
ImportSheet::Sheet(ref s) => Some(s),
ImportSheet::Refused => None,
}
}
/// Returns the media list for this import rule. pubfn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> { self.as_sheet().and_then(|s| s.media(guard))
}
/// Returns the rules for this import rule. pubfn rules<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'</span>a [CssRule] { matchself.as_sheet() {
Some(s) => s.rules(guard),
None => &[],
}
}
}
/// The layer specified in an import rule (can be none, anonymous, or named). #[derive(Debug, Clone)] pubenum ImportLayer { /// No layer specified
None,
/// Anonymous layer (`layer`)
Anonymous,
/// Named layer (`layer(name)`)
Named(LayerName),
}
/// The supports condition in an import rule. #[derive(Debug, Clone)] pubstruct ImportSupportsCondition { /// The supports condition. pub condition: SupportsCondition,
/// If the import is enabled, from the result of the import condition. pub enabled: bool,
}
/// The [`@import`][import] at-rule. /// /// [import]: https://drafts.csswg.org/css-cascade-3/#at-import #[derive(Debug)] pubstruct ImportRule { /// The `<url>` this `@import` rule is loading. pub url: CssUrl,
/// The stylesheet is always present. However, in the case of gecko async /// parsing, we don't actually have a Gecko sheet at first, and so the /// ImportSheet just has stub behavior until it appears. pub stylesheet: ImportSheet,
/// A <supports-condition> for the rule. pub supports: Option<ImportSupportsCondition>,
/// A `layer()` function name. pub layer: ImportLayer,
/// The line and column of the rule's source code. pub source_location: SourceLocation,
}
impl ImportRule { /// Parses the layer() / layer / supports() part of the import header, as per /// https://drafts.csswg.org/css-cascade-5/#at-import: /// /// [ layer | layer(<layer-name>) ]? /// [ supports([ <supports-condition> | <declaration> ]) ]? /// /// We do this here so that the import preloader can look at this without having to parse the /// whole import rule or parse the media query list or what not. pubfn parse_layer_and_supports<'i, 't>(
input: &mut Parser<'i, 't>,
context: &mut ParserContext,
) -> (ImportLayer, Option<ImportSupportsCondition>) { let layer = if input
.try_parse(|input| input.expect_ident_matching("layer"))
.is_ok()
{
ImportLayer::Anonymous
} else {
input
.try_parse(|input| {
input.expect_function_matching("layer")?;
input
.parse_nested_block(|input| LayerName::parse(context, input))
.map(|name| ImportLayer::Named(name))
})
.ok()
.unwrap_or(ImportLayer::None)
};
let supports = if !static_prefs::pref!("layout.css.import-supports.enabled") {
None
} else {
input
.try_parse(SupportsCondition::parse_for_import)
.map(|condition| { let enabled = context
.nest_for_rule(CssRuleType::Style, |context| condition.eval(context));
ImportSupportsCondition { condition, enabled }
})
.ok()
};
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.