Bug 1447009: Ignore title if the element is not in the document. r=heycam

Turns out this was well specified, see the linked bits.

MozReview-Commit-ID: HjdbFS78Mwj
This commit is contained in:
Emilio Cobos Álvarez 2018-05-08 18:05:25 +02:00
parent a104536e36
commit 50a8a26470
4 changed files with 96 additions and 2 deletions

View File

@ -90,8 +90,16 @@ nsStyleLinkElement::GetTitleAndMediaForElement(const Element& aSelf,
nsString& aTitle,
nsString& aMedia)
{
aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
aTitle.CompressWhitespace();
// Only honor title as stylesheet name for elements in the document (that is,
// ignore for Shadow DOM), per [1] and [2]. See [3].
//
// [1]: https://html.spec.whatwg.org/#attr-link-title
// [2]: https://html.spec.whatwg.org/#attr-style-title
// [3]: https://github.com/w3c/webcomponents/issues/535
if (aSelf.IsInUncomposedDoc()) {
aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
aTitle.CompressWhitespace();
}
aSelf.GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
// The HTML5 spec is formulated in terms of the CSSOM spec, which specifies

View File

@ -126745,6 +126745,18 @@
{}
]
],
"css/css-scoping/stylesheet-title-001.html": [
[
"/css/css-scoping/stylesheet-title-001.html",
[
[
"/css/css-scoping/reference/green-box.html",
"=="
]
],
{}
]
],
"css/css-shapes/shape-outside/formatting-context/shape-outside-formatting-context.tentative.html": [
[
"/css/css-shapes/shape-outside/formatting-context/shape-outside-formatting-context.tentative.html",
@ -317925,6 +317937,12 @@
{}
]
],
"css/css-scoping/stylesheet-title-002.html": [
[
"/css/css-scoping/stylesheet-title-002.html",
{}
]
],
"css/css-scroll-anchoring/abspos-containing-block-outside-scroller.html": [
[
"/css/css-scroll-anchoring/abspos-containing-block-outside-scroller.html",
@ -515280,6 +515298,14 @@
"27d36ba54623bbee2cdd09b7a9322873d5ab0011",
"reftest"
],
"css/css-scoping/stylesheet-title-001.html": [
"2e49b6d74d2021144444ca77e62acbc6aeffac2a",
"reftest"
],
"css/css-scoping/stylesheet-title-002.html": [
"9e228381a0aa11c76568b8ec893ed6745581bbf9",
"testharness"
],
"css/css-scroll-anchoring/README.md": [
"31205944cbcf321f7aa77e3bef0f8835cc7b6d13",
"support"

View File

@ -0,0 +1,24 @@
<!doctype html>
<meta charset="utf-8">
<title>CSS Test: title attribute in stylesheets not in the document tree is ignored</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="help" href="https://drafts.csswg.org/cssom/#preferred-css-style-sheet-set-name">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-style-title">
<link rel="help" href="https://github.com/w3c/webcomponents/issues/535">
<link rel="match" href="reference/green-box.html">
<p>Test passes if you see a single 100px by 100px green box below.</p>
<div id="host"></div>
<script>
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
div { width: 100px; height: 100px; }
</style>
<style title="Foo">
div { background: purple }
</style>
<style title="Bar">
div { background: green }
</style>
<div></div>
`;
</script>

View File

@ -0,0 +1,36 @@
<!doctype html>
<meta charset="utf-8">
<title>CSS Test: title attribute in stylesheets not in the document tree is ignored</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="help" href="https://drafts.csswg.org/cssom/#preferred-css-style-sheet-set-name">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-style-title">
<link rel="help" href="https://github.com/w3c/webcomponents/issues/535">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="host"></div>
<script>
test(function() {
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
div { width: 100px; height: 100px; }
</style>
<style title="Foo">
div { background: purple }
</style>
<style title="Bar">
div { background: green }
</style>
<div></div>
`;
assert_equals(host.shadowRoot.styleSheets.length, 3);
for (let sheet of host.shadowRoot.styleSheets) {
assert_equals(sheet.title, null, "Sheet outside of the document generates no setter");
sheet.title = "Foo";
assert_equals(sheet.title, null, "Mutation doesn't change the sheet title");
}
for (let element of host.shadowRoot.querySelectorAll("style")) {
element.setAttribute("title", "Foo");
assert_equals(element.sheet.title, null, "Attribute mutation doesn't change the sheet title");
}
}, "Title attribute in stylesheets not in the document tree is ignored");
</script>