diff --git a/components/style/gecko/pseudo_element.rs b/components/style/gecko/pseudo_element.rs index 7538b785858..dffd5acf086 100644 --- a/components/style/gecko/pseudo_element.rs +++ b/components/style/gecko/pseudo_element.rs @@ -116,6 +116,12 @@ impl PseudoElement { *self == PseudoElement::Marker } + /// Whether this pseudo-element is the ::selection pseudo. + #[inline] + pub fn is_selection(&self) -> bool { + *self == PseudoElement::Selection + } + /// Whether this pseudo-element is ::first-letter. #[inline] pub fn is_first_letter(&self) -> bool { diff --git a/components/style/invalidation/element/invalidator.rs b/components/style/invalidation/element/invalidator.rs index f00aa57fcff..414c81ee52b 100644 --- a/components/style/invalidation/element/invalidator.rs +++ b/components/style/invalidation/element/invalidator.rs @@ -805,6 +805,19 @@ where if pseudo.is_marker() && self.element.marker_pseudo_element().is_none() { invalidated_self = true; } + + // FIXME: ::selection doesn't generate elements, so the + // regular invalidation doesn't work for it. We store + // the cached selection style holding off the originating + // element, so we need to restyle it in order to invalidate + // it. This is still not quite correct, since nothing + // triggers a repaint necessarily, but matches old Gecko + // behavior, and the ::selection implementation needs to + // change significantly anyway to implement + // https://github.com/w3c/csswg-drafts/issues/2474. + if pseudo.is_selection() { + invalidated_self = true; + } } } diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs index 1ef49c87f9f..4bf3f38822a 100644 --- a/components/style/servo/selector_parser.rs +++ b/components/style/servo/selector_parser.rs @@ -143,6 +143,12 @@ impl PseudoElement { false } + /// Whether this pseudo-element is the ::selection pseudo. + #[inline] + pub fn is_selection(&self) -> bool { + *self == PseudoElement::Selection + } + /// Whether this pseudo-element is the ::before pseudo. #[inline] pub fn is_before(&self) -> bool {