Skip to content

Commit

Permalink
Bug 1819769 - don't dispatch a11y related events when there are no li…
Browse files Browse the repository at this point in the history
…steners, r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D175016
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Apr 11, 2023
1 parent c1ef50a commit de9de65
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ nsParser* nsContentUtils::sXMLFragmentParser = nullptr;
nsIFragmentContentSink* nsContentUtils::sXMLFragmentSink = nullptr;
bool nsContentUtils::sFragmentParsingActive = false;

bool nsContentUtils::sMayHaveFormCheckboxStateChangeListeners = false;
bool nsContentUtils::sMayHaveFormRadioStateChangeListeners = false;

mozilla::LazyLogModule nsContentUtils::gResistFingerprintingLog(
"nsResistFingerprinting");
mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump");
Expand Down
19 changes: 19 additions & 0 deletions dom/base/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3373,6 +3373,22 @@ class nsContentUtils {
*/
static void RequestGeckoTaskBurst();

static void SetMayHaveFormCheckboxStateChangeListeners() {
sMayHaveFormCheckboxStateChangeListeners = true;
}

static bool MayHaveFormCheckboxStateChangeListeners() {
return sMayHaveFormCheckboxStateChangeListeners;
}

static void SetMayHaveFormRadioStateChangeListeners() {
sMayHaveFormRadioStateChangeListeners = true;
}

static bool MayHaveFormRadioStateChangeListeners() {
return sMayHaveFormRadioStateChangeListeners;
}

private:
static bool InitializeEventTable();

Expand Down Expand Up @@ -3493,6 +3509,9 @@ class nsContentUtils {

static int32_t sInnerOrOuterWindowCount;
static uint32_t sInnerOrOuterWindowSerialCounter;

static bool sMayHaveFormCheckboxStateChangeListeners;
static bool sMayHaveFormRadioStateChangeListeners;
};

/* static */ inline ExtContentPolicyType
Expand Down
6 changes: 6 additions & 0 deletions dom/events/EventListenerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ void EventListenerManager::AddEventListenerInternal(
window->SetHasTransitionEventListeners();
}
break;
case eFormCheckboxStateChange:
nsContentUtils::SetMayHaveFormCheckboxStateChangeListeners();
break;
case eFormRadioStateChange:
nsContentUtils::SetMayHaveFormRadioStateChangeListeners();
break;
default:
// XXX Use NS_ASSERTION here to print resolvedEventMessage since
// MOZ_ASSERT can take only string literal, not pointer to
Expand Down
6 changes: 4 additions & 2 deletions dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3728,8 +3728,10 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
#ifdef ACCESSIBILITY
// Fire an event to notify accessibility
if (mType == FormControlType::InputCheckbox) {
FireEventForAccessibility(this, eFormCheckboxStateChange);
} else {
if (nsContentUtils::MayHaveFormCheckboxStateChangeListeners()) {
FireEventForAccessibility(this, eFormCheckboxStateChange);
}
} else if (nsContentUtils::MayHaveFormRadioStateChangeListeners()) {
FireEventForAccessibility(this, eFormRadioStateChange);
// Fire event for the previous selected radio.
nsCOMPtr<nsIContent> content = do_QueryInterface(aVisitor.mItemData);
Expand Down

0 comments on commit de9de65

Please sign in to comment.