Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSSOM: Make Stylesheet fields have their own synchronization #14232

Merged
merged 5 commits into from Nov 22, 2016

Replace Stylesheet::set_media with a constructor argument

  • Loading branch information
SimonSapin committed Nov 18, 2016
commit 236c575c50f97e6fbfb208fd6c8fcb5b1a1d6745
@@ -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"));
@@ -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();
@@ -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();
@@ -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.
///
@@ -174,8 +174,8 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl
SheetParsingMode::eUserSheetFeatures => Origin::User,
SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent,
};
let sheet = Arc::new(Stylesheet::from_str("", url, origin, Box::new(StdoutErrorReporter),
extra_data));
let sheet = Arc::new(Stylesheet::from_str(
"", url, origin, Default::default(), Box::new(StdoutErrorReporter), extra_data));
unsafe {
transmute(sheet)
}
@@ -204,8 +204,8 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(data: *const nsACString,
referrer: Some(GeckoArcURI::new(referrer)),
principal: Some(GeckoArcPrincipal::new(principal)),
}};
let sheet = Arc::new(Stylesheet::from_str(input, url, origin, Box::new(StdoutErrorReporter),
extra_data));
let sheet = Arc::new(Stylesheet::from_str(
input, url, origin, Default::default(), Box::new(StdoutErrorReporter), extra_data));
unsafe {
transmute(sheet)
}
@@ -26,8 +26,9 @@ impl ParseErrorReporter for CSSErrorReporterTest {

fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaList, &str) {
let url = ServoUrl::parse("http://localhost").unwrap();
let stylesheet = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest),
ParserContextExtraData::default());
let stylesheet = Stylesheet::from_str(
css, url, Origin::Author, Default::default(),
Box::new(CSSErrorReporterTest), ParserContextExtraData::default());
let mut rule_count = 0;
media_queries(&stylesheet.rules.0.read(), &mut |mq| {
rule_count += 1;
@@ -49,8 +50,9 @@ fn media_queries<F>(rules: &[CssRule], f: &mut F) where F: FnMut(&MediaList) {

fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
let url = ServoUrl::parse("http://localhost").unwrap();
let ss = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest),
ParserContextExtraData::default());
let ss = Stylesheet::from_str(
css, url, Origin::Author, Default::default(),
Box::new(CSSErrorReporterTest), ParserContextExtraData::default());
let mut rule_count = 0;
ss.effective_style_rules(device, |_| rule_count += 1);
assert!(rule_count == expected_rule_count, css.to_owned());
@@ -49,7 +49,7 @@ fn test_parse_stylesheet() {
}
}";
let url = ServoUrl::parse("about::test").unwrap();
let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent,
let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent, Default::default(),
Box::new(CSSErrorReporterTest),
ParserContextExtraData::default());
let expected = Stylesheet {
@@ -320,7 +320,7 @@ fn test_report_error_stylesheet() {

let errors = error_reporter.errors.clone();

Stylesheet::from_str(css, url, Origin::UserAgent, error_reporter,
Stylesheet::from_str(css, url, Origin::UserAgent, Default::default(), error_reporter,
ParserContextExtraData::default());

let mut errors = errors.lock().unwrap();
@@ -23,6 +23,7 @@ macro_rules! stylesheet {
$css,
ServoUrl::parse("http://localhost").unwrap(),
Origin::$origin,
Default::default(),
$error_reporter,
ParserContextExtraData::default()
))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.