mirror of
https://github.com/servo/servo.git
synced 2025-08-13 01:15:34 +01:00
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:
parent
482740bb11
commit
ac7bc414d9
14 changed files with 63 additions and 43 deletions
|
@ -6,6 +6,7 @@ use cssparser::{Parser, SourcePosition};
|
|||
use euclid::size::TypedSize2D;
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::ToOwned;
|
||||
use std::sync::Arc;
|
||||
use style::Atom;
|
||||
use style::error_reporting::ParseErrorReporter;
|
||||
use style::media_queries::*;
|
||||
|
@ -28,8 +29,10 @@ fn test_media_rule<F>(css: &str, callback: F)
|
|||
{
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let css_str = css.to_owned();
|
||||
let lock = SharedRwLock::new();
|
||||
let media_list = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(
|
||||
css, url, Origin::Author, Default::default(), SharedRwLock::new(),
|
||||
css, url, Origin::Author, media_list, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
let mut rule_count = 0;
|
||||
let guard = stylesheet.shared_lock.read();
|
||||
|
@ -55,8 +58,10 @@ fn media_queries<F>(guard: &SharedRwLockReadGuard, rules: &[CssRule], f: &mut F)
|
|||
|
||||
fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let lock = SharedRwLock::new();
|
||||
let media_list = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let ss = Stylesheet::from_str(
|
||||
css, url, Origin::Author, Default::default(), SharedRwLock::new(),
|
||||
css, url, Origin::Author, media_list, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
let mut rule_count = 0;
|
||||
ss.effective_style_rules(device, &ss.shared_lock.read(), |_| rule_count += 1);
|
||||
|
|
|
@ -42,13 +42,14 @@ impl<'a> Drop for AutoGCRuleTree<'a> {
|
|||
}
|
||||
|
||||
fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> {
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
|
||||
let s = Stylesheet::from_str(css,
|
||||
ServoUrl::parse("http://localhost").unwrap(),
|
||||
Origin::Author,
|
||||
MediaList {
|
||||
media_queries: vec![],
|
||||
},
|
||||
SharedRwLock::new(),
|
||||
media,
|
||||
lock,
|
||||
None,
|
||||
&ErrorringErrorReporter);
|
||||
let guard = s.shared_lock.read();
|
||||
|
|
|
@ -15,6 +15,7 @@ use std::sync::Mutex;
|
|||
use std::sync::atomic::AtomicBool;
|
||||
use style::error_reporting::ParseErrorReporter;
|
||||
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
|
||||
use style::media_queries::MediaList;
|
||||
use style::properties::Importance;
|
||||
use style::properties::{CSSWideKeyword, DeclaredValueOwned, PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use style::properties::longhands;
|
||||
|
@ -61,14 +62,15 @@ fn test_parse_stylesheet() {
|
|||
}
|
||||
}";
|
||||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
||||
SharedRwLock::new(), None,
|
||||
&CSSErrorReporterTest);
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
let mut namespaces = Namespaces::default();
|
||||
namespaces.default = Some(ns!(html));
|
||||
let expected = Stylesheet {
|
||||
origin: Origin::UserAgent,
|
||||
media: Arc::new(stylesheet.shared_lock.wrap(Default::default())),
|
||||
media: Arc::new(stylesheet.shared_lock.wrap(MediaList::empty())),
|
||||
shared_lock: stylesheet.shared_lock.clone(),
|
||||
namespaces: RwLock::new(namespaces),
|
||||
url_data: url,
|
||||
|
@ -323,9 +325,10 @@ fn test_report_error_stylesheet() {
|
|||
|
||||
let errors = error_reporter.errors.clone();
|
||||
|
||||
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
||||
SharedRwLock::new(), None,
|
||||
&error_reporter);
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
|
||||
None, &error_reporter);
|
||||
|
||||
let mut errors = errors.lock().unwrap();
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ use euclid::size::TypedSize2D;
|
|||
use media_queries::CSSErrorReporterTest;
|
||||
use servo_config::prefs::{PREFS, PrefValue};
|
||||
use servo_url::ServoUrl;
|
||||
use style::media_queries::{Device, MediaType};
|
||||
use std::sync::Arc;
|
||||
use style::media_queries::{Device, MediaList, MediaType};
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::{CssRuleType, Stylesheet, Origin};
|
||||
|
@ -27,7 +28,7 @@ macro_rules! stylesheet {
|
|||
$css,
|
||||
ServoUrl::parse("http://localhost").unwrap(),
|
||||
Origin::$origin,
|
||||
Default::default(),
|
||||
Arc::new($shared_lock.wrap(MediaList::empty())),
|
||||
$shared_lock,
|
||||
None,
|
||||
&$error_reporter
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue