-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[selectors4] Implement :dir pseudo-class
This patch adds support for the new ":dir" pseudo-class. The patch is covered by several of tests imported from the web tests including generic tests in addition to the tests from Firefox and apart from some minor changes on current tests to add the new selector. Intent-to-ship thread is available at: https://groups.google.com/u/1/a/chromium.org/g/blink-dev/c/p0Wc66rbVOc BUG=576815 Change-Id: I503c6af95d9c5817e3e71b1b2025a5562929f0d8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2460849 Commit-Queue: Miyoung Shin <myid.shin@igalia.com> Reviewed-by: Rune Lillesveen <futhark@chromium.org> Cr-Commit-Position: refs/heads/master@{#833712}
- Loading branch information
1 parent
eb57287
commit f028168
Showing
13 changed files
with
412 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<link rel="help" href="http://www.w3.org/TR/selectors4/#dir-pseudo"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<style> | ||
#div4_1 { | ||
direction: rtl; | ||
} | ||
</style> | ||
</head> | ||
|
||
<!-- ת is the Hebrew letter tav, i.e. RTL --> | ||
<body> | ||
<div id=testDivs> | ||
<div id=div1 dir=auto> | ||
<div id=div1_1>a</div> | ||
</div> | ||
<div id=div2 dir=auto> | ||
<div id=div2_1>ת</div> | ||
</div> | ||
<div id=div3 dir=auto> | ||
<div id=div3_1 dir=rtl>ת</div> | ||
<div id=div3_2>a</div> | ||
</div> | ||
<div id=div4 dir=auto> | ||
<div id=div4_1> | ||
<div id=div4_1_1>a</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
|
||
<script> | ||
function test_directionality(message, element, expected) { | ||
test(() => { | ||
var isLTR = document.querySelector("#" + element.id + ":dir(ltr)") == element; | ||
var isRTL = document.querySelector("#" + element.id + ":dir(rtl)") == element; | ||
if (expected == "ltr") { | ||
assert_true(isLTR); | ||
assert_false(isRTL); | ||
} else { | ||
assert_false(isLTR); | ||
assert_true(isRTL); | ||
} | ||
}, message + " directionality of element " + element.id + " is " + expected); | ||
} | ||
|
||
test_directionality("Initial ", div1, "ltr"); | ||
test_directionality("Initial ", div1_1, "ltr"); | ||
test_directionality("Initial ", div2, "rtl"); | ||
test_directionality("Initial ", div2_1, "rtl"); | ||
test_directionality("Initial ", div3, "ltr"); | ||
test_directionality("Initial ", div3_1, "rtl"); | ||
test_directionality("Initial ", div3_2, "ltr"); | ||
test_directionality("Initial ", div4, "ltr"); | ||
test_directionality("Initial ", div4_1, "ltr"); | ||
test_directionality("Initial ", div4_1_1, "ltr"); | ||
|
||
div1_1.innerText = "\u05EA"; | ||
div1_1.offsetTop; | ||
test_directionality("Updated ", div1, "rtl"); | ||
test_directionality("Updated ", div1_1, "rtl"); | ||
|
||
div1_1.dir = "ltr"; | ||
div1_1.offsetTop; | ||
test_directionality("Updated ", div1, "ltr"); | ||
test_directionality("Updated ", div1_1, "ltr"); | ||
|
||
div1_1.innerText = "a"; | ||
div1_1.offsetTop; | ||
test_directionality("Reupdated ", div1, "ltr"); | ||
test_directionality("Reupdated ", div1_1, "ltr"); | ||
|
||
div2_1.remove(); | ||
div2.offsetTop; | ||
test_directionality("Updated ", div2, "ltr"); | ||
|
||
div3_1.dir = ""; | ||
div3_1.offsetTop; | ||
test_directionality("Updated ", div3, "rtl"); | ||
div3.appendChild(div3_1); | ||
div3.offsetTop; | ||
test_directionality("Updated ", div3, "ltr"); | ||
|
||
div4_1_1.innerText = "\u05EA"; | ||
div4_1_1.offsetTop; | ||
test_directionality("Updated ", div4, "rtl"); | ||
test_directionality("Updated ", div4_1, "rtl"); | ||
test_directionality("Updated ", div4_1_1, "rtl"); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style type="text/css"> | ||
span { background-color: lime } | ||
</style> | ||
</head> | ||
<body> | ||
<div> | ||
<div> | ||
<div></div> | ||
<span>The background color should be lime</span> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>CSS Selectors Level 4 Test: Check for correctly updating :dir matching on dir attribute change from default(ltr) to rtl</title> | ||
<link rel="author" title="Miyoung Shin" href="mailto:myid.shin@igalia.com"> | ||
<link rel="help" href="http://www.w3.org/TR/selectors4/#dir-pseudo"> | ||
<link rel="match" href="selectors-dir-selector-change-001-ref.html"> | ||
<style type="text/css"> | ||
#x:dir(rtl) + span { background-color: lime } | ||
#outer { direction:ltr } | ||
</style> | ||
</head> | ||
<body> | ||
<div id="outer" style="-webkit-locale: 'en'"> | ||
<div> | ||
<div id="x"></div> | ||
<span>The background color should be lime</span> | ||
</div> | ||
</div> | ||
<script> | ||
outer.offsetTop; | ||
outer.setAttribute("dir", "rtl"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>CSS Selectors Level 4 Test: Check for correctly updating :dir matching on dir attribute change from default(ltr) to rtl</title> | ||
<link rel="author" title="Miyoung Shin" href="mailto:myid.shin@igalia.com"> | ||
<link rel="help" href="http://www.w3.org/TR/selectors4/#dir-pseudo"> | ||
<link rel="match" href="../reference/ref-filled-green-100px-square.xht"> | ||
<style type="text/css"> | ||
div { | ||
width: 100px; | ||
height: 100px; | ||
background-color: red; | ||
} | ||
|
||
div:dir(rtl) { | ||
background-color: green; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p> | ||
<div id="inner"></div> | ||
<script> | ||
inner.offsetTop; | ||
inner.setAttribute("dir", "rtl"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style type="text/css"> | ||
span { background-color: lime } | ||
</style> | ||
</head> | ||
<body> | ||
<div> | ||
<div> | ||
<div></div> | ||
<span>The background color should be lime</span> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>CSS Selectors Level 4 Test: Check for correctly updating :dir matching on dir attribute change from rtl to auto</title> | ||
<link rel="author" title="Miyoung Shin" href="mailto:myid.shin@igalia.com"> | ||
<link rel="help" href="http://www.w3.org/TR/selectors4/#dir-pseudo"> | ||
<link rel="match" href="selectors-dir-selector-change-003-ref.html"> | ||
<style type="text/css"> | ||
#x:dir(ltr) + span { background-color: lime } | ||
</style> | ||
</head> | ||
<body> | ||
<div id="outer" dir="rtl"> | ||
<div> | ||
<div id="x"></div> | ||
<span>The background color should be lime</span> | ||
</div> | ||
</div> | ||
<script> | ||
outer.offsetTop; | ||
outer.setAttribute("dir", "auto"); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<style type="text/css"> | ||
span { background-color: lime } | ||
</style> | ||
</head> | ||
<body> | ||
<div> | ||
<div dir="rtl"> | ||
<div></div> | ||
<span>מקור השם עברית</span> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>CSS Selectors Level 4 Test: Check for correctly updating :dir matching on directionality change from ltr to rtl</title> | ||
<link rel="author" title="Miyoung Shin" href="mailto:myid.shin@igalia.com"> | ||
<link rel="help" href="http://www.w3.org/TR/selectors4/#dir-pseudo"> | ||
<link rel="match" href="selectors-dir-selector-change-004-ref.html"> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<style type="text/css"> | ||
#x:dir(rtl) + span { background-color: lime } | ||
</style> | ||
</head> | ||
<body> | ||
<div dir="auto"> | ||
<div> | ||
<div id="x"></div> | ||
<span id="inner">The background color should be lime</span> | ||
</div> | ||
</div> | ||
<script> | ||
inner.offsetTop; | ||
inner.innerHTML = "מקור השם עברית"; | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>CSS Selectors Level 4 Test: exception handling for an invalid identifier of dir()</title> | ||
<link rel="author" title="Miyoung Shin" href="mailto:myid.shin@igalia.com"> | ||
<link rel="help" href="http://www.w3.org/TR/selectors4/#dir-pseudo"> | ||
<link rel="match" href="../reference/ref-filled-green-100px-square.xht"> | ||
<meta name="flags" content=""> | ||
<meta name="assert" content="The invalid identifier of :dir(ltrr) pseudo-class doesn't match an element that has a directionality of (ltr). Even if the div element has dir=ltr, the selector should not match."> | ||
<style type="text/css"> | ||
div { | ||
width: 100px; | ||
height: 100px; | ||
background-color: green; | ||
} | ||
|
||
div:dir(ltrr) { | ||
background-color: red; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p> | ||
<div dir="ltr"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>CSS Selectors Level 4 Test: exception handling for multiple identifiers of dir() </title> | ||
<link rel="author" title="Miyoung Shin" href="mailto:myid.shin@igalia.com"> | ||
<link rel="help" href="http://www.w3.org/TR/selectors4/#dir-pseudo"> | ||
<link rel="match" href="../reference/ref-filled-green-100px-square.xht"> | ||
<meta name="flags" content=""> | ||
<meta name="assert" content="The multiple identifiers of :dir(ltr, rtl) pseudo-class don't match an element that has a directionality of (ltr). Even if the div element has dir=ltr, the selector should not match."> | ||
<style type="text/css"> | ||
div { | ||
width: 100px; | ||
height: 100px; | ||
background-color: green; | ||
} | ||
|
||
div:dir(ltr, rtl) { | ||
background-color: red; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p> | ||
<div dir="ltr"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<link rel="help" href="http://www.w3.org/TR/selectors4/#dir-pseudo"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
|
||
<body> | ||
<div id=outer> | ||
<div id=div1></div> | ||
<div id=div2 dir=ltr> | ||
<div id=div2_1></div> | ||
<div id=div2_2 dir=ltr></div> | ||
<div id=div2_3 dir=rtl></div> | ||
</div> | ||
<div id=div3 dir=rtl> | ||
<div id=div3_1> | ||
<div id=div3_1_1></div> | ||
</div> | ||
<div id=div3_2 dir=ltr></div> | ||
<div id=div3_3 dir=rtl></div> | ||
</div> | ||
<div id=div4 dir=lol></div> | ||
<div id=div5 dir=auto></div> | ||
</div> | ||
</body> | ||
|
||
<script> | ||
test(() => { | ||
assert_equals(document.querySelector(":dir(lol)"), null); | ||
assert_equals(document.querySelector(":dir(lol )"), null); | ||
assert_equals(document.querySelector(":dir( auto)"), null); | ||
assert_equals(document.querySelector(":dir(\nauto\t)"), null); | ||
}, ":dir() allows any ident value but strings other than ltr/rtl don't match"); | ||
|
||
test(() => { | ||
assert_throws_dom("SYNTAX_ERR", () => { document.querySelector(":dir()"); }); | ||
assert_throws_dom("SYNTAX_ERR", () => { document.querySelector(":dir(ltr, rtl)"); }); | ||
assert_throws_dom("SYNTAX_ERR", () => { document.querySelector(":dir('ltr')"); }); | ||
}, ":dir() requires exactly an ident argument"); | ||
|
||
test(() => { | ||
assert_equals(document.querySelector(":dir(rtl)"), div2_3); | ||
assert_equals(document.querySelector("*:dir(rtl)"), div2_3); | ||
assert_equals(document.querySelector("div:dir(ltr)"), outer); | ||
assert_equals(document.querySelector("div:dir(ltr):dir(ltr)"), outer); | ||
assert_equals(document.querySelector(":dir(rtl)#div3_3"), div3_3); | ||
assert_equals(document.querySelector(":nth-child(2):dir(rtl)"), null); | ||
assert_equals(document.querySelector(":nth-child(3):dir(rtl)"), div2_3); | ||
assert_equals(document.querySelector(":nth-child(4):dir(ltr)"), div4); | ||
assert_equals(document.querySelector(":nth-last-child(3):dir(rtl)"), div3); | ||
}, ":dir() works in compound selectors"); | ||
|
||
test(() => { | ||
assert_equals(document.querySelector("#div2 :dir(ltr)"), div2_1); | ||
assert_equals(document.querySelector(":dir(rtl) div"), div3_1); | ||
assert_equals(document.querySelector("div + :dir(ltr)"), div2); | ||
assert_equals(document.querySelector(":dir(ltr) + :dir(rtl)"), div2_3); | ||
assert_equals(document.querySelector(":dir(rtl) :dir(rtl)"), div3_1); | ||
assert_equals(document.querySelector(":dir(rtl) + :dir(ltr)"), div3_2); | ||
assert_equals(document.querySelector(":dir(rtl) ~ :dir(rtl)"), div3_3); | ||
assert_equals(document.querySelector(":dir(rtl) :dir(ltr)"), div3_2); | ||
assert_equals(document.querySelector("* :dir(rtl) *"), div3_1); | ||
assert_equals(document.querySelector("div :dir(rtl) div"), div3_1); | ||
assert_equals(document.querySelector(":dir(ltr) :dir(rtl) + :dir(ltr)"), div3_2); | ||
assert_equals(document.querySelector(":dir(ltr) + :dir(rtl) + * + *"), div5); | ||
assert_equals(document.querySelector(":dir(rtl) > * > :dir(rtl)"), div3_1_1); | ||
}, ":dir() works in complex selectors"); | ||
</script> | ||
</html> |
18 changes: 18 additions & 0 deletions
18
css/selectors/selectors-dir-selector-white-space-001-ref.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style type="text/css"> | ||
div { | ||
width: 100px; | ||
height: 100px; | ||
background-color: green; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
</body> | ||
</html> |
Oops, something went wrong.