Commit graph

53 commits

Author SHA1 Message Date
teapotd
c7a31990a2 Allow deletion from overflowed textinput 2020-01-10 19:02:41 +01:00
Michal Mieczkowski
2726fc1dea Restore DummyClipboardContext for textinput.rs tests 2019-06-15 12:12:15 +02:00
Thomas Delacour
14c8bbb49d
ISSUE-20455: introduce stronger types for textinput indexing 2019-05-16 15:33:24 -04:00
Denis Merigoux
e1ea8fbd35 Fixed bug in textinput::adjust_vertical concerning selection_origin update
This bug was discovered using the F* formal verification framework.

Style changes (match -> if let)

Replace if let Some(_) by .is_some()
2018-12-22 17:50:24 +01:00
Pyfisch
7db13e93b7 Correct select all
Fixes assertion failure.
Set selection direction forward on select all.
2018-11-07 18:58:51 +01:00
Pyfisch
9e92eb205a Reorder imports 2018-11-06 22:35:07 +01:00
Pyfisch
cb07debcb6 Format remaining files 2018-11-06 22:30:31 +01:00
Pyfisch
0ccaa7e1a9 Use keyboard-types crate
Have embedders send DOM keys to servo and use a strongly typed KeyboardEvent
from the W3C UI Events spec. All keyboard handling now uses the new types.

Introduce a ShortcutMatcher to recognize key bindings. Shortcuts are now
recognized in a uniform way.

Updated the winit port.
Updated webdriver integration.

part of #20331
2018-10-07 22:39:00 +02:00
paavininanda
87e7b1ee7a Correct default selectionStart and selectionEnd 2018-02-23 02:37:11 +05:30
paavininanda
b517410a34 Revert "Correct default Selectionstart and SelectionEnd"
This reverts commit b2c1f89b93.
2018-02-23 01:55:21 +05:30
Jon Leighton
32f781234a Disallow mutating the internals of TextInput
The TextInput::assert_ok_selection() method is meant to ensure that we
are not getting into a state where a selection refers to a location in
the control's contents which doesn't exist.

However, before this change we could have a situation where the
internals of the TextInput are changed by another part of the code,
without using its public API. This could lead to us having an invalid
selection.

I did manage to trigger such a situation (see the test added in this
commit) although it is quite contrived. There may be others that I
didn't think of, and it's also possible that future changes could
introduce new cases. (Including ones which trigger panics, if indexing
is used on the assumption that the selection indices are always valid.)

The current HTML specification doesn't explicitly say that
selectionStart/End must remain within the length of the content, but
that does seems to be the consensus reached in a discussion of this:

https://github.com/whatwg/html/issues/2424

The test case I've added here is currently undefined in the spec which
is why I've added it in tests/wpt/mozilla.
2018-02-16 11:24:12 +01:00
paavininanda
b2c1f89b93 Correct default Selectionstart and SelectionEnd 2018-02-10 17:46:29 +05:30
paavininanda
7b58fb5fdd Changed offset_to_text_point function and added unit tests for the same 2018-02-07 01:18:50 +05:30
Jon Leighton
02883a6f54 Fix selection{Start,End} when selectionDirection is "backward"
Per the spec, selectionStart and selectionEnd should return the same
values regardless of the selectionDirection. (That is, selectionStart is
always less than or equal to selectionEnd; the direction then implies
which of selectionStart or selectionEnd is the cursor position.)

There was no explicit WPT test for this, so I added one.

This bug was initially quite hard to wrap my head around, and I think
part of the problem is the code in TextInput. Therefore, in the process
of fixing it I have refactored the implementation of TextInput:

* Rename selection_begin to selection_origin. This value doesn't
  necessarily correspond directly to the selectionStart DOM value - in
  the case of a backward selection, it corresponds to selectionEnd.
  I feel that "origin" doesn't imply a specific ordering as strongly as
  "begin" (or "start" for that matter) does.

* In various other cases where "begin" is used as a synonym for "start",
  just use "start" for consistency.

* Implement selection_start() and selection_end() methods (and their
  _offset() variants) which directly correspond to their DOM
  equivalents.

* Rename other related methods to make them less wordy and more
  consistent / intention-revealing.

* Add assertions to assert_ok_selection() to ensure that our assumptions
  about the ordering of selection_origin and edit_point are met. This
  then revealed a bug in adjust_selection_for_horizontal_change() where
  the value of selection_direction was not maintained correctly (causing
  a unit test failure when the new assertion failed).
2018-01-26 19:50:50 +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
Bastien Orivel
29b4eec141 Bump bitflags to 1.0 in every servo crate 2017-10-30 23:36:06 +01:00
Gecko Backout
11c64178d8 Backed out changeset e64e659c077d: servo PR #18809 and revendor for reftest failures, e.g. in layout/reftests/bugs/392435-1.html. r=backout on a CLOSED TREE
Backs out https://github.com/servo/servo/pull/18809
2017-10-19 21:26:51 +00:00
Bastien Orivel
e8e2d0a4b2 Update bitflags to 1.0 in every servo crate
It still needs dependencies update to remove all the other bitflags
versions.
2017-10-19 15:01:17 +02:00
Josh Matthews
7359b761f0 Conditionally import values for mac tests. 2017-07-27 00:05:27 -04:00
Josh Matthews
dc5a50fcd3 Clean up warnings in script unit tests. 2017-07-26 08:42:16 -04:00
bors-servo
e45546edf0 Auto merge of #15822 - charlesvdv:unicode-panic, r=emilio
Correct unicode handling for text input

<!-- Please describe your changes on the following line: -->
Allow proprer handling of unicode sequence in text input.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15819

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15822)
<!-- Reviewable:end -->
2017-04-16 15:08:59 -05:00
charlesvdv
49ea443146 add test for text input unicode handling 2017-04-16 11:52:21 +02:00
Clement Miao
ea3c840983 new keyboard shortcuts inside text input 2017-04-07 01:05:13 -07:00
Ms2ger
86d59212fe Introduce a script::test module to expose the APIs needed for unit tests. 2016-12-22 15:58:53 +01:00
Taryn Hill
2cb5adf6c6 Implement minlength for text inputs 2016-09-21 07:54:39 -05:00
UK992
93a103ba73 Reorder use statements 2016-09-09 04:55:19 +02:00
Connor Brewster
6c7e812966 Add unit test for setting selection with selection direction 2016-07-06 22:38:23 -06:00
Josh Matthews
6496d73210 Make textinput handle actual key values. Don't restrict character values to a single byte. 2016-07-06 00:10:24 -04:00
Anthony Ramine
cdc7bca944 Move DOMString back to script
This entirely removes the 'non-geckolib' feature of the util crate.
2016-05-24 10:54:57 +02:00
Alberto Corona
5e863f2eb8
Implement HTMLTextArea.setSelectionRange 2016-04-17 17:27:26 +02:00
Matt Brubeck
deca979967 TextInput::max_length should be in code units, not bytes 2016-04-02 07:33:53 -07:00
Matt Brubeck
29fb3f1150 Find the correct column index in adjust_vertical 2016-04-01 14:00:50 -07:00
Matt Brubeck
d7e6f8b0f1 Use correct byte indices in replace_selection 2016-04-01 13:54:02 -07:00
Matt Brubeck
db2c1841cb Fix delete_char when selection range is empty
An empty selection range should be treated the same as no selection.
Fixes browserhtml/browserhtml#930.
2016-03-25 08:39:53 -07:00
Sam Gibson
2ba1750c40 Resolves long-running merge conflicts 2015-12-03 14:00:53 +11:00
Sam Gibson
419a26e619 Adds a test for set_content to ignore max_length 2015-12-03 14:00:53 +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
Alan Jeffrey
84bde75b42 Replaced DOMString constructor by conversion functions.
Replaced DOMString(...) by DOMString::from(...).
Replaced ....0 by String::from(...).
Removed any uses of .to_owner() in DOMString::from("...").
2015-11-12 17:52:59 -06:00
Ms2ger
6b75078503 Make DOMString a newtype around String, rather than a typedef.
This should make it somewhat easier to experiment with alternative
representations in the future. To reduce churn, this commit leaves the String
field public, though.

Also, this will allow us to use the default String type to represent the IDL
USVString type, which explicitly forbids unpaired surrogates, ans as such is
a better match to the Rust String type.
2015-11-04 12:09:11 +01:00
Ms2ger
dab3926622 Create a helper function to create TextInput structs in its unit test. 2015-11-04 12:09:09 +01:00
Brandon Fairchild
de3547e401 Fix reported test-tidy errors for unmerged import blocks
This merges import blocks that were reported by tidy as unmerged.
2015-09-19 12:50:14 -04:00
bors-servo
4404809e6d Auto merge of #7459 - Mylainos:Issue-#7365, r=jdm
Issue #7365 : test cursor position after clearing selection

In textinput test if the cursor is at the correct position when clearing a selection by press an arrow key.

edit_point is always at the end of the selection, should I test when it's at the beginning ?

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7459)
<!-- Reviewable:end -->
2015-09-01 09:23:12 -06:00
erneyja
17663315dd make test-tidy check that = have space after them 2015-09-01 07:18:19 -04:00
Hugo Thiessard
6a2ae236d4 Issue #7365 : test for cursor position after clearing selection 2015-08-31 09:10:34 +02:00
Simon Sapin
95a252a650 Refactor script::textinput to count UTF-8 bytes rather than code points. 2015-08-28 11:57:40 +02:00
Johann Tuffe
ec07178b6f sort all uses 2015-08-20 20:47:12 +08:00
Avi Weinstock
f86252a60b Add set_clipboard_context function and relevant plumbing. Use Option more consistantly (less unwraps) in textinput's selection handling. 2015-07-29 12:19:37 -04:00
Corey Farwell
8e3f4bba85 Reduce max line length from 150 to 120 characters
Part of https://github.com/servo/servo/issues/6041
2015-05-24 00:01:49 -04:00
Avi Weinstock
d054946f7d Fix test_clipboard_paste to pass on Mac OS. 2015-05-06 15:30:29 -04:00
Avi Weinstock
b742eeca05 Made the clipboard-related functionality in TextInput more testable. Added test_clipboard_paste to the "test-unit" suite. 2015-05-06 11:46:18 -04:00