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 upstyle: :dir() pseudo class now represented by enum #19195
Conversation
highfive
commented
Nov 12, 2017
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @mbrubeck (or someone else) soon. |
highfive
commented
Nov 12, 2017
|
Heads up! This PR modifies the following files:
|
highfive
commented
Nov 12, 2017
|
Good start! I have a bunch of comments, let me know if any of those is unclear and I'm happy to clarify or help out. Thanks for working on this! |
| pub enum Direction { | ||
| Rtl, | ||
| Ltr, | ||
| Other(String), |
This comment has been minimized.
This comment has been minimized.
emilio
Nov 13, 2017
Member
This should still be Box<[u16]>, or Box<str> at least. That may avoid Component growing.
| @@ -14,8 +14,8 @@ use visitor::SelectorVisitor; | |||
| size_of_test!(size_of_selector, Selector<Impl>, 8); | |||
| size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24); | |||
|
|
|||
| size_of_test!(size_of_component, Component<Impl>, 32); | |||
| size_of_test!(size_of_pseudo_class, PseudoClass, 24); | |||
| size_of_test!(size_of_component, Component<Impl>, 48); | |||
This comment has been minimized.
This comment has been minimized.
| /// left-to-right semantic directionality | ||
| Ltr, | ||
| /// Some other provided directionality value | ||
| Other(String), |
This comment has been minimized.
This comment has been minimized.
| Other(String), | ||
| } | ||
|
|
||
| impl <'a> From<&'a str> for Direction { |
This comment has been minimized.
This comment has been minimized.
|
|
||
| impl <'a> From<&'a str> for Direction { | ||
| fn from(string: &'a str) -> Direction { | ||
| match string.to_lowercase().as_str() { |
This comment has been minimized.
This comment has been minimized.
| @@ -360,6 +417,10 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { | |||
| .chain(Some(0u16)).collect(); | |||
| NonTSPseudoClass::$k_name(utf16.into_boxed_slice()) | |||
| }, )* | |||
| "dir" => { | |||
| let name: &str = parser.expect_ident()?; | |||
This comment has been minimized.
This comment has been minimized.
| @@ -2066,6 +2065,15 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { | |||
| ) | |||
| } | |||
| } | |||
| NonTSPseudoClass::Dir(ref dir) => { | |||
| unsafe { | |||
| Gecko_MatchStringArgPseudo( | |||
This comment has been minimized.
This comment has been minimized.
emilio
Nov 13, 2017
Member
The point of converting to an enum is not having to go through Gecko_MatchStringArgPseudo.
Instead of that, we can just do:
match *dir {
Direction::Ltr => self.get_state().intersects(element_state::IN_HAS_DIR_ATTR_LTR_STATE),
Direction::Rtl => self.get_state().intersects(element_state::IN_HAS_DIR_ATTR_RTL_STATE),
Direction::Other(..) => false,
}| use invalidation::element::invalidation_map::dir_selector_to_state; | ||
| let selector_flag = dir_selector_to_state(s); |
This comment has been minimized.
This comment has been minimized.
emilio
Nov 13, 2017
Member
Similarly, we can simplify dir_selector_to_state to take &Direction, instead of comparing the string.
This comment has been minimized.
This comment has been minimized.
| @@ -0,0 +1,31 @@ | |||
| /* This Source Code Form is subject to the terms of the Mozilla Public | |||
This comment has been minimized.
This comment has been minimized.
| @@ -14,8 +14,8 @@ use visitor::SelectorVisitor; | |||
| size_of_test!(size_of_selector, Selector<Impl>, 8); | |||
| size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24); | |||
|
|
|||
| size_of_test!(size_of_component, Component<Impl>, 32); | |||
| size_of_test!(size_of_pseudo_class, PseudoClass, 24); | |||
| size_of_test!(size_of_component, Component<Impl>, 40); | |||
This comment has been minimized.
This comment has been minimized.
wilsoniya
Nov 14, 2017
Author
Contributor
Even using the Other<Box[u16]> enum variant type, the size of these structs is increased :(
This comment has been minimized.
This comment has been minimized.
emilio
Nov 14, 2017
Member
Hmm, that's pretty unfortunate, let's box the Direction then:
Dir(Box<Direction>)Mentioning that it allows not growing Component, even though it's slightly unfortunate.
This comment has been minimized.
This comment has been minimized.
emilio
Nov 14, 2017
Member
Oh, the other thing we can do instead, and it'll fix the serialization bug I just noted below too, I think, is using CustomIdent, which should just be one word and allow us not to box it:
enum Direction {
Rtl,
Ltr,
Other(CustomIdent),
}Then you don't even need to manually write the serialization code, and you can just #[derive(ToCss)] on it.
|
Hey, @emilio, thanks for the review! I think I've addressed your comments, with the exception of the change in size of Do you have ideas regarding how to eliminate the size increase on that struct? |
| Other(Box<[u16]>), | ||
| } | ||
|
|
||
| impl<'a> From<&'a Direction> for String { |
This comment has been minimized.
This comment has been minimized.
emilio
Nov 14, 2017
Member
Given we don't use the utf16 impl anyway, this could be Box<str>, and there'd be no need to allocate a String for serialization.
| @@ -14,8 +14,8 @@ use visitor::SelectorVisitor; | |||
| size_of_test!(size_of_selector, Selector<Impl>, 8); | |||
| size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24); | |||
|
|
|||
| size_of_test!(size_of_component, Component<Impl>, 32); | |||
| size_of_test!(size_of_pseudo_class, PseudoClass, 24); | |||
| size_of_test!(size_of_component, Component<Impl>, 40); | |||
This comment has been minimized.
This comment has been minimized.
emilio
Nov 14, 2017
Member
Hmm, that's pretty unfortunate, let's box the Direction then:
Dir(Box<Direction>)Mentioning that it allows not growing Component, even though it's slightly unfortunate.
| @@ -92,6 +94,12 @@ impl ToCss for NonTSPseudoClass { | |||
| dest.write_str(&value)?; | |||
| return dest.write_char(')') | |||
| }, )* | |||
| NonTSPseudoClass::Dir(ref dir) => { | |||
This comment has been minimized.
This comment has been minimized.
emilio
Nov 14, 2017
Member
Let's impl ToCss for Direction, and use that here, doing just:
dest.write_str(":dir(")?;
dir.to_css(dest)?;
dest.write_char(')')| NonTSPseudoClass::Dir(ref dir) => { | ||
| let value: String = dir.into(); | ||
| dest.write_str(concat!(":dir("))?; | ||
| dest.write_str(&value)?; |
This comment has been minimized.
This comment has been minimized.
emilio
Nov 14, 2017
Member
Also, I believe this is not correct, and should do escaping for the identifier... Though it's an existing bug.
| @@ -14,8 +14,8 @@ use visitor::SelectorVisitor; | |||
| size_of_test!(size_of_selector, Selector<Impl>, 8); | |||
| size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24); | |||
|
|
|||
| size_of_test!(size_of_component, Component<Impl>, 32); | |||
| size_of_test!(size_of_pseudo_class, PseudoClass, 24); | |||
| size_of_test!(size_of_component, Component<Impl>, 40); | |||
This comment has been minimized.
This comment has been minimized.
emilio
Nov 14, 2017
Member
Oh, the other thing we can do instead, and it'll fix the serialization bug I just noted below too, I think, is using CustomIdent, which should just be one word and allow us not to box it:
enum Direction {
Rtl,
Ltr,
Other(CustomIdent),
}Then you don't even need to manually write the serialization code, and you can just #[derive(ToCss)] on it.
|
@emilio Thanks for the follow-up. Regarding your comment regarding escaping: do you have a link to an issue about existing escaping shortcomings and/or thoughts on how to proceed? Your attention and patience on this PR is much appreciated! At this point it probably would have been faster for you to implement a fix yourself than to explain all these things to me :) |
|
Looks great! r=me with these two nits and the commits squashed. Thanks a lot for working on this! |
| @@ -92,6 +94,11 @@ impl ToCss for NonTSPseudoClass { | |||
| dest.write_str(&value)?; | |||
| return dest.write_char(')') | |||
| }, )* | |||
| NonTSPseudoClass::Dir(ref dir) => { | |||
| dest.write_str(concat!(":dir("))?; | |||
This comment has been minimized.
This comment has been minimized.
| let dir_str = match *self { | ||
| Direction::Rtl => "rtl", | ||
| Direction::Ltr => "ltr", | ||
| Direction::Other(ref other) => other, |
This comment has been minimized.
This comment has been minimized.
emilio
Nov 15, 2017
Member
Please add a FIXME here saying:
FIXME: This should be escaped as an identifier.
That can be a followup if you want, since that's a bugfix, requires tests and all that.
The short version is that it should use serialize_identifier, in order to properly handle escapes. I believe we have tests that test this where you could grab an example... But looking at what serialize_identifier handles, something like this:
:dir(\-) { .. }Should be a valid rule, but serializes back to:
:dir(-) { .. }Which isn't an identifier token IIRC.
This comment has been minimized.
This comment has been minimized.
|
@emilio are there any other changes you'd like to see before this is mergeable? |
| @@ -92,6 +94,12 @@ impl ToCss for NonTSPseudoClass { | |||
| dest.write_str(&value)?; | |||
| return dest.write_char(')') | |||
| }, )* | |||
| NonTSPseudoClass::Dir(ref dir) => { | |||
| dest.write_str(":dir(")?; | |||
| // FIXME: This should be escaped as an identifier; see #19231 | |||
This comment has been minimized.
This comment has been minimized.
emilio
Nov 21, 2017
Member
This comment should probably go in the to_css impl, but that can be done in a followup PR.
|
Nope, sorry! I had missed the latest update. Feel free to ping me sooner if this happens again. @bors-servo r+ |
|
|
|
Looks great, thanks a lot! |
style: :dir() pseudo class now represented by enum `:dir()` pseudo class param now represented as enum variants. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #16840 - [X] There are tests for these changes <!-- 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/19195) <!-- Reviewable:end -->
|
|
moving :dir() param serialization FIXME <!-- Please describe your changes on the following line: --> Per emilio's comment, #19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved. --- <!-- 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 do not require tests because they only modify comment lines <!-- 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/19332) <!-- Reviewable:end -->
…ilsoniya:moving-fixme); r=emilio <!-- Please describe your changes on the following line: --> Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved. --- <!-- 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 do not require tests because they only modify comment lines <!-- 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: 3ecd0174cc7817cdd2007850c29b8b069a845b46 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : bd40b06fc49360f0a8ac206558734ec557c741cc
…ilsoniya:moving-fixme); r=emilio <!-- Please describe your changes on the following line: --> Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved. --- <!-- 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 do not require tests because they only modify comment lines <!-- 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: 3ecd0174cc7817cdd2007850c29b8b069a845b46
…ilsoniya:moving-fixme); r=emilio <!-- Please describe your changes on the following line: --> Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved. --- <!-- 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 do not require tests because they only modify comment lines <!-- 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: 3ecd0174cc7817cdd2007850c29b8b069a845b46
…ilsoniya:moving-fixme); r=emilio <!-- Please describe your changes on the following line: --> Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved. --- <!-- 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 do not require tests because they only modify comment lines <!-- 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: 3ecd0174cc7817cdd2007850c29b8b069a845b46
…ilsoniya:moving-fixme); r=emilio <!-- Please describe your changes on the following line: --> Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved. --- <!-- 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 do not require tests because they only modify comment lines <!-- 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: 3ecd0174cc7817cdd2007850c29b8b069a845b46 UltraBlame original commit: 84b90d871c2c14c24356f2840b5bbe9413a5e729
…ilsoniya:moving-fixme); r=emilio <!-- Please describe your changes on the following line: --> Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved. --- <!-- 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 do not require tests because they only modify comment lines <!-- 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: 3ecd0174cc7817cdd2007850c29b8b069a845b46 UltraBlame original commit: 84b90d871c2c14c24356f2840b5bbe9413a5e729
…ilsoniya:moving-fixme); r=emilio <!-- Please describe your changes on the following line: --> Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved. --- <!-- 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 do not require tests because they only modify comment lines <!-- 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: 3ecd0174cc7817cdd2007850c29b8b069a845b46 UltraBlame original commit: 84b90d871c2c14c24356f2840b5bbe9413a5e729
wilsoniya commentedNov 12, 2017
•
edited by SimonSapin
:dir()pseudo class param now represented as enum variants../mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is