servo/components
Jon Leighton ce7bae8834 Implement setRangeText API
Spec: https://html.spec.whatwg.org/multipage/#dom-textarea/input-setrangetext

In order to do this, we need to define the SelectionMode enum in WebIDL:
https://html.spec.whatwg.org/multipage/#selectionmode

Since the enum is used by HTMLTextAreaElement and HTMLInputElement, it
doesn't seem to make sense to define it in the WebIDL file for one or
other of those.

However, we also can't create a stand-alone SelectionMode.webidl file,
because the current binding-generation code won't generate a "pub mod
SelectionMode;" line in mod.rs unless SelectionMode.webidl contains
either an interface or a namespace. (This logic happens in
components/script/dom/bindings/codegen/Configuration.py:35, in the
Configuration.__init__ method.)

I thought about changing the binding-generation code, but that seems
difficult. So I settled for placing the enum inside
HTMLFormElement.webidl, as that seems like a "neutral" location. We
could equally settle for putting it under HTMLTextAreaElement or
HTMLInputElement, it probably doesn't really matter.

The setRangeText algorithm set the "dirty value flag" on the
input/textarea. I made some clean-ups related to this:

1. HTMLTextAreaElement called its dirty value flag "value_changed"; I
   changed this to "value_dirty" to be consistent with the spec.

2. HTMLInputElement had a "value_changed" field and also a "value_dirty"
   field, which were each used in slightly different places (and
   sometimes in both places). I consolidated these into a single
   "value_dirty" field, which was necessary in order to make some of the
   tests pass.

TextControl::set_dom_range_text replaces part of the existing textinput
content with the replacement string (steps 9-10 of the algorithm). My
implementation changes the textinput's selection and then replaces the
selection. A downside of this approach is that we lose the original
selection state from before the call to setRangeText. Therefore, we have
to save the state into the original_selection_state variable so that we
can later pass it into TextControl::set_selection_range. This allows
TextControl::set_selection_range to correctly decide whether or not to
fire the select event.

An alternative approach would be to implement a method on TextInput
which allows a subtring of the content to be mutated, without touching
the current selection state. However, any such method would potentially
put the TextInput into an inconsistent state where the edit_point and/or
selection_origin is a TextPoint which doesn't exist in the content. It
would be up to the caller to subsequently make sure that the TextInput
gets put back into a valid state (which would actually happen, when
TextControl::set_selection_range is called).

I think TextInput's public API should not make it possible to put it
into an invalid state, as that would be a potential source of bugs.
That's why I didn't take this approach. (TextInput's public API does
currently make it possible to create an invalid state, but I'd like to
submit a follow-up patch to lock this down.)
2018-01-26 20:12:33 +01:00
..
allocator FreeType: don’t use usable_size() as deallocation size 2017-10-30 18:22:30 +01:00
atoms Bump string_cache, html5ever and xml5ever 2017-12-07 20:37:38 +01:00
bluetooth Bump bitflags to 1.0 in every servo crate 2017-10-30 23:36:06 +01:00
bluetooth_traits Update WR (details below): 2017-10-16 16:33:24 +10:00
canvas Auto merge of #19868 - CYBAI:specific-assertion, r=emilio 2018-01-25 18:06:33 -06:00
canvas_traits Update euclid, azure, skia, offscreen_gl_context, plane-split, webrender 2017-12-08 14:32:28 +01:00
compositing Use specific assertion for compositing compositor 2018-01-26 01:00:59 +08:00
config Use specific negative assertion for config opts 2018-01-26 01:39:54 +08:00
constellation Auto merge of #19798 - gootorov:move_cursor_from_mako, r=emilio 2018-01-20 12:10:58 -06:00
debugger
deny_public_fields deny_public_fields: display field identifier in help message 2017-06-25 18:12:43 +01:00
devtools Update cookie to 0.10 2017-11-24 10:49:14 +01:00
devtools_traits Update cookie to 0.10 2017-11-24 10:49:14 +01:00
dom_struct Upgrade to rustc 1.24.0-nightly (5a2465e2b 2017-12-06) 2017-12-07 13:50:09 +01:00
domobject_derive Fix quote dependency version 2017-08-23 18:35:42 +02:00
fallible Update smallvec to 0.6 2017-12-05 12:03:20 +01:00
geometry Introduce MaxRect trait 2018-01-17 23:29:57 +01:00
gfx Use specific negative assertion for gfx platform macos font 2018-01-26 01:46:39 +08:00
gfx_traits Decoupled gfx and metrics 2018-01-15 16:25:51 +01:00
hashglobe Use specific negative assertion for hashglobe hash set 2018-01-26 01:55:12 +08:00
jstraceable_derive Fix quote dependency version 2017-08-23 18:35:42 +02:00
layout Use specific negative assertion for layout floats 2018-01-26 01:55:24 +08:00
layout_thread style: Use CascadeFlags for what they're for. 2018-01-23 13:18:54 +01:00
layout_traits Update WR (details below): 2017-10-16 16:33:24 +10:00
malloc_size_of Use more WebRender types in gfx/display_list 2018-01-17 23:29:57 +01:00
malloc_size_of_derive Overhaul MallocSizeOf and related things. 2017-09-12 12:37:51 +10:00
metrics Decoupled gfx and metrics 2018-01-15 16:25:51 +01:00
msg Merge msg and msg_tests 2018-01-20 15:33:02 +01:00
net Auto merge of #19868 - CYBAI:specific-assertion, r=emilio 2018-01-25 18:06:33 -06:00
net_traits Use specific negative assertion for unit tests of net trait pub_domain 2018-01-26 01:55:39 +08:00
nonzero Replace NonZeroU32 and NonZeroUsize with a generic NonZero 2017-10-16 20:19:19 +02:00
profile added time to interactive metrics, refactored metrics to use traits 2017-10-24 21:02:56 +01:00
profile_traits added time to interactive metrics, refactored metrics to use traits 2017-10-24 21:02:56 +01:00
rand Update lazy_static to 1.0 2017-12-04 22:51:13 +01:00
range Replace all uses of the heapsize crate with malloc_size_of. 2017-10-18 22:20:37 +11:00
remutex Merge servo_remutex to servo_remutex_tests 2018-01-20 15:37:04 +01:00
script Implement setRangeText API 2018-01-26 20:12:33 +01:00
script_layout_interface style: Use CascadeFlags for what they're for. 2018-01-23 13:18:54 +01:00
script_plugins Make the unrooted_must_root conditional on a default Cargo feature. 2017-11-02 15:08:04 +01:00
script_traits style: Move cursor property out of mako 2018-01-20 19:06:29 +02:00
selectors Auto merge of #19822 - emilio:less-match-public, r=KiChjang 2018-01-19 23:05:18 -06:00
servo Update euclid, azure, skia, offscreen_gl_context, plane-split, webrender 2017-12-08 14:32:28 +01:00
servo_arc Use specific negative assertion for ServoArc 2018-01-26 02:24:06 +08:00
size_of_test Add size_of_test crate 2017-05-16 10:12:51 +02:00
style Auto merge of #19868 - CYBAI:specific-assertion, r=emilio 2018-01-25 18:06:33 -06:00
style_derive Derive ToCss for TransformOperation 2018-01-23 11:02:34 +01:00
style_traits Change ToCss to take a CssWriter<W> 2018-01-23 10:41:42 +01:00
url Replace all uses of the heapsize crate with malloc_size_of. 2017-10-18 22:20:37 +11:00
webdriver_server Use specific assertion for webdriver server 2018-01-26 01:19:00 +08:00
webvr Update euclid, azure, skia, offscreen_gl_context, plane-split, webrender 2017-12-08 14:32:28 +01:00
webvr_traits Update WR (details below): 2017-10-16 16:33:24 +10:00