mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Add a StylesheetLoader abstraction, and make it a no-op on Geckolib.
Servo doesn't compile at this stage.
This commit is contained in:
parent
444fef164e
commit
a42cfae153
9 changed files with 62 additions and 6 deletions
|
@ -1542,6 +1542,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
|||
None,
|
||||
Origin::UserAgent,
|
||||
Default::default(),
|
||||
None,
|
||||
Box::new(StdoutErrorReporter),
|
||||
ParserContextExtraData::default()))
|
||||
}
|
||||
|
@ -1555,7 +1556,8 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
|||
for &(ref contents, ref url) in &opts::get().user_stylesheets {
|
||||
user_or_user_agent_stylesheets.push(Stylesheet::from_bytes(
|
||||
&contents, url.clone(), None, None, Origin::User, Default::default(),
|
||||
Box::new(StdoutErrorReporter), ParserContextExtraData::default()));
|
||||
None, Box::new(StdoutErrorReporter),
|
||||
ParserContextExtraData::default()));
|
||||
}
|
||||
|
||||
let quirks_mode_stylesheet = try!(parse_ua_stylesheet("quirks-mode.css"));
|
||||
|
|
|
@ -307,6 +307,7 @@ impl CssRule {
|
|||
let mut rule_parser = TopLevelRuleParser {
|
||||
stylesheet_origin: parent_stylesheet.origin,
|
||||
context: context,
|
||||
loader: None,
|
||||
state: Cell::new(state),
|
||||
namespaces: &mut namespaces,
|
||||
};
|
||||
|
@ -605,9 +606,20 @@ rule_filter! {
|
|||
effective_keyframes_rules(Keyframes => KeyframesRule),
|
||||
}
|
||||
|
||||
/// The stylesheet loader is the abstraction used to trigger network requests
|
||||
/// for `@import` rules.
|
||||
pub trait StylesheetLoader {
|
||||
/// Request a stylesheet after parsing a given `@import` rule.
|
||||
///
|
||||
/// The called code is responsible to update the `stylesheet` rules field
|
||||
/// when the sheet is done loading.
|
||||
fn request_stylesheet(&self, import: &Arc<RwLock<ImportRule>>);
|
||||
}
|
||||
|
||||
struct TopLevelRuleParser<'a> {
|
||||
stylesheet_origin: Origin,
|
||||
namespaces: &'a mut Namespaces,
|
||||
loader: Option<&'a StylesheetLoader>,
|
||||
context: ParserContext<'a>,
|
||||
state: Cell<State>,
|
||||
}
|
||||
|
@ -679,6 +691,12 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
|
|||
}
|
||||
));
|
||||
|
||||
if is_valid_url {
|
||||
let loader = self.loader
|
||||
.expect("Expected a stylesheet loader for @import");
|
||||
loader.request_stylesheet(&import_rule);
|
||||
}
|
||||
|
||||
return Ok(AtRuleType::WithoutBlock(CssRule::Import(import_rule)))
|
||||
} else {
|
||||
self.state.set(State::Invalid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue