mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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
|
@ -113,7 +113,6 @@ use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode};
|
|||
use style::error_reporting::StdoutErrorReporter;
|
||||
use style::logical_geometry::LogicalPoint;
|
||||
use style::media_queries::{Device, MediaType};
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW};
|
||||
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards};
|
||||
use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets};
|
||||
|
@ -1586,8 +1585,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
|||
Default::default(),
|
||||
shared_lock.clone(),
|
||||
None,
|
||||
&StdoutErrorReporter,
|
||||
ParserContextExtraData::default()))
|
||||
&StdoutErrorReporter))
|
||||
}
|
||||
|
||||
let shared_lock = SharedRwLock::new();
|
||||
|
@ -1600,7 +1598,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
|||
for &(ref contents, ref url) in &opts::get().user_stylesheets {
|
||||
user_or_user_agent_stylesheets.push(Stylesheet::from_bytes(
|
||||
&contents, url.clone(), None, None, Origin::User, Default::default(),
|
||||
shared_lock.clone(), None, &StdoutErrorReporter, ParserContextExtraData::default()));
|
||||
shared_lock.clone(), None, &StdoutErrorReporter));
|
||||
}
|
||||
|
||||
let quirks_mode_stylesheet = try!(parse_ua_stylesheet(&shared_lock, "quirks-mode.css"));
|
||||
|
|
|
@ -19,7 +19,6 @@ use dom_struct::dom_struct;
|
|||
use servo_atoms::Atom;
|
||||
use std::sync::Arc;
|
||||
use style::keyframes::{Keyframe, KeyframeSelector};
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::stylesheets::KeyframesRule;
|
||||
|
||||
|
@ -83,8 +82,7 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule {
|
|||
|
||||
// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-appendrule
|
||||
fn AppendRule(&self, rule: DOMString) {
|
||||
let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet(),
|
||||
ParserContextExtraData::default());
|
||||
let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet());
|
||||
if let Ok(rule) = rule {
|
||||
let mut guard = self.cssrule.shared_lock().write();
|
||||
self.keyframesrule.write_with(&mut guard).keyframes.push(rule);
|
||||
|
|
|
@ -18,7 +18,6 @@ use servo_url::ServoUrl;
|
|||
use std::ascii::AsciiExt;
|
||||
use std::sync::Arc;
|
||||
use style::attr::AttrValue;
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::properties::{Importance, PropertyDeclarationBlock, PropertyId, LonghandId, ShorthandId};
|
||||
use style::properties::{parse_one_declaration, parse_style_attribute};
|
||||
use style::selector_parser::PseudoElement;
|
||||
|
@ -147,7 +146,7 @@ impl CSSStyleOwner {
|
|||
match *self {
|
||||
CSSStyleOwner::Element(ref el) => window_from_node(&**el).Document().base_url(),
|
||||
CSSStyleOwner::CSSRule(ref rule, _) => {
|
||||
rule.parent_stylesheet().style_stylesheet().base_url.clone()
|
||||
rule.parent_stylesheet().style_stylesheet().url_data.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -258,8 +257,7 @@ impl CSSStyleDeclaration {
|
|||
let window = self.owner.window();
|
||||
let result =
|
||||
parse_one_declaration(id, &value, &self.owner.base_url(),
|
||||
window.css_error_reporter(),
|
||||
ParserContextExtraData::default());
|
||||
window.css_error_reporter());
|
||||
|
||||
// Step 7
|
||||
let parsed = match result {
|
||||
|
@ -439,8 +437,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
|||
// Step 3
|
||||
*pdb = parse_style_attribute(&value,
|
||||
&self.owner.base_url(),
|
||||
window.css_error_reporter(),
|
||||
ParserContextExtraData::default());
|
||||
window.css_error_reporter());
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -101,7 +101,6 @@ use style::attr::{AttrValue, LengthOrPercentageOrAuto};
|
|||
use style::context::{QuirksMode, ReflowGoal};
|
||||
use style::element_state::*;
|
||||
use style::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
|
||||
use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size, overflow_x};
|
||||
use style::restyle_hints::RESTYLE_SELF;
|
||||
|
@ -2197,8 +2196,7 @@ impl VirtualMethods for Element {
|
|||
Arc::new(doc.style_shared_lock().wrap(parse_style_attribute(
|
||||
&attr.value(),
|
||||
&doc.base_url(),
|
||||
win.css_error_reporter(),
|
||||
ParserContextExtraData::default())))
|
||||
win.css_error_reporter())))
|
||||
};
|
||||
|
||||
Some(block)
|
||||
|
|
|
@ -105,7 +105,7 @@ impl HTMLMetaElement {
|
|||
rules: CssRules::new(vec![rule], shared_lock),
|
||||
origin: Origin::Author,
|
||||
shared_lock: shared_lock.clone(),
|
||||
base_url: window_from_node(self).get_url(),
|
||||
url_data: window_from_node(self).get_url(),
|
||||
namespaces: Default::default(),
|
||||
media: Arc::new(shared_lock.wrap(Default::default())),
|
||||
// Viewport constraints are always recomputed on resize; they don't need to
|
||||
|
|
|
@ -25,7 +25,6 @@ use script_layout_interface::message::Msg;
|
|||
use std::cell::Cell;
|
||||
use std::sync::Arc;
|
||||
use style::media_queries::parse_media_query_list;
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::stylesheets::{Stylesheet, Origin};
|
||||
use stylesheet_loader::{StylesheetLoader, StylesheetOwner};
|
||||
|
||||
|
@ -88,8 +87,7 @@ impl HTMLStyleElement {
|
|||
let loader = StylesheetLoader::for_element(self.upcast());
|
||||
let sheet = Stylesheet::from_str(&data, url, Origin::Author, mq,
|
||||
shared_lock, Some(&loader),
|
||||
win.css_error_reporter(),
|
||||
ParserContextExtraData::default());
|
||||
win.css_error_reporter());
|
||||
|
||||
let sheet = Arc::new(sheet);
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ use servo_url::ServoUrl;
|
|||
use std::mem;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use style::media_queries::MediaList;
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::shared_lock::Locked as StyleLocked;
|
||||
use style::stylesheets::{ImportRule, Stylesheet, Origin};
|
||||
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
||||
|
@ -146,8 +145,7 @@ impl FetchResponseListener for StylesheetContext {
|
|||
media.take().unwrap(),
|
||||
shared_lock,
|
||||
Some(&loader),
|
||||
win.css_error_reporter(),
|
||||
ParserContextExtraData::default()));
|
||||
win.css_error_reporter()));
|
||||
|
||||
if link.is_alternate() {
|
||||
sheet.set_disabled(true);
|
||||
|
@ -164,8 +162,7 @@ impl FetchResponseListener for StylesheetContext {
|
|||
protocol_encoding_label,
|
||||
Some(environment_encoding),
|
||||
Some(&loader),
|
||||
win.css_error_reporter(),
|
||||
ParserContextExtraData::default());
|
||||
win.css_error_reporter());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,10 @@ extern crate encoding;
|
|||
use cssparser::{stylesheet_encoding, EncodingSupport};
|
||||
use error_reporting::ParseErrorReporter;
|
||||
use media_queries::MediaList;
|
||||
use parser::ParserContextExtraData;
|
||||
use self::encoding::{EncodingRef, DecoderTrap};
|
||||
use servo_url::ServoUrl;
|
||||
use shared_lock::SharedRwLock;
|
||||
use std::str;
|
||||
use stylesheets::{Stylesheet, StylesheetLoader, Origin};
|
||||
use stylesheets::{Stylesheet, StylesheetLoader, Origin, UrlExtraData};
|
||||
|
||||
struct RustEncoding;
|
||||
|
||||
|
@ -50,26 +48,24 @@ impl Stylesheet {
|
|||
/// Takes care of decoding the network bytes and forwards the resulting
|
||||
/// string to `Stylesheet::from_str`.
|
||||
pub fn from_bytes(bytes: &[u8],
|
||||
base_url: ServoUrl,
|
||||
url_data: UrlExtraData,
|
||||
protocol_encoding_label: Option<&str>,
|
||||
environment_encoding: Option<EncodingRef>,
|
||||
origin: Origin,
|
||||
media: MediaList,
|
||||
shared_lock: SharedRwLock,
|
||||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData)
|
||||
error_reporter: &ParseErrorReporter)
|
||||
-> Stylesheet {
|
||||
let (string, _) = decode_stylesheet_bytes(
|
||||
bytes, protocol_encoding_label, environment_encoding);
|
||||
Stylesheet::from_str(&string,
|
||||
base_url,
|
||||
url_data,
|
||||
origin,
|
||||
media,
|
||||
shared_lock,
|
||||
stylesheet_loader,
|
||||
error_reporter,
|
||||
extra_data)
|
||||
error_reporter)
|
||||
}
|
||||
|
||||
/// Updates an empty stylesheet with a set of bytes that reached over the
|
||||
|
@ -79,14 +75,12 @@ impl Stylesheet {
|
|||
protocol_encoding_label: Option<&str>,
|
||||
environment_encoding: Option<EncodingRef>,
|
||||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData) {
|
||||
error_reporter: &ParseErrorReporter) {
|
||||
let (string, _) = decode_stylesheet_bytes(
|
||||
bytes, protocol_encoding_label, environment_encoding);
|
||||
Self::update_from_str(existing,
|
||||
&string,
|
||||
stylesheet_loader,
|
||||
error_reporter,
|
||||
extra_data)
|
||||
error_reporter)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
use cssparser::{Parser, SourcePosition};
|
||||
use log;
|
||||
use servo_url::ServoUrl;
|
||||
use stylesheets::UrlExtraData;
|
||||
|
||||
/// A generic trait for an error reporter.
|
||||
pub trait ParseErrorReporter : Sync + Send {
|
||||
|
@ -20,7 +20,7 @@ pub trait ParseErrorReporter : Sync + Send {
|
|||
input: &mut Parser,
|
||||
position: SourcePosition,
|
||||
message: &str,
|
||||
url: &ServoUrl);
|
||||
url: &UrlExtraData);
|
||||
}
|
||||
|
||||
/// An error reporter that reports the errors to the `info` log channel.
|
||||
|
@ -32,7 +32,7 @@ impl ParseErrorReporter for StdoutErrorReporter {
|
|||
input: &mut Parser,
|
||||
position: SourcePosition,
|
||||
message: &str,
|
||||
url: &ServoUrl) {
|
||||
url: &UrlExtraData) {
|
||||
if log_enabled!(log::LogLevel::Info) {
|
||||
let location = input.source_location(position);
|
||||
info!("Url:\t{}\n{}:{} {}", url.as_str(), location.line, location.column, message)
|
||||
|
|
|
@ -34,18 +34,9 @@ impl SpecifiedUrl {
|
|||
pub fn parse_from_string<'a>(url: Cow<'a, str>,
|
||||
context: &ParserContext)
|
||||
-> Result<Self, ()> {
|
||||
let extra = &context.extra_data;
|
||||
if extra.data.is_none() {
|
||||
// FIXME(heycam) should ensure we always have a principal, etc.,
|
||||
// when parsing style attributes and re-parsing due to CSS
|
||||
// Variables.
|
||||
warn!("stylo: skipping declaration without ParserContextExtraData");
|
||||
return Err(())
|
||||
}
|
||||
|
||||
Ok(SpecifiedUrl {
|
||||
serialization: Arc::new(url.into_owned()),
|
||||
extra_data: extra.data.as_ref().unwrap().clone(),
|
||||
extra_data: context.url_data.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ use gecko_bindings::bindings::Gecko_IsSignificantChild;
|
|||
use gecko_bindings::bindings::Gecko_MatchStringArgPseudo;
|
||||
use gecko_bindings::bindings::Gecko_UpdateAnimations;
|
||||
use gecko_bindings::structs;
|
||||
use gecko_bindings::structs::{RawGeckoElement, RawGeckoNode};
|
||||
use gecko_bindings::structs::{RawGeckoElement, RawGeckoNode, URLExtraData};
|
||||
use gecko_bindings::structs::{nsIAtom, nsIContent, nsStyleContext};
|
||||
use gecko_bindings::structs::EffectCompositor_CascadeLevel as CascadeLevel;
|
||||
use gecko_bindings::structs::NODE_HAS_ANIMATION_ONLY_DIRTY_DESCENDANTS_FOR_SERVO;
|
||||
|
@ -49,8 +49,8 @@ use gecko_bindings::structs::NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO;
|
|||
use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE;
|
||||
use gecko_bindings::structs::NODE_IS_NATIVE_ANONYMOUS;
|
||||
use gecko_bindings::sugar::ownership::HasArcFFI;
|
||||
use gecko_bindings::sugar::refptr::RefPtr;
|
||||
use parking_lot::RwLock;
|
||||
use parser::ParserContextExtraData;
|
||||
use properties::{ComputedValues, parse_style_attribute};
|
||||
use properties::PropertyDeclarationBlock;
|
||||
use properties::animated_properties::AnimationValueMap;
|
||||
|
@ -59,13 +59,13 @@ use selector_parser::{ElementExt, Snapshot};
|
|||
use selectors::Element;
|
||||
use selectors::matching::{ElementSelectorFlags, StyleRelations};
|
||||
use selectors::parser::{AttrSelector, NamespaceConstraint};
|
||||
use servo_url::ServoUrl;
|
||||
use shared_lock::Locked;
|
||||
use sink::Push;
|
||||
use std::fmt;
|
||||
use std::ptr;
|
||||
use std::sync::Arc;
|
||||
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||
use stylesheets::UrlExtraData;
|
||||
use stylist::ApplicableDeclarationBlock;
|
||||
|
||||
/// A simple wrapper over a non-null Gecko node (`nsINode`) pointer.
|
||||
|
@ -315,9 +315,8 @@ impl<'le> fmt::Debug for GeckoElement<'le> {
|
|||
impl<'le> GeckoElement<'le> {
|
||||
/// Parse the style attribute of an element.
|
||||
pub fn parse_style_attribute(value: &str,
|
||||
base_url: &ServoUrl,
|
||||
extra_data: ParserContextExtraData) -> PropertyDeclarationBlock {
|
||||
parse_style_attribute(value, base_url, &StdoutErrorReporter, extra_data)
|
||||
url_data: &UrlExtraData) -> PropertyDeclarationBlock {
|
||||
parse_style_attribute(value, url_data, &StdoutErrorReporter)
|
||||
}
|
||||
|
||||
fn flags(&self) -> u32 {
|
||||
|
@ -390,11 +389,13 @@ impl<'le> GeckoElement<'le> {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
/// A dummy base url in order to get it where we don't have any available.
|
||||
/// A dummy url data in order to get it where we don't have any available.
|
||||
///
|
||||
/// We need to get rid of this sooner than later.
|
||||
pub static ref DUMMY_BASE_URL: ServoUrl = {
|
||||
ServoUrl::parse("http://www.example.org").unwrap()
|
||||
pub static ref DUMMY_URL_DATA: RefPtr<URLExtraData> = {
|
||||
unsafe {
|
||||
RefPtr::from_addrefed(bindings::Gecko_URLExtraData_CreateDummy())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,15 @@ impl<T: RefCounted> RefPtr<T> {
|
|||
ret
|
||||
}
|
||||
|
||||
/// Create a reference to RefPtr from a reference to pointer.
|
||||
///
|
||||
/// The pointer must be valid and non null.
|
||||
///
|
||||
/// This method doesn't touch refcount.
|
||||
pub unsafe fn from_ptr_ref(ptr: &*mut T) -> &Self {
|
||||
mem::transmute(ptr)
|
||||
}
|
||||
|
||||
/// Produces an FFI-compatible RefPtr that can be stored in style structs.
|
||||
///
|
||||
/// structs::RefPtr does not have a destructor, so this may leak
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser};
|
||||
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule};
|
||||
use parser::{ParserContext, ParserContextExtraData, log_css_error};
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
|
||||
use properties::{PropertyDeclarationId, LonghandId, ParsedDeclaration};
|
||||
use properties::LonghandIdSet;
|
||||
|
@ -123,15 +123,12 @@ impl ToCssWithGuard for Keyframe {
|
|||
|
||||
impl Keyframe {
|
||||
/// Parse a CSS keyframe.
|
||||
pub fn parse(css: &str,
|
||||
parent_stylesheet: &Stylesheet,
|
||||
extra_data: ParserContextExtraData)
|
||||
pub fn parse(css: &str, parent_stylesheet: &Stylesheet)
|
||||
-> Result<Arc<Locked<Self>>, ()> {
|
||||
let error_reporter = MemoryHoleReporter;
|
||||
let context = ParserContext::new_with_extra_data(parent_stylesheet.origin,
|
||||
&parent_stylesheet.base_url,
|
||||
&error_reporter,
|
||||
extra_data);
|
||||
let context = ParserContext::new(parent_stylesheet.origin,
|
||||
&parent_stylesheet.url_data,
|
||||
&error_reporter);
|
||||
let mut input = Parser::new(css);
|
||||
|
||||
let mut rule_parser = KeyframeListParser {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>,
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ impl SpecifiedUrl {
|
|||
context: &ParserContext)
|
||||
-> Result<Self, ()> {
|
||||
let serialization = Arc::new(url.into_owned());
|
||||
let resolved = context.base_url.join(&serialization).ok();
|
||||
let resolved = context.url_data.join(&serialization).ok();
|
||||
Ok(SpecifiedUrl {
|
||||
original: Some(serialization),
|
||||
resolved: resolved,
|
||||
|
|
|
@ -16,14 +16,19 @@ use font_face::FontFaceRuleData;
|
|||
use font_face::parse_font_face_block;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use gecko::rules::FontFaceRule;
|
||||
#[cfg(feature = "gecko")]
|
||||
use gecko_bindings::structs::URLExtraData;
|
||||
#[cfg(feature = "gecko")]
|
||||
use gecko_bindings::sugar::refptr::RefPtr;
|
||||
use keyframes::{Keyframe, parse_keyframe_list};
|
||||
use media_queries::{Device, MediaList, parse_media_query_list};
|
||||
use parking_lot::RwLock;
|
||||
use parser::{ParserContext, ParserContextExtraData, log_css_error};
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
|
||||
use selector_parser::{SelectorImpl, SelectorParser};
|
||||
use selectors::parser::SelectorList;
|
||||
use servo_config::prefs::PREFS;
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
use servo_url::ServoUrl;
|
||||
use shared_lock::{SharedRwLock, Locked, ToCssWithGuard, SharedRwLockReadGuard};
|
||||
use std::cell::Cell;
|
||||
|
@ -37,6 +42,30 @@ use values::specified::url::SpecifiedUrl;
|
|||
use viewport::ViewportRule;
|
||||
|
||||
|
||||
/// Extra data that the backend may need to resolve url values.
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
pub type UrlExtraData = ServoUrl;
|
||||
|
||||
/// Extra data that the backend may need to resolve url values.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type UrlExtraData = RefPtr<URLExtraData>;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl UrlExtraData {
|
||||
/// Returns a string for the url.
|
||||
///
|
||||
/// Unimplemented currently.
|
||||
pub fn as_str(&self) -> &str {
|
||||
// TODO
|
||||
"(stylo: not supported)"
|
||||
}
|
||||
}
|
||||
|
||||
// XXX We probably need to figure out whether we should mark Eq here.
|
||||
// It is currently marked so because properties::UnparsedValue wants Eq.
|
||||
#[cfg(feature = "gecko")]
|
||||
impl Eq for UrlExtraData {}
|
||||
|
||||
/// Each style rule has an origin, which determines where it enters the cascade.
|
||||
///
|
||||
/// http://dev.w3.org/csswg/css-cascade/#cascading-origins
|
||||
|
@ -130,9 +159,7 @@ impl CssRules {
|
|||
// Step 3, 4
|
||||
// XXXManishearth should we also store the namespace map?
|
||||
let (new_rule, new_state) =
|
||||
try!(CssRule::parse(&rule, parent_stylesheet,
|
||||
ParserContextExtraData::default(),
|
||||
state, loader));
|
||||
try!(CssRule::parse(&rule, parent_stylesheet, state, loader));
|
||||
|
||||
// Step 5
|
||||
// Computes the maximum allowed parser state at a given index.
|
||||
|
@ -189,8 +216,8 @@ pub struct Stylesheet {
|
|||
pub media: Arc<Locked<MediaList>>,
|
||||
/// The origin of this stylesheet.
|
||||
pub origin: Origin,
|
||||
/// The base url this stylesheet should use.
|
||||
pub base_url: ServoUrl,
|
||||
/// The url data this stylesheet should use.
|
||||
pub url_data: UrlExtraData,
|
||||
/// The lock used for objects inside this stylesheet
|
||||
pub shared_lock: SharedRwLock,
|
||||
/// The namespaces that apply to this stylesheet.
|
||||
|
@ -265,7 +292,7 @@ impl ParseErrorReporter for MemoryHoleReporter {
|
|||
_: &mut Parser,
|
||||
_: SourcePosition,
|
||||
_: &str,
|
||||
_: &ServoUrl) {
|
||||
_: &UrlExtraData) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
@ -348,16 +375,14 @@ impl CssRule {
|
|||
#[allow(missing_docs)]
|
||||
pub fn parse(css: &str,
|
||||
parent_stylesheet: &Stylesheet,
|
||||
extra_data: ParserContextExtraData,
|
||||
state: Option<State>,
|
||||
loader: Option<&StylesheetLoader>)
|
||||
-> Result<(Self, State), SingleRuleParseError> {
|
||||
let error_reporter = MemoryHoleReporter;
|
||||
let mut namespaces = parent_stylesheet.namespaces.write();
|
||||
let context = ParserContext::new_with_extra_data(parent_stylesheet.origin,
|
||||
&parent_stylesheet.base_url,
|
||||
&error_reporter,
|
||||
extra_data);
|
||||
let context = ParserContext::new(parent_stylesheet.origin,
|
||||
&parent_stylesheet.url_data,
|
||||
&error_reporter);
|
||||
let mut input = Parser::new(css);
|
||||
|
||||
// nested rules are in the body state
|
||||
|
@ -571,12 +596,11 @@ impl Stylesheet {
|
|||
pub fn update_from_str(existing: &Stylesheet,
|
||||
css: &str,
|
||||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData) {
|
||||
error_reporter: &ParseErrorReporter) {
|
||||
let mut namespaces = Namespaces::default();
|
||||
let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
|
||||
css, &existing.base_url, existing.origin, &mut namespaces, &existing.shared_lock,
|
||||
stylesheet_loader, error_reporter, extra_data,
|
||||
css, &existing.url_data, existing.origin, &mut namespaces,
|
||||
&existing.shared_lock, stylesheet_loader, error_reporter,
|
||||
);
|
||||
|
||||
*existing.namespaces.write() = namespaces;
|
||||
|
@ -589,13 +613,12 @@ impl Stylesheet {
|
|||
}
|
||||
|
||||
fn parse_rules(css: &str,
|
||||
base_url: &ServoUrl,
|
||||
url_data: &UrlExtraData,
|
||||
origin: Origin,
|
||||
namespaces: &mut Namespaces,
|
||||
shared_lock: &SharedRwLock,
|
||||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData)
|
||||
error_reporter: &ParseErrorReporter)
|
||||
-> (Vec<CssRule>, bool) {
|
||||
let mut rules = Vec::new();
|
||||
let mut input = Parser::new(css);
|
||||
|
@ -604,10 +627,7 @@ impl Stylesheet {
|
|||
namespaces: namespaces,
|
||||
shared_lock: shared_lock,
|
||||
loader: stylesheet_loader,
|
||||
context: ParserContext::new_with_extra_data(origin,
|
||||
base_url,
|
||||
error_reporter,
|
||||
extra_data),
|
||||
context: ParserContext::new(origin, url_data, error_reporter),
|
||||
state: Cell::new(State::Start),
|
||||
};
|
||||
|
||||
|
@ -636,21 +656,20 @@ impl Stylesheet {
|
|||
/// Effectively creates a new stylesheet and forwards the hard work to
|
||||
/// `Stylesheet::update_from_str`.
|
||||
pub fn from_str(css: &str,
|
||||
base_url: ServoUrl,
|
||||
url_data: UrlExtraData,
|
||||
origin: Origin,
|
||||
media: MediaList,
|
||||
shared_lock: SharedRwLock,
|
||||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData) -> Stylesheet {
|
||||
error_reporter: &ParseErrorReporter) -> Stylesheet {
|
||||
let mut namespaces = Namespaces::default();
|
||||
let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
|
||||
css, &base_url, origin, &mut namespaces, &shared_lock,
|
||||
stylesheet_loader, error_reporter, extra_data,
|
||||
css, &url_data, origin, &mut namespaces,
|
||||
&shared_lock, stylesheet_loader, error_reporter,
|
||||
);
|
||||
Stylesheet {
|
||||
origin: origin,
|
||||
base_url: base_url,
|
||||
url_data: url_data,
|
||||
namespaces: RwLock::new(namespaces),
|
||||
rules: CssRules::new(rules, &shared_lock),
|
||||
media: Arc::new(shared_lock.wrap(media)),
|
||||
|
@ -869,7 +888,7 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
|
|||
media: Arc::new(self.shared_lock.wrap(media)),
|
||||
shared_lock: self.shared_lock.clone(),
|
||||
origin: self.context.stylesheet_origin,
|
||||
base_url: self.context.base_url.clone(),
|
||||
url_data: self.context.url_data.clone(),
|
||||
namespaces: RwLock::new(Namespaces::default()),
|
||||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||
disabled: AtomicBool::new(false),
|
||||
|
|
|
@ -8,7 +8,6 @@ use cssparser::ToCss as ParserToCss;
|
|||
use env_logger::LogBuilder;
|
||||
use parking_lot::RwLock;
|
||||
use selectors::Element;
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::Cow;
|
||||
use std::env;
|
||||
use std::fmt::Write;
|
||||
|
@ -26,7 +25,7 @@ use style::gecko::global_style_data::GLOBAL_STYLE_DATA;
|
|||
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
||||
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
|
||||
use style::gecko::traversal::RecalcStyleOnly;
|
||||
use style::gecko::wrapper::DUMMY_BASE_URL;
|
||||
use style::gecko::wrapper::DUMMY_URL_DATA;
|
||||
use style::gecko::wrapper::GeckoElement;
|
||||
use style::gecko_bindings::bindings;
|
||||
use style::gecko_bindings::bindings::{RawGeckoKeyframeListBorrowed, RawGeckoKeyframeListBorrowedMut};
|
||||
|
@ -63,11 +62,12 @@ use style::gecko_bindings::structs::nsCSSValueSharedList;
|
|||
use style::gecko_bindings::structs::nsresult;
|
||||
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasFFI, HasArcFFI, HasBoxFFI};
|
||||
use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
|
||||
use style::gecko_bindings::sugar::refptr::RefPtr;
|
||||
use style::gecko_properties::{self, style_structs};
|
||||
use style::keyframes::KeyframesStepValue;
|
||||
use style::media_queries::{MediaList, parse_media_query_list};
|
||||
use style::parallel;
|
||||
use style::parser::{ParserContext, ParserContextExtraData};
|
||||
use style::parser::ParserContext;
|
||||
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration};
|
||||
use style::properties::{PropertyDeclarationBlock, PropertyId};
|
||||
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
||||
|
@ -310,8 +310,6 @@ pub extern "C" fn Servo_Element_ClearData(element: RawGeckoElementBorrowed) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyleSheetStrong {
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let url = ServoUrl::parse("about:blank").unwrap();
|
||||
let extra_data = ParserContextExtraData::default();
|
||||
let origin = match mode {
|
||||
SheetParsingMode::eAuthorSheetFeatures => Origin::Author,
|
||||
SheetParsingMode::eUserSheetFeatures => Origin::User,
|
||||
|
@ -319,8 +317,8 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl
|
|||
};
|
||||
let shared_lock = global_style_data.shared_lock.clone();
|
||||
Arc::new(Stylesheet::from_str(
|
||||
"", url, origin, Default::default(), shared_lock, None,
|
||||
&StdoutErrorReporter, extra_data)
|
||||
"", DUMMY_URL_DATA.clone(), origin, Default::default(),
|
||||
shared_lock, None, &StdoutErrorReporter)
|
||||
).into_strong()
|
||||
}
|
||||
|
||||
|
@ -329,7 +327,7 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
|
|||
stylesheet: *mut ServoStyleSheet,
|
||||
data: *const nsACString,
|
||||
mode: SheetParsingMode,
|
||||
base_url: *const nsACString,
|
||||
_base_url: *const nsACString,
|
||||
extra_data: *mut URLExtraData)
|
||||
-> RawServoStyleSheetStrong {
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
|
@ -341,9 +339,7 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
|
|||
SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent,
|
||||
};
|
||||
|
||||
let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() };
|
||||
let url = ServoUrl::parse(base_str).unwrap();
|
||||
let extra_data = unsafe { ParserContextExtraData::new(extra_data) };
|
||||
let url_data = unsafe { RefPtr::from_ptr_ref(&extra_data) };
|
||||
let loader = if loader.is_null() {
|
||||
None
|
||||
} else {
|
||||
|
@ -358,8 +354,8 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
|
|||
|
||||
let shared_lock = global_style_data.shared_lock.clone();
|
||||
Arc::new(Stylesheet::from_str(
|
||||
input, url, origin, Default::default(), shared_lock, loader,
|
||||
&StdoutErrorReporter, extra_data)
|
||||
input, url_data.clone(), origin, Default::default(),
|
||||
shared_lock, loader, &StdoutErrorReporter)
|
||||
).into_strong()
|
||||
}
|
||||
|
||||
|
@ -368,10 +364,9 @@ pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheet
|
|||
loader: *mut Loader,
|
||||
gecko_stylesheet: *mut ServoStyleSheet,
|
||||
data: *const nsACString,
|
||||
extra_data: *mut URLExtraData)
|
||||
_extra_data: *mut URLExtraData)
|
||||
{
|
||||
let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
||||
let extra_data = unsafe { ParserContextExtraData::new(extra_data) };
|
||||
|
||||
let loader = if loader.is_null() {
|
||||
None
|
||||
|
@ -386,7 +381,7 @@ pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheet
|
|||
};
|
||||
|
||||
let sheet = Stylesheet::as_arc(&stylesheet);
|
||||
Stylesheet::update_from_str(&sheet, input, loader, &StdoutErrorReporter, extra_data);
|
||||
Stylesheet::update_from_str(&sheet, input, loader, &StdoutErrorReporter);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -776,20 +771,9 @@ pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) {
|
|||
let _ = data.into_box::<PerDocumentStyleData>();
|
||||
}
|
||||
|
||||
// Must be a macro since we need to store the base_url on the stack somewhere
|
||||
/// Initializes the data needed for constructing a ParserContext from
|
||||
/// Gecko-side values
|
||||
macro_rules! make_context {
|
||||
(($base:ident, $data:ident) => ($base_url:ident, $extra_data:ident)) => {
|
||||
let base_str = unsafe { $base.as_ref().unwrap().as_str_unchecked() };
|
||||
let $base_url = ServoUrl::parse(base_str).unwrap();
|
||||
let $extra_data = unsafe { ParserContextExtraData::new($data) };
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const nsACString,
|
||||
base: *const nsACString,
|
||||
_base: *const nsACString,
|
||||
data: *mut URLExtraData)
|
||||
-> RawServoDeclarationBlockStrong {
|
||||
let name = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
||||
|
@ -800,13 +784,9 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const
|
|||
};
|
||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||
|
||||
make_context!((base, data) => (base_url, extra_data));
|
||||
|
||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
||||
let reporter = StdoutErrorReporter;
|
||||
let context = ParserContext::new_with_extra_data(Origin::Author,
|
||||
&base_url,
|
||||
&reporter,
|
||||
extra_data);
|
||||
let context = ParserContext::new(Origin::Author, url_data, &reporter);
|
||||
|
||||
match ParsedDeclaration::parse(id, &context, &mut Parser::new(value), false) {
|
||||
Ok(parsed) => {
|
||||
|
@ -821,15 +801,15 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
|
||||
base: *const nsACString,
|
||||
_base: *const nsACString,
|
||||
data: *mut URLExtraData,
|
||||
output: nsTimingFunctionBorrowedMut)
|
||||
-> bool {
|
||||
use style::properties::longhands::transition_timing_function;
|
||||
|
||||
make_context!((base, data) => (base_url, extra_data));
|
||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
||||
let reporter = StdoutErrorReporter;
|
||||
let context = ParserContext::new_with_extra_data(Origin::Author, &base_url, &reporter, extra_data);
|
||||
let context = ParserContext::new(Origin::Author, url_data, &reporter);
|
||||
let easing = unsafe { (*easing).to_string() };
|
||||
match transition_timing_function::single_value::parse(&context, &mut Parser::new(&easing)) {
|
||||
Ok(parsed_easing) => {
|
||||
|
@ -842,14 +822,14 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString,
|
||||
base: *const nsACString,
|
||||
_base: *const nsACString,
|
||||
raw_extra_data: *mut URLExtraData)
|
||||
-> RawServoDeclarationBlockStrong {
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let value = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
||||
make_context!((base, raw_extra_data) => (base_url, extra_data));
|
||||
let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) };
|
||||
Arc::new(global_style_data.shared_lock.wrap(
|
||||
GeckoElement::parse_style_attribute(value, &base_url, extra_data))).into_strong()
|
||||
GeckoElement::parse_style_attribute(value, url_data))).into_strong()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -963,12 +943,12 @@ pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: Ra
|
|||
|
||||
fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId,
|
||||
value: *const nsACString, is_important: bool,
|
||||
base: *const nsACString, data: *mut URLExtraData) -> bool {
|
||||
_base: *const nsACString, data: *mut URLExtraData) -> bool {
|
||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||
|
||||
make_context!((base, data) => (base_url, extra_data));
|
||||
if let Ok(parsed) = parse_one_declaration(property_id, value, &base_url,
|
||||
&StdoutErrorReporter, extra_data) {
|
||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
||||
if let Ok(parsed) = parse_one_declaration(property_id, value, url_data,
|
||||
&StdoutErrorReporter) {
|
||||
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||
parsed.expand_set_into(decls, importance)
|
||||
|
@ -1360,10 +1340,8 @@ pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const
|
|||
};
|
||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||
|
||||
let base_url = &*DUMMY_BASE_URL;
|
||||
let extra_data = ParserContextExtraData::default();
|
||||
|
||||
parse_one_declaration(id, &value, &base_url, &StdoutErrorReporter, extra_data).is_ok()
|
||||
let url_data = &*DUMMY_URL_DATA;
|
||||
parse_one_declaration(id, &value, url_data, &StdoutErrorReporter).is_ok()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1372,9 +1350,9 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool {
|
|||
let mut input = Parser::new(&condition);
|
||||
let cond = parse_condition_or_declaration(&mut input);
|
||||
if let Ok(cond) = cond {
|
||||
let url = ServoUrl::parse("about:blank").unwrap();
|
||||
let url_data = &*DUMMY_URL_DATA;
|
||||
let reporter = StdoutErrorReporter;
|
||||
let context = ParserContext::new_for_cssom(&url, &reporter);
|
||||
let context = ParserContext::new_for_cssom(url_data, &reporter);
|
||||
cond.eval(&context)
|
||||
} else {
|
||||
false
|
||||
|
|
|
@ -9,7 +9,6 @@ use std::borrow::ToOwned;
|
|||
use style::Atom;
|
||||
use style::error_reporting::ParseErrorReporter;
|
||||
use style::media_queries::*;
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::servo::media_queries::*;
|
||||
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard};
|
||||
use style::stylesheets::{Stylesheet, Origin, CssRule};
|
||||
|
@ -31,8 +30,7 @@ fn test_media_rule<F>(css: &str, callback: F)
|
|||
let css_str = css.to_owned();
|
||||
let stylesheet = Stylesheet::from_str(
|
||||
css, url, Origin::Author, Default::default(), SharedRwLock::new(),
|
||||
None, &CSSErrorReporterTest,
|
||||
ParserContextExtraData::default());
|
||||
None, &CSSErrorReporterTest);
|
||||
let mut rule_count = 0;
|
||||
let guard = stylesheet.shared_lock.read();
|
||||
media_queries(&guard, &stylesheet.rules.read_with(&guard).0, &mut |mq| {
|
||||
|
@ -59,8 +57,7 @@ fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
|
|||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let ss = Stylesheet::from_str(
|
||||
css, url, Origin::Author, Default::default(), SharedRwLock::new(),
|
||||
None, &CSSErrorReporterTest,
|
||||
ParserContextExtraData::default());
|
||||
None, &CSSErrorReporterTest);
|
||||
let mut rule_count = 0;
|
||||
ss.effective_style_rules(device, &ss.shared_lock.read(), |_| rule_count += 1);
|
||||
assert!(rule_count == expected_rule_count, css.to_owned());
|
||||
|
|
|
@ -8,7 +8,6 @@ use servo_url::ServoUrl;
|
|||
use std::sync::Arc;
|
||||
use style::error_reporting::ParseErrorReporter;
|
||||
use style::media_queries::MediaList;
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::properties::{longhands, Importance, PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use style::rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
|
||||
use style::shared_lock::SharedRwLock;
|
||||
|
@ -46,8 +45,7 @@ fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> {
|
|||
},
|
||||
SharedRwLock::new(),
|
||||
None,
|
||||
&ErrorringErrorReporter,
|
||||
ParserContextExtraData {});
|
||||
&ErrorringErrorReporter);
|
||||
let guard = s.shared_lock.read();
|
||||
let rules = s.rules.read_with(&guard);
|
||||
rules.0.iter().filter_map(|rule| {
|
||||
|
|
|
@ -15,7 +15,6 @@ use std::sync::Mutex;
|
|||
use std::sync::atomic::AtomicBool;
|
||||
use style::error_reporting::ParseErrorReporter;
|
||||
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::properties::Importance;
|
||||
use style::properties::{CSSWideKeyword, DeclaredValueOwned, PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use style::properties::longhands;
|
||||
|
@ -64,8 +63,7 @@ fn test_parse_stylesheet() {
|
|||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
||||
SharedRwLock::new(), None,
|
||||
&CSSErrorReporterTest,
|
||||
ParserContextExtraData::default());
|
||||
&CSSErrorReporterTest);
|
||||
let mut namespaces = Namespaces::default();
|
||||
namespaces.default = Some(ns!(html));
|
||||
let expected = Stylesheet {
|
||||
|
@ -73,7 +71,7 @@ fn test_parse_stylesheet() {
|
|||
media: Arc::new(stylesheet.shared_lock.wrap(Default::default())),
|
||||
shared_lock: stylesheet.shared_lock.clone(),
|
||||
namespaces: RwLock::new(namespaces),
|
||||
base_url: url,
|
||||
url_data: url,
|
||||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||
disabled: AtomicBool::new(false),
|
||||
rules: CssRules::new(vec![
|
||||
|
@ -327,8 +325,7 @@ fn test_report_error_stylesheet() {
|
|||
|
||||
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
||||
SharedRwLock::new(), None,
|
||||
&error_reporter,
|
||||
ParserContextExtraData::default());
|
||||
&error_reporter);
|
||||
|
||||
let mut errors = errors.lock().unwrap();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use media_queries::CSSErrorReporterTest;
|
|||
use servo_config::prefs::{PREFS, PrefValue};
|
||||
use servo_url::ServoUrl;
|
||||
use style::media_queries::{Device, MediaType};
|
||||
use style::parser::{ParserContext, ParserContextExtraData};
|
||||
use style::parser::ParserContext;
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::{Stylesheet, Origin};
|
||||
use style::values::specified::LengthOrPercentageOrAuto::{self, Auto};
|
||||
|
@ -30,8 +30,7 @@ macro_rules! stylesheet {
|
|||
Default::default(),
|
||||
$shared_lock,
|
||||
None,
|
||||
&$error_reporter,
|
||||
ParserContextExtraData::default()
|
||||
&$error_reporter
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue