From fe82d175e94dee1e5906558282187f7c4ed7d7e9 Mon Sep 17 00:00:00 2001 From: Vincent Ricard Date: Sat, 10 Oct 2020 21:12:58 +0200 Subject: [PATCH] Implements StyleSheet.media --- components/script/dom/cssstylesheet.rs | 9 +++++ components/script/dom/stylesheet.rs | 6 ++++ .../script/dom/webidls/StyleSheet.webidl | 2 +- .../css/cssom/MediaList2.xhtml.ini | 12 ------- .../css/cssom/cssimportrule.html.ini | 3 -- .../css/cssom/idlharness.html.ini | 36 ------------------- .../css/cssom/medialist-dynamic-001.html.ini | 2 -- .../cssom/medialist-interfaces-001.html.ini | 3 -- .../cssom/medialist-interfaces-002.html.ini | 3 -- .../cssom/medialist-interfaces-004.html.ini | 7 ---- .../metadata/css/cssom/MediaList2.xhtml.ini | 12 ------- .../metadata/css/cssom/cssimportrule.html.ini | 3 -- .../metadata/css/cssom/idlharness.html.ini | 36 ------------------- .../css/cssom/medialist-dynamic-001.html.ini | 2 -- .../cssom/medialist-interfaces-001.html.ini | 3 -- .../cssom/medialist-interfaces-002.html.ini | 3 -- .../cssom/medialist-interfaces-004.html.ini | 8 ----- 17 files changed, 16 insertions(+), 134 deletions(-) delete mode 100644 tests/wpt/metadata-layout-2020/css/cssom/MediaList2.xhtml.ini delete mode 100644 tests/wpt/metadata-layout-2020/css/cssom/medialist-dynamic-001.html.ini delete mode 100644 tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-004.html.ini delete mode 100644 tests/wpt/metadata/css/cssom/MediaList2.xhtml.ini delete mode 100644 tests/wpt/metadata/css/cssom/medialist-dynamic-001.html.ini delete mode 100644 tests/wpt/metadata/css/cssom/medialist-interfaces-004.html.ini diff --git a/components/script/dom/cssstylesheet.rs b/components/script/dom/cssstylesheet.rs index 7ee5e44439491..dda321be153a8 100644 --- a/components/script/dom/cssstylesheet.rs +++ b/components/script/dom/cssstylesheet.rs @@ -10,6 +10,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::str::DOMString; use crate::dom::cssrulelist::{CSSRuleList, RulesSource}; use crate::dom::element::Element; +use crate::dom::medialist::MediaList; use crate::dom::node::{stylesheets_owner_from_node, Node}; use crate::dom::stylesheet::StyleSheet; use crate::dom::window::Window; @@ -100,6 +101,14 @@ impl CSSStyleSheet { pub fn set_origin_clean(&self, origin_clean: bool) { self.origin_clean.set(origin_clean); } + + pub fn medialist(&self) -> DomRoot { + MediaList::new( + self.global().as_window(), + self, + self.style_stylesheet().media.clone(), + ) + } } impl CSSStyleSheetMethods for CSSStyleSheet { diff --git a/components/script/dom/stylesheet.rs b/components/script/dom/stylesheet.rs index 56ce505d152fe..c03776dc7f656 100644 --- a/components/script/dom/stylesheet.rs +++ b/components/script/dom/stylesheet.rs @@ -9,6 +9,7 @@ use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::DOMString; use crate::dom::cssstylesheet::CSSStyleSheet; use crate::dom::element::Element; +use crate::dom::medialist::MediaList; use dom_struct::dom_struct; #[dom_struct] @@ -51,6 +52,11 @@ impl StyleSheetMethods for StyleSheet { self.downcast::().and_then(|s| s.get_owner()) } + // https://drafts.csswg.org/cssom/#dom-stylesheet-media + fn Media(&self) -> DomRoot { + self.downcast::().unwrap().medialist() + } + // https://drafts.csswg.org/cssom/#dom-stylesheet-title fn GetTitle(&self) -> Option { self.title.clone() diff --git a/components/script/dom/webidls/StyleSheet.webidl b/components/script/dom/webidls/StyleSheet.webidl index 67ac5f965e14c..cb8290cc30bcb 100644 --- a/components/script/dom/webidls/StyleSheet.webidl +++ b/components/script/dom/webidls/StyleSheet.webidl @@ -12,7 +12,7 @@ interface StyleSheet { // readonly attribute StyleSheet? parentStyleSheet; readonly attribute DOMString? title; - // [SameObject, PutForwards=mediaText] readonly attribute MediaList media; + [SameObject, PutForwards=mediaText] readonly attribute MediaList media; attribute boolean disabled; }; diff --git a/tests/wpt/metadata-layout-2020/css/cssom/MediaList2.xhtml.ini b/tests/wpt/metadata-layout-2020/css/cssom/MediaList2.xhtml.ini deleted file mode 100644 index 1e4eb9d46f693..0000000000000 --- a/tests/wpt/metadata-layout-2020/css/cssom/MediaList2.xhtml.ini +++ /dev/null @@ -1,12 +0,0 @@ -[MediaList2.xhtml] - [MediaList.mediaText] - expected: FAIL - - [MediaList.length] - expected: FAIL - - [MediaList getter] - expected: FAIL - - [MediaList.item] - expected: FAIL diff --git a/tests/wpt/metadata-layout-2020/css/cssom/cssimportrule.html.ini b/tests/wpt/metadata-layout-2020/css/cssom/cssimportrule.html.ini index f99f865f998d5..8d50837ea568f 100644 --- a/tests/wpt/metadata-layout-2020/css/cssom/cssimportrule.html.ini +++ b/tests/wpt/metadata-layout-2020/css/cssom/cssimportrule.html.ini @@ -8,9 +8,6 @@ [Existence and writability of CSSImportRule attributes] expected: FAIL - [StyleSheet : MediaList mediaText attribute should be updated due to [PutForwards\]] - expected: FAIL - [CSSImportRule : MediaList mediaText attribute should be updated due to [PutForwards\]] expected: FAIL diff --git a/tests/wpt/metadata-layout-2020/css/cssom/idlharness.html.ini b/tests/wpt/metadata-layout-2020/css/cssom/idlharness.html.ini index 6a59f55ca527c..2c49c8bac34dc 100644 --- a/tests/wpt/metadata-layout-2020/css/cssom/idlharness.html.ini +++ b/tests/wpt/metadata-layout-2020/css/cssom/idlharness.html.ini @@ -8,9 +8,6 @@ [CSSStyleDeclaration interface: style_element.style must inherit property "parentRule" with the proper type] expected: FAIL - [MediaList interface: sheet.media must inherit property "deleteMedium(CSSOMString)" with the proper type] - expected: FAIL - [CSSStyleDeclaration interface: sheet.cssRules[4\].style must inherit property "setProperty(CSSOMString, CSSOMString, optional CSSOMString)" with the proper type] expected: FAIL @@ -20,9 +17,6 @@ [Stringification of svg_element.style] expected: FAIL - [MediaList interface: calling item(unsigned long) on sheet.media with too few arguments must throw TypeError] - expected: FAIL - [CSSStyleSheet interface: sheet must inherit property "ownerRule" with the proper type] expected: FAIL @@ -53,18 +47,9 @@ [CSSMarginRule interface: sheet.cssRules[2\].cssRules[0\] must inherit property "style" with the proper type] expected: FAIL - [MediaList interface: sheet.media must inherit property "item(unsigned long)" with the proper type] - expected: FAIL - [CSSStyleDeclaration interface: svg_element.style must inherit property "getPropertyValue(CSSOMString)" with the proper type] expected: FAIL - [MediaList interface: sheet.media must inherit property "length" with the proper type] - expected: FAIL - - [StyleSheet interface: sheet must inherit property "media" with the proper type] - expected: FAIL - [SVGStyleElement interface: attribute sheet] expected: FAIL @@ -89,9 +74,6 @@ [StyleSheet interface: attribute type] expected: FAIL - [MediaList interface: calling appendMedium(CSSOMString) on sheet.media with too few arguments must throw TypeError] - expected: FAIL - [Stringification of sheet.cssRules[2\].cssRules[0\]] expected: FAIL @@ -248,9 +230,6 @@ [StyleSheet interface: sheet must inherit property "parentStyleSheet" with the proper type] expected: FAIL - [MediaList interface: calling deleteMedium(CSSOMString) on sheet.media with too few arguments must throw TypeError] - expected: FAIL - [CSSPageRule interface: sheet.cssRules[2\] must inherit property "selectorText" with the proper type] expected: FAIL @@ -275,9 +254,6 @@ [CSSStyleDeclaration interface: sheet.cssRules[2\].style must inherit property "getPropertyPriority(CSSOMString)" with the proper type] expected: FAIL - [MediaList interface: sheet.media must inherit property "mediaText" with the proper type] - expected: FAIL - [CSSStyleDeclaration interface: sheet.cssRules[2\].cssRules[0\].style must inherit property "removeProperty(CSSOMString)" with the proper type] expected: FAIL @@ -296,9 +272,6 @@ [CSSStyleDeclaration interface: calling getPropertyValue(CSSOMString) on sheet.cssRules[4\].style with too few arguments must throw TypeError] expected: FAIL - [MediaList interface: sheet.media must inherit property "appendMedium(CSSOMString)" with the proper type] - expected: FAIL - [CSSStyleDeclaration interface: sheet.cssRules[4\].style must inherit property "length" with the proper type] expected: FAIL @@ -323,9 +296,6 @@ [SVGElement interface: svg_element must inherit property "style" with the proper type] expected: FAIL - [StyleSheet interface: attribute media] - expected: FAIL - [CSSPageRule interface: attribute style] expected: FAIL @@ -344,9 +314,6 @@ [CSSStyleDeclaration interface: sheet.cssRules[4\].style must inherit property "getPropertyValue(CSSOMString)" with the proper type] expected: FAIL - [MediaList must be primary interface of sheet.media] - expected: FAIL - [CSSRule interface: sheet.cssRules[2\].cssRules[0\] must inherit property "PAGE_RULE" with the proper type] expected: FAIL @@ -407,9 +374,6 @@ [CSSStyleDeclaration interface: svg_element.style must inherit property "cssText" with the proper type] expected: FAIL - [Stringification of sheet.media] - expected: FAIL - [CSSRule interface: sheet.cssRules[2\].cssRules[0\] must inherit property "type" with the proper type] expected: FAIL diff --git a/tests/wpt/metadata-layout-2020/css/cssom/medialist-dynamic-001.html.ini b/tests/wpt/metadata-layout-2020/css/cssom/medialist-dynamic-001.html.ini deleted file mode 100644 index 0d28942060d2e..0000000000000 --- a/tests/wpt/metadata-layout-2020/css/cssom/medialist-dynamic-001.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[medialist-dynamic-001.html] - expected: FAIL diff --git a/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-001.html.ini b/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-001.html.ini index 483b4184033f9..2d952f7936e87 100644 --- a/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-001.html.ini +++ b/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-001.html.ini @@ -8,6 +8,3 @@ [mediatest_medialist_serialize_element] expected: FAIL - [mediatest_medialist_serialize_empty] - expected: FAIL - diff --git a/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-002.html.ini b/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-002.html.ini index a35bd5b44b9ed..3e87b803a3e69 100644 --- a/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-002.html.ini +++ b/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-002.html.ini @@ -2,6 +2,3 @@ [deleteMedium_no_matching_medium_to_remove] expected: FAIL - [deleteMedium_removes_correct_medium] - expected: FAIL - diff --git a/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-004.html.ini b/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-004.html.ini deleted file mode 100644 index 651a10aa275a4..0000000000000 --- a/tests/wpt/metadata-layout-2020/css/cssom/medialist-interfaces-004.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[medialist-interfaces-004.html] - [appendMedium_correctly_appends_medium_to_empty_MediaList] - expected: FAIL - - [appendMedium_correctly_appends_medium_to_nonempty_MediaList] - expected: FAIL - diff --git a/tests/wpt/metadata/css/cssom/MediaList2.xhtml.ini b/tests/wpt/metadata/css/cssom/MediaList2.xhtml.ini deleted file mode 100644 index 1e4eb9d46f693..0000000000000 --- a/tests/wpt/metadata/css/cssom/MediaList2.xhtml.ini +++ /dev/null @@ -1,12 +0,0 @@ -[MediaList2.xhtml] - [MediaList.mediaText] - expected: FAIL - - [MediaList.length] - expected: FAIL - - [MediaList getter] - expected: FAIL - - [MediaList.item] - expected: FAIL diff --git a/tests/wpt/metadata/css/cssom/cssimportrule.html.ini b/tests/wpt/metadata/css/cssom/cssimportrule.html.ini index eb8fb0ec633a8..57125ee8bb5c8 100644 --- a/tests/wpt/metadata/css/cssom/cssimportrule.html.ini +++ b/tests/wpt/metadata/css/cssom/cssimportrule.html.ini @@ -21,6 +21,3 @@ [CSSStyleDeclaration cssText attribute should be updated due to [PutForwards\]] expected: FAIL - [StyleSheet : MediaList mediaText attribute should be updated due to [PutForwards\]] - expected: FAIL - diff --git a/tests/wpt/metadata/css/cssom/idlharness.html.ini b/tests/wpt/metadata/css/cssom/idlharness.html.ini index aa800927b12e2..e3b2e64c3c421 100644 --- a/tests/wpt/metadata/css/cssom/idlharness.html.ini +++ b/tests/wpt/metadata/css/cssom/idlharness.html.ini @@ -8,18 +8,12 @@ [CSSStyleDeclaration interface: style_element.style must inherit property "parentRule" with the proper type] expected: FAIL - [MediaList interface: sheet.media must inherit property "deleteMedium(CSSOMString)" with the proper type] - expected: FAIL - [CSSStyleDeclaration interface: sheet.cssRules[2\].style must inherit property "removeProperty(CSSOMString)" with the proper type] expected: FAIL [Stringification of svg_element.style] expected: FAIL - [MediaList interface: calling item(unsigned long) on sheet.media with too few arguments must throw TypeError] - expected: FAIL - [CSSStyleSheet interface: sheet must inherit property "ownerRule" with the proper type] expected: FAIL @@ -56,18 +50,9 @@ [CSSMarginRule interface: sheet.cssRules[2\].cssRules[0\] must inherit property "style" with the proper type] expected: FAIL - [MediaList interface: sheet.media must inherit property "item(unsigned long)" with the proper type] - expected: FAIL - [CSSStyleDeclaration interface: svg_element.style must inherit property "getPropertyValue(CSSOMString)" with the proper type] expected: FAIL - [MediaList interface: sheet.media must inherit property "length" with the proper type] - expected: FAIL - - [StyleSheet interface: sheet must inherit property "media" with the proper type] - expected: FAIL - [SVGStyleElement interface: attribute sheet] expected: FAIL @@ -227,9 +212,6 @@ [CSSStyleDeclaration interface: sheet.cssRules[2\].cssRules[0\].style must inherit property "getPropertyValue(CSSOMString)" with the proper type] expected: FAIL - [MediaList interface: calling appendMedium(CSSOMString) on sheet.media with too few arguments must throw TypeError] - expected: FAIL - [CSSRule interface: sheet.cssRules[4\] must inherit property "cssText" with the proper type] expected: FAIL @@ -248,9 +230,6 @@ [CSSStyleDeclaration interface: sheet.cssRules[2\].cssRules[0\].style must inherit property "getPropertyPriority(CSSOMString)" with the proper type] expected: FAIL - [MediaList interface: calling deleteMedium(CSSOMString) on sheet.media with too few arguments must throw TypeError] - expected: FAIL - [CSSPageRule interface: sheet.cssRules[2\] must inherit property "selectorText" with the proper type] expected: FAIL @@ -275,9 +254,6 @@ [CSSStyleDeclaration interface: sheet.cssRules[2\].style must inherit property "getPropertyPriority(CSSOMString)" with the proper type] expected: FAIL - [MediaList interface: sheet.media must inherit property "mediaText" with the proper type] - expected: FAIL - [CSSStyleDeclaration interface: sheet.cssRules[2\].style must inherit property "length" with the proper type] expected: FAIL @@ -308,9 +284,6 @@ [CSSStyleDeclaration interface: calling getPropertyValue(CSSOMString) on sheet.cssRules[4\].style with too few arguments must throw TypeError] expected: FAIL - [MediaList interface: sheet.media must inherit property "appendMedium(CSSOMString)" with the proper type] - expected: FAIL - [CSSStyleDeclaration interface: sheet.cssRules[4\].style must inherit property "length" with the proper type] expected: FAIL @@ -335,9 +308,6 @@ [SVGElement interface: svg_element must inherit property "style" with the proper type] expected: FAIL - [StyleSheet interface: attribute media] - expected: FAIL - [CSSPageRule interface: attribute style] expected: FAIL @@ -356,9 +326,6 @@ [CSSStyleDeclaration interface: sheet.cssRules[4\].style must inherit property "getPropertyValue(CSSOMString)" with the proper type] expected: FAIL - [MediaList must be primary interface of sheet.media] - expected: FAIL - [CSSRule interface: sheet.cssRules[2\].cssRules[0\] must inherit property "PAGE_RULE" with the proper type] expected: FAIL @@ -413,9 +380,6 @@ [CSSStyleDeclaration interface: svg_element.style must inherit property "cssText" with the proper type] expected: FAIL - [Stringification of sheet.media] - expected: FAIL - [CSSRule interface: sheet.cssRules[2\].cssRules[0\] must inherit property "type" with the proper type] expected: FAIL diff --git a/tests/wpt/metadata/css/cssom/medialist-dynamic-001.html.ini b/tests/wpt/metadata/css/cssom/medialist-dynamic-001.html.ini deleted file mode 100644 index 0d28942060d2e..0000000000000 --- a/tests/wpt/metadata/css/cssom/medialist-dynamic-001.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[medialist-dynamic-001.html] - expected: FAIL diff --git a/tests/wpt/metadata/css/cssom/medialist-interfaces-001.html.ini b/tests/wpt/metadata/css/cssom/medialist-interfaces-001.html.ini index cf6011a8f9d64..ac84d3d0e0075 100644 --- a/tests/wpt/metadata/css/cssom/medialist-interfaces-001.html.ini +++ b/tests/wpt/metadata/css/cssom/medialist-interfaces-001.html.ini @@ -6,9 +6,6 @@ [mediatest_medialist_serialize_comma] expected: FAIL - [mediatest_medialist_serialize_empty] - expected: FAIL - [mediatest_medialist_serialize_lexicographical] expected: FAIL diff --git a/tests/wpt/metadata/css/cssom/medialist-interfaces-002.html.ini b/tests/wpt/metadata/css/cssom/medialist-interfaces-002.html.ini index 87b9a923fa10b..4bedbbc64b27a 100644 --- a/tests/wpt/metadata/css/cssom/medialist-interfaces-002.html.ini +++ b/tests/wpt/metadata/css/cssom/medialist-interfaces-002.html.ini @@ -1,8 +1,5 @@ [medialist-interfaces-002.html] type: testharness - [deleteMedium_removes_correct_medium] - expected: FAIL - [deleteMedium_no_matching_medium_to_remove] expected: FAIL diff --git a/tests/wpt/metadata/css/cssom/medialist-interfaces-004.html.ini b/tests/wpt/metadata/css/cssom/medialist-interfaces-004.html.ini deleted file mode 100644 index cc1b1f3548cca..0000000000000 --- a/tests/wpt/metadata/css/cssom/medialist-interfaces-004.html.ini +++ /dev/null @@ -1,8 +0,0 @@ -[medialist-interfaces-004.html] - type: testharness - [appendMedium_correctly_appends_medium_to_empty_MediaList] - expected: FAIL - - [appendMedium_correctly_appends_medium_to_nonempty_MediaList] - expected: FAIL -