mirror of
https://github.com/servo/servo.git
synced 2025-08-17 11:25:35 +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
|
@ -9,11 +9,10 @@
|
|||
use cssparser::{DeclarationListParser, parse_important};
|
||||
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
|
||||
use error_reporting::ParseErrorReporter;
|
||||
use parser::{ParserContext, ParserContextExtraData, log_css_error};
|
||||
use servo_url::ServoUrl;
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use stylesheets::Origin;
|
||||
use stylesheets::{Origin, UrlExtraData};
|
||||
use super::*;
|
||||
#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValueMap;
|
||||
|
||||
|
@ -610,14 +609,10 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
|
|||
/// A helper to parse the style attribute of an element, in order for this to be
|
||||
/// shared between Servo and Gecko.
|
||||
pub fn parse_style_attribute(input: &str,
|
||||
base_url: &ServoUrl,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData)
|
||||
url_data: &UrlExtraData,
|
||||
error_reporter: &ParseErrorReporter)
|
||||
-> PropertyDeclarationBlock {
|
||||
let context = ParserContext::new_with_extra_data(Origin::Author,
|
||||
base_url,
|
||||
error_reporter,
|
||||
extra_data);
|
||||
let context = ParserContext::new(Origin::Author, url_data, error_reporter);
|
||||
parse_property_declaration_list(&context, &mut Parser::new(input))
|
||||
}
|
||||
|
||||
|
@ -628,14 +623,10 @@ pub fn parse_style_attribute(input: &str,
|
|||
/// this does not attempt to parse !important at all
|
||||
pub fn parse_one_declaration(id: PropertyId,
|
||||
input: &str,
|
||||
base_url: &ServoUrl,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData)
|
||||
url_data: &UrlExtraData,
|
||||
error_reporter: &ParseErrorReporter)
|
||||
-> Result<ParsedDeclaration, ()> {
|
||||
let context = ParserContext::new_with_extra_data(Origin::Author,
|
||||
base_url,
|
||||
error_reporter,
|
||||
extra_data);
|
||||
let context = ParserContext::new(Origin::Author, url_data, error_reporter);
|
||||
Parser::new(input).parse_entirely(|parser| {
|
||||
ParsedDeclaration::parse(id, &context, parser, false)
|
||||
.map_err(|_| ())
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
pub mod single_value {
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext, ParserContextExtraData};
|
||||
use parser::{Parse, ParserContext};
|
||||
use properties::ShorthandId;
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::{computed, specified};
|
||||
|
@ -211,7 +211,7 @@
|
|||
#![allow(unused_imports)]
|
||||
% if not property.derived_from:
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext, ParserContextExtraData};
|
||||
use parser::{Parse, ParserContext};
|
||||
use properties::{UnparsedValue, ShorthandId};
|
||||
% endif
|
||||
use values::{Auto, Either, None_, Normal};
|
||||
|
@ -368,7 +368,7 @@
|
|||
Arc::new(UnparsedValue {
|
||||
css: css.into_owned(),
|
||||
first_token_type: first_token_type,
|
||||
base_url: context.base_url.clone(),
|
||||
url_data: context.url_data.clone(),
|
||||
from_shorthand: None,
|
||||
})))
|
||||
}
|
||||
|
@ -594,7 +594,7 @@
|
|||
Ok(ParsedDeclaration::${shorthand.camel_case}WithVariables(Arc::new(UnparsedValue {
|
||||
css: css.into_owned(),
|
||||
first_token_type: first_token_type,
|
||||
base_url: context.base_url.clone(),
|
||||
url_data: context.url_data.clone(),
|
||||
from_shorthand: Some(ShorthandId::${shorthand.camel_case}),
|
||||
})))
|
||||
} else {
|
||||
|
|
|
@ -27,13 +27,12 @@ use font_metrics::FontMetricsProvider;
|
|||
#[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
|
||||
use logical_geometry::WritingMode;
|
||||
use media_queries::Device;
|
||||
use parser::{Parse, ParserContext, ParserContextExtraData};
|
||||
use parser::{Parse, ParserContext};
|
||||
use properties::animated_properties::TransitionProperty;
|
||||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||
use servo_url::ServoUrl;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use style_traits::ToCss;
|
||||
use stylesheets::Origin;
|
||||
use stylesheets::{Origin, UrlExtraData};
|
||||
#[cfg(feature = "servo")] use values::Either;
|
||||
use values::{HasViewportPercentage, computed};
|
||||
use cascade_info::CascadeInfo;
|
||||
|
@ -296,18 +295,13 @@ impl PropertyDeclarationIdSet {
|
|||
% endif
|
||||
{
|
||||
if let DeclaredValue::WithVariables(ref with_variables) = *value {
|
||||
// FIXME(heycam): A ParserContextExtraData should be built from data
|
||||
// stored in the WithVariables, in case variable expansion results in
|
||||
// a url() value.
|
||||
let extra_data = ParserContextExtraData::default();
|
||||
substitute_variables_${property.ident}_slow(&with_variables.css,
|
||||
with_variables.first_token_type,
|
||||
&with_variables.base_url,
|
||||
&with_variables.url_data,
|
||||
with_variables.from_shorthand,
|
||||
custom_properties,
|
||||
f,
|
||||
error_reporter,
|
||||
extra_data);
|
||||
error_reporter);
|
||||
} else {
|
||||
f(value);
|
||||
}
|
||||
|
@ -318,12 +312,11 @@ impl PropertyDeclarationIdSet {
|
|||
fn substitute_variables_${property.ident}_slow<F>(
|
||||
css: &String,
|
||||
first_token_type: TokenSerializationType,
|
||||
base_url: &ServoUrl,
|
||||
url_data: &UrlExtraData,
|
||||
from_shorthand: Option<ShorthandId>,
|
||||
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
f: F,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData)
|
||||
error_reporter: &ParseErrorReporter)
|
||||
% if property.boxed:
|
||||
where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>)
|
||||
% else:
|
||||
|
@ -337,9 +330,7 @@ impl PropertyDeclarationIdSet {
|
|||
//
|
||||
// FIXME(pcwalton): Cloning the error reporter is slow! But so are custom
|
||||
// properties, so whatever...
|
||||
let context = ParserContext::new_with_extra_data(
|
||||
::stylesheets::Origin::Author, base_url, error_reporter,
|
||||
extra_data);
|
||||
let context = ParserContext::new(Origin::Author, url_data, error_reporter);
|
||||
Parser::new(&css).parse_entirely(|input| {
|
||||
match from_shorthand {
|
||||
None => {
|
||||
|
@ -652,8 +643,8 @@ pub struct UnparsedValue {
|
|||
css: String,
|
||||
/// The first token type for this serialization.
|
||||
first_token_type: TokenSerializationType,
|
||||
/// The base url.
|
||||
base_url: ServoUrl,
|
||||
/// The url data for resolving url values.
|
||||
url_data: UrlExtraData,
|
||||
/// The shorthand this came from.
|
||||
from_shorthand: Option<ShorthandId>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue