[whatwg] activeElement

Ian Hickson ian at hixie.ch
Mon Jun 4 21:15:34 PDT 2007


On Thu, 17 May 2007, Hallvord R M Steen wrote:
>
> if WHATWG is defining document.activeElement, perhaps the WHAT spec 
> should match IE's behaviour more closely on some points. I refer to: 
> http://www.whatwg.org/specs/web-apps/current-work/#activeelement
> 
> * when the document is loaded, before any interaction activeElement is 
> the body element (!) (probably not important, I doubt any site would 
> rely on this)

I've made the default the <body> element instead of the root element, 
which does indeed seem to more accurately reflect IE's behaviour.


> * activeElement is set after mousedown. (important, maybe implied by 
> other stuff about focus handling? I didn't test keydown for e.g. tabbing 
> but pretty sure the same applies.)

This flows from the fact that that's when focus is set. It would vary on a 
platform with different focusing semantics.


> * it is set to the event's target if it is "focusable" (A, INPUT, BUTTON 
> etc.), otherwise it is set to the event's target's .offsetParent 
> (important, and the offsetParent stuff isn't covered in the current 
> spec)

I couldn't reproduce this. In my testing, only positioned <div> and <span> 
elements were magical in this way.

For example, click the "uuu" text on this test case and you'll see the 
offsetParent (written to the log) is the B element, but the activeElement 
is the DIV element.

   http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cbody%20onclick%3D%22w%28event.srcElement.offsetParent.tagName%29%22%3E%0D%0A%3Cpre%3E%28...%29%3C/pre%3E%0D%0A%3Cdiv%20style%3D%22position%3Aabsolute%22%3Eddd%3Ci%3Eiii%3Cb%20style%3D%22position%3Aabsolute%22%3Ebbb%3Cu%3Euuu%3Cinput%3E%3C/u%3E%3C/b%3E%3C/i%3E%3C/div%3E%0D%0A%3Cscript%3E%0D%0A%20setInterval%28function%20%28%29%20%7B%0D%0A%20%20%20var%20pre%20%3D%20document.getElementsByTagName%28%27pre%27%29%5B0%5D%3B%0D%0A%20%20%20pre.firstChild.data%20%3D%20document.activeElement.tagName%3B%0D%0A%20%7D%2C%20100%29%3B%0D%0A%3C/script%3E

I haven't made the spec let positioned <div> and <span> elements get 
focused in this way, because whether an element is positioned or not 
should have no bearing on the semantics of the document.


> * it keeps pointing to the same element until another interaction with 
> the document sets it again (important)

That's already in the spec.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list