[webkit-dev] Add SelectionChange event for content editable regions

Ryosuke Niwa rniwa at webkit.org
Thu Oct 7 15:47:06 PDT 2010


Greetings all,

I propose to implement selectionchange event, an event dispatched whenever
selection changes.  This event allows developers to be notified of selection
change, and can be used to update status for RTE (e.g. toggling the
appearance of bold button based on the context around caret).  This event
has already been implemented by Internet Explorer for document
node<http://msdn.microsoft.com/en-us/library/ms536968(VS.85).aspx>
.

For example, if you do:

document.addEventListener('selectionchange', function () {alert("selection
changed!"), false);

alert is shown whenever selection changes inside the current document.  I'd
like to make this event attachable to other elements as well so that
developers can be notified of only relevant selection changes (target
element is always document in MSIE's implementation).  For example, we can
easily extend this event to be fired from root editable elements because
selection does not cross editing boundary.

Alternatively, we can extend the existing select event to fire for root
editable elements as supposed to fire only for input / textarea elements.
 For this alternative, see the note in the section 5.2.1. of the DOM Level 3
Events specification where it says:
*Note:* The select<http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#event-type-select>
event
may not be available for all elements in all languages. For example, in [
HTML5<http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#references-HTML5>
], select<http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#event-type-select>
events
may only be dispatched on only form input and textarea elements.
Implementations may dispatch
select<http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#event-type-select>
events
in any context deemed appropriate, including text selections outside of form
controls, or image or markup selections such as in SVG.

Best regards,
Ryosuke Niwa
Software Engineer
Google Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20101007/98f51905/attachment.html>


More information about the webkit-dev mailing list