Commit graph

34 commits

Author SHA1 Message Date
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
Jon Leighton
0148e9705b Support the select() method on input/textarea
Issue #19171
2018-01-26 19:50:45 +01:00
Jon Leighton
71a013dd50 Handle cases where selection API doesn't apply
The selection API only applies to certain <input> types:

https://html.spec.whatwg.org/multipage/#do-not-apply

This commit ensures that we handle that correctly.

Some notes:

1. TextControl::set_dom_selection_direction now calls
   set_selection_range(), which means that setting selectionDirection will
   now fire a selection event, as it should per the spec.

2. There is a test for the firing of the select event in
   tests/wpt/web-platform-tests/html/semantics/forms/textfieldselection/select-event.html,
   however the test did not run due to this syntax error:

   (pid:26017) "ERROR:script::dom::bindings::error: Error at http://web-platform.test:8000/html/semantics/forms/textfieldselection/select-event.html:50:11 missing = in const declaration"

   This happens due to the us of the "for (const foo of ...)" construct.
   Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
   this should actually work, so it's somewhat unsatisfying to have to
   change the test.

4. If an <input>'s type is unset, it defaults to a text, and the
   selection API applies. Also, if an <input>'s type is set to an
   invalid value, it defaults to a text too. I've expanded the tests
   to account for this second case.
2017-12-08 21:07:05 +01:00
Connor Brewster
2460997ee1 Add CEReactions where needed 2017-07-18 12:22:20 -06:00
Connor Brewster
d951dee640 Add HTMLConstructor attributes where needed 2017-06-15 21:16:57 -06:00
Taryn Hill
2cb5adf6c6 Implement minlength for text inputs 2016-09-21 07:54:39 -05:00
Maciej Skrzypkowski
9fa6d5083c Partial fix for #12415: expose interfaces of some HTML Elements 2016-07-28 14:38:47 +02:00
Ms2ger
ed743bb50c Explicitly expose everything everywhere. 2016-07-12 13:06:48 +02:00
Zhen Zhang
5e051c08f6 Add ability to WPT-test file uploads and fetches, fixes #12322 2016-07-09 15:31:00 +08:00
Zhen Zhang
6ca531fb8f Fix file-type input element 2016-06-30 14:18:11 +08:00
edunham
7ae63b1213 Remove modelines everywhere but tests/wpt 2016-04-20 10:49:09 -07:00
Arnaud Marant
9b8f183cba Issue #10491 add HTMLInputElement attributes that reflect content identically
it uses a new version of string-cache https://github.com/servo/string-cache/pull/148
2016-04-12 00:15:57 +02:00
Saurav Sachidanand
a3d77790a6 Implement input.setSelectionRange 2016-03-10 19:54:21 +05:30
Greg Guthe
e6c31e305d Get input value IDL attribute matching spec
Refs: https://github.com/servo/servo/issues/9455
2016-02-25 18:59:34 -05:00
Keith Yeung
3395e54585 Implement basic framework for static and interactive validation on forms 2015-12-15 16:34:42 -08:00
Sam Gibson
9668500e97 Makes setting negative values to maxLength throw an IndexSize exception 2015-12-03 14:00:59 +11:00
Sam Gibson
d26c555e2a Adds support for input element's maxlength attr
servo/servo#7320
servo/servo#7004
2015-12-03 14:00:51 +11:00
Corey Farwell
9df375195e Implement 'labels' attribute on 'labelable elements' 2015-11-01 09:50:14 -05:00
Corey Farwell
9b68d715de Explicitly place '/' before fragment for multipage spec links
This prevents us from 301 redirecting, which could cause the fragment to
get lost
2015-10-10 12:07:10 -04:00
Corey Farwell
85f2b6fc5b Replace usage of old-style WHATWG spec links 2015-10-10 11:55:09 -04:00
Manish Goregaokar
b677f0f4ae Add form getter for input/button elements; update test expectations 2015-09-24 11:58:24 +05:30
Corey Farwell
9415c92a5c Clean up whitespace, long lines for WebIDLs 2015-07-26 22:12:10 +07:00
Anthony Ramine
fedad2af1f Improve support of limited unsigned long attributes 2015-05-06 20:18:08 +02:00
Corey Farwell
5eaa922045 Update WHATWG links to use HTTPS
Extracted this out of #5649

This commit was created with the following commands:

```
find . -iname "*.webidl" -type f -print0 | xargs -0 sed -i '' 's/http:\(.*\)whatwg.org/https:\1whatwg.org/g'
```

```
find . -iname "*.rs" -type f -print0 | xargs -0 sed -i '' 's/http:\(.*\)whatwg.org/https:\1whatwg.org/g'
```
2015-04-13 21:34:27 -07:00
Mikko Vanhatalo
29387f6c4c Implemented HTMLInputElement placeholder attribute
+ modified HTMLInputElement.webidl to include placeholder
+ modified placeholder test expectations
2015-04-04 14:44:32 +03:00
Matthew Rasmus
38e4d86b14 Implements DefaultChecked and resets of checkboxes 2014-12-16 11:34:04 -08:00
Matthew Rasmus
f932a6947a Implements HTMLInputElement.defaultValue
...and changes SetValue to update the input text instead of the content
attr.

Also includes a comment summarizing everything I currently know with
respect to an input elements checkedness vs its IDL attributes vs its
content attributes.
2014-12-16 11:06:56 -08:00
Manish Goregaokar
14a6e54371 Move InputCheckbox to Activatable 2014-12-05 18:32:13 -08:00
Manish Goregaokar
7d51a543d8 Implement form control mutability, rename FormOwner -> FormControl 2014-12-05 18:32:11 -08:00
Rohan Prinja
05134e6d1f Add form submission via input element 2014-10-14 21:24:36 +05:30
Manish Goregaokar
76219df816 Address review comments 2014-10-11 16:10:02 +05:30
Manish Goregaokar
8a2c746e61 Add type IDL attr for submittable elements 2014-10-11 09:48:15 +05:30
Josh Matthews
f70bb68503 Implement simple layout for text, button, radio, and checkbox inputs. Implement simple interaction for checkboxes and radio buttons. 2014-10-01 15:35:42 -04:00
Jack Moffitt
c6ab60dbfc Cargoify servo 2014-09-08 20:21:42 -06:00
Renamed from src/components/script/dom/webidls/HTMLInputElement.webidl (Browse further)