Re: [css3-selectors] Elements that can have :focus pseudo-class

Brad Kemper wrote:
> I think there is no WINDOW element in HTML or CSS where I can specify 
> (in HTML or CSS) what should happens in response to the window gaining 
> focus.

That's correct.

> HTML solves this by allowing the onfocus handler to be attached 
> to the BODY tag, which seems like a sensible, intuitive place to put it.

No, browsers solve this problem by mapping <body> event handlers to 
Window.  HTML says nothing about the matter.

> So, is there some other abstraction of a screen region that does 
> represent the window or viewport, in which the :focus pseudo-class can 
> be used

No, there is not.

>>> With this, the background-color of the body will turn green when it 
>>> comes into focus
>>
>> No, it'll turn green when the window comes into focus.
> 
> It seems to me that you are spitting hairs that JavaScript and HTML do 
> not split.

Sure they do.  Did you try my suggestion of attaching event handlers 
using addEventListener?

> It is useful in JavaScript to have the event listening attributes on the BODY tag

It's "useful" in the sense that it predates the existence of 
addEventListener.

> since there is no WINDOW element to use with selectors.

I don't see what this has to do with JavaScript.

> So why would you think it would be less desirable to have the 
> :focus pseudo-element work in a consistent manner?

Did I ever say that?  Please read what I _did_ say again, carefully.

> Is there another way of doing this that will select the focused viewport?

There is not, but perhaps there should be.

> What would then? A reference to the event handlers as they are expressed 
> as attributes in HTML?

Some way of matching particular nodes in a window that is focused sounds 
like what you want.  I see no problem with this in principle.

> And there is no mousedown event for the window itself that can be set as 
> an attribute.

There seems to be massive terminology confusion here.  In an effort to 
cover all bases:

1)  There is no way to set HTML attributes on the window.
2)  There is a way to set JS properties (also known as DOM attributes)
     on the window; this can be done programmatically.
3)  There is a way to add event listeners to the window using
     addEventListener.
4)  There is a way to add event listeners to the window by setting on*
     JS properties on the window.
5)  As a matter of backwards compatibility, on* HTML attributes on
     the body in many cases set on* JS properties on the window.

In particular, <body onmousedown="..."> will actually add a mousedown 
handler to the window in some browsers; this can be trivially tested by 
creating a page for which the <body> is smaller than the viewport.

> I prefer a way of correcting it that is similar to the 
> way it was dealt with in HTML (pretending that the BODY is the WINDOW, 
> for certain things)

And I see no reason to perpetuate this hack into realms where it's not 
strictly needed for compat with existing content, I guess.  I'm also 
somewhat interested in non-HTML languages (SVG comes to mind) benefiting 
from whatever happens here.

-Boris

Received on Sunday, 16 November 2008 20:35:30 UTC