Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1340683 - stylo: Implement the :-moz-any pseudo-class #15966

Merged
merged 1 commit into from Mar 16, 2017

Conversation

@mbrubeck
Copy link
Contributor

mbrubeck commented Mar 15, 2017

Adds support for the non-standard :-moz-any selector.



This change is Reviewable

@highfive
Copy link

highfive commented Mar 15, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/style/gecko/wrapper.rs, components/style/gecko/selector_parser.rs
  • @emilio: components/style/gecko/wrapper.rs, components/style/gecko/selector_parser.rs
@highfive
Copy link

highfive commented Mar 15, 2017

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Mar 15, 2017

@highfive highfive assigned SimonSapin and unassigned emilio Mar 15, 2017
@mbrubeck mbrubeck changed the title Bug 1340683 - stylo: Implement the :-moz-any pseudo-class WIP: Bug 1340683 - stylo: Implement the :-moz-any pseudo-class Mar 15, 2017
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Mar 15, 2017

This still fails the layout/style/test/test_any_dynamic.html mochitest; it doesn't handle dynamic updates correctly. I need to update affects_siblings and other selector methods to take :-moz-any into account.

@@ -120,7 +120,7 @@ pub trait Parser {
}
}

#[derive(PartialEq, Clone, Debug)]
#[derive(PartialEq, Eq, Hash, Clone, Debug)]

This comment has been minimized.

@emilio

emilio Mar 15, 2017

Member

Is this change needed just due to the bounds in SelectorImpls definition?

If so, I believe we can remove them since we switched to conditional compilation in style and should have a concrete type now.

Also, in pseudo-classes it doesn't really matter I think, since we only store PseudoElements in HashMaps.

This comment has been minimized.

@mbrubeck

mbrubeck Mar 15, 2017

Author Contributor

No, it's also required by #[derive(Clone, Eq, Hash, PartialEq)]
for struct ComplexSelector.

@@ -661,7 +661,8 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
NonTSPseudoClass::MozTableBorderNonzero |
NonTSPseudoClass::MozBrowserFrame => unsafe {
Gecko_MatchesElement(pseudo_class.to_gecko_pseudoclasstype().unwrap(), self.0)
}
},
NonTSPseudoClass::MozAny(ref selectors) => matches(&selectors.0, self, None),

This comment has been minimized.

@emilio

emilio Mar 15, 2017

Member

This doesn't pass the ElementFlags, nor the StyleRelations here. I believe it should be ok, because we unconditionally insert the appropriate flag for all the custom non-tree-structural pseudo-classes, and because of the limit on only-descendant combinators.

Can you verify that something like http://searchfox.org/mozilla-central/source/layout/reftests/css-selectors/state-dependent-in-any.html (perhaps tweaking manually with :hover or :active, or something we actually implement instead of :valid) works?

This comment has been minimized.

@mbrubeck

mbrubeck Mar 15, 2017

Author Contributor

Can you verify that something like http://searchfox.org/mozilla-central/source/layout/reftests/css-selectors/state-dependent-in-any.html (perhaps tweaking manually with :hover or :active, or something we actually implement instead of :valid) works?

Selectors like :-moz-any(:hover) do not seem to update correctly on state changes; I'm not certain why, since as you said AFFECTED_BY_STATE is always set.

Also, things like :-moz-any(:first-child) are valid and should set HAS_EDGE_CHILD_SELECTOR and AFFECTED_BY_CHILD_INDEX, so I think we do need to pass the relations and flags here.

This comment has been minimized.

@mbrubeck

mbrubeck Mar 15, 2017

Author Contributor

Ah, part of the problem is that pseudo_class_state_flag was not implemented correctly for MozAny.

This comment has been minimized.

@mbrubeck

mbrubeck Mar 15, 2017

Author Contributor

Fixed.

@emilio
Copy link
Member

emilio commented Mar 15, 2017

Oh, I had already started reviewing before you commented :)

Upon reflection, I believe the dynamic changes will not pass until https://bugzilla.mozilla.org/show_bug.cgi?id=1338982 is fixed (I'm going to fix it in https://bugzilla.mozilla.org/show_bug.cgi?id=1345950, but I wanted #15890 to land first)

match_ignore_ascii_case! { &name,
"-moz-any" => {
// https://developer.mozilla.org/en-US/docs/Web/CSS/:any
// The selectors may not contain pseudo-elements and the only combinator allowed is

This comment has been minimized.

@bzbarsky

bzbarsky Mar 15, 2017

Contributor

The devmo docs don't seem to match the code. The code has:

// Check that none of the selectors in the list have combinators or
// pseudo-elements. 

and proceeds to do just that. See http://searchfox.org/mozilla-central/rev/ca7015fa45b30b29176fbaa70ba0a36fe9263c38/layout/style/nsCSSParser.cpp#6511-6518

This comment has been minimized.

@mbrubeck

mbrubeck Mar 15, 2017

Author Contributor

Fixed to match the Gecko code.

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 15, 2017

Note that we also have tests for this at http://searchfox.org/mozilla-central/rev/ca7015fa45b30b29176fbaa70ba0a36fe9263c38/layout/style/test/test_selectors.html#1184-1209 and the second test there tests that descendant combinators don't parse...

But it looks like lack of support for other things earlier in the test (e.g. :placeholder-shown) causes it to throw exceptions that prevent it from even reaching this part. :(

Maybe we should change should_serialize_to to more gracefully handle cases when the selector is not supported at all. :( @upsuper

@mbrubeck mbrubeck force-pushed the mbrubeck:any branch from 435611e to 3058019 Mar 15, 2017
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Mar 15, 2017

I need to update affects_siblings and other selector methods to take :-moz-any into account.

Done. I think this is ready for re-review now.

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Mar 15, 2017

Oops, I didn't see all of the review comments because I hadn't refreshed the page. Addressing some more..

@mbrubeck mbrubeck force-pushed the mbrubeck:any branch 2 times, most recently from b72298c to 10ad449 Mar 15, 2017
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Mar 15, 2017

Updated to correctly calculate ElementStyleFlags, ElementState, and StyleRelations for selectors like :-moz-any(:hover).

@bors-servo
Copy link
Contributor

bors-servo commented Mar 16, 2017

The latest upstream changes (presumably #15971) made this pull request unmergeable. Please resolve the merge conflicts.

@mbrubeck mbrubeck force-pushed the mbrubeck:any branch from 10ad449 to 097222a Mar 16, 2017
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Mar 16, 2017

Rebased.

@emilio emilio assigned emilio and unassigned SimonSapin Mar 16, 2017
@mbrubeck mbrubeck changed the title WIP: Bug 1340683 - stylo: Implement the :-moz-any pseudo-class Bug 1340683 - stylo: Implement the :-moz-any pseudo-class Mar 16, 2017
@emilio
emilio approved these changes Mar 16, 2017
Copy link
Member

emilio left a comment

Looks good. We've talked over IRC and we'll make sure there are bugs on file for the remaining failures in layout/style/test/test_any_dynamic.html, and layout/style/test/test_bug635286.html.

I'm pretty sure they'll be fixed by:

But better getting them on file.

@@ -207,6 +245,10 @@ impl NonTSPseudoClass {
match *self {
$(NonTSPseudoClass::$name => flag!($state),)*
$(NonTSPseudoClass::$s_name(..) => flag!($s_state),)*
NonTSPseudoClass::MozAny(ref selectors) => {
selectors.iter().fold(ElementState::empty(), |state, s|

This comment has been minimized.

@emilio

emilio Mar 16, 2017

Member

nit: since the closure wraps to the next line, let's just wrap it with braces.

This comment has been minimized.

@mbrubeck

mbrubeck Mar 16, 2017

Author Contributor

Done.

@@ -293,6 +336,11 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> {
let name = String::from(parser.expect_ident_or_string()?).into_boxed_str();
NonTSPseudoClass::$s_name(name)
}, )*
"-moz-any" => {
let selectors = parser.parse_comma_separated(|input|
ComplexSelector::parse(self, input))?;

This comment has been minimized.

@emilio

emilio Mar 16, 2017

Member

same here.

This comment has been minimized.

@mbrubeck

mbrubeck Mar 16, 2017

Author Contributor

Done.

/// Returns the union of any `ElementState` flags for components of a `ComplexSelector`
pub fn complex_selector_to_state(sel: &ComplexSelector<SelectorImpl>) -> ElementState {
sel.compound_selector.iter().fold(ElementState::empty(), |state, s|
state | selector_to_state(s)

This comment has been minimized.

@emilio

emilio Mar 16, 2017

Member

and here.

This comment has been minimized.

@mbrubeck

mbrubeck Mar 16, 2017

Author Contributor

Done.

@emilio
Copy link
Member

emilio commented Mar 16, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Mar 16, 2017

📌 Commit 097222a has been approved by emilio

@emilio
Copy link
Member

emilio commented Mar 16, 2017

Whoops.

@bors-servo r-

Please address the review nits, then r=me

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Mar 16, 2017

@bors-servo r=emilio

@bors-servo
Copy link
Contributor

bors-servo commented Mar 16, 2017

📌 Commit 097222a has been approved by emilio

@mbrubeck mbrubeck force-pushed the mbrubeck:any branch from 097222a to 2872c8b Mar 16, 2017
@mbrubeck
Copy link
Contributor Author

mbrubeck commented Mar 16, 2017

@bors-servo r=emilio

@bors-servo
Copy link
Contributor

bors-servo commented Mar 16, 2017

📌 Commit 2872c8b has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Mar 16, 2017

Testing commit 2872c8b with merge 0a747e2...

bors-servo added a commit that referenced this pull request Mar 16, 2017
Bug 1340683 - stylo: Implement the :-moz-any pseudo-class

Adds support for the non-standard [:-moz-any](https://developer.mozilla.org/en-US/docs/Web/CSS/:any) selector.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix https://bugzilla.mozilla.org/show_bug.cgi?id=1340683
- [x] These changes do not require tests because they are gecko-only

<!-- 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/15966)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Mar 16, 2017

@bors-servo bors-servo merged commit 2872c8b into servo:master Mar 16, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.