mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add stylo FFI for CSSStyleRule
This commit is contained in:
parent
9d4ab0d3e9
commit
a9296bc89c
4 changed files with 50 additions and 4 deletions
|
@ -335,7 +335,8 @@ COMPILATION_TARGETS = {
|
|||
"ServoComputedValues",
|
||||
"ServoCssRules",
|
||||
"RawServoStyleSheet",
|
||||
"RawServoDeclarationBlock"
|
||||
"RawServoDeclarationBlock",
|
||||
"RawServoStyleRule",
|
||||
],
|
||||
"servo_owned_types": [
|
||||
"RawServoStyleSet",
|
||||
|
|
|
@ -11,13 +11,14 @@
|
|||
use app_units::Au;
|
||||
use gecko::values::{convert_rgba_to_nscolor, StyleCoordHelpers};
|
||||
use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue};
|
||||
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, ServoComputedValues, ServoCssRules};
|
||||
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, RawServoStyleRule};
|
||||
use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules};
|
||||
use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
|
||||
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
|
||||
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
|
||||
use parking_lot::RwLock;
|
||||
use properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
use stylesheets::{CssRule, Stylesheet};
|
||||
use stylesheets::{CssRule, Stylesheet, StyleRule};
|
||||
use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
|
||||
unsafe impl HasFFI for Stylesheet {
|
||||
|
@ -39,6 +40,11 @@ unsafe impl HasFFI for RwLock<Vec<CssRule>> {
|
|||
}
|
||||
unsafe impl HasArcFFI for RwLock<Vec<CssRule>> {}
|
||||
|
||||
unsafe impl HasFFI for RwLock<StyleRule> {
|
||||
type FFIType = RawServoStyleRule;
|
||||
}
|
||||
unsafe impl HasArcFFI for RwLock<StyleRule> {}
|
||||
|
||||
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
|
||||
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
|
||||
let has_percentage = other.percentage.is_some();
|
||||
|
|
|
@ -24,6 +24,11 @@ pub type RawServoDeclarationBlockBorrowedOrNull<'a> = Option<&'a RawServoDeclara
|
|||
pub type RawServoDeclarationBlockBorrowed<'a> = &'a RawServoDeclarationBlock;
|
||||
enum RawServoDeclarationBlockVoid{ }
|
||||
pub struct RawServoDeclarationBlock(RawServoDeclarationBlockVoid);
|
||||
pub type RawServoStyleRuleStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoStyleRule>;
|
||||
pub type RawServoStyleRuleBorrowedOrNull<'a> = Option<&'a RawServoStyleRule>;
|
||||
pub type RawServoStyleRuleBorrowed<'a> = &'a RawServoStyleRule;
|
||||
enum RawServoStyleRuleVoid{ }
|
||||
pub struct RawServoStyleRule(RawServoStyleRuleVoid);
|
||||
pub type RawGeckoNodeBorrowed<'a> = &'a RawGeckoNode;
|
||||
pub type RawGeckoNodeBorrowedOrNull<'a> = Option<&'a RawGeckoNode>;
|
||||
pub type RawGeckoElementBorrowed<'a> = &'a RawGeckoElement;
|
||||
|
@ -220,6 +225,12 @@ extern "C" {
|
|||
pub fn Servo_DeclarationBlock_Release(ptr:
|
||||
RawServoDeclarationBlockBorrowed);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_StyleRule_AddRef(ptr: RawServoStyleRuleBorrowed);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_StyleRule_Release(ptr: RawServoStyleRuleBorrowed);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_StyleSet_Drop(ptr: RawServoStyleSetOwned);
|
||||
}
|
||||
|
@ -994,6 +1005,11 @@ extern "C" {
|
|||
pub fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
|
||||
result: nsTArrayBorrowed_uintptr_t);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_CssRules_GetStyleRuleAt(rules: ServoCssRulesBorrowed,
|
||||
index: u32)
|
||||
-> RawServoStyleRuleStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_ParseProperty(property: *const nsACString_internal,
|
||||
value: *const nsACString_internal,
|
||||
|
|
|
@ -23,6 +23,7 @@ use style::gecko::wrapper::{GeckoElement, GeckoNode};
|
|||
use style::gecko::wrapper::DUMMY_BASE_URL;
|
||||
use style::gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoNodeBorrowed};
|
||||
use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong};
|
||||
use style::gecko_bindings::bindings::{RawServoStyleRuleBorrowed, RawServoStyleRuleStrong};
|
||||
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
|
||||
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
|
||||
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
|
||||
|
@ -47,7 +48,7 @@ use style::properties::{apply_declarations, parse_one_declaration};
|
|||
use style::selector_parser::PseudoElementCascadeType;
|
||||
use style::sequential;
|
||||
use style::string_cache::Atom;
|
||||
use style::stylesheets::{CssRule, Origin, Stylesheet};
|
||||
use style::stylesheets::{CssRule, Origin, Stylesheet, StyleRule};
|
||||
use style::thread_state;
|
||||
use style::timer::Timer;
|
||||
use style_traits::ToCss;
|
||||
|
@ -290,6 +291,18 @@ pub extern "C" fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
|
|||
result.iter_mut().zip(iter).fold((), |_, (r, v)| *r = v);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_CssRules_GetStyleRuleAt(rules: ServoCssRulesBorrowed, index: u32)
|
||||
-> RawServoStyleRuleStrong {
|
||||
let rules = RwLock::<Vec<CssRule>>::as_arc(&rules).read();
|
||||
match rules[index as usize] {
|
||||
CssRule::Style(ref rule) => rule.clone().into_strong(),
|
||||
_ => {
|
||||
unreachable!("GetStyleRuleAt should only be called on a style rule");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_CssRules_AddRef(rules: ServoCssRulesBorrowed) -> () {
|
||||
unsafe { RwLock::<Vec<CssRule>>::addref(rules) };
|
||||
|
@ -300,6 +313,16 @@ pub extern "C" fn Servo_CssRules_Release(rules: ServoCssRulesBorrowed) -> () {
|
|||
unsafe { RwLock::<Vec<CssRule>>::release(rules) };
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleRule_AddRef(rule: RawServoStyleRuleBorrowed) -> () {
|
||||
unsafe { RwLock::<StyleRule>::addref(rule) };
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () {
|
||||
unsafe { RwLock::<StyleRule>::release(rule) };
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
|
||||
-> ServoComputedValuesStrong {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue