Re: Selection of a document that doesn't have a window

On Thu, Jan 12, 2012 at 3:07 PM, Ojan Vafai <ojan@chromium.org> wrote:
> Can you do anything useful with a selection on a document that doesn't have
> a window? If so, the IE9 behavior makes sense. If not, I prefer the WebKit
> behavior.

Per spec, you can add any Range at all to a Selection, so you can
programmatically manipulate it just fine.  However, the Selection of a
document without a window wouldn't have any user-visible function, so
WebKit's behavior probably does make the most sense.

Does anyone object to WebKit's behavior -- i.e.,
Document.prototype.getSelection() returning null if there's no
associated Window (however that's defined)?

> For phrasing it, could you define it in terms of document.defaultView? In
> other words that document.getSelection is just "return document.defaultView
> ? document.defaultView.getSelection() : null".

That's actually how I used to define it until just now, when I
revamped the details of Selection to better match reality in other
ways.

On Thu, Jan 12, 2012 at 1:20 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> In Gecko, this is arguably an implementation bug.  It returns the selection
> associated with a particular Window object.  Which Window that is depends on
> how the document was created; I don't know that there's any such concept in
> the spec.

After consulting with #whatwg, I had previously defined it as the
window that contained the interface prototype object for the document.
 I.e., such that w.Document.prototype == Object.getPrototypeOf(doc).
But this might not be useful.  Returning null probably makes more
sense.

On Fri, Jan 13, 2012 at 2:37 AM, Simon Pieters <simonp@opera.com> wrote:
> HTML uses this concept in lots of places, e.g.
> http://www.whatwg.org/specs/web-apps/current-work/#cookie-free-document-object
>
> "A Document that has no browsing context."

That's what Hixie suggested, but that's not actually defined anywhere, is it?

On Fri, Jan 13, 2012 at 11:12 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> Ah, that's better than using defaultView (because behavior for defaultView
> on navigation and such is not defined in the spec and is not consistent
> across browsers).

Actually, defaultView is defined to return the Document's browsing
context's WindowProxy object, if it has one, and null otherwise.  Thus
per spec, defaultView returns null if and only if the document has no
browsing context.  The concept doesn't seem well-defined anywhere I
can find.  I filed a bug against HTML:

https://www.w3.org/Bugs/Public/show_bug.cgi?id=15548

For now I'm inclined to go with defaultView being null, just because
that's at least readily testable.  If defaultView isn't defined well
enough, that should be fixed in the HTML spec.

Received on Friday, 13 January 2012 20:21:04 UTC