mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Further changes required by Servo
This commit is contained in:
parent
04282ff04c
commit
07dbd9d637
5 changed files with 26 additions and 23 deletions
|
@ -96,19 +96,15 @@ impl CSSStyleRuleMethods for CSSStyleRule {
|
|||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssstylerule-selectortext
|
||||
fn SetSelectorText(&self, value: DOMString) {
|
||||
let contents = &self.cssrule.parent_stylesheet().style_stylesheet().contents;
|
||||
// It's not clear from the spec if we should use the stylesheet's namespaces.
|
||||
// https://github.com/w3c/csswg-drafts/issues/1511
|
||||
let namespaces = self
|
||||
.cssrule
|
||||
.parent_stylesheet()
|
||||
.style_stylesheet()
|
||||
.contents
|
||||
.namespaces
|
||||
.read();
|
||||
let namespaces = contents.namespaces.read();
|
||||
let url_data = contents.url_data.read();
|
||||
let parser = SelectorParser {
|
||||
stylesheet_origin: Origin::Author,
|
||||
namespaces: &namespaces,
|
||||
url_data: None,
|
||||
url_data: &url_data,
|
||||
};
|
||||
let mut css_parser = CssParserInput::new(&*value);
|
||||
let mut css_parser = CssParser::new(&mut css_parser);
|
||||
|
|
|
@ -2700,12 +2700,14 @@ impl ElementMethods for Element {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-element-matches
|
||||
fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
|
||||
let selectors = match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||
let doc = document_from_node(self);
|
||||
let url = doc.url();
|
||||
let selectors = match SelectorParser::parse_author_origin_no_namespace(&selectors, &url) {
|
||||
Err(_) => return Err(Error::Syntax),
|
||||
Ok(selectors) => selectors,
|
||||
};
|
||||
|
||||
let quirks_mode = document_from_node(self).quirks_mode();
|
||||
let quirks_mode = doc.quirks_mode();
|
||||
let element = DomRoot::from_ref(self);
|
||||
|
||||
Ok(dom_apis::element_matches(&element, &selectors, quirks_mode))
|
||||
|
@ -2718,12 +2720,14 @@ impl ElementMethods for Element {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-element-closest
|
||||
fn Closest(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
||||
let selectors = match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||
let doc = document_from_node(self);
|
||||
let url = doc.url();
|
||||
let selectors = match SelectorParser::parse_author_origin_no_namespace(&selectors, &url) {
|
||||
Err(_) => return Err(Error::Syntax),
|
||||
Ok(selectors) => selectors,
|
||||
};
|
||||
|
||||
let quirks_mode = document_from_node(self).quirks_mode();
|
||||
let quirks_mode = doc.quirks_mode();
|
||||
Ok(dom_apis::element_closest(
|
||||
DomRoot::from_ref(self),
|
||||
&selectors,
|
||||
|
|
|
@ -949,18 +949,15 @@ impl Node {
|
|||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||
pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<DomRoot<Element>>> {
|
||||
// Step 1.
|
||||
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||
let doc = self.owner_doc();
|
||||
match SelectorParser::parse_author_origin_no_namespace(&selectors, &doc.url()) {
|
||||
// Step 2.
|
||||
Err(_) => Err(Error::Syntax),
|
||||
// Step 3.
|
||||
Ok(selectors) => {
|
||||
// FIXME(bholley): Consider an nth-index cache here.
|
||||
let mut ctx = MatchingContext::new(
|
||||
MatchingMode::Normal,
|
||||
None,
|
||||
None,
|
||||
self.owner_doc().quirks_mode(),
|
||||
);
|
||||
let mut ctx =
|
||||
MatchingContext::new(MatchingMode::Normal, None, None, doc.quirks_mode());
|
||||
Ok(self
|
||||
.traverse_preorder(ShadowIncluding::No)
|
||||
.filter_map(DomRoot::downcast)
|
||||
|
@ -975,7 +972,8 @@ impl Node {
|
|||
/// whilst iterating, otherwise the iterator may be invalidated.
|
||||
pub fn query_selector_iter(&self, selectors: DOMString) -> Fallible<QuerySelectorIterator> {
|
||||
// Step 1.
|
||||
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
|
||||
let url = self.owner_doc().url();
|
||||
match SelectorParser::parse_author_origin_no_namespace(&selectors, &url) {
|
||||
// Step 2.
|
||||
Err(_) => Err(Error::Syntax),
|
||||
// Step 3.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use cssparser::{Parser, ParserInput, ToCss};
|
||||
use selectors::parser::SelectorList;
|
||||
use servo_url::ServoUrl;
|
||||
use style::selector_parser::{SelectorImpl, SelectorParser};
|
||||
use style::stylesheets::{Namespaces, Origin};
|
||||
use style_traits::ParseError;
|
||||
|
@ -14,10 +15,11 @@ fn parse_selector<'i, 't>(
|
|||
let mut ns = Namespaces::default();
|
||||
ns.prefixes
|
||||
.insert("svg".into(), style::Namespace::new(ns!(svg)));
|
||||
let dummy_url = ServoUrl::parse("about:blank").unwrap();
|
||||
let parser = SelectorParser {
|
||||
stylesheet_origin: Origin::UserAgent,
|
||||
namespaces: &ns,
|
||||
url_data: None,
|
||||
url_data: &dummy_url,
|
||||
};
|
||||
SelectorList::parse(&parser, input)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use euclid::Size2D;
|
|||
use selectors::parser::{AncestorHashes, Selector};
|
||||
use servo_arc::Arc;
|
||||
use servo_atoms::Atom;
|
||||
use servo_url::ServoUrl;
|
||||
use style::context::QuirksMode;
|
||||
use style::media_queries::{Device, MediaType};
|
||||
use style::properties::{longhands, Importance};
|
||||
|
@ -24,6 +25,7 @@ use style::thread_state::{self, ThreadState};
|
|||
/// Helper method to get some Rules from selector strings.
|
||||
/// Each sublist of the result contains the Rules for one StyleRule.
|
||||
fn get_mock_rules(css_selectors: &[&str]) -> (Vec<Vec<Rule>>, SharedRwLock) {
|
||||
let dummy_url = &ServoUrl::parse("about:blank").unwrap();
|
||||
let shared_lock = SharedRwLock::new();
|
||||
(
|
||||
css_selectors
|
||||
|
@ -31,7 +33,7 @@ fn get_mock_rules(css_selectors: &[&str]) -> (Vec<Vec<Rule>>, SharedRwLock) {
|
|||
.enumerate()
|
||||
.map(|(i, selectors)| {
|
||||
let selectors =
|
||||
SelectorParser::parse_author_origin_no_namespace(selectors).unwrap();
|
||||
SelectorParser::parse_author_origin_no_namespace(selectors, dummy_url).unwrap();
|
||||
|
||||
let locked = Arc::new(shared_lock.wrap(StyleRule {
|
||||
selectors: selectors,
|
||||
|
@ -64,10 +66,11 @@ fn get_mock_rules(css_selectors: &[&str]) -> (Vec<Vec<Rule>>, SharedRwLock) {
|
|||
}
|
||||
|
||||
fn parse_selectors(selectors: &[&str]) -> Vec<Selector<SelectorImpl>> {
|
||||
let dummy_url = &ServoUrl::parse("about:blank").unwrap();
|
||||
selectors
|
||||
.iter()
|
||||
.map(|x| {
|
||||
SelectorParser::parse_author_origin_no_namespace(x)
|
||||
SelectorParser::parse_author_origin_no_namespace(x, dummy_url)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue