From 9ef129295789bfc1741bbd3646739e38bd86e5f1 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 3 Nov 2016 15:03:13 +1100 Subject: [PATCH] Add binding functions for getting/removing property --- components/style/gecko_bindings/bindings.rs | 22 ++++++++++++ ports/geckolib/glue.rs | 38 +++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index b3fa77ee974..e054a37eec9 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -960,6 +960,28 @@ extern "C" { *mut nsAString_internal) -> bool; } +extern "C" { + pub fn Servo_DeclarationBlock_GetPropertyValue(declarations: + RawServoDeclarationBlockBorrowed, + property: *mut nsIAtom, + is_custom: bool, + value: + *mut nsAString_internal); +} +extern "C" { + pub fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: + RawServoDeclarationBlockBorrowed, + property: + *mut nsIAtom, + is_custom: bool) + -> bool; +} +extern "C" { + pub fn Servo_DeclarationBlock_RemoveProperty(declarations: + RawServoDeclarationBlockBorrowed, + property: *mut nsIAtom, + is_custom: bool); +} extern "C" { pub fn Servo_CSSSupports(name: *const nsACString_internal, value: *const nsACString_internal) -> bool; diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index becd1ff7dc0..ce65420c6a9 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -508,6 +508,44 @@ pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDe } } +// FIXME Methods of PropertyDeclarationBlock should take atoms directly. +// This function is just a temporary workaround before that finishes. +fn get_property_name_from_atom(atom: *mut nsIAtom, is_custom: bool) -> String { + let atom = Atom::from(atom); + if !is_custom { + atom.to_string() + } else { + let mut result = String::with_capacity(atom.len() as usize + 2); + write!(result, "--{}", atom).unwrap(); + result + } +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_GetPropertyValue(declarations: RawServoDeclarationBlockBorrowed, + property: *mut nsIAtom, is_custom: bool, + value: *mut nsAString) { + let declarations = RwLock::::as_arc(&declarations); + let property = get_property_name_from_atom(property, is_custom); + declarations.read().property_value_to_css(&property, unsafe { value.as_mut().unwrap() }).unwrap(); +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: RawServoDeclarationBlockBorrowed, + property: *mut nsIAtom, is_custom: bool) -> bool { + let declarations = RwLock::::as_arc(&declarations); + let property = get_property_name_from_atom(property, is_custom); + declarations.read().property_priority(&property).important() +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_RemoveProperty(declarations: RawServoDeclarationBlockBorrowed, + property: *mut nsIAtom, is_custom: bool) { + let declarations = RwLock::::as_arc(&declarations); + let property = get_property_name_from_atom(property, is_custom); + declarations.write().remove_property(&property); +} + #[no_mangle] pub extern "C" fn Servo_CSSSupports(property: *const nsACString, value: *const nsACString) -> bool { let property = unsafe { property.as_ref().unwrap().as_str_unchecked() };