Bug 1795620 - Make it work better to activate/inactivate checkboxes and radio buttons like the other browsers r=smaug
First, the test compares `document.querySelector(":active")` and a checkbox or
a radio button. However, Gecko activates ancestor elements too. Therefore,
Gecko returns `<html>` element or `null` for the selector. However, this is
an issue of CSS pseudo class compatibility which is **not** scope of the test.
Therefore, this patch makes it compare `document.querySelector("input:active")`
and a checkbox or a radio button instead.
Next, Gecko does not activate checkboxes and radio buttons when user presses
the space key, but the other browsers do it. Therefore, this patch makes
`HTMLInputElement::PostHandleEvent` do it and
`EventStateManager::PostHandleEvent` clear it at `keyup` of the space key.
Next, Gecko does not inactive active elements when it gets lost focus.
Therefore, this patch makes `nsFocusManager::NotifyFocusStateChange` do it
like the other browsers.
Finally, with manual testing of draft patches, I found some issues of
inactivating them when they are activated by `<label>`s. Therefore, I add new
tests in a separate file. Note that Chrome fails only in the cases testing
`<input type="radio">` with `<label>`.
Differential Revision: https://phabricator.services.mozilla.com/D160494
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "mozilla/dom/MutationEventBinding.h"
|
||||
#include "mozilla/dom/WheelEventBinding.h"
|
||||
#include "mozilla/dom/WindowGlobalChild.h"
|
||||
#include "mozilla/EventStateManager.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
@@ -3737,6 +3738,22 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case eKeyDown: {
|
||||
// For compatibility with the other browsers, we should active this
|
||||
// element at least when a checkbox or a radio button.
|
||||
// TODO: Investigate which elements are activated by space key in the
|
||||
// other browsers.
|
||||
if (aVisitor.mPresContext && keyEvent->IsTrusted() && !IsDisabled() &&
|
||||
keyEvent->ShouldWorkAsSpaceKey() &&
|
||||
(mType == FormControlType::InputCheckbox ||
|
||||
mType == FormControlType::InputRadio)) {
|
||||
EventStateManager::SetActiveManager(
|
||||
aVisitor.mPresContext->EventStateManager(), this);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case eKeyPress: {
|
||||
if (mType == FormControlType::InputRadio && keyEvent->IsTrusted() &&
|
||||
!keyEvent->IsAlt() && !keyEvent->IsControl() &&
|
||||
|
||||
Reference in New Issue
Block a user