mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Use a UrlExtraData type alias to unify url handling logic.
This commit is contained in:
parent
a097a293b5
commit
37585309e9
24 changed files with 166 additions and 272 deletions
|
@ -8,92 +8,38 @@
|
|||
|
||||
use cssparser::{Parser, SourcePosition, UnicodeRange};
|
||||
use error_reporting::ParseErrorReporter;
|
||||
#[cfg(feature = "gecko")]
|
||||
use gecko_bindings::structs::URLExtraData;
|
||||
#[cfg(feature = "gecko")]
|
||||
use gecko_bindings::sugar::refptr::RefPtr;
|
||||
use servo_url::ServoUrl;
|
||||
use style_traits::OneOrMoreCommaSeparated;
|
||||
use stylesheets::Origin;
|
||||
use stylesheets::{Origin, UrlExtraData};
|
||||
|
||||
/// Extra data that the style backend may need to parse stylesheets.
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
pub struct ParserContextExtraData;
|
||||
|
||||
/// Extra data that the style backend may need to parse stylesheets.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub struct ParserContextExtraData {
|
||||
/// The URL extra data.
|
||||
pub data: Option<RefPtr<URLExtraData>>,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
impl Default for ParserContextExtraData {
|
||||
fn default() -> Self {
|
||||
ParserContextExtraData
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl Default for ParserContextExtraData {
|
||||
fn default() -> Self {
|
||||
ParserContextExtraData { data: None }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ParserContextExtraData {
|
||||
/// Construct from a GeckoParserExtraData
|
||||
///
|
||||
/// GeckoParserExtraData must live longer than this call
|
||||
pub unsafe fn new(data: *mut URLExtraData) -> Self {
|
||||
ParserContextExtraData {
|
||||
data: Some(RefPtr::new(data)),
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The data that the parser needs from outside in order to parse a stylesheet.
|
||||
pub struct ParserContext<'a> {
|
||||
/// The `Origin` of the stylesheet, whether it's a user, author or
|
||||
/// user-agent stylesheet.
|
||||
pub stylesheet_origin: Origin,
|
||||
/// The base url we're parsing this stylesheet as.
|
||||
pub base_url: &'a ServoUrl,
|
||||
/// The extra data we need for resolving url values.
|
||||
pub url_data: &'a UrlExtraData,
|
||||
/// An error reporter to report syntax errors.
|
||||
pub error_reporter: &'a ParseErrorReporter,
|
||||
/// Implementation-dependent extra data.
|
||||
pub extra_data: ParserContextExtraData,
|
||||
}
|
||||
|
||||
impl<'a> ParserContext<'a> {
|
||||
/// Create a `ParserContext` with extra data.
|
||||
pub fn new_with_extra_data(stylesheet_origin: Origin,
|
||||
base_url: &'a ServoUrl,
|
||||
error_reporter: &'a ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData)
|
||||
-> ParserContext<'a> {
|
||||
/// Create a parser context.
|
||||
pub fn new(stylesheet_origin: Origin,
|
||||
url_data: &'a UrlExtraData,
|
||||
error_reporter: &'a ParseErrorReporter)
|
||||
-> ParserContext<'a> {
|
||||
ParserContext {
|
||||
stylesheet_origin: stylesheet_origin,
|
||||
base_url: base_url,
|
||||
url_data: url_data,
|
||||
error_reporter: error_reporter,
|
||||
extra_data: extra_data,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a parser context with the default extra data.
|
||||
pub fn new(stylesheet_origin: Origin,
|
||||
base_url: &'a ServoUrl,
|
||||
error_reporter: &'a ParseErrorReporter)
|
||||
-> ParserContext<'a> {
|
||||
let extra_data = ParserContextExtraData::default();
|
||||
Self::new_with_extra_data(stylesheet_origin, base_url, error_reporter, extra_data)
|
||||
}
|
||||
|
||||
/// Create a parser context for on-the-fly parsing in CSSOM
|
||||
pub fn new_for_cssom(base_url: &'a ServoUrl,
|
||||
pub fn new_for_cssom(url_data: &'a UrlExtraData,
|
||||
error_reporter: &'a ParseErrorReporter)
|
||||
-> ParserContext<'a> {
|
||||
Self::new(Origin::User, base_url, error_reporter)
|
||||
Self::new(Origin::User, url_data, error_reporter)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,8 +50,8 @@ pub fn log_css_error(input: &mut Parser,
|
|||
position: SourcePosition,
|
||||
message: &str,
|
||||
parsercontext: &ParserContext) {
|
||||
let servo_url = parsercontext.base_url;
|
||||
parsercontext.error_reporter.report_error(input, position, message, servo_url);
|
||||
let url_data = parsercontext.url_data;
|
||||
parsercontext.error_reporter.report_error(input, position, message, url_data);
|
||||
}
|
||||
|
||||
// XXXManishearth Replace all specified value parse impls with impls of this
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue