Skip to content

Commit 2e65dbf

Browse files
josepharharChromium LUCI CQ
authored andcommitted
Update CommandEvent/ToggleEvent retargeting logic
Apparently the original implementation could leak nodes out of the shadowroot due to a misreading of the spec: whatwg/html#11345 (review) This patch makes the new retargeting logic use currentTarget, and if currentTarget is null, then null is returned instead of returning the original node. Bug: 420639769 Change-Id: Ib5e580f83e68aa58ca5b9e8f024391e0191cb604 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6853807 Commit-Queue: Joey Arhar <[email protected]> Reviewed-by: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1509850}
1 parent 1999c22 commit 2e65dbf

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

third_party/blink/renderer/core/dom/events/event.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,18 @@ void Event::SetRelatedTargetIfExists(EventTarget* related_target) {
285285

286286
void Event::ReceivedTarget() {}
287287

288-
Element* Event::Retarget(const Element* element) const {
288+
Element* Event::Retarget(Element* element) const {
289289
CHECK(RuntimeEnabledFeatures::ImprovedSourceRetargetingEnabled());
290-
EventTarget* retarget_against = currentTarget() ? currentTarget() : target();
291-
if (element && retarget_against && retarget_against->ToNode()) {
292-
return &retarget_against->ToNode()->GetTreeScope().Retarget(*element);
290+
if (!element) {
291+
return nullptr;
292+
}
293+
if (EventTarget* current_target = currentTarget()) {
294+
if (auto* current_target_node = current_target->ToNode()) {
295+
return &current_target_node->GetTreeScope().Retarget(*element);
296+
}
293297
}
294-
return nullptr;
298+
// retarget against the topmost TreeScope if there isn't a current target.
299+
return &element->GetDocument().Retarget(*element);
295300
}
296301

297302
void Event::SetUnderlyingEvent(const Event* ue) {

third_party/blink/renderer/core/dom/events/event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class CORE_EXPORT Event : public ScriptWrappable {
344344
// retargeted against currentTarget(). Otherwise, it is retargeted against
345345
// target(). target() may be null after event dispatch to prevent leaking,
346346
// and in that case, this method will return null as well.
347-
Element* Retarget(const Element* element) const;
347+
Element* Retarget(Element* element) const;
348348

349349
private:
350350
AtomicString type_;

third_party/blink/web_tests/external/wpt/html/semantics/the-button-element/command-and-commandfor/event-interface-expected.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)