mirror of
https://github.com/servo/servo.git
synced 2025-09-04 20:18:21 +01:00
style: Remove dependency on servo_url (#31358)
In order for stylo to be a separate crate, it needs to depend on less things from Servo. This change makes it so that stylo no longer depends on servo_url.
This commit is contained in:
parent
29e1dfe1e4
commit
9a6973d629
42 changed files with 236 additions and 144 deletions
|
@ -20,6 +20,6 @@ selectors = {path = "../../../components/selectors", features = ["shmem"] }
|
|||
servo_arc = {path = "../../../components/servo_arc"}
|
||||
servo_atoms = {path = "../../../components/atoms"}
|
||||
servo_config = {path = "../../../components/config"}
|
||||
servo_url = {path = "../../../components/url"}
|
||||
style = {path = "../../../components/style", features = ["servo"]}
|
||||
style_traits = {path = "../../../components/style_traits"}
|
||||
url = { workspace = true }
|
||||
|
|
|
@ -15,10 +15,10 @@ extern crate selectors;
|
|||
extern crate serde_json;
|
||||
extern crate servo_arc;
|
||||
extern crate servo_atoms;
|
||||
extern crate servo_url;
|
||||
extern crate style;
|
||||
extern crate style_traits;
|
||||
extern crate test;
|
||||
extern crate url;
|
||||
|
||||
mod animated_properties;
|
||||
mod attr;
|
||||
|
|
|
@ -9,6 +9,7 @@ use style::context::QuirksMode;
|
|||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style_traits::{ParseError, ParsingMode};
|
||||
use url::Url;
|
||||
|
||||
fn parse<T, F>(f: F, s: &'static str) -> Result<T, ParseError<'static>>
|
||||
where
|
||||
|
@ -22,10 +23,10 @@ fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result
|
|||
where
|
||||
F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>>,
|
||||
{
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let url_data = Url::parse("http://localhost").unwrap().into();
|
||||
let context = ParserContext::new(
|
||||
Origin::Author,
|
||||
&url,
|
||||
&url_data,
|
||||
Some(CssRuleType::Style),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
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;
|
||||
use url::Url;
|
||||
|
||||
fn parse_selector<'i, 't>(
|
||||
input: &mut Parser<'i, 't>,
|
||||
|
@ -15,11 +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 dummy_url_data = Url::parse("about:blank").unwrap().into();
|
||||
let parser = SelectorParser {
|
||||
stylesheet_origin: Origin::UserAgent,
|
||||
namespaces: &ns,
|
||||
url_data: &dummy_url,
|
||||
url_data: &dummy_url_data,
|
||||
for_supports_rule: false,
|
||||
};
|
||||
SelectorList::parse(&parser, input)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
use cssparser::SourceLocation;
|
||||
use rayon;
|
||||
use servo_arc::Arc;
|
||||
use servo_url::ServoUrl;
|
||||
use style::applicable_declarations::CascadePriority;
|
||||
use style::context::QuirksMode;
|
||||
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
|
@ -14,13 +13,19 @@ use style::properties::{longhands, Importance, PropertyDeclaration, PropertyDecl
|
|||
use style::rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
|
||||
use style::shared_lock::{SharedRwLock, StylesheetGuards};
|
||||
use style::stylesheets::layer_rule::LayerOrder;
|
||||
use style::stylesheets::{AllowImportRules, CssRule, Origin, Stylesheet};
|
||||
use style::stylesheets::{AllowImportRules, CssRule, Origin, Stylesheet, UrlExtraData};
|
||||
use style::thread_state::{self, ThreadState};
|
||||
use test::{self, Bencher};
|
||||
use url::Url;
|
||||
|
||||
struct ErrorringErrorReporter;
|
||||
impl ParseErrorReporter for ErrorringErrorReporter {
|
||||
fn report_error(&self, url: &ServoUrl, location: SourceLocation, error: ContextualParseError) {
|
||||
fn report_error(
|
||||
&self,
|
||||
url: &UrlExtraData,
|
||||
location: SourceLocation,
|
||||
error: ContextualParseError,
|
||||
) {
|
||||
panic!(
|
||||
"CSS error: {}\t\n{}:{} {}",
|
||||
url.as_str(),
|
||||
|
@ -59,9 +64,10 @@ impl<'a> Drop for AutoGCRuleTree<'a> {
|
|||
fn parse_rules(lock: &SharedRwLock, css: &str) -> Vec<(StyleSource, CascadeLevel)> {
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
|
||||
let url_data = Url::parse("http://localhost").unwrap().into();
|
||||
let s = Stylesheet::from_str(
|
||||
css,
|
||||
ServoUrl::parse("http://localhost").unwrap(),
|
||||
url_data,
|
||||
Origin::Author,
|
||||
media,
|
||||
lock.clone(),
|
||||
|
|
|
@ -6,16 +6,16 @@ use std::cell::RefCell;
|
|||
|
||||
use cssparser::SourceLocation;
|
||||
use servo_arc::Arc;
|
||||
use servo_url::ServoUrl;
|
||||
use style::context::QuirksMode;
|
||||
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
use style::media_queries::MediaList;
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::{AllowImportRules, Origin, Stylesheet};
|
||||
use style::stylesheets::{AllowImportRules, Origin, Stylesheet, UrlExtraData};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CSSError {
|
||||
pub url: ServoUrl,
|
||||
pub url: Arc<Url>,
|
||||
pub line: u32,
|
||||
pub column: u32,
|
||||
pub message: String,
|
||||
|
@ -60,9 +60,14 @@ impl TestingErrorReporter {
|
|||
}
|
||||
|
||||
impl ParseErrorReporter for TestingErrorReporter {
|
||||
fn report_error(&self, url: &ServoUrl, location: SourceLocation, error: ContextualParseError) {
|
||||
fn report_error(
|
||||
&self,
|
||||
url: &UrlExtraData,
|
||||
location: SourceLocation,
|
||||
error: ContextualParseError,
|
||||
) {
|
||||
self.errors.borrow_mut().push(CSSError {
|
||||
url: url.clone(),
|
||||
url: url.0.clone(),
|
||||
line: location.line,
|
||||
column: location.column,
|
||||
message: error.to_string(),
|
||||
|
@ -88,14 +93,14 @@ fn test_report_error_stylesheet() {
|
|||
@supports (color: green) and invalid and (margin: 0) {}
|
||||
@keyframes foo { from invalid {} to { margin: 0 invalid 0; } }
|
||||
";
|
||||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let url = Url::parse("about::test").unwrap();
|
||||
let error_reporter = TestingErrorReporter::new();
|
||||
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
Stylesheet::from_str(
|
||||
css,
|
||||
url.clone(),
|
||||
url.clone().into(),
|
||||
Origin::UserAgent,
|
||||
media,
|
||||
lock,
|
||||
|
@ -134,7 +139,7 @@ fn test_report_error_stylesheet() {
|
|||
),
|
||||
]);
|
||||
|
||||
assert_eq!(error_reporter.errors.borrow()[0].url, url);
|
||||
assert_eq!(*error_reporter.errors.borrow()[0].url, url);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -146,14 +151,14 @@ fn test_no_report_unrecognized_vendor_properties() {
|
|||
-moz-background-color: red;
|
||||
}
|
||||
";
|
||||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let url = Url::parse("about::test").unwrap();
|
||||
let error_reporter = TestingErrorReporter::new();
|
||||
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
Stylesheet::from_str(
|
||||
css,
|
||||
url,
|
||||
url.into(),
|
||||
Origin::UserAgent,
|
||||
media,
|
||||
lock,
|
||||
|
@ -182,12 +187,12 @@ fn test_source_map_url() {
|
|||
];
|
||||
|
||||
for test in tests {
|
||||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let url = Url::parse("about::test").unwrap();
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(
|
||||
test.0,
|
||||
url.clone(),
|
||||
url.into(),
|
||||
Origin::UserAgent,
|
||||
media,
|
||||
lock,
|
||||
|
@ -210,12 +215,12 @@ fn test_source_url() {
|
|||
];
|
||||
|
||||
for test in tests {
|
||||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let url = Url::parse("about::test").unwrap();
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(
|
||||
test.0,
|
||||
url.clone(),
|
||||
url.into(),
|
||||
Origin::UserAgent,
|
||||
media,
|
||||
lock,
|
||||
|
|
|
@ -7,7 +7,6 @@ use euclid::{Scale, 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, PropertyDeclaration, PropertyDeclarationBlock};
|
||||
|
@ -19,11 +18,12 @@ use style::stylist::{
|
|||
needs_revalidation_for_testing, ContainerConditionId, LayerId, Rule, Stylist,
|
||||
};
|
||||
use style::thread_state::{self, ThreadState};
|
||||
use url::Url;
|
||||
|
||||
/// 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 dummy_url_data = Url::parse("about:blank").unwrap().into();
|
||||
let shared_lock = SharedRwLock::new();
|
||||
(
|
||||
css_selectors
|
||||
|
@ -31,7 +31,8 @@ fn get_mock_rules(css_selectors: &[&str]) -> (Vec<Vec<Rule>>, SharedRwLock) {
|
|||
.enumerate()
|
||||
.map(|(i, selectors)| {
|
||||
let selectors =
|
||||
SelectorParser::parse_author_origin_no_namespace(selectors, dummy_url).unwrap();
|
||||
SelectorParser::parse_author_origin_no_namespace(selectors, &dummy_url_data)
|
||||
.unwrap();
|
||||
|
||||
let locked = Arc::new(shared_lock.wrap(StyleRule {
|
||||
selectors: selectors,
|
||||
|
@ -66,11 +67,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();
|
||||
let dummy_url_data = Url::parse("about:blank").unwrap().into();
|
||||
selectors
|
||||
.iter()
|
||||
.map(|x| {
|
||||
SelectorParser::parse_author_origin_no_namespace(x, dummy_url)
|
||||
SelectorParser::parse_author_origin_no_namespace(x, &dummy_url_data)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue