From 31945c287f2ac84eb71f3cd0a52286320f1a5c85 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 12 Feb 2017 16:02:29 -0800 Subject: [PATCH] stylo: Add necessary stubbed-out bindings for ServoSpecifiedValues --- components/style/build_gecko.rs | 1 + components/style/gecko_bindings/bindings.rs | 66 ++++++++- ports/geckolib/glue.rs | 145 +++++++++++++------- 3 files changed, 158 insertions(+), 54 deletions(-) diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index 58064f4f897..23361cc1734 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -584,6 +584,7 @@ mod bindings { "nsStyleVisibility", "nsStyleXUL", "nsTimingFunction", + "nscolor", "nscoord", "nsresult", "Loader", diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 415bf710781..e79b7f47dd3 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -159,6 +159,7 @@ use gecko_bindings::structs::nsStyleXUL; unsafe impl Send for nsStyleXUL {} unsafe impl Sync for nsStyleXUL {} use gecko_bindings::structs::nsTimingFunction; +use gecko_bindings::structs::nscolor; use gecko_bindings::structs::nscoord; use gecko_bindings::structs::nsresult; use gecko_bindings::structs::Loader; @@ -1440,11 +1441,68 @@ extern "C" { nsCSSPropertyID); } extern "C" { - pub fn Servo_DeclarationBlock_AddPresValue(declarations: + pub fn Servo_DeclarationBlock_PropertyIsSet(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID) + -> bool; +} +extern "C" { + pub fn Servo_DeclarationBlock_SetIdentStringValue(declarations: + RawServoDeclarationBlockBorrowed, + property: + nsCSSPropertyID, + value: + *const nsAString_internal); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetKeywordValue(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID, + value: i32); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetIntValue(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID, + value: i32); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetPixelValue(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID, + value: f32); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetPercentValue(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID, + value: f32); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetAutoValue(declarations: RawServoDeclarationBlockBorrowed, - property: nsCSSPropertyID, - css_value: - nsCSSValueBorrowedMut); + property: nsCSSPropertyID); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetCurrentColor(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetColorValue(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID, + value: nscolor); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetFontFamily(declarations: + RawServoDeclarationBlockBorrowed, + value: + *const nsAString_internal); +} +extern "C" { + pub fn Servo_DeclarationBlock_SetTextDecorationColorOverride(declarations: + RawServoDeclarationBlockBorrowed); } extern "C" { pub fn Servo_CSSSupports2(name: *const nsACString_internal, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index a61dcf52370..026ea2f8808 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -36,7 +36,7 @@ use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSet use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed}; use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong}; use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong}; -use style::gecko_bindings::bindings::{nsACString, nsCSSValueBorrowedMut, nsAString}; +use style::gecko_bindings::bindings::{nsACString, nsAString}; use style::gecko_bindings::bindings::Gecko_AnimationAppendKeyframe; use style::gecko_bindings::bindings::RawGeckoAnimationValueListBorrowedMut; use style::gecko_bindings::bindings::RawGeckoElementBorrowed; @@ -952,58 +952,103 @@ pub extern "C" fn Servo_DeclarationBlock_RemovePropertyById(declarations: RawSer remove_property(declarations, get_property_id_from_nscsspropertyid!(property, ())) } +macro_rules! get_longhand_from_id { + ($id:expr, $retval:expr) => { + match PropertyId::from_nscsspropertyid($id) { + Ok(PropertyId::Longhand(long)) => long, + _ => { + error!("stylo: unknown presentation property with id {:?}", $id); + return $retval + } + } + } +} + #[no_mangle] -pub extern "C" fn Servo_DeclarationBlock_AddPresValue(declarations: RawServoDeclarationBlockBorrowed, - property: nsCSSPropertyID, - css_value: nsCSSValueBorrowedMut) { - use style::gecko::values::convert_nscolor_to_rgba; - use style::properties::{DeclaredValue, LonghandId, PropertyDeclaration, PropertyId, longhands}; - use style::values::specified; - +pub extern "C" fn Servo_DeclarationBlock_PropertyIsSet(declarations: + RawServoDeclarationBlockBorrowed, + property: nsCSSPropertyID) + -> bool { + use style::properties::PropertyDeclarationId; let declarations = RwLock::::as_arc(&declarations); - let prop = PropertyId::from_nscsspropertyid(property); + let long = get_longhand_from_id!(property, false); + declarations.read().get(PropertyDeclarationId::Longhand(long)).is_some() +} - let long = match prop { - Ok(PropertyId::Longhand(long)) => long, - _ => { - warn!("stylo: unknown presentation property with id {:?}", property); - return - } - }; - let decl = match long { - LonghandId::FontSize => { - if let Some(int) = css_value.integer() { - PropertyDeclaration::FontSize(DeclaredValue::Value( - longhands::font_size::SpecifiedValue( - specified::LengthOrPercentage::Length( - specified::NoCalcLength::from_font_size_int(int as u8) - ) - ) - )) - } else { - warn!("stylo: got unexpected non-integer value for font-size presentation attribute"); - return - } - } - LonghandId::Color => { - if let Some(color) = css_value.color_value() { - PropertyDeclaration::Color(DeclaredValue::Value( - specified::CSSRGBA { - parsed: convert_nscolor_to_rgba(color), - authored: None - } - )) - } else { - warn!("stylo: got unexpected non-integer value for color presentation attribute"); - return - } - } - _ => { - warn!("stylo: cannot handle longhand {:?} from presentation attribute", long); - return - } - }; - declarations.write().declarations.push((decl, Importance::Normal)); +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetIdentStringValue(_: + RawServoDeclarationBlockBorrowed, + _: + nsCSSPropertyID, + _: + *const nsAString) { + // + error!("stylo: Don't know how to handle ident presentation attributes (-x-lang)"); +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(_: + RawServoDeclarationBlockBorrowed, + _: nsCSSPropertyID, + _: i32) { + +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetIntValue(_: RawServoDeclarationBlockBorrowed, + _: nsCSSPropertyID, + _: i32) { + error!("stylo: Don't know how to handle integer presentation attributes (-x-span)"); +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(_: + RawServoDeclarationBlockBorrowed, + _: nsCSSPropertyID, + _: f32) { + +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(_: + RawServoDeclarationBlockBorrowed, + _: nsCSSPropertyID, + _: f32) { + +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(_: + RawServoDeclarationBlockBorrowed, + _: nsCSSPropertyID) { + +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetCurrentColor(_: + RawServoDeclarationBlockBorrowed, + _: nsCSSPropertyID) { + +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetColorValue(_: + RawServoDeclarationBlockBorrowed, + _: nsCSSPropertyID, + _: structs::nscolor) { + +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(_: + RawServoDeclarationBlockBorrowed, + _: *const nsAString) { + +} + +#[no_mangle] +pub extern "C" fn Servo_DeclarationBlock_SetTextDecorationColorOverride(_: + RawServoDeclarationBlockBorrowed) { }