diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 2f8a6aa9c34..9d355444e27 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1317,8 +1317,11 @@ extern "C" { nsCSSPropertyID); } extern "C" { - pub fn Servo_CSSSupports(name: *const nsACString_internal, - value: *const nsACString_internal) -> bool; + pub fn Servo_CSSSupports2(name: *const nsACString_internal, + value: *const nsACString_internal) -> bool; +} +extern "C" { + pub fn Servo_CSSSupports(cond: *const nsACString_internal) -> bool; } extern "C" { pub fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 166ac850be2..70ec377cce7 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -64,6 +64,7 @@ use style::sequential; use style::string_cache::Atom; use style::stylesheets::{CssRule, CssRules, Origin, Stylesheet, StyleRule, ImportRule}; use style::stylesheets::StylesheetLoader as StyleStylesheetLoader; +use style::supports::parse_condition_or_declaration; use style::thread_state; use style::timer::Timer; use style::traversal::{resolve_style, DomTraversal}; @@ -902,7 +903,7 @@ pub extern "C" fn Servo_DeclarationBlock_RemovePropertyById(declarations: RawSer } #[no_mangle] -pub extern "C" fn Servo_CSSSupports(property: *const nsACString, value: *const nsACString) -> bool { +pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const nsACString) -> bool { let property = unsafe { property.as_ref().unwrap().as_str_unchecked() }; let id = if let Ok(id) = PropertyId::parse(property.into()) { id @@ -920,6 +921,20 @@ pub extern "C" fn Servo_CSSSupports(property: *const nsACString, value: *const n } } +#[no_mangle] +pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool { + let condition = unsafe { cond.as_ref().unwrap().as_str_unchecked() }; + let mut input = Parser::new(&condition); + let cond = parse_condition_or_declaration(&mut input); + if let Ok(cond) = cond { + let url = ServoUrl::parse("about:blank").unwrap(); + let context = ParserContext::new_for_cssom(&url); + cond.eval(&context) + } else { + false + } +} + /// Only safe to call on the main thread, with exclusive access to the element and /// its ancestors. unsafe fn maybe_restyle<'a>(data: &'a mut AtomicRefMut, element: GeckoElement)