Skip to content

Commit

Permalink
Bug 1873330 - Part 3: Store modifiers for user activation with input …
Browse files Browse the repository at this point in the history
…event. r=smaug

Depends on D197860

Differential Revision: https://phabricator.services.mozilla.com/D197861
  • Loading branch information
arai-a committed Jan 11, 2024
1 parent aeb2eac commit 1eb9eb9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
5 changes: 4 additions & 1 deletion docshell/base/WindowContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,12 @@ void WindowContext::AddSecurityState(uint32_t aStateFlags) {
}
}

void WindowContext::NotifyUserGestureActivation() {
void WindowContext::NotifyUserGestureActivation(
UserActivation::Modifiers
aModifiers /* = UserActivation::Modifiers::None() */) {
UserActivation::StateAndModifiers stateAndModifiers;
stateAndModifiers.SetState(UserActivation::State::FullActivated);
stateAndModifiers.SetModifiers(aModifiers);
Unused << SetUserActivationStateAndModifiers(stateAndModifiers.GetRawData());
}

Expand Down
3 changes: 2 additions & 1 deletion docshell/base/WindowContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class WindowContext : public nsISupports, public nsWrapperCache {

// This function would be called when its corresponding window is activated
// by user gesture.
void NotifyUserGestureActivation();
void NotifyUserGestureActivation(
UserActivation::Modifiers aModifiers = UserActivation::Modifiers::None());

// This function would be called when we want to reset the user gesture
// activation flag.
Expand Down
10 changes: 6 additions & 4 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16756,7 +16756,9 @@ BrowsingContext* Document::GetBrowsingContext() const {
: nullptr;
}

void Document::NotifyUserGestureActivation() {
void Document::NotifyUserGestureActivation(
UserActivation::Modifiers
aModifiers /* = UserActivation::Modifiers::None() */) {
// https://html.spec.whatwg.org/multipage/interaction.html#activation-notification
// 1. "Assert: document is fully active."
RefPtr<BrowsingContext> currentBC = GetBrowsingContext();
Expand All @@ -16772,12 +16774,12 @@ void Document::NotifyUserGestureActivation() {
// 2. "Let windows be « document's relevant global object"
// Instead of assembling a list, we just call notify for wanted windows as we
// find them
currentWC->NotifyUserGestureActivation();
currentWC->NotifyUserGestureActivation(aModifiers);

// 3. "...windows with the active window of each of document's ancestor
// navigables."
for (WindowContext* wc = currentWC; wc; wc = wc->GetParentWindowContext()) {
wc->NotifyUserGestureActivation();
wc->NotifyUserGestureActivation(aModifiers);
}

// 4. "windows with the active window of each of document's descendant
Expand All @@ -16795,7 +16797,7 @@ void Document::NotifyUserGestureActivation() {
return;
}

wc->NotifyUserGestureActivation();
wc->NotifyUserGestureActivation(aModifiers);
});
}

Expand Down
4 changes: 3 additions & 1 deletion dom/base/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "mozilla/dom/TreeOrderedArray.h"
#include "mozilla/dom/ViewportMetaData.h"
#include "mozilla/dom/LargestContentfulPaint.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/WakeLockBinding.h"
#include "mozilla/glean/GleanMetrics.h"
#include "nsAtom.h"
Expand Down Expand Up @@ -3642,7 +3643,8 @@ class Document : public nsINode,
// keyboard shortcuts, etc). This is used to decide whether we should
// permit autoplay audible media. This also gesture activates all other
// content documents in this tab.
void NotifyUserGestureActivation();
void NotifyUserGestureActivation(
UserActivation::Modifiers aModifiers = UserActivation::Modifiers::None());

// This function is used for mochitest only.
void ClearUserGestureActivation();
Expand Down
17 changes: 16 additions & 1 deletion dom/events/EventStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,22 @@ void EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,

MOZ_ASSERT(aEvent->mMessage == eKeyDown || aEvent->mMessage == eMouseDown ||
aEvent->mMessage == ePointerDown || aEvent->mMessage == eTouchEnd);
doc->NotifyUserGestureActivation();
UserActivation::Modifiers modifiers;
if (WidgetInputEvent* inputEvent = aEvent->AsInputEvent()) {
if (inputEvent->IsShift()) {
modifiers.SetShift();
}
if (inputEvent->IsMeta()) {
modifiers.SetMeta();
}
if (inputEvent->IsControl()) {
modifiers.SetControl();
}
if (inputEvent->IsAlt()) {
modifiers.SetAlt();
}
}
doc->NotifyUserGestureActivation(modifiers);
}

// https://html.spec.whatwg.org/multipage/popover.html#popover-light-dismiss
Expand Down

0 comments on commit 1eb9eb9

Please sign in to comment.