[webkit-dev] Selection model is broken

Ojan Vafai ojan at chromium.org
Thu Jan 5 15:31:46 PST 2012

Selections on the web are document ordered (i.e. all the DOM between two
points). So, any CSS that puts elements out of document order gives a
crappy selection to the user.

<div style="position:relative">foo<div

If you select "foobaz", clearly no user would expect "bar" to get selected.
The same problem arises with floats, negative margins, flexbox and grid
ordering. I expect it's likely that CSS will continue to get more ways to
put elements out of document order.

The only solution I can think of to this is to create a hit-test rect when
making a selection from the start point to the end point and then only
include the DOM contents that overlaps the rect. We'd still include all the
inline content of overlapping elements, but elements that don't overlap at
all would be excluded.

So, instead of a selection being a start and end DOM position, it would be
a list of disjoint start and end DOM positions.

Does this seem technically feasible? I think we can get the APIs exposed to
JS to work with this if we are willing to make the change.

The big pro is that selections will be much more intuitive for a large and
growing class of layouts.

-Making a selection is slower now and involves hit-testing a full rect
instead of just two points. (is this even possible?)
-The code that deals with selections now needs to operate on multiple
selections (e.g. hitting delete in an editable area needs to separately
delete each sub-range).
-JavaScript code that operates on selections may need to change. Or maybe
we need to add new APIs in order to maintain backwards compatibility for
the old APIs.

Is this too crazy? Are there other solutions?

See http://peter.sh/examples/?/css/flexbox.html for an example of how
crappy these selections are.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20120105/193b9731/attachment.html>

More information about the webkit-dev mailing list