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