mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #15040 - Manishearth:stylo-supports, r=heycam
stylo: support 1-arg CSS.supports() r=heycam in https://bugzilla.mozilla.org/show_bug.cgi?id=1331316 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15040) <!-- Reviewable:end -->
This commit is contained in:
commit
b9c6f9f76e
2 changed files with 21 additions and 3 deletions
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue