Support pseudo-element properly in HasAuthorSpecifiedRules.

This commit is contained in:
Xidorn Quan 2017-10-11 10:29:32 +11:00
parent be5839fae6
commit 0c40ae70ed
3 changed files with 28 additions and 19 deletions

View file

@ -2944,7 +2944,9 @@ extern "C" {
primary_style: ServoStyleContextBorrowed); primary_style: ServoStyleContextBorrowed);
} }
extern "C" { extern "C" {
pub fn Servo_HasAuthorSpecifiedRules(element: RawGeckoElementBorrowed, pub fn Servo_HasAuthorSpecifiedRules(style: ServoStyleContextBorrowed,
element: RawGeckoElementBorrowed,
pseudo_type: CSSPseudoElementType,
rule_type_mask: u32, rule_type_mask: u32,
author_colors_allowed: bool) -> bool; author_colors_allowed: bool) -> bool;
} }

View file

@ -7,6 +7,8 @@
//! The rule tree. //! The rule tree.
use applicable_declarations::ApplicableDeclarationList; use applicable_declarations::ApplicableDeclarationList;
#[cfg(feature = "gecko")]
use gecko::selector_parser::PseudoElement;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use heapsize::HeapSizeOf; use heapsize::HeapSizeOf;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
@ -1077,6 +1079,7 @@ impl StrongRuleNode {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub fn has_author_specified_rules<E>(&self, pub fn has_author_specified_rules<E>(&self,
mut element: E, mut element: E,
mut pseudo: Option<PseudoElement>,
guards: &StylesheetGuards, guards: &StylesheetGuards,
rule_type_mask: u32, rule_type_mask: u32,
author_colors_allowed: bool) author_colors_allowed: bool)
@ -1291,14 +1294,20 @@ impl StrongRuleNode {
if !have_explicit_ua_inherit { break } if !have_explicit_ua_inherit { break }
// Continue to the parent element and search for the inherited properties. // Continue to the parent element and search for the inherited properties.
element = match element.inheritance_parent() { if let Some(pseudo) = pseudo.take() {
Some(parent) => parent, if pseudo.inherits_from_default_values() {
None => break break;
}; }
} else {
element = match element.inheritance_parent() {
Some(parent) => parent,
None => break
};
let parent_data = element.mutate_data().unwrap(); let parent_data = element.mutate_data().unwrap();
let parent_rule_node = parent_data.styles.primary().rules().clone(); let parent_rule_node = parent_data.styles.primary().rules().clone();
element_rule_node = Cow::Owned(parent_rule_node); element_rule_node = Cow::Owned(parent_rule_node);
}
properties = inherited_properties; properties = inherited_properties;
} }

View file

@ -1863,26 +1863,24 @@ pub extern "C" fn Servo_SetExplicitStyle(element: RawGeckoElementBorrowed,
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_HasAuthorSpecifiedRules(element: RawGeckoElementBorrowed, pub extern "C" fn Servo_HasAuthorSpecifiedRules(style: ServoStyleContextBorrowed,
element: RawGeckoElementBorrowed,
pseudo_type: CSSPseudoElementType,
rule_type_mask: u32, rule_type_mask: u32,
author_colors_allowed: bool) author_colors_allowed: bool)
-> bool -> bool
{ {
let element = GeckoElement(element); let element = GeckoElement(element);
let pseudo = PseudoElement::from_pseudo_type(pseudo_type);
let data =
element.borrow_data()
.expect("calling Servo_HasAuthorSpecifiedRules on an unstyled element");
let primary_style = data.styles.primary();
let guard = (*GLOBAL_STYLE_DATA).shared_lock.read(); let guard = (*GLOBAL_STYLE_DATA).shared_lock.read();
let guards = StylesheetGuards::same(&guard); let guards = StylesheetGuards::same(&guard);
primary_style.rules().has_author_specified_rules(element, style.rules().has_author_specified_rules(element,
&guards, pseudo,
rule_type_mask, &guards,
author_colors_allowed) rule_type_mask,
author_colors_allowed)
} }
fn get_pseudo_style( fn get_pseudo_style(