W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2014

Re: [whatwg] Document.activeElement should return the root element in non-HTML documents when no element has focus

From: Ian Hickson <ian@hixie.ch>
Date: Mon, 3 Feb 2014 19:42:33 +0000 (UTC)
To: Anne van Kesteren <annevk@annevk.nl>, Boris Zbarsky <bzbarsky@MIT.EDU>, Simon Pieters <simonp@opera.com>
Message-ID: <alpine.DEB.2.00.1402031939280.30855@ps20323.dreamhostps.com>
Cc: Cameron McCormack <cam@mcc.id.au>, whatwg@lists.whatwg.org, WHATWG <whatwg@whatwg.org>
On Mon, 3 Feb 2014, Anne van Kesteren wrote:
> On Mon, Feb 3, 2014 at 3:34 AM, Cameron McCormack <cam@mcc.id.au> wrote:
> > When the document isn't an HTML document and when there is no element 
> > with focus.  Browsers agree on returning null in an HTML document when 
> > there is no element with focus, no <body> element, but still a 
> > document element.

That case is obscure, though (I mean, it can only happen if you literally 
replace the <body> or <frameset> element with something else, like a 
<div>... and while I acknowledge that the Web is a wild, wild place, I 
doubt there are many pages that actually do that and, on top of that, 
depend on activeElement returning null).

It seems simpler to just try to use "the body element" (as defined in the 
HTML spec, it's not a <body> necessarily), and if that fails, use the root 
if there is one or null otherwise.


On Mon, 3 Feb 2014, Boris Zbarsky wrote:
>
> What Gecko does is that if the document is an HTMLDocument (so is 
> text/html or application/xhtml+xml) and hence has a .body property we 
> use that.  Otherwise we use .documentElement.
> 
> Of course the spec has no concept of HTMLDocument and has a .body on all 
> documents...

Yeah, that would hurt the ability to use HTML from other namespaces (since 
the HTML helper stuff on the Document would be missing).

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Monday, 3 February 2014 19:42:56 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:15 UTC