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

style: Sync changes from mozilla-central. #22111

Merged
merged 32 commits into from Nov 5, 2018
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
26040d1
style: Remove unused style constant.
emilio Oct 24, 2018
a9af61e
style: Don't allow auto in grid line names.
emilio Oct 28, 2018
a3fcfb6
style: Add a fast path for querySelector{,All} when we have classes o…
emilio Oct 29, 2018
62aaf86
style: Ignore border-image-source when overriding document colors.
Oct 29, 2018
badb8f3
style: Support ::before / ::after on ::slotted pseudos.
emilio Oct 29, 2018
edf6e6a
style: Update cbindgen due to breaking change.
emilio Oct 30, 2018
8bc8a0b
style: Interpolate the angle between mis-matched rotate() functions w…
birtles Oct 30, 2018
b00bbb3
style: Add a special list for cbindgen types to avoid generating redu…
BorisChiou Oct 31, 2018
591a478
style: Use alias for StyleAppearance.
BorisChiou Oct 31, 2018
cb2533d
style: Use alias for StyleDisplay and StyleDisplayMode.
BorisChiou Oct 31, 2018
c7027e2
style: Use alias for StyleFillRule.
BorisChiou Oct 31, 2018
b81bbb8
style: Use alias for StylePathCommand.
BorisChiou Oct 31, 2018
33b2514
style: Drop "mozilla" prefix in cbindgen_types in ServoBindings.toml.
BorisChiou Oct 31, 2018
5976956
style: Handle reversed ranges in @font-face descriptors.
heycam Oct 31, 2018
d43c4ce
style: Support unprefixed image-rendering: crisp-edges.
heycam Nov 1, 2018
52c3ba0
style: Fix inconsistent CRISPEDGES constant name.
heycam Nov 1, 2018
a7b5ba1
style: Use references in the shapes code.
emilio Nov 2, 2018
33fed65
style: Don't match document author rules if not needed for revalidation.
emilio Nov 5, 2018
d035d02
style: Don't keep a separate list of ignored-when-colors-disabled lon…
emilio Nov 5, 2018
282edf1
style: Move shorthand IDL order stuff out of animated_properties.
emilio Nov 4, 2018
f159c20
style: Move the keyframes property priority stuff outside of animated…
emilio Nov 4, 2018
778ae7d
style: Move various length animation implementations to its own file.
emilio Nov 4, 2018
707bd84
style: Move various font-related animation code to its own file.
emilio Nov 4, 2018
8b49ef8
style: Remove nscsspropertyid_is_{animatable,transitionable}.
emilio Nov 4, 2018
c88a483
style: Move animation of svg-related bits outside of animated_propert…
emilio Nov 4, 2018
5af6abf
style: Simplify the SVG animation code.
emilio Nov 4, 2018
b7da1ba
style: Implement the env() function with hardcoded zeros for safe-are…
emilio Nov 5, 2018
99f9d84
style: Simplify invalid custom property handling.
emilio Nov 5, 2018
29f5691
Update remaining references to cssparser 0.24.
emilio Nov 5, 2018
8560c8d
Fix tidy issues.
emilio Nov 5, 2018
64e70e2
style: Add the safe area constant names as atoms.
emilio Nov 5, 2018
ac6f921
style: Fix servo build.
emilio Nov 5, 2018
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

style: Support ::before / ::after on ::slotted pseudos.

See w3c/csswg-drafts#3150 for the issue that would
expand this to all pseudos.

Differential Revision: https://phabricator.services.mozilla.com/D9994
  • Loading branch information
emilio committed Nov 5, 2018
commit badb8f398aefd244febfaf09a63eb68ec1a09470
@@ -36,6 +36,11 @@ pub trait PseudoElement: Sized + ToCss {
) -> bool {
false
}

/// Whether this pseudo-element is valid after a ::slotted(..) pseudo.
fn valid_after_slotted(&self) -> bool {
false
}
}

/// A trait that represents a pseudo-class.
@@ -69,6 +74,8 @@ pub enum SelectorParseErrorKind<'i> {
DanglingCombinator,
NonSimpleSelectorInNegation,
NonCompoundSelector,
NonPseudoElementAfterSlotted,
InvalidPseudoElementAfterSlotted,
UnexpectedTokenInAttributeSelector(Token<'i>),
PseudoElementExpectedColon(Token<'i>),
PseudoElementExpectedIdent(Token<'i>),
@@ -1832,7 +1839,6 @@ where
input.skip_whitespace();

let mut empty = true;
let mut slot = false;
if !parse_type_selector(parser, input, builder)? {
if let Some(url) = parser.default_namespace() {
// If there was no explicit type selector, but there is a
@@ -1845,82 +1851,119 @@ where
}

let mut pseudo = false;
let mut slot = false;
loop {
let parse_result =
match parse_one_simple_selector(parser, input, /* inside_negation = */ false)? {
None => break,
Some(result) => result,
};

empty = false;

let slotted_selector;
let pseudo_element;

match parse_result {
SimpleSelectorParseResult::SimpleSelector(s) => {
builder.push_simple_selector(s);
empty = false
continue;
},
SimpleSelectorParseResult::PseudoElement(p) => {
// Try to parse state to its right. There are only 3 allowable
// state selectors that can go on pseudo-elements.
let mut state_selectors = SmallVec::<[Component<Impl>; 3]>::new();

loop {
let location = input.current_source_location();
match input.next_including_whitespace() {
Ok(&Token::Colon) => {},
Ok(&Token::WhiteSpace(_)) | Err(_) => break,
Ok(t) => {
let e = SelectorParseErrorKind::PseudoElementExpectedColon(t.clone());
return Err(location.new_custom_error(e));
},
slotted_selector = None;
pseudo_element = Some(p);
}
SimpleSelectorParseResult::SlottedPseudo(selector) => {
slotted_selector = Some(selector);
let maybe_pseudo = parse_one_simple_selector(
parser,
input,
/* inside_negation = */ false,
)?;

pseudo_element = match maybe_pseudo {
None => None,
Some(SimpleSelectorParseResult::PseudoElement(pseudo)) => {
if !pseudo.valid_after_slotted() {
return Err(input.new_custom_error(
SelectorParseErrorKind::InvalidPseudoElementAfterSlotted
));
}
Some(pseudo)
}

let location = input.current_source_location();
// TODO(emilio): Functional pseudo-classes too?
// We don't need it for now.
let name = match input.next_including_whitespace()? {
&Token::Ident(ref name) => name.clone(),
t => {
return Err(location.new_custom_error(
SelectorParseErrorKind::NoIdentForPseudo(t.clone()),
))
},
};

let pseudo_class =
P::parse_non_ts_pseudo_class(parser, location, name.clone())?;
if !p.supports_pseudo_class(&pseudo_class) {
Some(SimpleSelectorParseResult::SimpleSelector(..)) |
Some(SimpleSelectorParseResult::SlottedPseudo(..)) => {
return Err(input.new_custom_error(
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name),
SelectorParseErrorKind::NonPseudoElementAfterSlotted
));
}
state_selectors.push(Component::NonTSPseudoClass(pseudo_class));
}
};
}
}

if !builder.is_empty() {
builder.push_combinator(Combinator::PseudoElement);
debug_assert!(slotted_selector.is_some() || pseudo_element.is_some());
// Try to parse state to the right of the pseudo-element.
//
// There are only 3 allowable state selectors that can go on
// pseudo-elements as of right now.
let mut state_selectors = SmallVec::<[Component<Impl>; 3]>::new();
if let Some(ref p) = pseudo_element {
loop {
let location = input.current_source_location();
match input.next_including_whitespace() {
Ok(&Token::Colon) => {},
Ok(&Token::WhiteSpace(_)) | Err(_) => break,
Ok(t) => {
let e = SelectorParseErrorKind::PseudoElementExpectedColon(t.clone());
return Err(location.new_custom_error(e));
},
}

builder.push_simple_selector(Component::PseudoElement(p));
for state_selector in state_selectors.drain() {
builder.push_simple_selector(state_selector);
}
let location = input.current_source_location();
// TODO(emilio): Functional pseudo-classes too?
// We don't need it for now.
let name = match input.next_including_whitespace()? {
&Token::Ident(ref name) => name.clone(),
t => {
return Err(location.new_custom_error(
SelectorParseErrorKind::NoIdentForPseudo(t.clone()),
))
},
};

pseudo = true;
empty = false;
break;
},
SimpleSelectorParseResult::SlottedPseudo(selector) => {
empty = false;
slot = true;
if !builder.is_empty() {
builder.push_combinator(Combinator::SlotAssignment);
let pseudo_class =
P::parse_non_ts_pseudo_class(parser, location, name.clone())?;
if !p.supports_pseudo_class(&pseudo_class) {
return Err(input.new_custom_error(
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name),
));
}
builder.push_simple_selector(Component::Slotted(selector));
// FIXME(emilio): ::slotted() should support ::before and
// ::after after it, so we shouldn't break, but we shouldn't
// push more type selectors either.
break;
},
state_selectors.push(Component::NonTSPseudoClass(pseudo_class));
}
}

if let Some(slotted) = slotted_selector {
slot = true;
if !builder.is_empty() {
builder.push_combinator(Combinator::SlotAssignment);
}
builder.push_simple_selector(Component::Slotted(slotted));
}

if let Some(p) = pseudo_element {
pseudo = true;
if !builder.is_empty() {
builder.push_combinator(Combinator::PseudoElement);
}

builder.push_simple_selector(Component::PseudoElement(p));

for state_selector in state_selectors.drain() {
builder.push_simple_selector(state_selector);
}
}

break;
}
if empty {
// An empty selector is invalid.
@@ -2133,6 +2176,10 @@ pub mod tests {
PseudoClass::Active | PseudoClass::Lang(..) => false,
}
}

fn valid_after_slotted(&self) -> bool {
true
}
}

impl parser::NonTSPseudoClass for PseudoClass {
@@ -2818,8 +2865,7 @@ pub mod tests {
assert!(parse("div + slot::slotted(div)").is_ok());
assert!(parse("div + slot::slotted(div.foo)").is_ok());
assert!(parse("slot::slotted(div,foo)::first-line").is_err());
// TODO
assert!(parse("::slotted(div)::before").is_err());
assert!(parse("::slotted(div)::before").is_ok());
assert!(parse("slot::slotted(div,foo)").is_err());
}

@@ -27,6 +27,14 @@ include!(concat!(
impl ::selectors::parser::PseudoElement for PseudoElement {
type Impl = SelectorImpl;

fn valid_after_slotted(&self) -> bool {
// TODO(emilio): Remove this function or this comment after [1] is
// resolved.
//
// [1]: https://github.com/w3c/csswg-drafts/issues/3150
self.is_before_or_after()
}

fn supports_pseudo_class(&self, pseudo_class: &NonTSPseudoClass) -> bool {
if !self.supports_user_action_state() {
return false;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.