mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add base_url and namespaces to style::Stylesheet
This commit is contained in:
parent
eb7032f6dd
commit
0714e2291c
3 changed files with 35 additions and 23 deletions
|
@ -100,6 +100,8 @@ impl HTMLMetaElement {
|
|||
*self.stylesheet.borrow_mut() = Some(Arc::new(Stylesheet {
|
||||
rules: vec![CssRule::Viewport(Arc::new(RwLock::new(translated_rule)))].into(),
|
||||
origin: Origin::Author,
|
||||
base_url: window_from_node(self).get_url(),
|
||||
namespaces: Default::default(),
|
||||
media: Default::default(),
|
||||
// Viewport constraints are always recomputed on resize; they don't need to
|
||||
// force all styles to be recomputed.
|
||||
|
|
|
@ -44,7 +44,7 @@ pub enum Origin {
|
|||
User,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Default, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct Namespaces {
|
||||
pub default: Option<Namespace>,
|
||||
|
@ -166,6 +166,8 @@ pub struct Stylesheet {
|
|||
/// List of media associated with the Stylesheet.
|
||||
pub media: Arc<RwLock<MediaList>>,
|
||||
pub origin: Origin,
|
||||
pub base_url: ServoUrl,
|
||||
pub namespaces: RwLock<Namespaces>,
|
||||
pub dirty_on_viewport_size_change: AtomicBool,
|
||||
pub disabled: AtomicBool,
|
||||
}
|
||||
|
@ -435,37 +437,40 @@ impl Stylesheet {
|
|||
error_reporter: Box<ParseErrorReporter + Send>,
|
||||
extra_data: ParserContextExtraData) -> Stylesheet {
|
||||
let mut namespaces = Namespaces::default();
|
||||
let rule_parser = TopLevelRuleParser {
|
||||
stylesheet_origin: origin,
|
||||
namespaces: &mut namespaces,
|
||||
context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter.clone(),
|
||||
extra_data),
|
||||
state: Cell::new(State::Start),
|
||||
};
|
||||
let mut input = Parser::new(css);
|
||||
input.look_for_viewport_percentages();
|
||||
|
||||
let mut rules = vec![];
|
||||
let dirty_on_viewport_size_change;
|
||||
{
|
||||
let mut iter = RuleListParser::new_for_stylesheet(&mut input, rule_parser);
|
||||
while let Some(result) = iter.next() {
|
||||
match result {
|
||||
Ok(rule) => rules.push(rule),
|
||||
Err(range) => {
|
||||
let pos = range.start;
|
||||
let message = format!("Invalid rule: '{}'", iter.input.slice(range));
|
||||
let context = ParserContext::new(origin, &base_url, error_reporter.clone());
|
||||
log_css_error(iter.input, pos, &*message, &context);
|
||||
let rule_parser = TopLevelRuleParser {
|
||||
stylesheet_origin: origin,
|
||||
namespaces: &mut namespaces,
|
||||
context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter, extra_data),
|
||||
state: Cell::new(State::Start),
|
||||
};
|
||||
let mut input = Parser::new(css);
|
||||
input.look_for_viewport_percentages();
|
||||
{
|
||||
let mut iter = RuleListParser::new_for_stylesheet(&mut input, rule_parser);
|
||||
while let Some(result) = iter.next() {
|
||||
match result {
|
||||
Ok(rule) => rules.push(rule),
|
||||
Err(range) => {
|
||||
let pos = range.start;
|
||||
let message = format!("Invalid rule: '{}'", iter.input.slice(range));
|
||||
log_css_error(iter.input, pos, &*message, &iter.parser.context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dirty_on_viewport_size_change = input.seen_viewport_percentages();
|
||||
}
|
||||
|
||||
Stylesheet {
|
||||
origin: origin,
|
||||
base_url: base_url,
|
||||
namespaces: RwLock::new(namespaces),
|
||||
rules: rules.into(),
|
||||
media: Arc::new(RwLock::new(media)),
|
||||
dirty_on_viewport_size_change: AtomicBool::new(input.seen_viewport_percentages()),
|
||||
dirty_on_viewport_size_change: AtomicBool::new(dirty_on_viewport_size_change),
|
||||
disabled: AtomicBool::new(false),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ use style::parser::ParserContextExtraData;
|
|||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, DeclaredValue, longhands};
|
||||
use style::properties::Importance;
|
||||
use style::properties::longhands::animation_play_state;
|
||||
use style::stylesheets::{Stylesheet, NamespaceRule, CssRule, StyleRule, KeyframesRule, Origin};
|
||||
use style::stylesheets::{Origin, Namespaces};
|
||||
use style::stylesheets::{Stylesheet, NamespaceRule, CssRule, StyleRule, KeyframesRule};
|
||||
use style::values::specified::{LengthOrPercentageOrAuto, Percentage};
|
||||
|
||||
#[test]
|
||||
|
@ -50,12 +51,16 @@ fn test_parse_stylesheet() {
|
|||
}
|
||||
}";
|
||||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent, Default::default(),
|
||||
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
||||
Box::new(CSSErrorReporterTest),
|
||||
ParserContextExtraData::default());
|
||||
let mut namespaces = Namespaces::default();
|
||||
namespaces.default = Some(ns!(html));
|
||||
let expected = Stylesheet {
|
||||
origin: Origin::UserAgent,
|
||||
media: Default::default(),
|
||||
namespaces: RwLock::new(namespaces),
|
||||
base_url: url,
|
||||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||
disabled: AtomicBool::new(false),
|
||||
rules: vec![
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue