Skip to content

Commit

Permalink
Don't trigger :focus-visible matching if a meta-key was pressed.
Browse files Browse the repository at this point in the history
Also, move UpdateHadKeyboardEvent() call into KeyboardEventManager::KeyEvent().

Happy to revert the latter change if folks don't like it, but it seemed logically consistent with e.g. gesture detection.

Bug: 920458
Change-Id: Ia423a0533325314ae4f83e619337b5a81af0f4c4
  • Loading branch information
Alice Boxhall authored and chromium-wpt-export-bot committed Oct 24, 2019
1 parent e68120d commit 718277d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
Expand Up @@ -29,16 +29,21 @@
<button id="button">Tab to me and press ENTER.</button>
<div id="el" tabindex="-1">I will be focused programmatically.</el>
<script>
button.addEventListener("click", () => {
el.focus();
});
if ("async_test" in window) {
async_test(function(t) {
button.addEventListener("click", t.step_func(() => {
el.focus();
}));
el.addEventListener("focus", t.step_func(function() {
assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)");
t.done();
}));
el.focus();
}, "Programmatic focus after keypress should match :focus-visible");
} else {
button.addEventListener("click", () => {
el.focus();
});
}
</script>
</body>
</html>
10 changes: 5 additions & 5 deletions css/selectors/focus-visible-009.html
Expand Up @@ -9,17 +9,17 @@
<script src="/resources/testharnessreport.js"></script>
<style>
:focus-visible {
outline: darkgreen auto 5px;
background-color: tomato;;
outline-color: tomato;
}

#button:focus:not(:focus-visible) {
background-color: tomato;;
outline: 0;
outline: darkgreen auto 5px;
}
</style>
</head>
<body>
This test checks that any element focused via an <code>autofocus</code> attribute will have <code>:focus-visible</code> matching enabled.
This test checks that any element focused via an <code>autofocus</code> attribute will not have <code>:focus-visible</code> matching enabled.
<ul id="instructions">
<li>If the button that says "I will be focused automatically" has a red background, then the test result is FAILURE. If it has a green outline, then the test result is SUCCESS.</li>
</ul>
Expand All @@ -38,7 +38,7 @@
t.done();
}

}, "Autofocus should match :focus-visible");
}, "Autofocus should not match :focus-visible");
</script>
</body>
</html>
8 changes: 4 additions & 4 deletions css/selectors/focus-visible-010.html
Expand Up @@ -9,12 +9,12 @@
<script src="/resources/testharnessreport.js"></script>
<style>
:focus-visible {
outline: darkgreen auto 5px;
background-color: tomato;
outline-color: tomato;
}

:focus:not(:focus-visible) {
background-color: tomato;
outline: 0;
outline: darkgreen auto 5px;
}
</style>
</head>
Expand All @@ -35,7 +35,7 @@
assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)");
t.done();
}));
}, "Programmatic focus on page load bshould match :focus-visible");
}, "Programmatic focus on page load should not match :focus-visible");
</script>
</body>
</html>
51 changes: 51 additions & 0 deletions css/selectors/focus-visible-012-manual.html
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CSS Test (Selectors): Keyboard shortcut combinations do not trigger :focus-visible</title>
<link rel="author" title="Alice Boxhall" href="aboxhall@chromium.org" />
<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
:focus-visible {
outline: 0;
outline-color: tomato;
background-color: tomato;
}

:focus:not(:focus-visible) {
outline: darkgreen dotted 1px; /* fallback for Edge */
outline: darkgreen auto 5px;
}
</style>
</head>
<body>
This test checks that using keyboard combinations with [Ctrl], [Alt] or [Cmd]
do not trigger <code>:focus-visible</code> matching.
<ol id="instructions">
<li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li>
<li>Click the element below that says "Click me, then use a keyboard shortcut."</li>
<li>Press a keyboard combination including [Ctrl], [Alt] or [Cmd], such as <code>Ctrl</code> + <code>y</code></li>
<li>If the element has a red background, then the test result is FAILURE. If the element has a green outline, then the test result is SUCCESS.</li>
</ol>
<br>
<div id="el" tabindex="0">Click me, then use a keyboard shortcut.</div>
<script>
async_test(function(t) {
el.addEventListener("focus", t.step_func(function(e) {
assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)", "after focus()");
}));
el.addEventListener("keydown", t.step_func(function(e) {
if (e.altKey || e.ctrlKey || e.metaKey) {
assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)", "after kb event");
t.done();
return;
}
assert_true(false, "No modifier key");
t.done();
}));
}, "Keyboard focus should match :focus-visible");
</script>
</body>
</html>

0 comments on commit 718277d

Please sign in to comment.