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

Expose public getter to stylesheet's owner #23073

Merged
merged 1 commit into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion components/script/dom/cssrulelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::CSSRuleListBinding;
use crate::dom::bindings::codegen::Bindings::CSSRuleListBinding::CSSRuleListMethods;
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::csskeyframerule::CSSKeyframeRule;
use crate::dom::cssrule::CSSRule;
use crate::dom::cssstylesheet::CSSStyleSheet;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::window::Window;
use crate::stylesheet_loader::StylesheetLoader;
use dom_struct::dom_struct;
use servo_arc::Arc;
use style::shared_lock::Locked;
Expand Down Expand Up @@ -101,14 +104,20 @@ impl CSSRuleList {
let index = idx as usize;

let parent_stylesheet = self.parent_stylesheet.style_stylesheet();
let owner = self
.parent_stylesheet
.get_owner()
.downcast::<HTMLElement>()
.unwrap();
let loader = StylesheetLoader::for_element(owner);
let new_rule = css_rules.with_raw_offset_arc(|arc| {
arc.insert_rule(
&parent_stylesheet.shared_lock,
rule,
&parent_stylesheet.contents,
index,
nested,
None,
Some(&loader),
)
})?;

Expand Down
4 changes: 4 additions & 0 deletions components/script/dom/cssstylesheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ impl CSSStyleSheet {
self.style_stylesheet.disabled()
}

pub fn get_owner(&self) -> &Element {
&*self.owner
}

pub fn set_disabled(&self, disabled: bool) {
if self.style_stylesheet.set_disabled(disabled) {
self.global()
Expand Down
43 changes: 43 additions & 0 deletions tests/wpt/metadata/MANIFEST.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"items": {
"conformancechecker": {
"css/cssom/stylesheet-owner.html": []
},
"manual": {
"2dcontext/conformance-requirements/2d.coordinatespace-manual.html": [
[
Expand Down Expand Up @@ -10573,6 +10576,7 @@
{}
]
],
"css/cssom/stylesheet-owner.html": [],
"css/selectors/focus-visible-001-manual.html": [
[
"css/selectors/focus-visible-001-manual.html",
Expand Down Expand Up @@ -172253,6 +172257,18 @@
{}
]
],
"css/cssom/insertRule-from-script.html": [
[
"css/cssom/insertRule-from-script.html",
[
[
"/css/cssom/insertRule-from-script-ref.html",
"=="
]
],
{}
]
],
"css/cssom/medialist-dynamic-001.html": [
[
"css/cssom/medialist-dynamic-001.html",
Expand Down Expand Up @@ -201725,6 +201741,7 @@
]
},
"stub": {
"css/cssom/stylesheet-owner.html": [],
"service-workers/stub-3.1-service-worker-obj.html": [
[
"service-workers/stub-3.1-service-worker-obj.html",
Expand Down Expand Up @@ -282062,6 +282079,11 @@
{}
]
],
"css/cssom/insertRule-from-script-ref.html": [
[
{}
]
],
"css/cssom/medialist-dynamic-001-ref.html": [
[
{}
Expand All @@ -282072,6 +282094,7 @@
{}
]
],
"css/cssom/stylesheet-owner.html": [],
"css/cssom/stylesheet-replacedata-dynamic-ref.html": [
[
{}
Expand Down Expand Up @@ -282142,6 +282165,11 @@
{}
]
],
"css/cssom/support/black.css": [
[
{}
]
],
"css/cssom/support/c-red.css": [
[
{}
Expand Down Expand Up @@ -364795,6 +364823,7 @@
{}
]
],
"css/cssom/stylesheet-owner.html": [],
"css/cssom/stylesheet-same-origin.sub.html": [
[
"css/cssom/stylesheet-same-origin.sub.html",
Expand Down Expand Up @@ -471825,6 +471854,7 @@
{}
]
],
"css/cssom/stylesheet-owner.html": [],
"css/mediaqueries/media-queries-001.xht": [
[
"css/mediaqueries/media-queries-001.xht",
Expand Down Expand Up @@ -472925,6 +472955,7 @@
]
},
"wdspec": {
"css/cssom/stylesheet-owner.html": [],
"infrastructure/webdriver/tests/test_load_file.py": [
[
"infrastructure/webdriver/tests/test_load_file.py",
Expand Down Expand Up @@ -625992,6 +626023,14 @@
"16f2358dc2d806de878bf2a1403aec9e6c41d9bd",
"testharness"
],
"css/cssom/insertRule-from-script-ref.html": [
"2fa45526a66565f86832f843ec477fe76e496775",
"support"
],
"css/cssom/insertRule-from-script.html": [
"c364afc282b061ef6520b9f8c9b5271f0b11d000",
"reftest"
],
"css/cssom/insertRule-import-no-index.html": [
"ad3622f86aaa4dfd58ee18015d1ef8dd1ebd6a70",
"testharness"
Expand Down Expand Up @@ -626172,6 +626211,10 @@
"a0473f5ca26652c1229290bbf1f81eabc1e37280",
"support"
],
"css/cssom/support/black.css": [
"833a0e00926ba4eb4615d177df63747cdb23f321",
"support"
],
"css/cssom/support/c-red.css": [
"d4ba5c64e95406f541e2f8cc19e192e9f521ed6b",
"support"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!doctype html>
<head>
<meta charset="utf-8">
<title>insertrule @import test reference</title>
<link rel="stylesheet" href="support/black.css">
</head>
12 changes: 12 additions & 0 deletions tests/wpt/web-platform-tests/css/cssom/insertRule-from-script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<head>
<meta charset="utf-8">
<title>insertrule @import test</title>
<link rel="help" href="https://drafts.csswg.org/cssom/">
<link rel="help" href="http://www.w3.org/TR/cssom-1/#the-cssrule-interface">
<link rel="match" href="insertRule-from-script-ref.html">
<style></style>
</head>
<body>
<script>document.styleSheets[0].insertRule("@import url(\"support/black.css\");");</script>
</body>
4 changes: 4 additions & 0 deletions tests/wpt/web-platform-tests/css/cssom/support/black.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
html {
background-color: black;
color: white;
}