Repository navigation
style: moved css longhand counter-reset out of mako - #19529
Conversation
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon. |
|
Heads up! This PR modifies the following files:
|
|
Ok, so... First of all, nice work! Here's the fix for the errors you're getting: Detailsdiff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs
index 08516ed928..f0f4e60ae0 100644
--- a/components/style/properties/gecko.mako.rs
+++ b/components/style/properties/gecko.mako.rs
@@ -5691,7 +5691,7 @@ clip-path
}
% for counter_property in ["Increment", "Reset"]:
- pub fn set_counter_${counter_property.lower()}(&mut self, v: longhands::counter_increment::computed_value::T) {
+ pub fn set_counter_${counter_property.lower()}(&mut self, v: longhands::counter_${counter_property.lower()}::computed_value::T) {
unsafe {
bindings::Gecko_ClearAndResizeCounter${counter_property}s(&mut self.gecko,
v.0.len() as u32);
@@ -5712,11 +5712,11 @@ clip-path
self.copy_counter_${counter_property.lower()}_from(other)
}
- pub fn clone_counter_${counter_property.lower()}(&self) -> longhands::counter_increment::computed_value::T {
+ pub fn clone_counter_${counter_property.lower()}(&self) -> longhands::counter_${counter_property.lower()}::computed_value::T {
use values::CustomIdent;
use gecko_string_cache::Atom;
- longhands::counter_increment::computed_value::T(
+ longhands::counter_${counter_property.lower()}::computed_value::T(
self.gecko.m${counter_property}s.iter().map(|ref gecko_counter| {
(CustomIdent(Atom::from(gecko_counter.mCounter.to_string())), gecko_counter.mValue)
}).collect()There was some code assuming that the types for counter-reset and counter-increment were the same, so that needs to be fixed too. |
emilio
left a comment
There was a problem hiding this comment.
Nice start!
This does add a lot of code, any chance we can also move counter-increment at the same time to deduplicate it? (Maybe renaming it to CounterIntegerList or something like that?)
Once that's done, this is ok to land. It'd be even nicer to add something to the generics module, and do something like:
struct CounterIntegerList<Integer>(Vec<(CustomIdent, Integer)>);Then in computed and specified, you just need to specify computed::Integer or specified::Integer as you please.
That should allow you to not duplicate the ToCss implementation, and to avoid writing ToComputedValue too, I think.
Anyway, that can be a followup.
Nice start, thanks for the patch!
| /// A specified value for the `counter-reset` property. | ||
| #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct CounterReset(pub Vec<(CustomIdent, super::Integer)>); |
There was a problem hiding this comment.
nit: No need to use super::Integer, just use Integer, since you're importing it too.
| pub struct CounterReset(pub Vec<(CustomIdent, super::Integer)>); | ||
|
|
||
| impl Parse for CounterReset { | ||
| fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) |
There was a problem hiding this comment.
nit: Indentation here looks odd, let's do:
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {| return Ok(CounterReset(Vec::new())) | ||
| } | ||
|
|
||
| let mut counters: Vec<(CustomIdent, super::Integer)> = Vec::new(); |
| } | ||
| } | ||
|
|
||
| impl ToComputedValue for CounterReset { |
There was a problem hiding this comment.
Let's move ToComputedValue to the computed module.
|
Thank you for the feedback! I will implement your proposed changes as soon as I have a little more time on my hands. :) |
|
Hey, I have now moved type CounterIncrement = CounterIntegerList<Integer>;
type CounterReset = CounterIntegerList<Integer>(computed values respectively with The issue I'm having right now is that both Can you give me some hint how to best achieve this? Thanks! |
|
Hey, sorry for the huge lag, I missed that comment :(. You would wrap the type in a newtype and implement pub struct CounterIncrement(CounterIntegerList<Integer>);
impl Parse for CounterIncrement {
fn parse(..) -> .. {
Ok(CounterIncrement(CounterIntegerList::parse_with_default(1)?))
}
}
// .. |
|
(Or something of the sort). Thanks a lot again @DonatJR, and sorry again for the huge lag. If you're busy or whatever feel free to push your changes without that and I can finish it up. |
|
@emilio No worries and thanks for the tip, I will probably get to it in the next few days. :) |
|
hey @emilio sorry this took so long, I implemented the two properties by wrapping the generic type like you suggested, unfortunately this required me to add and change a few lines / files more than previously |
emilio
left a comment
There was a problem hiding this comment.
Over all looks good, thank you!
I need to maybe take a closer look tomorrow, but there are some nits I'd rather point out now.
Thank you!
|
|
||
| /// Returns a clone of the values of the CounterIntegerList object. | ||
| pub fn get_values(&self) -> Vec<(CustomIdent, I)> where I: Copy { | ||
| self.0.clone() |
There was a problem hiding this comment.
Let's make this return a reference, please, instead of a vector by value, which implies allocating and copying
There was a problem hiding this comment.
Hmm, and actually, I wonder if there are a few places (like in gecko.mako.rs, where we'd benefit / need from take_values().
There was a problem hiding this comment.
I don't think it is needed (at least I got the geckolib to build without it), but I'm not sure about there being a benefit at some point...
| pub struct CounterIncrement<Integer>(Box<[(CustomIdent, Integer)]); | ||
| /// Keyword `none` is represented by an empty vector. | ||
| #[derive(Clone, Debug, MallocSizeOf, PartialEq)] | ||
| pub struct CounterIntegerList<I>(Vec<(CustomIdent, I)>); |
There was a problem hiding this comment.
This was a Box<[]> very intentionally, to save a word of memory.
| use values::CustomIdent; | ||
|
|
||
| /// A generic value for the `counter-increment` property. | ||
| // use values::computed::{Context, CounterReset as ComputedValue, ToComputedValue}; |
|
|
||
| impl ToCss for CounterReset { | ||
| fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result | ||
| where W: fmt::Write, |
There was a problem hiding this comment.
nit: Indentation looks off here.
emilio
left a comment
There was a problem hiding this comment.
Looks good! Just noticed we can clean it up a bit more to avoid duplication.
| } | ||
| } | ||
|
|
||
| impl ToCss for CounterIncrement { |
| type ComputedValue = CounterIncrement; | ||
|
|
||
| fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { | ||
| CounterIncrement::new(self.get_values().iter().map(|&(ref name, ref value)| { |
There was a problem hiding this comment.
This doesn't need to do this, instead, let's use self.0.to_computed_value() and derive(ToComputedValue).
There was a problem hiding this comment.
(I think CounterIntegerList already implements ToComputedValue, so you'd only need to call it here).
| pub struct CounterReset(ComputedIntegerList); | ||
|
|
||
| impl ToCss for CounterReset { | ||
| fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result |
|
|
||
| fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { | ||
| CounterReset::new(self.get_values().iter().map(|&(ref name, ref value)| { | ||
| (name.clone(), value.to_computed_value(context)) |
There was a problem hiding this comment.
This needs the same change as CounterIncrement.
| } | ||
| } | ||
|
|
||
| impl ToCss for CounterIncrement { |
| } | ||
| } | ||
|
|
||
| impl ToCss for CounterReset { |
emilio
left a comment
There was a problem hiding this comment.
Looks great, thank you! mind squashing your commits?
|
not at all, go ahead! and thanks again for all the great feedback |
|
Since this ended up being somewhat non-trivial, just for sanity I pushed a Gecko try run: https://treeherder.mozilla.org/#/jobs?repo=try&revision=3da82ff05b6c418a530524910aaa0957011284a0 Assuming everything is green there we can go ahead and merge this. Thanks a lot again! |
f02fc0f to
d24301b
Compare
|
Looks green! @bors-servo r+ |
|
📌 Commit d24301b has been approved by |
style: moved css longhand counter-reset out of mako <!-- Please describe your changes on the following line: --> This is a sub-PR of #19015 Code does not yet compile with `build-geckolib`. r? emilio --- <!-- 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 #19387 <!-- Either: --> - [x] These changes do not require tests <!-- 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/19529) <!-- Reviewable:end -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
This is a sub-PR of #19015
Code does not yet compile with
build-geckolib.r? emilio
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is