mirror of
https://github.com/servo/servo.git
synced 2025-06-30 12:03:38 +01:00
Add stylo FFI for CSSRuleList
This commit is contained in:
parent
210b1be1d0
commit
9d4ab0d3e9
5 changed files with 105 additions and 4 deletions
|
@ -328,8 +328,13 @@ COMPILATION_TARGETS = {
|
||||||
"nsStyleVisibility",
|
"nsStyleVisibility",
|
||||||
"nsStyleXUL",
|
"nsStyleXUL",
|
||||||
],
|
],
|
||||||
|
"array_types": {
|
||||||
|
"uintptr_t": "usize",
|
||||||
|
},
|
||||||
"servo_nullable_arc_types": [
|
"servo_nullable_arc_types": [
|
||||||
"ServoComputedValues", "RawServoStyleSheet",
|
"ServoComputedValues",
|
||||||
|
"ServoCssRules",
|
||||||
|
"RawServoStyleSheet",
|
||||||
"RawServoDeclarationBlock"
|
"RawServoDeclarationBlock"
|
||||||
],
|
],
|
||||||
"servo_owned_types": [
|
"servo_owned_types": [
|
||||||
|
@ -535,6 +540,14 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
|
||||||
flags.append("--opaque-type")
|
flags.append("--opaque-type")
|
||||||
flags.append(ty)
|
flags.append(ty)
|
||||||
|
|
||||||
|
if "array_types" in current_target:
|
||||||
|
for cpp_type, rust_type in current_target["array_types"].items():
|
||||||
|
flags.append("--blacklist-type")
|
||||||
|
flags.append("nsTArrayBorrowed_{}".format(cpp_type))
|
||||||
|
flags.append("--raw-line")
|
||||||
|
flags.append("pub type nsTArrayBorrowed_{0}<'a> = &'a mut ::gecko_bindings::structs::nsTArray<{1}>;"
|
||||||
|
.format(cpp_type, rust_type))
|
||||||
|
|
||||||
if "blacklist_types" in current_target:
|
if "blacklist_types" in current_target:
|
||||||
for ty in current_target["blacklist_types"]:
|
for ty in current_target["blacklist_types"]:
|
||||||
flags.append("--blacklist-type")
|
flags.append("--blacklist-type")
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use gecko::values::{convert_rgba_to_nscolor, StyleCoordHelpers};
|
use gecko::values::{convert_rgba_to_nscolor, StyleCoordHelpers};
|
||||||
use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue};
|
use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue};
|
||||||
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, ServoComputedValues};
|
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, ServoComputedValues, ServoCssRules};
|
||||||
use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
|
use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
|
||||||
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
|
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
|
||||||
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
|
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use properties::{ComputedValues, PropertyDeclarationBlock};
|
use properties::{ComputedValues, PropertyDeclarationBlock};
|
||||||
use stylesheets::Stylesheet;
|
use stylesheets::{CssRule, Stylesheet};
|
||||||
use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto};
|
use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||||
|
|
||||||
unsafe impl HasFFI for Stylesheet {
|
unsafe impl HasFFI for Stylesheet {
|
||||||
|
@ -34,6 +34,11 @@ unsafe impl HasFFI for RwLock<PropertyDeclarationBlock> {
|
||||||
}
|
}
|
||||||
unsafe impl HasArcFFI for RwLock<PropertyDeclarationBlock> {}
|
unsafe impl HasArcFFI for RwLock<PropertyDeclarationBlock> {}
|
||||||
|
|
||||||
|
unsafe impl HasFFI for RwLock<Vec<CssRule>> {
|
||||||
|
type FFIType = ServoCssRules;
|
||||||
|
}
|
||||||
|
unsafe impl HasArcFFI for RwLock<Vec<CssRule>> {}
|
||||||
|
|
||||||
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
|
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
|
||||||
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
|
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
|
||||||
let has_percentage = other.percentage.is_some();
|
let has_percentage = other.percentage.is_some();
|
||||||
|
|
|
@ -3,11 +3,17 @@
|
||||||
pub use nsstring::{nsACString, nsAString};
|
pub use nsstring::{nsACString, nsAString};
|
||||||
type nsACString_internal = nsACString;
|
type nsACString_internal = nsACString;
|
||||||
type nsAString_internal = nsAString;
|
type nsAString_internal = nsAString;
|
||||||
|
pub type nsTArrayBorrowed_uintptr_t<'a> = &'a mut ::gecko_bindings::structs::nsTArray<usize>;
|
||||||
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
|
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
|
||||||
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
|
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
|
||||||
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
|
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
|
||||||
enum ServoComputedValuesVoid{ }
|
enum ServoComputedValuesVoid{ }
|
||||||
pub struct ServoComputedValues(ServoComputedValuesVoid);
|
pub struct ServoComputedValues(ServoComputedValuesVoid);
|
||||||
|
pub type ServoCssRulesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoCssRules>;
|
||||||
|
pub type ServoCssRulesBorrowedOrNull<'a> = Option<&'a ServoCssRules>;
|
||||||
|
pub type ServoCssRulesBorrowed<'a> = &'a ServoCssRules;
|
||||||
|
enum ServoCssRulesVoid{ }
|
||||||
|
pub struct ServoCssRules(ServoCssRulesVoid);
|
||||||
pub type RawServoStyleSheetStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoStyleSheet>;
|
pub type RawServoStyleSheetStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoStyleSheet>;
|
||||||
pub type RawServoStyleSheetBorrowedOrNull<'a> = Option<&'a RawServoStyleSheet>;
|
pub type RawServoStyleSheetBorrowedOrNull<'a> = Option<&'a RawServoStyleSheet>;
|
||||||
pub type RawServoStyleSheetBorrowed<'a> = &'a RawServoStyleSheet;
|
pub type RawServoStyleSheetBorrowed<'a> = &'a RawServoStyleSheet;
|
||||||
|
@ -188,6 +194,12 @@ unsafe impl Sync for nsStyleXUL {}
|
||||||
pub type RawGeckoNode = nsINode;
|
pub type RawGeckoNode = nsINode;
|
||||||
pub type RawGeckoElement = Element;
|
pub type RawGeckoElement = Element;
|
||||||
pub type RawGeckoDocument = nsIDocument;
|
pub type RawGeckoDocument = nsIDocument;
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_CssRules_AddRef(ptr: ServoCssRulesBorrowed);
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_CssRules_Release(ptr: ServoCssRulesBorrowed);
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSheet_AddRef(ptr: RawServoStyleSheetBorrowed);
|
pub fn Servo_StyleSheet_AddRef(ptr: RawServoStyleSheetBorrowed);
|
||||||
}
|
}
|
||||||
|
@ -950,6 +962,10 @@ extern "C" {
|
||||||
pub fn Servo_StyleSheet_HasRules(sheet: RawServoStyleSheetBorrowed)
|
pub fn Servo_StyleSheet_HasRules(sheet: RawServoStyleSheetBorrowed)
|
||||||
-> bool;
|
-> bool;
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_StyleSheet_GetRules(sheet: RawServoStyleSheetBorrowed)
|
||||||
|
-> ServoCssRulesStrong;
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_Init() -> RawServoStyleSetOwned;
|
pub fn Servo_StyleSet_Init() -> RawServoStyleSetOwned;
|
||||||
}
|
}
|
||||||
|
@ -974,6 +990,10 @@ extern "C" {
|
||||||
reference:
|
reference:
|
||||||
RawServoStyleSheetBorrowed);
|
RawServoStyleSheetBorrowed);
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
|
||||||
|
result: nsTArrayBorrowed_uintptr_t);
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ParseProperty(property: *const nsACString_internal,
|
pub fn Servo_ParseProperty(property: *const nsACString_internal,
|
||||||
value: *const nsACString_internal,
|
value: *const nsACString_internal,
|
||||||
|
|
|
@ -136,6 +136,30 @@ pub enum CssRule {
|
||||||
Keyframes(Arc<RwLock<KeyframesRule>>),
|
Keyframes(Arc<RwLock<KeyframesRule>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum CssRuleType {
|
||||||
|
// https://drafts.csswg.org/cssom/#the-cssrule-interface
|
||||||
|
Style = 1,
|
||||||
|
Charset = 2,
|
||||||
|
Import = 3,
|
||||||
|
Media = 4,
|
||||||
|
FontFace = 5,
|
||||||
|
Page = 6,
|
||||||
|
// https://drafts.csswg.org/css-animations-1/#interface-cssrule-idl
|
||||||
|
Keyframes = 7,
|
||||||
|
Keyframe = 8,
|
||||||
|
// https://drafts.csswg.org/cssom/#the-cssrule-interface
|
||||||
|
Margin = 9,
|
||||||
|
Namespace = 10,
|
||||||
|
// https://drafts.csswg.org/css-counter-styles-3/#extentions-to-cssrule-interface
|
||||||
|
CounterStyle = 11,
|
||||||
|
// https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface
|
||||||
|
Supports = 12,
|
||||||
|
// https://drafts.csswg.org/css-fonts-3/#om-fontfeaturevalues
|
||||||
|
FontFeatureValues = 14,
|
||||||
|
// https://drafts.csswg.org/css-device-adapt/#css-rule-interface
|
||||||
|
Viewport = 15,
|
||||||
|
}
|
||||||
|
|
||||||
/// Error reporter which silently forgets errors
|
/// Error reporter which silently forgets errors
|
||||||
pub struct MemoryHoleReporter;
|
pub struct MemoryHoleReporter;
|
||||||
|
|
||||||
|
@ -157,6 +181,17 @@ pub enum SingleRuleParseError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CssRule {
|
impl CssRule {
|
||||||
|
pub fn rule_type(&self) -> CssRuleType {
|
||||||
|
match *self {
|
||||||
|
CssRule::Style(_) => CssRuleType::Style,
|
||||||
|
CssRule::Media(_) => CssRuleType::Media,
|
||||||
|
CssRule::FontFace(_) => CssRuleType::FontFace,
|
||||||
|
CssRule::Keyframes(_) => CssRuleType::Keyframes,
|
||||||
|
CssRule::Namespace(_) => CssRuleType::Namespace,
|
||||||
|
CssRule::Viewport(_) => CssRuleType::Viewport,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Call `f` with the slice of rules directly contained inside this rule.
|
/// Call `f` with the slice of rules directly contained inside this rule.
|
||||||
///
|
///
|
||||||
/// Note that only some types of rules can contain rules. An empty slice is used for others.
|
/// Note that only some types of rules can contain rules. An empty slice is used for others.
|
||||||
|
|
|
@ -26,10 +26,12 @@ use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServo
|
||||||
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
|
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
|
||||||
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
|
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
|
||||||
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
|
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
|
||||||
|
use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong};
|
||||||
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
|
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
|
||||||
use style::gecko_bindings::bindings::{nsACString, nsAString};
|
use style::gecko_bindings::bindings::{nsACString, nsAString};
|
||||||
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
|
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
|
||||||
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
||||||
|
use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
|
||||||
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
||||||
use style::gecko_bindings::structs::ServoElementSnapshot;
|
use style::gecko_bindings::structs::ServoElementSnapshot;
|
||||||
use style::gecko_bindings::structs::nsRestyleHint;
|
use style::gecko_bindings::structs::nsRestyleHint;
|
||||||
|
@ -45,7 +47,7 @@ use style::properties::{apply_declarations, parse_one_declaration};
|
||||||
use style::selector_parser::PseudoElementCascadeType;
|
use style::selector_parser::PseudoElementCascadeType;
|
||||||
use style::sequential;
|
use style::sequential;
|
||||||
use style::string_cache::Atom;
|
use style::string_cache::Atom;
|
||||||
use style::stylesheets::{Origin, Stylesheet};
|
use style::stylesheets::{CssRule, Origin, Stylesheet};
|
||||||
use style::thread_state;
|
use style::thread_state;
|
||||||
use style::timer::Timer;
|
use style::timer::Timer;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
@ -262,6 +264,11 @@ pub extern "C" fn Servo_StyleSheet_HasRules(raw_sheet: RawServoStyleSheetBorrowe
|
||||||
!Stylesheet::as_arc(&raw_sheet).rules.0.read().is_empty()
|
!Stylesheet::as_arc(&raw_sheet).rules.0.read().is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_StyleSheet_GetRules(sheet: RawServoStyleSheetBorrowed) -> ServoCssRulesStrong {
|
||||||
|
Stylesheet::as_arc(&sheet).rules.0.clone().into_strong()
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSheet_AddRef(sheet: RawServoStyleSheetBorrowed) -> () {
|
pub extern "C" fn Servo_StyleSheet_AddRef(sheet: RawServoStyleSheetBorrowed) -> () {
|
||||||
unsafe { Stylesheet::addref(sheet) };
|
unsafe { Stylesheet::addref(sheet) };
|
||||||
|
@ -272,6 +279,27 @@ pub extern "C" fn Servo_StyleSheet_Release(sheet: RawServoStyleSheetBorrowed) ->
|
||||||
unsafe { Stylesheet::release(sheet) };
|
unsafe { Stylesheet::release(sheet) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
|
||||||
|
result: nsTArrayBorrowed_uintptr_t) -> () {
|
||||||
|
let rules = RwLock::<Vec<CssRule>>::as_arc(&rules).read();
|
||||||
|
let iter = rules.iter().map(|rule| rule.rule_type() as usize);
|
||||||
|
let (size, upper) = iter.size_hint();
|
||||||
|
debug_assert_eq!(size, upper.unwrap());
|
||||||
|
unsafe { result.set_len(size as u32) };
|
||||||
|
result.iter_mut().zip(iter).fold((), |_, (r, v)| *r = v);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_CssRules_AddRef(rules: ServoCssRulesBorrowed) -> () {
|
||||||
|
unsafe { RwLock::<Vec<CssRule>>::addref(rules) };
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_CssRules_Release(rules: ServoCssRulesBorrowed) -> () {
|
||||||
|
unsafe { RwLock::<Vec<CssRule>>::release(rules) };
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
|
pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
|
||||||
-> ServoComputedValuesStrong {
|
-> ServoComputedValuesStrong {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue