mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
stylo: support 1-arg CSS.supports()
This commit is contained in:
parent
ad1b11771b
commit
98fd42df17
2 changed files with 21 additions and 3 deletions
|
@ -1317,8 +1317,11 @@ extern "C" {
|
||||||
nsCSSPropertyID);
|
nsCSSPropertyID);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_CSSSupports(name: *const nsACString_internal,
|
pub fn Servo_CSSSupports2(name: *const nsACString_internal,
|
||||||
value: *const nsACString_internal) -> bool;
|
value: *const nsACString_internal) -> bool;
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_CSSSupports(cond: *const nsACString_internal) -> bool;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
|
pub fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
|
||||||
|
|
|
@ -64,6 +64,7 @@ use style::sequential;
|
||||||
use style::string_cache::Atom;
|
use style::string_cache::Atom;
|
||||||
use style::stylesheets::{CssRule, CssRules, Origin, Stylesheet, StyleRule, ImportRule};
|
use style::stylesheets::{CssRule, CssRules, Origin, Stylesheet, StyleRule, ImportRule};
|
||||||
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
||||||
|
use style::supports::parse_condition_or_declaration;
|
||||||
use style::thread_state;
|
use style::thread_state;
|
||||||
use style::timer::Timer;
|
use style::timer::Timer;
|
||||||
use style::traversal::{resolve_style, DomTraversal};
|
use style::traversal::{resolve_style, DomTraversal};
|
||||||
|
@ -902,7 +903,7 @@ pub extern "C" fn Servo_DeclarationBlock_RemovePropertyById(declarations: RawSer
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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 property = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
||||||
let id = if let Ok(id) = PropertyId::parse(property.into()) {
|
let id = if let Ok(id) = PropertyId::parse(property.into()) {
|
||||||
id
|
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
|
/// Only safe to call on the main thread, with exclusive access to the element and
|
||||||
/// its ancestors.
|
/// its ancestors.
|
||||||
unsafe fn maybe_restyle<'a>(data: &'a mut AtomicRefMut<ElementData>, element: GeckoElement)
|
unsafe fn maybe_restyle<'a>(data: &'a mut AtomicRefMut<ElementData>, element: GeckoElement)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue