This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24083 - Window.getSelection() and HTMLDocument.getSelection() should return a nullable
Summary: Window.getSelection() and HTMLDocument.getSelection() should return a nullable
Status: RESOLVED WONTFIX
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Selection API (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Ryosuke Niwa
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-13 01:40 UTC by Ehsan Akhgari [:ehsan]
Modified: 2014-09-17 00:01 UTC (History)
5 users (show)

See Also:


Attachments

Description Ehsan Akhgari [:ehsan] 2013-12-13 01:40:28 UTC
This is what Gecko implements.  One of the reasons why a selection might be null is if the presentation of the document has not yet been set up (for example, this can happen to an iframe's selection object when you add it a document before we hit the event loop.)  These tests exercise this condition: <https://dvcs.w3.org/hg/editing/file/57abe6d3cb60/selecttest/getSelection.html#l157>
Comment 1 Boris Zbarsky 2013-12-13 02:13:45 UTC
Note that it's not clear to me that Gecko's setup here (tying the selection object to the presentation instead of the document) is sane...  There isn't even a concept of "presentation" in the specs right now as things stand.
Comment 2 Ehsan Akhgari [:ehsan] 2013-12-13 02:59:06 UTC
Fair enough.  It's conceivable for us to be able to move our selection code to attach it to the document rather than its "presentation".  But still I think there are other reasons why getSelection() could be conceived to return null, such as the UA operating in an environment where user selection is not supported.
Comment 3 Aryeh Gregor 2014-04-03 12:32:28 UTC
Anything that returns a usable object in all normal cases and fails in weird cases will break any code that tries to use the API in the weird case, because no code will account for the weird case.  Returning null is only okay if it comes up in common cases, or is logically unavoidable.

I think a Selection should be returned in all cases.  If selection is not allowed, the returned selection should have no ranges in it.  If a script adds a range, the user agent is free to ignore it if selections are not currently supported.  If selections later become allowed, like if the iframe is added to a document, the added range should take effect.  This approach would make author code very likely to work correctly even if selections are not supported.

So I'm inclined to say WONTFIX.  Gecko is what should change here.
Comment 4 Aryeh Gregor 2014-04-24 15:36:36 UTC
Over to you, Ryosuke.
Comment 5 Ryosuke Niwa 2014-09-15 23:59:53 UTC
I tend to agree with Aryeh that returning null in getSelection() may break things.  It might be better to add a property to Selection that indicates whether the user could interact with selection or not.
Comment 6 Ehsan Akhgari [:ehsan] 2014-09-16 15:38:32 UTC
OK, I'm convinced!  :)