Auto merge of #16328 - bradwerth:computedStyles, r=heycam

Stylo: Add FFI interfaces for exposing style sources.

https://bugzilla.mozilla.org/show_bug.cgi?id=1346256
https://reviewboard.mozilla.org/r/119044/

<!-- 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/16328)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-10 04:04:54 -05:00 committed by GitHub
commit a0a60ba61d
6 changed files with 59 additions and 6 deletions

View file

@ -615,9 +615,11 @@ mod bindings {
"RawServoAnimationValue",
"RawServoAnimationValueMap",
"RawServoDeclarationBlock",
"RawServoStyleRule",
"RawGeckoPresContext",
"RawGeckoPresContextOwned",
"RawGeckoStyleAnimationList",
"RawGeckoServoStyleRuleList",
"RawGeckoURLExtraData",
"RefPtr",
"CSSPseudoClassType",
@ -733,6 +735,7 @@ mod bindings {
"RawGeckoKeyframeList",
"RawGeckoComputedKeyframeValuesList",
"RawGeckoFontFaceRuleList",
"RawGeckoServoStyleRuleList",
];
for &ty in structs_types.iter() {
builder = builder.hide_type(ty)

View file

@ -9,9 +9,10 @@
#![allow(non_snake_case, missing_docs)]
use gecko_bindings::bindings::{RawServoMediaList, RawServoMediaRule, RawServoNamespaceRule, RawServoPageRule};
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoStyleRule, RawServoImportRule};
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoImportRule};
use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules};
use gecko_bindings::structs::{RawServoAnimationValue, RawServoAnimationValueMap, RawServoDeclarationBlock};
use gecko_bindings::structs::{RawServoAnimationValue, RawServoAnimationValueMap};
use gecko_bindings::structs::{RawServoDeclarationBlock, RawServoStyleRule};
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
use media_queries::MediaList;
use parking_lot::RwLock;

View file

@ -16,9 +16,11 @@ use gecko_bindings::structs::RawGeckoAnimationValueList;
use gecko_bindings::structs::RawServoAnimationValue;
use gecko_bindings::structs::RawServoAnimationValueMap;
use gecko_bindings::structs::RawServoDeclarationBlock;
use gecko_bindings::structs::RawServoStyleRule;
use gecko_bindings::structs::RawGeckoPresContext;
use gecko_bindings::structs::RawGeckoPresContextOwned;
use gecko_bindings::structs::RawGeckoStyleAnimationList;
use gecko_bindings::structs::RawGeckoServoStyleRuleList;
use gecko_bindings::structs::RawGeckoURLExtraData;
use gecko_bindings::structs::RefPtr;
use gecko_bindings::structs::CSSPseudoClassType;
@ -208,8 +210,6 @@ pub type RawServoDeclarationBlockBorrowedOrNull<'a> = Option<&'a RawServoDeclara
pub type RawServoStyleRuleStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoStyleRule>;
pub type RawServoStyleRuleBorrowed<'a> = &'a RawServoStyleRule;
pub type RawServoStyleRuleBorrowedOrNull<'a> = Option<&'a RawServoStyleRule>;
enum RawServoStyleRuleVoid { }
pub struct RawServoStyleRule(RawServoStyleRuleVoid);
pub type RawServoImportRuleStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoImportRule>;
pub type RawServoImportRuleBorrowed<'a> = &'a RawServoImportRule;
pub type RawServoImportRuleBorrowedOrNull<'a> = Option<&'a RawServoImportRule>;
@ -307,6 +307,10 @@ pub type RawGeckoFontFaceRuleListBorrowed<'a> = &'a RawGeckoFontFaceRuleList;
pub type RawGeckoFontFaceRuleListBorrowedOrNull<'a> = Option<&'a RawGeckoFontFaceRuleList>;
pub type RawGeckoFontFaceRuleListBorrowedMut<'a> = &'a mut RawGeckoFontFaceRuleList;
pub type RawGeckoFontFaceRuleListBorrowedMutOrNull<'a> = Option<&'a mut RawGeckoFontFaceRuleList>;
pub type RawGeckoServoStyleRuleListBorrowed<'a> = &'a RawGeckoServoStyleRuleList;
pub type RawGeckoServoStyleRuleListBorrowedOrNull<'a> = Option<&'a RawGeckoServoStyleRuleList>;
pub type RawGeckoServoStyleRuleListBorrowedMut<'a> = &'a mut RawGeckoServoStyleRuleList;
pub type RawGeckoServoStyleRuleListBorrowedMutOrNull<'a> = Option<&'a mut RawGeckoServoStyleRuleList>;
extern "C" {
pub fn Gecko_EnsureTArrayCapacity(aArray: *mut ::std::os::raw::c_void,
@ -1918,6 +1922,11 @@ extern "C" {
pub fn Servo_Element_GetSnapshot(element: RawGeckoElementBorrowed)
-> *mut ServoElementSnapshot;
}
extern "C" {
pub fn Servo_Element_GetStyleRuleList(element: RawGeckoElementBorrowed,
rules:
RawGeckoServoStyleRuleListBorrowedMut);
}
extern "C" {
pub fn Servo_NoteExplicitHints(element: RawGeckoElementBorrowed,
restyle_hint: nsRestyleHint,

View file

@ -26659,6 +26659,9 @@ pub mod root {
pub struct RawServoDeclarationBlock([u8; 0]);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct RawServoStyleRule([u8; 0]);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct RawServoAnimationValue([u8; 0]);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@ -26680,6 +26683,8 @@ pub mod root {
pub type RawGeckoAnimationPropertySegment =
root::mozilla::AnimationPropertySegment;
pub type RawGeckoComputedTiming = root::mozilla::ComputedTiming;
pub type RawGeckoServoStyleRuleList =
root::nsTArray<*const root::RawServoStyleRule>;
pub type RawServoAnimationValueMapBorrowed =
*const root::RawServoAnimationValueMap;
pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode;
@ -26706,6 +26711,8 @@ pub mod root {
*const root::RawGeckoAnimationPropertySegment;
pub type RawGeckoComputedTimingBorrowed =
*const root::RawGeckoComputedTiming;
pub type RawGeckoServoStyleRuleListBorrowedMut =
*mut root::RawGeckoServoStyleRuleList;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct nsSVGAngle([u8; 0]);

View file

@ -26000,6 +26000,9 @@ pub mod root {
pub struct RawServoDeclarationBlock([u8; 0]);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct RawServoStyleRule([u8; 0]);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct RawServoAnimationValue([u8; 0]);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@ -26021,6 +26024,8 @@ pub mod root {
pub type RawGeckoAnimationPropertySegment =
root::mozilla::AnimationPropertySegment;
pub type RawGeckoComputedTiming = root::mozilla::ComputedTiming;
pub type RawGeckoServoStyleRuleList =
root::nsTArray<*const root::RawServoStyleRule>;
pub type RawServoAnimationValueMapBorrowed =
*const root::RawServoAnimationValueMap;
pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode;
@ -26047,6 +26052,8 @@ pub mod root {
*const root::RawGeckoAnimationPropertySegment;
pub type RawGeckoComputedTimingBorrowed =
*const root::RawGeckoComputedTiming;
pub type RawGeckoServoStyleRuleListBorrowedMut =
*mut root::RawGeckoServoStyleRuleList;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct nsSVGAngle([u8; 0]);

View file

@ -34,7 +34,6 @@ use style::gecko_bindings::bindings::{RawServoMediaListBorrowed, RawServoMediaLi
use style::gecko_bindings::bindings::{RawServoMediaRule, RawServoMediaRuleBorrowed};
use style::gecko_bindings::bindings::{RawServoNamespaceRule, RawServoNamespaceRuleBorrowed};
use style::gecko_bindings::bindings::{RawServoPageRule, RawServoPageRuleBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleRule, RawServoStyleRuleBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
@ -46,20 +45,22 @@ use style::gecko_bindings::bindings::RawGeckoComputedKeyframeValuesListBorrowedM
use style::gecko_bindings::bindings::RawGeckoComputedTimingBorrowed;
use style::gecko_bindings::bindings::RawGeckoElementBorrowed;
use style::gecko_bindings::bindings::RawGeckoFontFaceRuleListBorrowedMut;
use style::gecko_bindings::bindings::RawGeckoServoStyleRuleListBorrowedMut;
use style::gecko_bindings::bindings::RawServoAnimationValueBorrowed;
use style::gecko_bindings::bindings::RawServoAnimationValueMapBorrowed;
use style::gecko_bindings::bindings::RawServoAnimationValueStrong;
use style::gecko_bindings::bindings::RawServoImportRuleBorrowed;
use style::gecko_bindings::bindings::RawServoStyleRuleBorrowed;
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
use style::gecko_bindings::structs;
use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleSheet};
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom, nsCSSPropertyID};
use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, nsCSSFontFaceRule};
use style::gecko_bindings::structs::Loader;
use style::gecko_bindings::structs::RawGeckoPresContextOwned;
use style::gecko_bindings::structs::ServoStyleSheet;
use style::gecko_bindings::structs::URLExtraData;
use style::gecko_bindings::structs::nsCSSValueSharedList;
use style::gecko_bindings::structs::nsresult;
@ -77,6 +78,7 @@ use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
use style::properties::animated_properties::{AnimationValue, Interpolate, TransitionProperty};
use style::properties::parse_one_declaration;
use style::restyle_hints::{self, RestyleHint};
use style::rule_tree::StyleSource;
use style::selector_parser::PseudoElementCascadeType;
use style::sequential;
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard, Locked};
@ -1560,6 +1562,30 @@ pub extern "C" fn Servo_Element_GetSnapshot(element: RawGeckoElementBorrowed) ->
snapshot
}
#[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.get_styles() {
Some(styles) => &styles.primary,
None => return,
};
let mut result = vec![];
for rule_node in computed.rules.self_and_ancestors() {
if let Some(&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,