Mozilla doesn't implement document.hasFocus like IE

RESOLVED FIXED

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
13 years ago
10 years ago

People

(Reporter: jdperlow, Assigned: Peter Kasting)

Tracking

(Blocks: 1 bug)

Trunk
x86
Windows XP
Points:
---
Bug Flags:
blocking-aviary1.5 -

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: see also bug 296471)

Attachments

(2 attachments, 3 obsolete attachments)

(Reporter)

Description

13 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3

IE implements document.hasFocus which provides a reliable way to determine
whether any element in the browser window has focus. Mozilla should have this
too. Some browser applications will behave differently based on whether the page
has focus.

Reproducible: Always

Comment 1

13 years ago
I'm working on a new product that will have a lot of usage. This functionality
is essential to it working well. Would be very happy to see this in FF1.1 so
that the Firefox experience can be at least as good as the IE experience.
Flags: blocking-aviary1.1?
Created attachment 185720 [details]
HTML file using document.hasFocus

This was taken from
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/hasfocus.asp
which exemplifies the use of document.hasFocus. It works on IE but doesn't work
for me.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511
Firefox/1.0.4
Created attachment 185723 [details]
Workaround for missing hasFocus attribute

This is the same file with a very simple modification that replaces
document.hasFocus. Something a little more robust might be necessary for a
decent workaround, but this works.
(Reporter)

Comment 4

13 years ago
That workaround doesn't work if there are nested iframes in the page. If a
nested iframe has focus, the workaround doesn't return the right value. In IE,
document.hasFocus() returns true if anything nested in the document has focus,
including content inside iframes.

Updated

13 years ago
Flags: blocking-aviary1.1? → blocking-aviary1.1-
(Assignee)

Updated

12 years ago
Assignee: general → pkasting
Status: UNCONFIRMED → NEW
Ever confirmed: true
Whiteboard: see also bug 296471
(Assignee)

Comment 5

12 years ago
Created attachment 224139 [details] [diff] [review]
patch v1

This seems to do the right thing as far as I can tell.  Testcase files to be attached shortly.
Attachment #224139 - Flags: superreview?(bzbarsky)
Attachment #224139 - Flags: review?(bryner)
(Assignee)

Comment 6

12 years ago
Created attachment 224140 [details]
Testcases

Unzip this .tgz file somewhere.  test.html is a simple test based on the test already attached to this bug.  test1.html and test2.html are more complex tests that we get the proper behavior with nested iframes.

In all cases, mousing over the "mouse over me" text should display a message iff that document or any children have focus.
Attachment #185720 - Attachment is obsolete: true
Attachment #185723 - Attachment is obsolete: true
I'd really prefer that someone more familiar with focus than I looked at this... but in any case, you need to change the IID of the interface and please add at the end, not in the middle?
(Assignee)

Comment 8

12 years ago
OK, I can change it.  The reason I didn't change it was because the last couple of additions to that file hadn't changed it, but maybe I was looking in the wrong place or something.
(Assignee)

Comment 9

12 years ago
Created attachment 224142 [details] [diff] [review]
patch v2

Address bzbarsky's comments.
Attachment #224139 - Attachment is obsolete: true
Attachment #224142 - Flags: superreview?(bzbarsky)
Attachment #224142 - Flags: review?(bryner)
Attachment #224139 - Flags: superreview?(bzbarsky)
Attachment #224139 - Flags: review?(bryner)
(Assignee)

Comment 10

12 years ago
This patch is included (in a slightly modified form) inside the patch I just attached to bug 337631, with the same reviewers.
Blocks: 296471
Comment on attachment 224142 [details] [diff] [review]
patch v2

removing this review since the patch is folded into bug 337631
Attachment #224142 - Flags: review?(bryner)
(Assignee)

Comment 12

12 years ago
Comment on attachment 224142 [details] [diff] [review]
patch v2

In that case I'll remove the SR request as well.
Attachment #224142 - Flags: superreview?(bzbarsky)
(Assignee)

Comment 13

12 years ago
FIXED by the commit of bug 337631 to the trunk.
Status: NEW → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → FIXED

Updated

10 years ago
Component: DOM: Core → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.