Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upExpand InputType to cover all possible types #19471
Conversation
highfive
commented
Dec 3, 2017
|
Heads up! This PR modifies the following files:
|
|
r? @nox |
| InputCheckbox, | ||
| InputRadio, | ||
| InputPassword | ||
| pub enum InputType { |
This comment has been minimized.
This comment has been minimized.
jonleighton
Dec 3, 2017
Author
Contributor
I took the liberty of removing the Input prefix from the enum members, as this seemed redundant. Let me know if that's not OK.
| &atom!("time") => InputType::Time, | ||
| &atom!("url") => InputType::Url, | ||
| &atom!("week") => InputType::Week, | ||
| v if *v == Atom::from("range") => InputType::Range, |
This comment has been minimized.
This comment has been minimized.
jonleighton
Dec 3, 2017
Author
Contributor
I couldn't get it to compile without this hack. The compiler said that "range" didn't match the atom! macro. I'm not sure what the right thing to do here is, but I suspect this isn't it! Please let me know.
This comment has been minimized.
This comment has been minimized.
KiChjang
Dec 4, 2017
Member
You'll need to add the "range" string to this file in order for the atom! macro to work with it.
This comment has been minimized.
This comment has been minimized.
jonleighton
Dec 4, 2017
Author
Contributor
Thanks. Seems like the way atoms work could really use some documentation, I've had a lot of questions about this area of the code.
| Checkbox, | ||
| Color, | ||
| Date, | ||
| Datetime, |
This comment has been minimized.
This comment has been minimized.
jonleighton
Dec 3, 2017
Author
Contributor
Do we really need this? datetime is an obsolete value and is not in the spec. It's also unsupported in Firefox. Doesn't seem like it needs to exist in Servo?
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
|
|
||
| pub fn input_type(&self) -> InputType { |
This comment has been minimized.
This comment has been minimized.
KiChjang
Dec 4, 2017
Member
I don't actually feel like this is THAT much of an improvement, since this essentially only saves us from typing .get. In fact, I think this may even hurt performance since we have to go through another function call... but since you've already made the change everywhere to use input_type(), the least we can do to mitigate this is to add a #[inline] annotation above.
This comment has been minimized.
This comment has been minimized.
jonleighton
Dec 4, 2017
Author
Contributor
Thanks, done. Note that there need to be some public way to get the InputType from outside of the crate, which is part of the reason that I added this function (the other part of the reason is indeed that I think it's slightly nicer to not have to repeat input_type.get() everywhere.
c3f9e0b
to
dded910
|
|
903033d
to
9f7801d
| Checkbox, | ||
| Color, | ||
| Date, | ||
| Datetime, |
This comment has been minimized.
This comment has been minimized.
|
@bors-servo: r+ |
|
|
Expand InputType to cover all possible types This came out of a conversation with nox in IRC: https://mozilla.logbot.info/servo/20171201#c13946454-c13946594 The code I was working on which motivated this change is here: #19461 Previously, InputType::Text was used to represent several different values of the type attribute on an input element. If an input element doesn't have a type attribute, or its type attribute doesn't contain a recognised value, then the input's type defaults to "text". Before this change, there were a number of checks in the code which directly looked at the type attribute. If those checks matched against the value "text", then they were potentially buggy, since an input with type=invalid should also behave like an input with type=text. Rather than have every conditional which cares about the input type also have to deal with invalid input types, we can convert the type attribute to an InputType enum once, and then match against the enum. A secondary benefit is that the compiler can tell us whether we've missed branches in a match expression. While working on this I discovered that the HTMLInputElement::value_mode() method misses a case for inputs with type=hidden (this resulted in a failing WPT test passing). I've also implemented the Default trait for InputType, so we now only have one place in the code which knows that InputType::Text is the default, where previously there were several. <!-- 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/19471) <!-- Reviewable:end -->
|
|
|
I'll take a look at those failures |
This came out of a conversation with nox in IRC: https://mozilla.logbot.info/servo/20171201#c13946454-c13946594 The code I was working on which motivated this change is here: #19461 Previously, InputType::Text was used to represent several different values of the type attribute on an input element. If an input element doesn't have a type attribute, or its type attribute doesn't contain a recognised value, then the input's type defaults to "text". Before this change, there were a number of checks in the code which directly looked at the type attribute. If those checks matched against the value "text", then they were potentially buggy, since an input with type=invalid should also behave like an input with type=text. Rather than have every conditional which cares about the input type also have to deal with invalid input types, we can convert the type attribute to an InputType enum once, and then match against the enum. A secondary benefit is that the compiler can tell us whether we've missed branches in a match expression. While working on this I discovered that the HTMLInputElement::value_mode() method misses a case for inputs with type=hidden (this resulted in a failing WPT test passing). I've also implemented the Default trait for InputType, so we now only have one place in the code which knows that InputType::Text is the default, where previously there were several.
|
Fixed. I needed to make |
|
@bors-servo r+ |
|
|
Expand InputType to cover all possible types This came out of a conversation with nox in IRC: https://mozilla.logbot.info/servo/20171201#c13946454-c13946594 The code I was working on which motivated this change is here: #19461 Previously, InputType::Text was used to represent several different values of the type attribute on an input element. If an input element doesn't have a type attribute, or its type attribute doesn't contain a recognised value, then the input's type defaults to "text". Before this change, there were a number of checks in the code which directly looked at the type attribute. If those checks matched against the value "text", then they were potentially buggy, since an input with type=invalid should also behave like an input with type=text. Rather than have every conditional which cares about the input type also have to deal with invalid input types, we can convert the type attribute to an InputType enum once, and then match against the enum. A secondary benefit is that the compiler can tell us whether we've missed branches in a match expression. While working on this I discovered that the HTMLInputElement::value_mode() method misses a case for inputs with type=hidden (this resulted in a failing WPT test passing). I've also implemented the Default trait for InputType, so we now only have one place in the code which knows that InputType::Text is the default, where previously there were several. <!-- 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/19471) <!-- Reviewable:end -->
|
|
It has been removed from the spec: whatwg/html#336 See also servo#19471 (review)
Remove support for <input type=datetime> It has been removed from the spec: whatwg/html#336 See also #19471 (review) --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- 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/19509) <!-- Reviewable:end -->
…jonleighton:remove-input-type-datetime); r=jdm It has been removed from the spec: whatwg/html#336 See also servo/servo#19471 (review) --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8e3056d0cc7caebc218d51373b3aa0ccd331fa20 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 76bd32c1d97be56bee2675857fcb5b20f2ed2d42
…jonleighton:remove-input-type-datetime); r=jdm It has been removed from the spec: whatwg/html#336 See also servo/servo#19471 (review) --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8e3056d0cc7caebc218d51373b3aa0ccd331fa20
…jonleighton:remove-input-type-datetime); r=jdm It has been removed from the spec: whatwg/html#336 See also servo/servo#19471 (review) --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 8e3056d0cc7caebc218d51373b3aa0ccd331fa20
jonleighton commentedDec 3, 2017
•
edited by SimonSapin
This came out of a conversation with nox in IRC:
https://mozilla.logbot.info/servo/20171201#c13946454-c13946594
The code I was working on which motivated this change is here:
#19461
Previously, InputType::Text was used to represent several different
values of the type attribute on an input element.
If an input element doesn't have a type attribute, or its type attribute
doesn't contain a recognised value, then the input's type defaults to
"text".
Before this change, there were a number of checks in the code which
directly looked at the type attribute. If those checks matched against
the value "text", then they were potentially buggy, since an input with
type=invalid should also behave like an input with type=text.
Rather than have every conditional which cares about the input type also
have to deal with invalid input types, we can convert the type attribute
to an InputType enum once, and then match against the enum.
A secondary benefit is that the compiler can tell us whether we've
missed branches in a match expression. While working on this I
discovered that the HTMLInputElement::value_mode() method misses a case
for inputs with type=hidden (this resulted in a failing WPT test
passing).
I've also implemented the Default trait for InputType, so we now only
have one place in the code which knows that InputType::Text is the
default, where previously there were several.
This change is