Auto merge of #17646 - upsuper:bug1372464, r=heycam

stylo: Use ComputedValues rather than element to get style rule list

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

<!-- 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/17646)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-07-09 20:07:41 -07:00 committed by GitHub
commit 95a85a301f
2 changed files with 24 additions and 29 deletions

View file

@ -2664,17 +2664,18 @@ extern "C" {
ServoComputedValuesBorrowed)
-> ServoComputedValuesStrong;
}
extern "C" {
pub fn Servo_ComputedValues_GetStyleRuleList(values:
ServoComputedValuesBorrowed,
rules:
RawGeckoServoStyleRuleListBorrowedMut);
}
extern "C" {
pub fn Servo_Initialize(dummy_url_data: *mut RawGeckoURLExtraData);
}
extern "C" {
pub fn Servo_Shutdown();
}
extern "C" {
pub fn Servo_Element_GetStyleRuleList(element: RawGeckoElementBorrowed,
rules:
RawGeckoServoStyleRuleListBorrowedMut);
}
extern "C" {
pub fn Servo_NoteExplicitHints(element: RawGeckoElementBorrowed,
restyle_hint: nsRestyleHint,

View file

@ -1705,6 +1705,24 @@ pub extern "C" fn Servo_ComputedValues_SpecifiesAnimationsOrTransitions(values:
b.specifies_animations() || b.specifies_transitions()
}
#[no_mangle]
pub extern "C" fn Servo_ComputedValues_GetStyleRuleList(values: ServoComputedValuesBorrowed,
rules: RawGeckoServoStyleRuleListBorrowedMut) {
let values = ComputedValues::as_arc(&values);
if let Some(ref rule_node) = values.rules {
let mut result = vec![];
for node in rule_node.self_and_ancestors() {
if let &StyleSource::Style(ref rule) = node.style_source() {
result.push(Locked::<StyleRule>::arc_as_borrowed(&rule));
}
}
unsafe { rules.set_len(result.len() as u32) };
for (&src, dest) in result.into_iter().zip(rules.iter_mut()) {
*dest = src;
}
}
}
/// See the comment in `Device` to see why it's ok to pass an owned reference to
/// the pres context (hint: the context outlives the StyleSet, that holds the
/// device alive).
@ -2626,30 +2644,6 @@ unsafe fn maybe_restyle<'a>(data: &'a mut AtomicRefMut<ElementData>,
Some(&mut data.restyle)
}
#[no_mangle]
pub extern "C" fn Servo_Element_GetStyleRuleList(element: RawGeckoElementBorrowed,
rules: RawGeckoServoStyleRuleListBorrowedMut) {
let element = GeckoElement(element);
let data = match element.borrow_data() {
Some(element_data) => element_data,
None => return,
};
let computed = match data.styles.get_primary() {
Some(values) => values,
None => return,
};
let mut result = vec![];
for rule_node in computed.rules().self_and_ancestors() {
if let &StyleSource::Style(ref rule) = rule_node.style_source() {
result.push(Locked::<StyleRule>::arc_as_borrowed(&rule));
}
}
unsafe { rules.set_len(result.len() as u32) };
for (&src, dest) in result.into_iter().zip(rules.iter_mut()) {
*dest = src;
}
}
#[no_mangle]
pub extern "C" fn Servo_NoteExplicitHints(element: RawGeckoElementBorrowed,
restyle_hint: nsRestyleHint,