Bug 1325878: Pass the MediaList down to Servo, making <style media> work. r=xidorn

MozReview-Commit-ID: BUCSQJs2CNI
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-04-11 22:13:16 +08:00
parent 482740bb11
commit ac7bc414d9
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
14 changed files with 63 additions and 43 deletions

View file

@ -15,7 +15,7 @@ use dom::window::Window;
use dom_struct::dom_struct;
use std::sync::Arc;
use style::shared_lock::Locked;
use style::stylesheets::{CssRules, KeyframesRule, RulesMutateError};
use style::stylesheets::{CssRules, CssRulesHelpers, KeyframesRule, RulesMutateError};
#[allow(unsafe_code)]
unsafe_no_jsmanaged_fields!(RulesSource);
@ -90,15 +90,13 @@ impl CSSRuleList {
let index = idx as usize;
let parent_stylesheet = self.parent_stylesheet.style_stylesheet();
let new_rule = {
let mut guard = parent_stylesheet.shared_lock.write();
// FIXME We should probably pass in a proper StylesheetLoader.
// See servo/servo#16240
css_rules.write_with(&mut guard).insert_rule(rule, parent_stylesheet,
index, nested, None)?
// Drop `guard` here,
// CSSRule::new_specific re-acquires the lock for @support and @media.
};
let new_rule =
css_rules.insert_rule(&parent_stylesheet.shared_lock,
rule,
parent_stylesheet,
index,
nested,
None)?;
let parent_stylesheet = &*self.parent_stylesheet;
let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule);

View file

@ -24,6 +24,7 @@ use std::ascii::AsciiExt;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use style::attr::AttrValue;
use style::media_queries::MediaList;
use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::{Stylesheet, CssRule, CssRules, Origin};
use style::viewport::ViewportRule;
@ -107,7 +108,7 @@ impl HTMLMetaElement {
shared_lock: shared_lock.clone(),
url_data: window_from_node(self).get_url(),
namespaces: Default::default(),
media: Arc::new(shared_lock.wrap(Default::default())),
media: Arc::new(shared_lock.wrap(MediaList::empty())),
// Viewport constraints are always recomputed on resize; they don't need to
// force all styles to be recomputed.
dirty_on_viewport_size_change: AtomicBool::new(false),

View file

@ -86,8 +86,9 @@ impl HTMLStyleElement {
let context = CssParserContext::new_for_cssom(&url,
win.css_error_reporter(),
Some(CssRuleType::Media));
let mq = parse_media_query_list(&context, &mut CssParser::new(&mq_str));
let shared_lock = node.owner_doc().style_shared_lock().clone();
let mq = Arc::new(shared_lock.wrap(
parse_media_query_list(&context, &mut CssParser::new(&mq_str))));
let loader = StylesheetLoader::for_element(self.upcast());
let sheet = Stylesheet::from_str(&data, win.get_url(), Origin::Author, mq,
shared_lock, Some(&loader),

View file

@ -67,7 +67,7 @@ impl MediaListMethods for MediaList {
// Step 2
if value.is_empty() {
// Step 1
*media_queries = StyleMediaList::default();
*media_queries = StyleMediaList::empty();
return;
}
// Step 3