Rename media_queries::MediaQueryList to MediaList

This commit is contained in:
Xidorn Quan 2016-11-08 12:11:21 +11:00
parent d8ac5100e8
commit 2733ec3bdc
6 changed files with 24 additions and 27 deletions

View file

@ -92,7 +92,7 @@ use std::sync::mpsc::{Receiver, Sender};
use std::time::{SystemTime, Instant}; use std::time::{SystemTime, Instant};
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto}; use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
use style::element_state::*; use style::element_state::*;
use style::media_queries::MediaQueryList; use style::media_queries::MediaList;
use style::properties::PropertyDeclarationBlock; use style::properties::PropertyDeclarationBlock;
use style::selector_impl::{PseudoElement, Snapshot}; use style::selector_impl::{PseudoElement, Snapshot};
use style::values::specified::Length; use style::values::specified::Length;
@ -369,7 +369,7 @@ no_jsmanaged_fields!(WebGLProgramId);
no_jsmanaged_fields!(WebGLRenderbufferId); no_jsmanaged_fields!(WebGLRenderbufferId);
no_jsmanaged_fields!(WebGLShaderId); no_jsmanaged_fields!(WebGLShaderId);
no_jsmanaged_fields!(WebGLTextureId); no_jsmanaged_fields!(WebGLTextureId);
no_jsmanaged_fields!(MediaQueryList); no_jsmanaged_fields!(MediaList);
impl JSTraceable for Box<ScriptChan + Send> { impl JSTraceable for Box<ScriptChan + Send> {
#[inline] #[inline]

View file

@ -42,7 +42,7 @@ use std::default::Default;
use std::mem; use std::mem;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use style::attr::AttrValue; use style::attr::AttrValue;
use style::media_queries::{MediaQueryList, parse_media_query_list}; use style::media_queries::{MediaList, parse_media_query_list};
use style::parser::ParserContextExtraData; use style::parser::ParserContextExtraData;
use style::str::HTML_SPACE_CHARACTERS; use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::{Stylesheet, Origin}; use style::stylesheets::{Stylesheet, Origin};
@ -297,7 +297,7 @@ impl HTMLLinkElement {
struct StylesheetContext { struct StylesheetContext {
/// The element that initiated the request. /// The element that initiated the request.
elem: Trusted<HTMLLinkElement>, elem: Trusted<HTMLLinkElement>,
media: Option<MediaQueryList>, media: Option<MediaList>,
/// The response body received to date. /// The response body received to date.
data: Vec<u8>, data: Vec<u8>,
/// The response metadata received to date. /// The response metadata received to date.

View file

@ -19,8 +19,7 @@ use euclid::scale_factor::ScaleFactor;
use js::jsapi::JSTracer; use js::jsapi::JSTracer;
use std::cell::Cell; use std::cell::Cell;
use std::rc::Rc; use std::rc::Rc;
use style; use style::media_queries::{Device, MediaList, MediaType};
use style::media_queries::{Device, MediaType};
use style_traits::{PagePx, ToCss, ViewportPx}; use style_traits::{PagePx, ToCss, ViewportPx};
pub enum MediaQueryListMatchState { pub enum MediaQueryListMatchState {
@ -32,13 +31,12 @@ pub enum MediaQueryListMatchState {
pub struct MediaQueryList { pub struct MediaQueryList {
eventtarget: EventTarget, eventtarget: EventTarget,
document: JS<Document>, document: JS<Document>,
media_query_list: style::media_queries::MediaQueryList, media_query_list: MediaList,
last_match_state: Cell<Option<bool>> last_match_state: Cell<Option<bool>>
} }
impl MediaQueryList { impl MediaQueryList {
fn new_inherited(document: &Document, fn new_inherited(document: &Document, media_query_list: MediaList) -> MediaQueryList {
media_query_list: style::media_queries::MediaQueryList) -> MediaQueryList {
MediaQueryList { MediaQueryList {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
document: JS::from_ref(document), document: JS::from_ref(document),
@ -47,8 +45,7 @@ impl MediaQueryList {
} }
} }
pub fn new(document: &Document, pub fn new(document: &Document, media_query_list: MediaList) -> Root<MediaQueryList> {
media_query_list: style::media_queries::MediaQueryList) -> Root<MediaQueryList> {
reflect_dom_object(box MediaQueryList::new_inherited(document, media_query_list), reflect_dom_object(box MediaQueryList::new_inherited(document, media_query_list),
document.window(), document.window(),
MediaQueryListBinding::Wrap) MediaQueryListBinding::Wrap)

View file

@ -19,11 +19,11 @@ use values::specified;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct MediaQueryList { pub struct MediaList {
pub media_queries: Vec<MediaQuery> pub media_queries: Vec<MediaQuery>
} }
impl ToCss for MediaQueryList { impl ToCss for MediaList {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write where W: fmt::Write
{ {
@ -252,7 +252,7 @@ impl MediaQuery {
} }
} }
pub fn parse_media_query_list(input: &mut Parser) -> MediaQueryList { pub fn parse_media_query_list(input: &mut Parser) -> MediaList {
let queries = if input.is_exhausted() { let queries = if input.is_exhausted() {
vec![MediaQuery::new(None, MediaQueryType::All, vec!())] vec![MediaQuery::new(None, MediaQueryType::All, vec!())]
} else { } else {
@ -271,10 +271,10 @@ pub fn parse_media_query_list(input: &mut Parser) -> MediaQueryList {
} }
media_queries media_queries
}; };
MediaQueryList { media_queries: queries } MediaList { media_queries: queries }
} }
impl MediaQueryList { impl MediaList {
pub fn evaluate(&self, device: &Device) -> bool { pub fn evaluate(&self, device: &Device) -> bool {
let viewport_size = device.au_viewport_size(); let viewport_size = device.au_viewport_size();

View file

@ -11,7 +11,7 @@ use encoding::EncodingRef;
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
use font_face::{FontFaceRule, parse_font_face_block}; use font_face::{FontFaceRule, parse_font_face_block};
use keyframes::{Keyframe, parse_keyframe_list}; use keyframes::{Keyframe, parse_keyframe_list};
use media_queries::{Device, MediaQueryList, parse_media_query_list}; use media_queries::{Device, MediaList, parse_media_query_list};
use parking_lot::RwLock; use parking_lot::RwLock;
use parser::{ParserContext, ParserContextExtraData, log_css_error}; use parser::{ParserContext, ParserContextExtraData, log_css_error};
use properties::{PropertyDeclarationBlock, parse_property_declaration_list}; use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
@ -46,7 +46,7 @@ pub struct Stylesheet {
/// cascading order) /// cascading order)
pub rules: Vec<CSSRule>, pub rules: Vec<CSSRule>,
/// List of media associated with the Stylesheet, if any. /// List of media associated with the Stylesheet, if any.
pub media: Option<MediaQueryList>, pub media: Option<MediaList>,
pub origin: Origin, pub origin: Origin,
pub dirty_on_viewport_size_change: bool, pub dirty_on_viewport_size_change: bool,
} }
@ -77,7 +77,7 @@ impl CSSRule {
/// ///
/// Note that only some types of rules can contain rules. An empty slice is used for others. /// Note that only some types of rules can contain rules. An empty slice is used for others.
pub fn with_nested_rules_and_mq<F, R>(&self, mut f: F) -> R pub fn with_nested_rules_and_mq<F, R>(&self, mut f: F) -> R
where F: FnMut(&[CSSRule], Option<&MediaQueryList>) -> R { where F: FnMut(&[CSSRule], Option<&MediaList>) -> R {
match *self { match *self {
CSSRule::Namespace(_) | CSSRule::Namespace(_) |
CSSRule::Style(_) | CSSRule::Style(_) |
@ -111,7 +111,7 @@ pub struct KeyframesRule {
#[derive(Debug)] #[derive(Debug)]
pub struct MediaRule { pub struct MediaRule {
pub media_queries: Arc<RwLock<MediaQueryList>>, pub media_queries: Arc<RwLock<MediaList>>,
pub rules: Vec<CSSRule>, pub rules: Vec<CSSRule>,
} }
@ -187,15 +187,15 @@ impl Stylesheet {
} }
} }
/// Set the MediaQueryList associated with the style-sheet. /// Set the MediaList associated with the style-sheet.
pub fn set_media(&mut self, media: Option<MediaQueryList>) { pub fn set_media(&mut self, media: Option<MediaList>) {
self.media = media; self.media = media;
} }
/// Returns whether the style-sheet applies for the current device depending /// Returns whether the style-sheet applies for the current device depending
/// on the associated MediaQueryList. /// on the associated MediaList.
/// ///
/// Always true if no associated MediaQueryList exists. /// Always true if no associated MediaList exists.
pub fn is_effective_for_device(&self, device: &Device) -> bool { pub fn is_effective_for_device(&self, device: &Device) -> bool {
self.media.as_ref().map_or(true, |ref media| media.evaluate(device)) self.media.as_ref().map_or(true, |ref media| media.evaluate(device))
} }
@ -287,7 +287,7 @@ enum AtRulePrelude {
/// A @font-face rule prelude. /// A @font-face rule prelude.
FontFace, FontFace,
/// A @media rule prelude, with its media queries. /// A @media rule prelude, with its media queries.
Media(Arc<RwLock<MediaQueryList>>), Media(Arc<RwLock<MediaList>>),
/// A @viewport rule prelude. /// A @viewport rule prelude.
Viewport, Viewport,
/// A @keyframes rule, with its animation name. /// A @keyframes rule, with its animation name.

View file

@ -24,7 +24,7 @@ impl ParseErrorReporter for CSSErrorReporterTest {
} }
} }
fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaQueryList, &str) { fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaList, &str) {
let url = Url::parse("http://localhost").unwrap(); let url = Url::parse("http://localhost").unwrap();
let stylesheet = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest), let stylesheet = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest),
ParserContextExtraData::default()); ParserContextExtraData::default());
@ -36,7 +36,7 @@ fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaQueryList, &str)
assert!(rule_count > 0); assert!(rule_count > 0);
} }
fn media_queries<F>(rules: &[CSSRule], f: &mut F) where F: FnMut(&MediaQueryList) { fn media_queries<F>(rules: &[CSSRule], f: &mut F) where F: FnMut(&MediaList) {
for rule in rules { for rule in rules {
rule.with_nested_rules_and_mq(|rules, mq| { rule.with_nested_rules_and_mq(|rules, mq| {
if let Some(mq) = mq { if let Some(mq) = mq {