New issue
Advanced search Search tips

Issue 654908 link

Starred by 3 users

Issue metadata

Status: Duplicate
Merged: issue 364966
Owner: ----
Closed: Feb 2018
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

document.hasFocus() returns false inside onfocus event on Windows

Reported by mathieu....@gmail.com, Oct 11 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.41 Safari/537.36

Steps to reproduce the problem:
1. Open test page or https://jsfiddle.net/j7ugz61f/2/ on Windows
2. focus in the page (or frame if fiddle)
3. click on desktop, or another window / tab. Observe correct hasFocus=false inside blur event
4. click back into the page. Observe incorrect hasFocus=false inside focus event

What is the expected behavior?
The hasFocus() method should always return the current state of the focus. 
Since a focus event is dispatched at the end of the focus update steps (https://html.spec.whatwg.org/multipage/interaction.html#focus-update-steps), the value of hasFocus() should be correct inside a focus event handler.

What went wrong?
On Windows, often (not always), the hasFocus() method returns false inside the onfocus event handler.
In the next turn of the run-loop, the hasFocus() method correctly returns true.
Sometimes, the hasFocus() will correctly return true on Windows, which makes it feel like a race condition somewhere.

hasFocus will often (always?) return true if the window loses and regains focus inside a single alt-tab press (press and hold alt, press tab, press shift + tab, release alt).

This issue does not occur on Mac.

Did this work before? N/A 

Does this work in other browsers? Yes

Chrome version: 54.0.2840.41  Channel: beta
OS Version: 10.0
Flash Version: Shockwave Flash 23.0 r0
 
focus.html
1.1 KB View Download

Comment 1 by kochi@chromium.org, Oct 18 2016

Status: Available (was: Unconfirmed)
This might be same as  issue 364966 , but this is different for Win and Mac,
probably a separate issue, but at least I think related.


Components: Blink>HTML>Focus
Components: -Blink>Focus

Comment 4 by r...@igalia.com, Feb 7 2018

Mergedinto: 364966
Status: Duplicate (was: Available)
I've been investigating this problem, and I have a patch that fixes it and also   issue #364966 , so I'm merging both.

The CL: https://chromium-review.googlesource.com/c/chromium/src/+/906528
Project Member

Comment 5 by bugdroid1@chromium.org, Feb 8 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fb153490856d41a8f21272c210922b29bc647822

commit fb153490856d41a8f21272c210922b29bc647822
Author: Manuel Rego Casasnovas <rego@igalia.com>
Date: Thu Feb 08 05:31:30 2018

Fix document.hasFocus() when "focus" event is dispatched

There was an issue related to document.hasFocus() if you check it
when the "focus" element is dispatched, sometimes you get "false"
(mainly when you come from a different window or the omnibox).

The problem was that the method FocusController::IsDocumentFocused()
checks that the document is focused, but also that it's active.
Current implementations of WebWidget::SetFocus() were setting
the document as active after focusing it. So when the "focus" event
was fired, the document wasn't active yet and
the document.hasFocus() call returned "false".

The patch marks the document as active, before setting it as focused.
That way when the "focus" event is dispatched document.hasFocus()
always returns "true" as expected.

BUG= 364966 , 654908 
TEST=WebViewTest.DocumentHasFocus

Change-Id: I93a7e7fe8a9c0c8a108b4826cccc944e4514d0b4
Reviewed-on: https://chromium-review.googlesource.com/906528
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Manuel Rego Casasnovas <rego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#535312}
[modify] https://crrev.com/fb153490856d41a8f21272c210922b29bc647822/third_party/WebKit/Source/core/exported/WebPagePopupImpl.cpp
[modify] https://crrev.com/fb153490856d41a8f21272c210922b29bc647822/third_party/WebKit/Source/core/exported/WebViewImpl.cpp
[modify] https://crrev.com/fb153490856d41a8f21272c210922b29bc647822/third_party/WebKit/Source/core/exported/WebViewTest.cpp
[modify] https://crrev.com/fb153490856d41a8f21272c210922b29bc647822/third_party/WebKit/Source/core/frame/WebFrameWidgetImpl.cpp

Sign in to add a comment