Replace Stylesheet::set_media with a constructor argument

This commit is contained in:
Simon Sapin 2016-11-15 16:43:33 +01:00
parent f4dcc38816
commit 236c575c50
8 changed files with 29 additions and 31 deletions

View file

@ -1531,6 +1531,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
None,
None,
Origin::UserAgent,
Default::default(),
Box::new(StdoutErrorReporter),
ParserContextExtraData::default()))
}
@ -1543,8 +1544,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, Box::new(StdoutErrorReporter),
ParserContextExtraData::default()));
&contents, url.clone(), None, None, Origin::User, Default::default(),
Box::new(StdoutErrorReporter), ParserContextExtraData::default()));
}
let quirks_mode_stylesheet = try!(parse_ua_stylesheet("quirks-mode.css"));

View file

@ -370,12 +370,10 @@ impl FetchResponseListener for StylesheetContext {
let win = window_from_node(&*elem);
let mut sheet = Stylesheet::from_bytes(&data, final_url, protocol_encoding_label,
Some(environment_encoding), Origin::Author,
win.css_error_reporter(),
ParserContextExtraData::default());
sheet.set_media(self.media.take().unwrap());
let sheet = Arc::new(sheet);
let sheet = Arc::new(Stylesheet::from_bytes(
&data, final_url, protocol_encoding_label, Some(environment_encoding),
Origin::Author, self.media.take().unwrap(), win.css_error_reporter(),
ParserContextExtraData::default()));
let win = window_from_node(&*elem);
win.layout_chan().send(Msg::AddStylesheet(sheet.clone())).unwrap();

View file

@ -65,10 +65,9 @@ impl HTMLStyleElement {
};
let data = node.GetTextContent().expect("Element.textContent must be a string");
let mut sheet = Stylesheet::from_str(&data, url, Origin::Author, win.css_error_reporter(),
ParserContextExtraData::default());
let mut css_parser = CssParser::new(&mq_str);
sheet.set_media(parse_media_query_list(&mut css_parser));
let mq = parse_media_query_list(&mut CssParser::new(&mq_str));
let sheet = Stylesheet::from_str(&data, url, Origin::Author, mq, win.css_error_reporter(),
ParserContextExtraData::default());
let sheet = Arc::new(sheet);
win.layout_chan().send(Msg::AddStylesheet(sheet.clone())).unwrap();

View file

@ -174,15 +174,17 @@ impl Stylesheet {
base_url: ServoUrl,
protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>,
origin: Origin, error_reporter: Box<ParseErrorReporter + Send>,
origin: Origin,
media: MediaList,
error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData)
-> Stylesheet {
let (string, _) = decode_stylesheet_bytes(
bytes, protocol_encoding_label, environment_encoding);
Stylesheet::from_str(&string, base_url, origin, error_reporter, extra_data)
Stylesheet::from_str(&string, base_url, origin, media, error_reporter, extra_data)
}
pub fn from_str(css: &str, base_url: ServoUrl, origin: Origin,
pub fn from_str(css: &str, base_url: ServoUrl, origin: Origin, media: MediaList,
error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData) -> Stylesheet {
let rule_parser = TopLevelRuleParser {
@ -212,17 +214,12 @@ impl Stylesheet {
Stylesheet {
origin: origin,
rules: rules.into(),
media: Arc::new(RwLock::new(Default::default())),
media: Arc::new(RwLock::new(media)),
dirty_on_viewport_size_change:
input.seen_viewport_percentages(),
}
}
/// Set the MediaList associated with the style-sheet.
pub fn set_media(&mut self, media: MediaList) {
*self.media.write() = media;
}
/// Returns whether the style-sheet applies for the current device depending
/// on the associated MediaList.
///