Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylo: Implement Element.matches using stylo. #18721

Merged
merged 2 commits into from Oct 3, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -6,7 +6,7 @@ use cssparser::{Parser, ParserInput};
use cssparser::ToCss as ParserToCss;
use env_logger::LogBuilder;
use malloc_size_of::MallocSizeOfOps;
use selectors::Element;
use selectors::{self, Element};
use selectors::matching::{MatchingContext, MatchingMode, matches_selector};
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
use std::cell::RefCell;
@@ -122,7 +122,7 @@ use style::properties::animated_properties::compare_property_priority;
use style::properties::parse_one_declaration_into;
use style::rule_cache::RuleCacheConditions;
use style::rule_tree::{CascadeLevel, StyleSource};
use style::selector_parser::PseudoElementCascadeType;
use style::selector_parser::{PseudoElementCascadeType, SelectorImpl};
use style::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard, Locked};
use style::string_cache::Atom;
use style::style_adjuster::StyleAdjuster;
@@ -1522,6 +1522,22 @@ pub extern "C" fn Servo_StyleRule_SelectorMatchesElement(rule: RawServoStyleRule
})
}

#[no_mangle]
pub unsafe extern "C" fn Servo_SelectorList_Matches(
element: RawGeckoElementBorrowed,
selectors: &::selectors::SelectorList<SelectorImpl>,
) -> bool {
let element = GeckoElement(element);
let mut context = MatchingContext::new(
MatchingMode::Normal,
None,
None,
element.owner_document_quirks_mode(),
);

selectors::matching::matches_selector_list(selectors, &element, &mut context)
}

#[no_mangle]
pub extern "C" fn Servo_ImportRule_GetHref(rule: RawServoImportRuleBorrowed, result: *mut nsAString) {
read_locked_arc(rule, |rule: &ImportRule| {
@@ -4102,3 +4118,25 @@ pub extern "C" fn Servo_CorruptRuleHashAndCrash(set: RawServoStyleSetBorrowed, i
let per_doc_data = PerDocumentStyleData::from_ffi(set).borrow();
per_doc_data.stylist.corrupt_rule_hash_and_crash(index);
}

#[no_mangle]
pub unsafe extern "C" fn Servo_SelectorList_Parse(
selector_list: *const nsACString,
) -> *mut ::selectors::SelectorList<SelectorImpl> {
use style::selector_parser::SelectorParser;

debug_assert!(!selector_list.is_null());

let input = ::std::str::from_utf8_unchecked(&**selector_list);
let selector_list = match SelectorParser::parse_author_origin_no_namespace(&input) {
Ok(selector_list) => selector_list,
Err(..) => return ptr::null_mut(),
};

Box::into_raw(Box::new(selector_list))
}

#[no_mangle]
pub unsafe extern "C" fn Servo_SelectorList_Drop(list: *mut ::selectors::SelectorList<SelectorImpl>) {
let _ = Box::from_raw(list);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.