Bug 125393 - Don't dispatch blur/focus events if the element's page is not focused
Summary: Don't dispatch blur/focus events if the element's page is not focused
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BlinkMergeCandidate, InRadar
Depends on:
Blocks:
 
Reported: 2013-12-07 12:17 PST by Ryosuke Niwa
Modified: 2022-09-29 10:42 PDT (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2013-12-07 12:17:46 PST
Consider merging https://chromium.googlesource.com/chromium/blink/+/60ed87d48e7c337cada58f2ae25da4d9eb426207

When the page loses focus a blur event is dispatched once, prevent a second dispatch (via e.g. programmatic blur()-ing), when a page doesn't have focus, prevent a focus event dispatch (via e.g. programmatic focus()-ing), as it will receive a focus event when the page regains focus.
Comment 1 Ryosuke Niwa 2013-12-07 12:20:40 PST
Got reverted in http://src.chromium.org/viewvc/blink?view=revision&revision=160140.

But the concept of the change seems correct.

Also see https://code.google.com/p/chromium/issues/detail?id=276757
Comment 2 Ahmad Saleem 2022-08-22 16:15:58 PDT
It landed in this commit:

https://src.chromium.org/viewvc/blink?view=revision&revision=164069

I took a test case from the above and changed it into JSFiddle:

https://jsfiddle.net/8ueL62kx/

*** Firefox Nightly 105 ***

Load test, it would be focused in input field but no event is fired and then click any where besides "input" field, it will fire "blur" event.

*** Chrome Canary 106 ***

Load test, it would be focused in input field but no event is fired and then click any where besides "input" field, it will fire "blurfocus" event.

*** Safari Technology Preview 151 ***

Load test, it would be focused in input field but no event is fired and then click any where besides "input" field, it will fire "blurfocus" event.

_______

I am not sure on web-spec or whether something else is required but just going to share what I tested or observed. Thanks!
Comment 3 Radar WebKit Bug Importer 2022-08-23 12:25:26 PDT
<rdar://problem/99045743>
Comment 4 Ahmad Saleem 2022-09-29 10:42:47 PDT
I tried to land this change in following PR based Comment 03 - commit of Chromium:

Link - https://github.com/WebKit/WebKit/pull/4774

and these are learnings:

1) Fixing Developer Tools test case is easy and can be followed from Chromium patch without any issue.

2) Someone need to update "TestRunner" - testRunner.focusWebView part to accommodate this change to ensure that the focus work properly since it leads to 77 API failures on iOS:

https://ews-build.webkit.org/#/builders/9/builds/81789

____

Since it is beyond my capability to update (2), I will leave it for someone else to fix this bug but will document my attempt for others. Thanks!