stylo: support 1-arg CSS.supports()

This commit is contained in:
Manish Goregaokar 2017-01-15 23:09:42 -08:00 committed by Manish Goregaokar
parent ad1b11771b
commit 98fd42df17
2 changed files with 21 additions and 3 deletions

View file

@ -1317,9 +1317,12 @@ extern "C" {
nsCSSPropertyID);
}
extern "C" {
pub fn Servo_CSSSupports(name: *const nsACString_internal,
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:
ServoComputedValuesBorrowedOrNull,

View file

@ -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<ElementData>, element: GeckoElement)