Bug 1762653 - Expose EventStateManager::IsKeyboardEventUserActivity on nsIDOMWindowUtils. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D142728
This commit is contained in:
Mike Conley 2022-04-04 13:33:35 +00:00
parent efecaff737
commit dd9df31950
4 changed files with 32 additions and 7 deletions

View File

@ -26,6 +26,7 @@
#include "mozilla/dom/Event.h"
#include "mozilla/dom/Touch.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/PendingAnimationTracker.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/SharedStyleSheetCache.h"
@ -4052,6 +4053,19 @@ nsDOMWindowUtils::SetHandlingUserInput(bool aHandlingUserInput,
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::IsKeyboardEventUserActivity(Event* aEvent, bool* aResult) {
NS_ENSURE_STATE(aEvent);
if (!aEvent->AsKeyboardEvent()) {
return NS_ERROR_INVALID_ARG;
}
WidgetEvent* internalEvent = aEvent->WidgetEventPtr();
NS_ENSURE_STATE(internalEvent);
*aResult = EventStateManager::IsKeyboardEventUserActivity(internalEvent);
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetContentAPZTestData(
JSContext* aContext, JS::MutableHandleValue aOutContentTestData) {

View File

@ -430,12 +430,14 @@ static bool IsMessageGamepadUserActivity(EventMessage aMessage) {
aMessage == eGamepadAxisMove;
}
// We ignore things that shouldn't cause popups, but also things that look
// like shortcut presses. In some obscure cases these may actually be
// website input, but any meaningful website will have other input anyway,
// and we can't very well tell whether shortcut input was supposed to be
// directed at chrome or the document.
static bool IsKeyboardEventUserActivity(WidgetEvent* aEvent) {
// static
bool EventStateManager::IsKeyboardEventUserActivity(WidgetEvent* aEvent) {
// We ignore things that shouldn't cause popups, but also things that look
// like shortcut presses. In some obscure cases these may actually be
// website input, but any meaningful website will have other input anyway,
// and we can't very well tell whether shortcut input was supposed to be
// directed at chrome or the document.
WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
// Access keys should be treated as page interaction.
if (keyEvent->ModifiersMatchWithAccessKey(AccessKeyType::eContent)) {
@ -491,7 +493,7 @@ static void OnTypingInteractionEnded() {
}
static void HandleKeyUpInteraction(WidgetKeyboardEvent* aKeyEvent) {
if (IsKeyboardEventUserActivity(aKeyEvent)) {
if (EventStateManager::IsKeyboardEventUserActivity(aKeyEvent)) {
TimeStamp now = TimeStamp::Now();
if (gTypingEndTime.IsNull()) {
gTypingEndTime = now;

View File

@ -191,6 +191,8 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
*/
void TryToFlushPendingNotificationsToIME();
static bool IsKeyboardEventUserActivity(WidgetEvent* aEvent);
/**
* Register accesskey on the given element. When accesskey is activated then
* the element will be notified via Element::PerformAccesskey() method.

View File

@ -1930,6 +1930,13 @@ interface nsIDOMWindowUtils : nsISupports {
*/
nsIJSRAIIHelper setHandlingUserInput(in boolean aHandlingInput);
/**
* Returns true if a keyboard event qualifies as "user activity" such that
* it would mark the document with the ChromeOnly userHasInteracted
* property.
*/
bool isKeyboardEventUserActivity(in Event aKeyboardEvent);
/**
* Get the content- and compositor-side APZ test data instances.
* The return values are of type APZTestData (see APZTestData.webidl).