Commit 92ac3c56 authored by Alice Boxhall's avatar Alice Boxhall Committed by Commit Bot

Don't trigger :focus-visible matching if a meta-key was pressed.

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
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1871715
Commit-Queue: Alice Boxhall <aboxhall@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709357}
parent a47f454a
...@@ -228,11 +228,6 @@ inline EventDispatchContinuation EventDispatcher::DispatchEventPreProcess( ...@@ -228,11 +228,6 @@ inline EventDispatchContinuation EventDispatcher::DispatchEventPreProcess(
activation_target->PreDispatchEventHandler(*event_); activation_target->PreDispatchEventHandler(*event_);
} }
// If this is a trusted keyboard event, update the keyboard event state and
// trigger :focus-visible matching if necessary.
if (event_->isTrusted() && event_->IsKeyboardEvent())
node_->UpdateHadKeyboardEvent(*event_);
return (event_->GetEventPath().IsEmpty() || event_->PropagationStopped()) return (event_->GetEventPath().IsEmpty() || event_->PropagationStopped())
? kDoneDispatching ? kDoneDispatching
: kContinueDispatching; : kContinueDispatching;
......
...@@ -273,6 +273,11 @@ WebInputEventResult KeyboardEventManager::KeyEvent( ...@@ -273,6 +273,11 @@ WebInputEventResult KeyboardEventManager::KeyEvent(
keydown->SetStopPropagation(!send_key_event); keydown->SetStopPropagation(!send_key_event);
// If this keydown did not involve a meta-key press, update the keyboard event
// state and trigger :focus-visible matching if necessary.
if (!keydown->ctrlKey() && !keydown->altKey() && !keydown->metaKey())
node->UpdateHadKeyboardEvent(*keydown);
DispatchEventResult dispatch_result = node->DispatchEvent(*keydown); DispatchEventResult dispatch_result = node->DispatchEvent(*keydown);
if (dispatch_result != DispatchEventResult::kNotCanceled) if (dispatch_result != DispatchEventResult::kNotCanceled)
return event_handling_util::ToWebInputEventResult(dispatch_result); return event_handling_util::ToWebInputEventResult(dispatch_result);
......
...@@ -29,16 +29,21 @@ ...@@ -29,16 +29,21 @@
<button id="button">Tab to me and press ENTER.</button> <button id="button">Tab to me and press ENTER.</button>
<div id="el" tabindex="-1">I will be focused programmatically.</el> <div id="el" tabindex="-1">I will be focused programmatically.</el>
<script> <script>
button.addEventListener("click", () => { if ("async_test" in window) {
el.focus();
});
async_test(function(t) { async_test(function(t) {
button.addEventListener("click", t.step_func(() => {
el.focus();
}));
el.addEventListener("focus", t.step_func(function() { el.addEventListener("focus", t.step_func(function() {
assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)"); assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)");
t.done(); t.done();
})); }));
el.focus();
}, "Programmatic focus after keypress should match :focus-visible"); }, "Programmatic focus after keypress should match :focus-visible");
} else {
button.addEventListener("click", () => {
el.focus();
});
}
</script> </script>
</body> </body>
</html> </html>
<!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>
var t = async_test( "Keyboard focus should match :focus-visible");
el.addEventListener("click", t.step_func(function(e) {
assert_equals(getComputedStyle(el).outlineColor, "rgb(0, 100, 0)", "after focus()");
}), true);
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();
}));
window.setTimeout(t.step_func_done(()=> {
assert_true(false, "timeout");
}), 1000);
</script>
</body>
</html>
importAutomationScript('/input-events/inputevent_common_input.js');
function inject_input() {
return keyDown("Tab").then(() => {
return keyDown("Enter");
});
};
function keyDown(key, modifiers) {
return new Promise(function(resolve, reject) {
if (window.eventSender) {
eventSender.keyDown(key, modifiers);
resolve();
} else {
reject();
}
});
}
const boundaryOffset = 2;
function mouseClickInTarget(targetSelector) {
var targetDocument = document;
var frameLeft = 0;
var frameTop = 0;
var button = 0;
return new Promise(function(resolve, reject) {
if (window.chrome && chrome.gpuBenchmarking) {
var target = targetDocument.querySelector(targetSelector);
var targetRect = target.getBoundingClientRect();
var xPosition = frameLeft + targetRect.left + boundaryOffset;
var yPosition = frameTop + targetRect.top + boundaryOffset;
chrome.gpuBenchmarking.pointerActionSequence(
[{
source: 'mouse',
actions: [
{name: 'pointerMove', x: xPosition, y: yPosition},
{name: 'pointerDown', x: xPosition, y: yPosition, button: button},
{name: 'pointerUp', button: button}
]
}],
resolve);
} else {
reject();
}
});
}
function inject_input() {
return mouseClickInTarget("#el").then(() => {
return keyDown("y", ["ctrlKey"]);
});
};
inject_input();
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment