Closed Bug 1370501 Opened 7 years ago Closed 7 years ago

stylo: Implement ServoStyleRule::GetSpecificity

Categories

(Core :: CSS Parsing and Computation, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: ferjm, Assigned: ferjm)

References

Details

Attachments

(2 files)

      No description provided.
Summary: stylo: Implement inDOMUtils::GetSpecificity → stylo: Implement ServoStyleRule::GetSpecificity
Assignee: nobody → ferjmoreno
Comment on attachment 8876042 [details]
Bug 1370501 - stylo: Fix ServoStyleRule::GetSelectorTextFromIndex.

https://reviewboard.mozilla.org/r/147496/#review151788

::: servo/components/selectors/parser.rs:191
(Diff revision 1)
>      }
> +
> +    pub fn specificity(&self, from_index: usize) -> u32 {
> +        let mut result = 0;
> +        let iter = self.0.iter().skip(from_index);
> +        for selector_and_hashes in iter {

So, this is wrong, afaict. You're summing the specificity of the complex selectors in the selector list, and that's definitely not what this code does on Gecko.

The `aSelectorIndex` parameter means the selector in this selector list at index `aSelectorIndex`.

The confusion is that the equivalent to `Selector` in Servo is `nsCSSSelectorList*`. Oh well.

So this needs to effectively return `self.0[index].specificity()`, but not crash if the index is invalid.

I misreviewed the `GetSelectorTextFromIndex` because you named the function `FromIndex`, but what it is doing is `AtIndex`. So it needs to do `self.0[index].to_css()`, not all the following selectors. Please fix that too.
Attachment #8876042 - Flags: review?(emilio+bugs) → review-
Comment on attachment 8876042 [details]
Bug 1370501 - stylo: Fix ServoStyleRule::GetSelectorTextFromIndex.

https://reviewboard.mozilla.org/r/147496/#review151858

::: servo/components/selectors/parser.rs:171
(Diff revision 2)
>      /// Creates a SelectorList from a Vec of selectors. Used in tests.
>      pub fn from_vec(v: Vec<Selector<Impl>>) -> Self {
>          SelectorList(v.into_iter().map(SelectorAndHashes::new).collect())
>      }
>  
> -    pub fn to_css_from_index<W>(&self, from_index: usize, dest: &mut W)
> +    pub fn to_css_at_index<W>(&self, index: usize, dest: &mut W)

I'd consider to just inline this in the glue.rs file, it's unlikely we want to reuse this.

::: servo/components/selectors/parser.rs:176
(Diff revision 2)
> -        first.selector.to_css(dest)?;
> -        for selector_and_hashes in iter {
> -            dest.write_str(", ")?;
> -            selector_and_hashes.selector.to_css(dest)?;
>          }
> -        Ok(())
> +        self.0[index].to_css()

`to_css(dest)`, right?
Attachment #8876042 - Flags: review?(emilio+bugs) → review+
Comment on attachment 8876151 [details]
Bug 1370501 - stylo: Implement ServoStyleRule::GetSpecificity.

https://reviewboard.mozilla.org/r/147562/#review151860

::: servo/components/selectors/parser.rs:176
(Diff revision 1)
>      pub fn to_css_at_index<W>(&self, index: usize, dest: &mut W)
>          -> fmt::Result where W: fmt::Write {
>          if index >= self.0.len() {
>              return Ok(());
>          }
> -        self.0[index].to_css()
> +        self.0[index].selector.to_css(dest)

heh, you fixed it here, please move this part to the previous commit.

::: servo/components/selectors/parser.rs:179
(Diff revision 1)
>              return Ok(());
>          }
> -        self.0[index].to_css()
> +        self.0[index].selector.to_css(dest)
> +    }
> +
> +    pub fn specificity(&self, index: usize) -> u32 {

similarly, the error handling here is unconventional, so let's inline this in glue.rs
Attachment #8876151 - Flags: review?(emilio+bugs) → review+
Pushed by ferjmoreno@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/31d8aedf2c5a
stylo: Fix ServoStyleRule::GetSelectorTextFromIndex. r=emilio
https://hg.mozilla.org/integration/autoland/rev/d38ff648548c
stylo: Implement ServoStyleRule::GetSpecificity. r=emilio
https://hg.mozilla.org/mozilla-central/rev/31d8aedf2c5a
https://hg.mozilla.org/mozilla-central/rev/d38ff648548c
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: