Auto merge of #18962 - upsuper:tree-pseudos, r=emilio

Support matching for ::-moz-tree-* pseudo-elements

This is the Servo side change of [bug 1397644](https://bugzilla.mozilla.org/show_bug.cgi?id=1397644).

<!-- 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/18962)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-10-20 04:18:53 -05:00 committed by GitHub
commit b1e6f05ae4
13 changed files with 489 additions and 257 deletions

View file

@ -84,6 +84,7 @@ use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong,
use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsAtom, nsCSSPropertyID};
use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule};
use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, PropertyValuePair};
use style::gecko_bindings::structs::AtomArray;
use style::gecko_bindings::structs::IterationCompositeOperation;
use style::gecko_bindings::structs::MallocSizeOf as GeckoMallocSizeOf;
use style::gecko_bindings::structs::OriginFlags;
@ -126,7 +127,7 @@ use style::rule_cache::RuleCacheConditions;
use style::rule_tree::{CascadeLevel, StrongRuleNode, StyleSource};
use style::selector_parser::{PseudoElementCascadeType, SelectorImpl};
use style::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard, Locked};
use style::string_cache::Atom;
use style::string_cache::{Atom, WeakAtom};
use style::style_adjuster::StyleAdjuster;
use style::stylesheets::{CssRule, CssRules, CssRuleType, CssRulesHelpers, DocumentRule};
use style::stylesheets::{FontFeatureValuesRule, ImportRule, KeyframesRule, MediaRule};
@ -1911,6 +1912,7 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
inherited_style,
&*doc_data,
is_probe,
/* matching_func = */ None,
);
match style {
@ -1922,6 +1924,66 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
}
}
fn debug_atom_array(atoms: &AtomArray) -> String {
let mut result = String::from("[");
for atom in atoms.iter() {
if atom.mRawPtr.is_null() {
result += "(null), ";
} else {
let atom = unsafe { WeakAtom::new(atom.mRawPtr) };
write!(result, "{}, ", atom).unwrap();
}
}
result.push(']');
result
}
#[no_mangle]
pub extern "C" fn Servo_ComputedValues_ResolveXULTreePseudoStyle(
element: RawGeckoElementBorrowed,
pseudo_tag: *mut nsAtom,
inherited_style: ServoStyleContextBorrowed,
input_word: *const AtomArray,
raw_data: RawServoStyleSetBorrowed
) -> ServoStyleContextStrong {
let element = GeckoElement(element);
let data = element.borrow_data()
.expect("Calling ResolveXULTreePseudoStyle on unstyled element?");
let pseudo = unsafe {
Atom::with(pseudo_tag, |atom| {
PseudoElement::from_tree_pseudo_atom(atom, Box::new([]))
}).expect("ResolveXULTreePseudoStyle with a non-tree pseudo?")
};
let input_word = unsafe { input_word.as_ref().unwrap() };
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
debug!("ResolveXULTreePseudoStyle: {:?} {:?} {}",
element, pseudo, debug_atom_array(input_word));
let matching_fn = |pseudo: &PseudoElement| {
let args = pseudo.tree_pseudo_args().expect("Not a tree pseudo-element?");
args.iter().all(|atom| {
input_word.iter().any(|item| atom.as_ptr() == item.mRawPtr)
})
};
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
get_pseudo_style(
&guard,
element,
&pseudo,
RuleInclusion::All,
&data.styles,
Some(inherited_style),
&*doc_data,
/* is_probe = */ false,
Some(&matching_fn),
).unwrap().into()
}
#[no_mangle]
pub extern "C" fn Servo_SetExplicitStyle(element: RawGeckoElementBorrowed,
style: ServoStyleContextBorrowed)
@ -1965,6 +2027,7 @@ fn get_pseudo_style(
inherited_styles: Option<&ComputedValues>,
doc_data: &PerDocumentStyleDataImpl,
is_probe: bool,
matching_func: Option<&Fn(&PseudoElement) -> bool>,
) -> Option<Arc<ComputedValues>> {
let style = match pseudo.cascade_type() {
PseudoElementCascadeType::Eager => {
@ -2038,6 +2101,7 @@ fn get_pseudo_style(
base,
is_probe,
&metrics,
matching_func,
)
},
};
@ -3269,6 +3333,7 @@ pub extern "C" fn Servo_ResolveStyleLazily(
/* inherited_styles = */ None,
&*data,
is_probe,
/* matching_func = */ None,
)
}
None => Some(styles.primary().clone()),