mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Further changes required by Servo
This commit is contained in:
parent
1ac62a4ce8
commit
9ce567d7fe
3 changed files with 58 additions and 9 deletions
|
@ -22,7 +22,7 @@ use servo_url::{ImmutableOrigin, ServoUrl};
|
|||
use style::media_queries::MediaList;
|
||||
use style::parser::ParserContext;
|
||||
use style::shared_lock::{Locked, SharedRwLock};
|
||||
use style::stylesheets::import_rule::{ImportLayer, ImportSheet};
|
||||
use style::stylesheets::import_rule::{ImportLayer, ImportSheet, ImportSupportsCondition};
|
||||
use style::stylesheets::{
|
||||
CssRules, ImportRule, Origin, Stylesheet, StylesheetContents,
|
||||
StylesheetLoader as StyleStylesheetLoader,
|
||||
|
@ -361,8 +361,20 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
|
|||
context: &ParserContext,
|
||||
lock: &SharedRwLock,
|
||||
media: Arc<Locked<MediaList>>,
|
||||
supports: Option<ImportSupportsCondition>,
|
||||
layer: Option<ImportLayer>,
|
||||
) -> Arc<Locked<ImportRule>> {
|
||||
// Ensure the supports conditions for this @import are true, if not, refuse to load
|
||||
if !supports.as_ref().map_or(true, |s| s.enabled) {
|
||||
return Arc::new(lock.wrap(ImportRule {
|
||||
url,
|
||||
stylesheet: ImportSheet::new_refused(),
|
||||
supports,
|
||||
layer,
|
||||
source_location,
|
||||
}));
|
||||
}
|
||||
|
||||
let sheet = Arc::new(Stylesheet {
|
||||
contents: StylesheetContents::from_data(
|
||||
CssRules::new(Vec::new(), lock),
|
||||
|
@ -375,10 +387,11 @@ impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
|
|||
disabled: AtomicBool::new(false),
|
||||
});
|
||||
|
||||
let stylesheet = ImportSheet(sheet.clone());
|
||||
let stylesheet = ImportSheet::new(sheet.clone());
|
||||
let import = ImportRule {
|
||||
url,
|
||||
stylesheet,
|
||||
supports,
|
||||
layer,
|
||||
source_location,
|
||||
};
|
||||
|
|
|
@ -107,18 +107,45 @@ impl DeepCloneWithLock for ImportSheet {
|
|||
/// A sheet that is held from an import rule.
|
||||
#[cfg(feature = "servo")]
|
||||
#[derive(Debug)]
|
||||
pub struct ImportSheet(pub ::servo_arc::Arc<crate::stylesheets::Stylesheet>);
|
||||
pub enum 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.
|
||||
pub fn new(sheet: ::servo_arc::Arc<crate::stylesheets::Stylesheet>) -> Self {
|
||||
ImportSheet::Sheet(sheet)
|
||||
}
|
||||
|
||||
/// Creates a refused ImportSheet for a load that will not happen.
|
||||
pub fn new_refused() -> Self {
|
||||
ImportSheet::Refused
|
||||
}
|
||||
|
||||
/// Returns a reference to the stylesheet in this ImportSheet, if it exists.
|
||||
pub fn 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.
|
||||
pub fn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> {
|
||||
self.0.media(guard)
|
||||
self.as_sheet().and_then(|s| s.media(guard))
|
||||
}
|
||||
|
||||
/// Returns the rules for this import rule.
|
||||
pub fn rules<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a [CssRule] {
|
||||
self.0.rules(guard)
|
||||
match self.as_sheet() {
|
||||
Some(s) => s.rules(guard),
|
||||
None => &[],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,9 +157,13 @@ impl DeepCloneWithLock for ImportSheet {
|
|||
_guard: &SharedRwLockReadGuard,
|
||||
_params: &DeepCloneParams,
|
||||
) -> Self {
|
||||
use servo_arc::Arc;
|
||||
|
||||
ImportSheet(Arc::new((&*self.0).clone()))
|
||||
match *self {
|
||||
ImportSheet::Sheet(ref s) => {
|
||||
use servo_arc::Arc;
|
||||
ImportSheet::Sheet(Arc::new((&**s).clone()))
|
||||
},
|
||||
ImportSheet::Refused => ImportSheet::Refused,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -241,7 +241,12 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
let url_string = input.expect_url_or_string()?.as_ref().to_owned();
|
||||
let url = CssUrl::parse_from_string(url_string, &self.context, CorsMode::None);
|
||||
|
||||
let supports = if !static_prefs::pref!("layout.css.import-supports.enabled") {
|
||||
#[cfg(feature = "gecko")]
|
||||
let supports_enabled = static_prefs::pref!("layout.css.import-supports.enabled");
|
||||
#[cfg(feature = "servo")]
|
||||
let supports_enabled = false;
|
||||
|
||||
let supports = if !supports_enabled {
|
||||
None
|
||||
} else {
|
||||
input.try_parse(SupportsCondition::parse_for_import).map(|condition| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue