Bug 119727
| Summary: | Do not dispatch 'focus' or 'blur' event twice when window active state is changed | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ryosuke Niwa <rniwa> |
| Component: | UI Events | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW | ||
| Severity: | Normal | CC: | ahmad.saleem792, ap, benjamin, darin, tkent |
| Priority: | P2 | Keywords: | BlinkMergeCandidate |
| Version: | 528+ (Nightly build) | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Ryosuke Niwa
* Bug
On Windows, 'focus' event for the window object or a focused element is
dispatched twice when the browser tab gets active, and 'blue' evnet is
dispatched twice when the browser tab gets inactive.
On OSX, 'blur' evnet is dispatched twice when the browser tab gets inactive.
On Android, we don't have this bug.
* Root cause
Focus/blue event is dispatched in dispatchEventsOnWindowAndFocusedNode
in these cases. FocusController::setFocused(bool) calls it, and
FocusController::setActive(bool) also calls it if setFocused(true) was
already called.
On Windows, these functions are called in the following sequence:
Activation:
WebView::setFocus(true)
FocusController::setFocused(true)
FocusController::setActive(true)
WebView::setIsActive(true)
Inactivation:
WebView::setIsActive(false)
FocusController::setActive(false)
WebView::setFocus(false)
FocusController::setFocused(false)
On OSX, these functions are called in the following sequence:
Activation:
WebView::setIsActive(true)
FocusController::setActive(true)
WebView::setFocus(true)
FocusController::setFocused(true)
FocusController::setActive(true)
Inactivation:
WebView::setIsActive(false)
FocusController::setActive(false)
WebView::setFocus(false)
FocusController::setFocused(false);
On Android, these functions are called in the following sequence:
Activation:
WebView::setFocus(true)
FocusController::setFocused(true)
FocusController::setActive(true)
Inactivation:
WebView::setFocus(false)
FocusController::setFocused(false);
* Fix
We don't need to call dispatchEventsOnWindowAndFocusedNode in
setActive() because we don't make a window focused state true when the
window is inactive.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Kent Tamura
AFAIK, Apple Mac port doesn't have this issue.
Test page: http://jsfiddle.net/FbzNA/
Ryosuke Niwa
(In reply to comment #1)
> AFAIK, Apple Mac port doesn't have this issue.
>
> Test page: http://jsfiddle.net/FbzNA/
Thanks for the info! We should probably add a test though.
Ahmad Saleem
(In reply to Ryosuke Niwa from comment #2)
> (In reply to comment #1)
> > AFAIK, Apple Mac port doesn't have this issue.
> >
> > Test page: http://jsfiddle.net/FbzNA/
>
> Thanks for the info! We should probably add a test though.
This commit does not have any test - https://src.chromium.org/viewvc/blink?view=revision&revision=155558
Do we require this at this point? Thanks!
Ahmad Saleem
(In reply to Ahmad Saleem from comment #3)
> (In reply to Ryosuke Niwa from comment #2)
> > (In reply to comment #1)
> > > AFAIK, Apple Mac port doesn't have this issue.
> > >
> > > Test page: http://jsfiddle.net/FbzNA/
> >
> > Thanks for the info! We should probably add a test though.
>
> This commit does not have any test -
> https://src.chromium.org/viewvc/blink?view=revision&revision=155558
>
> Do we require this at this point? Thanks!
It seems to be reproducible in macOS 12.6 using testcase mentioned on Comment 01:
*** Safari 16 ***
Thu Sep 29 2022 22:34:59 GMT+0100 (British Summer Time): window focus
Thu Sep 29 2022 22:35:01 GMT+0100 (British Summer Time): window blur
Thu Sep 29 2022 22:35:02 GMT+0100 (British Summer Time): window focus
Thu Sep 29 2022 22:35:02 GMT+0100 (British Summer Time): window focus
^ When you activate JSFiddle result window and then you switch to other tab and come back
*** Chrome Canary 108 ***
Thu Sep 29 2022 22:35:43 GMT+0100 (British Summer Time): window focus
Thu Sep 29 2022 22:35:45 GMT+0100 (British Summer Time): window blur
Thu Sep 29 2022 22:35:45 GMT+0100 (British Summer Time): window focus
*** Firefox Nightly 107 ***
Thu Sep 29 2022 22:36:17 GMT+0100 (British Summer Time): window focus
Thu Sep 29 2022 22:36:18 GMT+0100 (British Summer Time): window blur
Thu Sep 29 2022 22:36:19 GMT+0100 (British Summer Time): window focus
______
As can be seen "Safari" show "window focus" twice when activating tab again.
Ahmad Saleem
I tried to land this in following:
https://github.com/WebKit/WebKit/pull/4808
but it didn't compile and give quite a few errors, which I am not able to resolve. So appreciate if someone else can try. Thanks!