Skip to content

Commit

Permalink
Stylo: Add FFI interfaces for exposing style sources.
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: BlAb8sQ5WYl
  • Loading branch information
bradwerth committed Apr 10, 2017
1 parent a460585 commit bfc7e84
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
3 changes: 3 additions & 0 deletions components/style/build_gecko.rs
Expand Up @@ -614,9 +614,11 @@ mod bindings {
"RawServoAnimationValue",
"RawServoAnimationValueMap",
"RawServoDeclarationBlock",
"RawServoStyleRule",
"RawGeckoPresContext",
"RawGeckoPresContextOwned",
"RawGeckoStyleAnimationList",
"RawGeckoServoStyleRuleList",
"RawGeckoURLExtraData",
"RefPtr",
"CSSPseudoClassType",
Expand Down Expand Up @@ -731,6 +733,7 @@ mod bindings {
"RawGeckoKeyframeList",
"RawGeckoComputedKeyframeValuesList",
"RawGeckoFontFaceRuleList",
"RawGeckoServoStyleRuleList",
];
for &ty in structs_types.iter() {
builder = builder.hide_type(ty)
Expand Down
5 changes: 3 additions & 2 deletions components/style/gecko/arc_types.rs
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -207,8 +209,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>;
Expand Down Expand Up @@ -306,6 +306,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,
Expand Down Expand Up @@ -1911,6 +1915,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,
Expand Down
7 changes: 7 additions & 0 deletions components/style/gecko_bindings/structs_debug.rs
Expand Up @@ -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)]
Expand All @@ -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;
Expand All @@ -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]);
Expand Down
7 changes: 7 additions & 0 deletions components/style/gecko_bindings/structs_release.rs
Expand Up @@ -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)]
Expand All @@ -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;
Expand All @@ -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]);
Expand Down
30 changes: 28 additions & 2 deletions ports/geckolib/glue.rs
Expand Up @@ -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};
Expand All @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bfc7e84

Please sign in to comment.