mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #16241 - upsuper:bug1352763-bug1352025, r=Manishearth,emilio
Stop passing url as string into Servo side This is the Servo side changes of [bug 1352763](https://bugzilla.mozilla.org/show_bug.cgi?id=1352763) and [bug 1352025](https://bugzilla.mozilla.org/show_bug.cgi?id=1352025) which have been reviewed on Bugzilla.
This commit is contained in:
commit
679b418937
32 changed files with 269 additions and 308 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -945,7 +945,6 @@ dependencies = [
|
||||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"selectors 0.18.0",
|
"selectors 0.18.0",
|
||||||
"servo_url 0.0.1",
|
|
||||||
"style 0.0.1",
|
"style 0.0.1",
|
||||||
"style_traits 0.0.1",
|
"style_traits 0.0.1",
|
||||||
"stylo_tests 0.0.1",
|
"stylo_tests 0.0.1",
|
||||||
|
|
|
@ -113,7 +113,6 @@ use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode};
|
||||||
use style::error_reporting::StdoutErrorReporter;
|
use style::error_reporting::StdoutErrorReporter;
|
||||||
use style::logical_geometry::LogicalPoint;
|
use style::logical_geometry::LogicalPoint;
|
||||||
use style::media_queries::{Device, MediaType};
|
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::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW};
|
||||||
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards};
|
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards};
|
||||||
use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets};
|
use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets};
|
||||||
|
@ -1586,8 +1585,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
||||||
Default::default(),
|
Default::default(),
|
||||||
shared_lock.clone(),
|
shared_lock.clone(),
|
||||||
None,
|
None,
|
||||||
&StdoutErrorReporter,
|
&StdoutErrorReporter))
|
||||||
ParserContextExtraData::default()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let shared_lock = SharedRwLock::new();
|
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 {
|
for &(ref contents, ref url) in &opts::get().user_stylesheets {
|
||||||
user_or_user_agent_stylesheets.push(Stylesheet::from_bytes(
|
user_or_user_agent_stylesheets.push(Stylesheet::from_bytes(
|
||||||
&contents, url.clone(), None, None, Origin::User, Default::default(),
|
&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"));
|
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 servo_atoms::Atom;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::keyframes::{Keyframe, KeyframeSelector};
|
use style::keyframes::{Keyframe, KeyframeSelector};
|
||||||
use style::parser::ParserContextExtraData;
|
|
||||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||||
use style::stylesheets::KeyframesRule;
|
use style::stylesheets::KeyframesRule;
|
||||||
|
|
||||||
|
@ -83,8 +82,7 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule {
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-appendrule
|
// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-appendrule
|
||||||
fn AppendRule(&self, rule: DOMString) {
|
fn AppendRule(&self, rule: DOMString) {
|
||||||
let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet(),
|
let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet());
|
||||||
ParserContextExtraData::default());
|
|
||||||
if let Ok(rule) = rule {
|
if let Ok(rule) = rule {
|
||||||
let mut guard = self.cssrule.shared_lock().write();
|
let mut guard = self.cssrule.shared_lock().write();
|
||||||
self.keyframesrule.write_with(&mut guard).keyframes.push(rule);
|
self.keyframesrule.write_with(&mut guard).keyframes.push(rule);
|
||||||
|
|
|
@ -92,7 +92,10 @@ impl CSSRuleList {
|
||||||
let parent_stylesheet = self.parent_stylesheet.style_stylesheet();
|
let parent_stylesheet = self.parent_stylesheet.style_stylesheet();
|
||||||
let new_rule = {
|
let new_rule = {
|
||||||
let mut guard = parent_stylesheet.shared_lock.write();
|
let mut guard = parent_stylesheet.shared_lock.write();
|
||||||
css_rules.write_with(&mut guard).insert_rule(rule, parent_stylesheet, index, nested)?
|
// FIXME We should probably pass in a proper StylesheetLoader.
|
||||||
|
// See servo/servo#16240
|
||||||
|
css_rules.write_with(&mut guard).insert_rule(rule, parent_stylesheet,
|
||||||
|
index, nested, None)?
|
||||||
// Drop `guard` here,
|
// Drop `guard` here,
|
||||||
// CSSRule::new_specific re-acquires the lock for @support and @media.
|
// CSSRule::new_specific re-acquires the lock for @support and @media.
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,6 @@ use servo_url::ServoUrl;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::attr::AttrValue;
|
use style::attr::AttrValue;
|
||||||
use style::parser::ParserContextExtraData;
|
|
||||||
use style::properties::{Importance, PropertyDeclarationBlock, PropertyId, LonghandId, ShorthandId};
|
use style::properties::{Importance, PropertyDeclarationBlock, PropertyId, LonghandId, ShorthandId};
|
||||||
use style::properties::{parse_one_declaration, parse_style_attribute};
|
use style::properties::{parse_one_declaration, parse_style_attribute};
|
||||||
use style::selector_parser::PseudoElement;
|
use style::selector_parser::PseudoElement;
|
||||||
|
@ -147,7 +146,7 @@ impl CSSStyleOwner {
|
||||||
match *self {
|
match *self {
|
||||||
CSSStyleOwner::Element(ref el) => window_from_node(&**el).Document().base_url(),
|
CSSStyleOwner::Element(ref el) => window_from_node(&**el).Document().base_url(),
|
||||||
CSSStyleOwner::CSSRule(ref rule, _) => {
|
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 window = self.owner.window();
|
||||||
let result =
|
let result =
|
||||||
parse_one_declaration(id, &value, &self.owner.base_url(),
|
parse_one_declaration(id, &value, &self.owner.base_url(),
|
||||||
window.css_error_reporter(),
|
window.css_error_reporter());
|
||||||
ParserContextExtraData::default());
|
|
||||||
|
|
||||||
// Step 7
|
// Step 7
|
||||||
let parsed = match result {
|
let parsed = match result {
|
||||||
|
@ -439,8 +437,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
// Step 3
|
// Step 3
|
||||||
*pdb = parse_style_attribute(&value,
|
*pdb = parse_style_attribute(&value,
|
||||||
&self.owner.base_url(),
|
&self.owner.base_url(),
|
||||||
window.css_error_reporter(),
|
window.css_error_reporter());
|
||||||
ParserContextExtraData::default());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -101,7 +101,6 @@ use style::attr::{AttrValue, LengthOrPercentageOrAuto};
|
||||||
use style::context::{QuirksMode, ReflowGoal};
|
use style::context::{QuirksMode, ReflowGoal};
|
||||||
use style::element_state::*;
|
use style::element_state::*;
|
||||||
use style::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
|
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::{Importance, PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
|
||||||
use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size, overflow_x};
|
use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size, overflow_x};
|
||||||
use style::restyle_hints::RESTYLE_SELF;
|
use style::restyle_hints::RESTYLE_SELF;
|
||||||
|
@ -2197,8 +2196,7 @@ impl VirtualMethods for Element {
|
||||||
Arc::new(doc.style_shared_lock().wrap(parse_style_attribute(
|
Arc::new(doc.style_shared_lock().wrap(parse_style_attribute(
|
||||||
&attr.value(),
|
&attr.value(),
|
||||||
&doc.base_url(),
|
&doc.base_url(),
|
||||||
win.css_error_reporter(),
|
win.css_error_reporter())))
|
||||||
ParserContextExtraData::default())))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(block)
|
Some(block)
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl HTMLMetaElement {
|
||||||
rules: CssRules::new(vec![rule], shared_lock),
|
rules: CssRules::new(vec![rule], shared_lock),
|
||||||
origin: Origin::Author,
|
origin: Origin::Author,
|
||||||
shared_lock: shared_lock.clone(),
|
shared_lock: shared_lock.clone(),
|
||||||
base_url: window_from_node(self).get_url(),
|
url_data: window_from_node(self).get_url(),
|
||||||
namespaces: Default::default(),
|
namespaces: Default::default(),
|
||||||
media: Arc::new(shared_lock.wrap(Default::default())),
|
media: Arc::new(shared_lock.wrap(Default::default())),
|
||||||
// Viewport constraints are always recomputed on resize; they don't need to
|
// 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::cell::Cell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::media_queries::parse_media_query_list;
|
use style::media_queries::parse_media_query_list;
|
||||||
use style::parser::ParserContextExtraData;
|
|
||||||
use style::stylesheets::{Stylesheet, Origin};
|
use style::stylesheets::{Stylesheet, Origin};
|
||||||
use stylesheet_loader::{StylesheetLoader, StylesheetOwner};
|
use stylesheet_loader::{StylesheetLoader, StylesheetOwner};
|
||||||
|
|
||||||
|
@ -88,8 +87,7 @@ impl HTMLStyleElement {
|
||||||
let loader = StylesheetLoader::for_element(self.upcast());
|
let loader = StylesheetLoader::for_element(self.upcast());
|
||||||
let sheet = Stylesheet::from_str(&data, url, Origin::Author, mq,
|
let sheet = Stylesheet::from_str(&data, url, Origin::Author, mq,
|
||||||
shared_lock, Some(&loader),
|
shared_lock, Some(&loader),
|
||||||
win.css_error_reporter(),
|
win.css_error_reporter());
|
||||||
ParserContextExtraData::default());
|
|
||||||
|
|
||||||
let sheet = Arc::new(sheet);
|
let sheet = Arc::new(sheet);
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ use servo_url::ServoUrl;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use style::media_queries::MediaList;
|
use style::media_queries::MediaList;
|
||||||
use style::parser::ParserContextExtraData;
|
|
||||||
use style::shared_lock::Locked as StyleLocked;
|
use style::shared_lock::Locked as StyleLocked;
|
||||||
use style::stylesheets::{ImportRule, Stylesheet, Origin};
|
use style::stylesheets::{ImportRule, Stylesheet, Origin};
|
||||||
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
||||||
|
@ -146,8 +145,7 @@ impl FetchResponseListener for StylesheetContext {
|
||||||
media.take().unwrap(),
|
media.take().unwrap(),
|
||||||
shared_lock,
|
shared_lock,
|
||||||
Some(&loader),
|
Some(&loader),
|
||||||
win.css_error_reporter(),
|
win.css_error_reporter()));
|
||||||
ParserContextExtraData::default()));
|
|
||||||
|
|
||||||
if link.is_alternate() {
|
if link.is_alternate() {
|
||||||
sheet.set_disabled(true);
|
sheet.set_disabled(true);
|
||||||
|
@ -163,9 +161,9 @@ impl FetchResponseListener for StylesheetContext {
|
||||||
&data,
|
&data,
|
||||||
protocol_encoding_label,
|
protocol_encoding_label,
|
||||||
Some(environment_encoding),
|
Some(environment_encoding),
|
||||||
|
&final_url,
|
||||||
Some(&loader),
|
Some(&loader),
|
||||||
win.css_error_reporter(),
|
win.css_error_reporter());
|
||||||
ParserContextExtraData::default());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,10 @@ extern crate encoding;
|
||||||
use cssparser::{stylesheet_encoding, EncodingSupport};
|
use cssparser::{stylesheet_encoding, EncodingSupport};
|
||||||
use error_reporting::ParseErrorReporter;
|
use error_reporting::ParseErrorReporter;
|
||||||
use media_queries::MediaList;
|
use media_queries::MediaList;
|
||||||
use parser::ParserContextExtraData;
|
|
||||||
use self::encoding::{EncodingRef, DecoderTrap};
|
use self::encoding::{EncodingRef, DecoderTrap};
|
||||||
use servo_url::ServoUrl;
|
|
||||||
use shared_lock::SharedRwLock;
|
use shared_lock::SharedRwLock;
|
||||||
use std::str;
|
use std::str;
|
||||||
use stylesheets::{Stylesheet, StylesheetLoader, Origin};
|
use stylesheets::{Stylesheet, StylesheetLoader, Origin, UrlExtraData};
|
||||||
|
|
||||||
struct RustEncoding;
|
struct RustEncoding;
|
||||||
|
|
||||||
|
@ -50,26 +48,24 @@ impl Stylesheet {
|
||||||
/// Takes care of decoding the network bytes and forwards the resulting
|
/// Takes care of decoding the network bytes and forwards the resulting
|
||||||
/// string to `Stylesheet::from_str`.
|
/// string to `Stylesheet::from_str`.
|
||||||
pub fn from_bytes(bytes: &[u8],
|
pub fn from_bytes(bytes: &[u8],
|
||||||
base_url: ServoUrl,
|
url_data: UrlExtraData,
|
||||||
protocol_encoding_label: Option<&str>,
|
protocol_encoding_label: Option<&str>,
|
||||||
environment_encoding: Option<EncodingRef>,
|
environment_encoding: Option<EncodingRef>,
|
||||||
origin: Origin,
|
origin: Origin,
|
||||||
media: MediaList,
|
media: MediaList,
|
||||||
shared_lock: SharedRwLock,
|
shared_lock: SharedRwLock,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter)
|
||||||
extra_data: ParserContextExtraData)
|
|
||||||
-> Stylesheet {
|
-> Stylesheet {
|
||||||
let (string, _) = decode_stylesheet_bytes(
|
let (string, _) = decode_stylesheet_bytes(
|
||||||
bytes, protocol_encoding_label, environment_encoding);
|
bytes, protocol_encoding_label, environment_encoding);
|
||||||
Stylesheet::from_str(&string,
|
Stylesheet::from_str(&string,
|
||||||
base_url,
|
url_data,
|
||||||
origin,
|
origin,
|
||||||
media,
|
media,
|
||||||
shared_lock,
|
shared_lock,
|
||||||
stylesheet_loader,
|
stylesheet_loader,
|
||||||
error_reporter,
|
error_reporter)
|
||||||
extra_data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates an empty stylesheet with a set of bytes that reached over the
|
/// Updates an empty stylesheet with a set of bytes that reached over the
|
||||||
|
@ -78,15 +74,15 @@ impl Stylesheet {
|
||||||
bytes: &[u8],
|
bytes: &[u8],
|
||||||
protocol_encoding_label: Option<&str>,
|
protocol_encoding_label: Option<&str>,
|
||||||
environment_encoding: Option<EncodingRef>,
|
environment_encoding: Option<EncodingRef>,
|
||||||
|
url_data: &UrlExtraData,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter) {
|
||||||
extra_data: ParserContextExtraData) {
|
|
||||||
let (string, _) = decode_stylesheet_bytes(
|
let (string, _) = decode_stylesheet_bytes(
|
||||||
bytes, protocol_encoding_label, environment_encoding);
|
bytes, protocol_encoding_label, environment_encoding);
|
||||||
Self::update_from_str(existing,
|
Self::update_from_str(existing,
|
||||||
&string,
|
&string,
|
||||||
|
url_data,
|
||||||
stylesheet_loader,
|
stylesheet_loader,
|
||||||
error_reporter,
|
error_reporter)
|
||||||
extra_data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
use cssparser::{Parser, SourcePosition};
|
use cssparser::{Parser, SourcePosition};
|
||||||
use log;
|
use log;
|
||||||
use servo_url::ServoUrl;
|
use stylesheets::UrlExtraData;
|
||||||
|
|
||||||
/// A generic trait for an error reporter.
|
/// A generic trait for an error reporter.
|
||||||
pub trait ParseErrorReporter : Sync + Send {
|
pub trait ParseErrorReporter : Sync + Send {
|
||||||
|
@ -20,7 +20,7 @@ pub trait ParseErrorReporter : Sync + Send {
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
position: SourcePosition,
|
position: SourcePosition,
|
||||||
message: &str,
|
message: &str,
|
||||||
url: &ServoUrl);
|
url: &UrlExtraData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error reporter that reports the errors to the `info` log channel.
|
/// An error reporter that reports the errors to the `info` log channel.
|
||||||
|
@ -32,7 +32,7 @@ impl ParseErrorReporter for StdoutErrorReporter {
|
||||||
input: &mut Parser,
|
input: &mut Parser,
|
||||||
position: SourcePosition,
|
position: SourcePosition,
|
||||||
message: &str,
|
message: &str,
|
||||||
url: &ServoUrl) {
|
url: &UrlExtraData) {
|
||||||
if log_enabled!(log::LogLevel::Info) {
|
if log_enabled!(log::LogLevel::Info) {
|
||||||
let location = input.source_location(position);
|
let location = input.source_location(position);
|
||||||
info!("Url:\t{}\n{}:{} {}", url.as_str(), location.line, location.column, message)
|
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>,
|
pub fn parse_from_string<'a>(url: Cow<'a, str>,
|
||||||
context: &ParserContext)
|
context: &ParserContext)
|
||||||
-> Result<Self, ()> {
|
-> 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 {
|
Ok(SpecifiedUrl {
|
||||||
serialization: Arc::new(url.into_owned()),
|
serialization: Arc::new(url.into_owned()),
|
||||||
extra_data: extra.data.as_ref().unwrap().clone(),
|
extra_data: context.url_data.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE;
|
||||||
use gecko_bindings::structs::NODE_IS_NATIVE_ANONYMOUS;
|
use gecko_bindings::structs::NODE_IS_NATIVE_ANONYMOUS;
|
||||||
use gecko_bindings::sugar::ownership::HasArcFFI;
|
use gecko_bindings::sugar::ownership::HasArcFFI;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use parser::ParserContextExtraData;
|
|
||||||
use properties::{ComputedValues, parse_style_attribute};
|
use properties::{ComputedValues, parse_style_attribute};
|
||||||
use properties::PropertyDeclarationBlock;
|
use properties::PropertyDeclarationBlock;
|
||||||
use properties::animated_properties::AnimationValueMap;
|
use properties::animated_properties::AnimationValueMap;
|
||||||
|
@ -59,13 +58,13 @@ use selector_parser::{ElementExt, Snapshot};
|
||||||
use selectors::Element;
|
use selectors::Element;
|
||||||
use selectors::matching::{ElementSelectorFlags, StyleRelations};
|
use selectors::matching::{ElementSelectorFlags, StyleRelations};
|
||||||
use selectors::parser::{AttrSelector, NamespaceConstraint};
|
use selectors::parser::{AttrSelector, NamespaceConstraint};
|
||||||
use servo_url::ServoUrl;
|
|
||||||
use shared_lock::Locked;
|
use shared_lock::Locked;
|
||||||
use sink::Push;
|
use sink::Push;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||||
|
use stylesheets::UrlExtraData;
|
||||||
use stylist::ApplicableDeclarationBlock;
|
use stylist::ApplicableDeclarationBlock;
|
||||||
|
|
||||||
/// A simple wrapper over a non-null Gecko node (`nsINode`) pointer.
|
/// A simple wrapper over a non-null Gecko node (`nsINode`) pointer.
|
||||||
|
@ -315,9 +314,8 @@ impl<'le> fmt::Debug for GeckoElement<'le> {
|
||||||
impl<'le> GeckoElement<'le> {
|
impl<'le> GeckoElement<'le> {
|
||||||
/// Parse the style attribute of an element.
|
/// Parse the style attribute of an element.
|
||||||
pub fn parse_style_attribute(value: &str,
|
pub fn parse_style_attribute(value: &str,
|
||||||
base_url: &ServoUrl,
|
url_data: &UrlExtraData) -> PropertyDeclarationBlock {
|
||||||
extra_data: ParserContextExtraData) -> PropertyDeclarationBlock {
|
parse_style_attribute(value, url_data, &StdoutErrorReporter)
|
||||||
parse_style_attribute(value, base_url, &StdoutErrorReporter, extra_data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flags(&self) -> u32 {
|
fn flags(&self) -> u32 {
|
||||||
|
@ -389,15 +387,6 @@ impl<'le> GeckoElement<'le> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
/// A dummy base url 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()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts flags from the layout used by rust-selectors to the layout used
|
/// Converts flags from the layout used by rust-selectors to the layout used
|
||||||
/// by Gecko. We could align these and then do this without conditionals, but
|
/// by Gecko. We could align these and then do this without conditionals, but
|
||||||
/// it's probably not worth the trouble.
|
/// it's probably not worth the trouble.
|
||||||
|
|
|
@ -428,11 +428,14 @@ extern "C" {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_LoadStyleSheet(loader: *mut Loader,
|
pub fn Gecko_LoadStyleSheet(loader: *mut Loader,
|
||||||
parent: *mut ServoStyleSheet,
|
parent: *mut ServoStyleSheet,
|
||||||
import_rule: RawServoImportRuleBorrowed,
|
child_sheet: RawServoStyleSheetBorrowed,
|
||||||
base_url_data: *mut RawGeckoURLExtraData,
|
base_url_data: *mut RawGeckoURLExtraData,
|
||||||
url_bytes: *const u8, url_length: u32,
|
url_bytes: *const u8, url_length: u32,
|
||||||
media_bytes: *const u8, media_length: u32);
|
media_bytes: *const u8, media_length: u32);
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Gecko_URLExtraData_CreateDummy() -> *mut RawGeckoURLExtraData;
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_MaybeCreateStyleChildrenIterator(node: RawGeckoNodeBorrowed)
|
pub fn Gecko_MaybeCreateStyleChildrenIterator(node: RawGeckoNodeBorrowed)
|
||||||
-> StyleChildrenIteratorOwnedOrNull;
|
-> StyleChildrenIteratorOwnedOrNull;
|
||||||
|
@ -1377,7 +1380,6 @@ extern "C" {
|
||||||
*mut ServoStyleSheet,
|
*mut ServoStyleSheet,
|
||||||
data: *const nsACString,
|
data: *const nsACString,
|
||||||
parsing_mode: SheetParsingMode,
|
parsing_mode: SheetParsingMode,
|
||||||
base_url: *const nsACString,
|
|
||||||
extra_data:
|
extra_data:
|
||||||
*mut RawGeckoURLExtraData)
|
*mut RawGeckoURLExtraData)
|
||||||
-> RawServoStyleSheetStrong;
|
-> RawServoStyleSheetStrong;
|
||||||
|
@ -1466,8 +1468,9 @@ extern "C" {
|
||||||
pub fn Servo_CssRules_InsertRule(rules: ServoCssRulesBorrowed,
|
pub fn Servo_CssRules_InsertRule(rules: ServoCssRulesBorrowed,
|
||||||
sheet: RawServoStyleSheetBorrowed,
|
sheet: RawServoStyleSheetBorrowed,
|
||||||
rule: *const nsACString, index: u32,
|
rule: *const nsACString, index: u32,
|
||||||
nested: bool, rule_type: *mut u16)
|
nested: bool, loader: *mut Loader,
|
||||||
-> nsresult;
|
gecko_stylesheet: *mut ServoStyleSheet,
|
||||||
|
rule_type: *mut u16) -> nsresult;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_CssRules_DeleteRule(rules: ServoCssRulesBorrowed, index: u32)
|
pub fn Servo_CssRules_DeleteRule(rules: ServoCssRulesBorrowed, index: u32)
|
||||||
|
@ -1549,13 +1552,11 @@ extern "C" {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ParseProperty(property: *const nsACString,
|
pub fn Servo_ParseProperty(property: *const nsACString,
|
||||||
value: *const nsACString,
|
value: *const nsACString,
|
||||||
base: *const nsACString,
|
|
||||||
data: *mut RawGeckoURLExtraData)
|
data: *mut RawGeckoURLExtraData)
|
||||||
-> RawServoDeclarationBlockStrong;
|
-> RawServoDeclarationBlockStrong;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ParseEasing(easing: *const nsAString,
|
pub fn Servo_ParseEasing(easing: *const nsAString,
|
||||||
base: *const nsACString,
|
|
||||||
data: *mut RawGeckoURLExtraData,
|
data: *mut RawGeckoURLExtraData,
|
||||||
output: nsTimingFunctionBorrowedMut) -> bool;
|
output: nsTimingFunctionBorrowedMut) -> bool;
|
||||||
}
|
}
|
||||||
|
@ -1610,7 +1611,6 @@ extern "C" {
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ParseStyleAttribute(data: *const nsACString,
|
pub fn Servo_ParseStyleAttribute(data: *const nsACString,
|
||||||
base: *const nsACString,
|
|
||||||
extra_data: *mut RawGeckoURLExtraData)
|
extra_data: *mut RawGeckoURLExtraData)
|
||||||
-> RawServoDeclarationBlockStrong;
|
-> RawServoDeclarationBlockStrong;
|
||||||
}
|
}
|
||||||
|
@ -1678,7 +1678,6 @@ extern "C" {
|
||||||
property: *const nsACString,
|
property: *const nsACString,
|
||||||
value: *const nsACString,
|
value: *const nsACString,
|
||||||
is_important: bool,
|
is_important: bool,
|
||||||
base: *const nsACString,
|
|
||||||
data: *mut RawGeckoURLExtraData)
|
data: *mut RawGeckoURLExtraData)
|
||||||
-> bool;
|
-> bool;
|
||||||
}
|
}
|
||||||
|
@ -1688,7 +1687,6 @@ extern "C" {
|
||||||
property: nsCSSPropertyID,
|
property: nsCSSPropertyID,
|
||||||
value: *const nsACString,
|
value: *const nsACString,
|
||||||
is_important: bool,
|
is_important: bool,
|
||||||
base: *const nsACString,
|
|
||||||
data:
|
data:
|
||||||
*mut RawGeckoURLExtraData)
|
*mut RawGeckoURLExtraData)
|
||||||
-> bool;
|
-> bool;
|
||||||
|
|
|
@ -5626,7 +5626,8 @@ pub mod root {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StyleSheet {
|
pub struct StyleSheet {
|
||||||
pub _base: root::nsIDOMCSSStyleSheet,
|
pub _base: root::nsIDOMCSSStyleSheet,
|
||||||
pub _base_1: root::nsWrapperCache,
|
pub _base_1: root::nsICSSLoaderObserver,
|
||||||
|
pub _base_2: root::nsWrapperCache,
|
||||||
pub mRefCnt: root::nsCycleCollectingAutoRefCnt,
|
pub mRefCnt: root::nsCycleCollectingAutoRefCnt,
|
||||||
pub _mOwningThread: root::nsAutoOwningThread,
|
pub _mOwningThread: root::nsAutoOwningThread,
|
||||||
pub mParent: *mut root::mozilla::StyleSheet,
|
pub mParent: *mut root::mozilla::StyleSheet,
|
||||||
|
@ -5709,7 +5710,7 @@ pub mod root {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_StyleSheet() {
|
fn bindgen_test_layout_StyleSheet() {
|
||||||
assert_eq!(::std::mem::size_of::<StyleSheet>() , 128usize , concat
|
assert_eq!(::std::mem::size_of::<StyleSheet>() , 136usize , concat
|
||||||
! ( "Size of: " , stringify ! ( StyleSheet ) ));
|
! ( "Size of: " , stringify ! ( StyleSheet ) ));
|
||||||
assert_eq! (::std::mem::align_of::<StyleSheet>() , 8usize , concat
|
assert_eq! (::std::mem::align_of::<StyleSheet>() , 8usize , concat
|
||||||
! ( "Alignment of " , stringify ! ( StyleSheet ) ));
|
! ( "Alignment of " , stringify ! ( StyleSheet ) ));
|
||||||
|
@ -14743,6 +14744,30 @@ pub mod root {
|
||||||
fn clone(&self) -> Self { *self }
|
fn clone(&self) -> Self { *self }
|
||||||
}
|
}
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy)]
|
||||||
|
pub struct nsICSSLoaderObserver {
|
||||||
|
pub _base: root::nsISupports,
|
||||||
|
}
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct nsICSSLoaderObserver_COMTypeInfo<T, U> {
|
||||||
|
pub _address: u8,
|
||||||
|
pub _phantom_0: ::std::marker::PhantomData<T>,
|
||||||
|
pub _phantom_1: ::std::marker::PhantomData<U>,
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_nsICSSLoaderObserver() {
|
||||||
|
assert_eq!(::std::mem::size_of::<nsICSSLoaderObserver>() , 8usize ,
|
||||||
|
concat ! (
|
||||||
|
"Size of: " , stringify ! ( nsICSSLoaderObserver ) ));
|
||||||
|
assert_eq! (::std::mem::align_of::<nsICSSLoaderObserver>() , 8usize ,
|
||||||
|
concat ! (
|
||||||
|
"Alignment of " , stringify ! ( nsICSSLoaderObserver ) ));
|
||||||
|
}
|
||||||
|
impl Clone for nsICSSLoaderObserver {
|
||||||
|
fn clone(&self) -> Self { *self }
|
||||||
|
}
|
||||||
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsAttrValue {
|
pub struct nsAttrValue {
|
||||||
pub mBits: usize,
|
pub mBits: usize,
|
||||||
|
|
|
@ -5535,7 +5535,8 @@ pub mod root {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StyleSheet {
|
pub struct StyleSheet {
|
||||||
pub _base: root::nsIDOMCSSStyleSheet,
|
pub _base: root::nsIDOMCSSStyleSheet,
|
||||||
pub _base_1: root::nsWrapperCache,
|
pub _base_1: root::nsICSSLoaderObserver,
|
||||||
|
pub _base_2: root::nsWrapperCache,
|
||||||
pub mRefCnt: root::nsCycleCollectingAutoRefCnt,
|
pub mRefCnt: root::nsCycleCollectingAutoRefCnt,
|
||||||
pub mParent: *mut root::mozilla::StyleSheet,
|
pub mParent: *mut root::mozilla::StyleSheet,
|
||||||
pub mTitle: ::nsstring::nsStringRepr,
|
pub mTitle: ::nsstring::nsStringRepr,
|
||||||
|
@ -5617,7 +5618,7 @@ pub mod root {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_StyleSheet() {
|
fn bindgen_test_layout_StyleSheet() {
|
||||||
assert_eq!(::std::mem::size_of::<StyleSheet>() , 120usize , concat
|
assert_eq!(::std::mem::size_of::<StyleSheet>() , 128usize , concat
|
||||||
! ( "Size of: " , stringify ! ( StyleSheet ) ));
|
! ( "Size of: " , stringify ! ( StyleSheet ) ));
|
||||||
assert_eq! (::std::mem::align_of::<StyleSheet>() , 8usize , concat
|
assert_eq! (::std::mem::align_of::<StyleSheet>() , 8usize , concat
|
||||||
! ( "Alignment of " , stringify ! ( StyleSheet ) ));
|
! ( "Alignment of " , stringify ! ( StyleSheet ) ));
|
||||||
|
@ -14233,6 +14234,30 @@ pub mod root {
|
||||||
fn clone(&self) -> Self { *self }
|
fn clone(&self) -> Self { *self }
|
||||||
}
|
}
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy)]
|
||||||
|
pub struct nsICSSLoaderObserver {
|
||||||
|
pub _base: root::nsISupports,
|
||||||
|
}
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct nsICSSLoaderObserver_COMTypeInfo<T, U> {
|
||||||
|
pub _address: u8,
|
||||||
|
pub _phantom_0: ::std::marker::PhantomData<T>,
|
||||||
|
pub _phantom_1: ::std::marker::PhantomData<U>,
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_nsICSSLoaderObserver() {
|
||||||
|
assert_eq!(::std::mem::size_of::<nsICSSLoaderObserver>() , 8usize ,
|
||||||
|
concat ! (
|
||||||
|
"Size of: " , stringify ! ( nsICSSLoaderObserver ) ));
|
||||||
|
assert_eq! (::std::mem::align_of::<nsICSSLoaderObserver>() , 8usize ,
|
||||||
|
concat ! (
|
||||||
|
"Alignment of " , stringify ! ( nsICSSLoaderObserver ) ));
|
||||||
|
}
|
||||||
|
impl Clone for nsICSSLoaderObserver {
|
||||||
|
fn clone(&self) -> Self { *self }
|
||||||
|
}
|
||||||
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsAttrValue {
|
pub struct nsAttrValue {
|
||||||
pub mBits: usize,
|
pub mBits: usize,
|
||||||
|
|
|
@ -71,6 +71,15 @@ impl<T: RefCounted> RefPtr<T> {
|
||||||
ret
|
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.
|
/// Produces an FFI-compatible RefPtr that can be stored in style structs.
|
||||||
///
|
///
|
||||||
/// structs::RefPtr does not have a destructor, so this may leak
|
/// structs::RefPtr does not have a destructor, so this may leak
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser};
|
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser};
|
||||||
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule};
|
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::{Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
|
||||||
use properties::{PropertyDeclarationId, LonghandId, ParsedDeclaration};
|
use properties::{PropertyDeclarationId, LonghandId, ParsedDeclaration};
|
||||||
use properties::LonghandIdSet;
|
use properties::LonghandIdSet;
|
||||||
|
@ -123,15 +123,12 @@ impl ToCssWithGuard for Keyframe {
|
||||||
|
|
||||||
impl Keyframe {
|
impl Keyframe {
|
||||||
/// Parse a CSS keyframe.
|
/// Parse a CSS keyframe.
|
||||||
pub fn parse(css: &str,
|
pub fn parse(css: &str, parent_stylesheet: &Stylesheet)
|
||||||
parent_stylesheet: &Stylesheet,
|
|
||||||
extra_data: ParserContextExtraData)
|
|
||||||
-> Result<Arc<Locked<Self>>, ()> {
|
-> Result<Arc<Locked<Self>>, ()> {
|
||||||
let error_reporter = MemoryHoleReporter;
|
let error_reporter = MemoryHoleReporter;
|
||||||
let context = ParserContext::new_with_extra_data(parent_stylesheet.origin,
|
let context = ParserContext::new(parent_stylesheet.origin,
|
||||||
&parent_stylesheet.base_url,
|
&parent_stylesheet.url_data,
|
||||||
&error_reporter,
|
&error_reporter);
|
||||||
extra_data);
|
|
||||||
let mut input = Parser::new(css);
|
let mut input = Parser::new(css);
|
||||||
|
|
||||||
let mut rule_parser = KeyframeListParser {
|
let mut rule_parser = KeyframeListParser {
|
||||||
|
|
|
@ -8,92 +8,38 @@
|
||||||
|
|
||||||
use cssparser::{Parser, SourcePosition, UnicodeRange};
|
use cssparser::{Parser, SourcePosition, UnicodeRange};
|
||||||
use error_reporting::ParseErrorReporter;
|
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 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.
|
/// The data that the parser needs from outside in order to parse a stylesheet.
|
||||||
pub struct ParserContext<'a> {
|
pub struct ParserContext<'a> {
|
||||||
/// The `Origin` of the stylesheet, whether it's a user, author or
|
/// The `Origin` of the stylesheet, whether it's a user, author or
|
||||||
/// user-agent stylesheet.
|
/// user-agent stylesheet.
|
||||||
pub stylesheet_origin: Origin,
|
pub stylesheet_origin: Origin,
|
||||||
/// The base url we're parsing this stylesheet as.
|
/// The extra data we need for resolving url values.
|
||||||
pub base_url: &'a ServoUrl,
|
pub url_data: &'a UrlExtraData,
|
||||||
/// An error reporter to report syntax errors.
|
/// An error reporter to report syntax errors.
|
||||||
pub error_reporter: &'a ParseErrorReporter,
|
pub error_reporter: &'a ParseErrorReporter,
|
||||||
/// Implementation-dependent extra data.
|
|
||||||
pub extra_data: ParserContextExtraData,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ParserContext<'a> {
|
impl<'a> ParserContext<'a> {
|
||||||
/// Create a `ParserContext` with extra data.
|
/// Create a parser context.
|
||||||
pub fn new_with_extra_data(stylesheet_origin: Origin,
|
pub fn new(stylesheet_origin: Origin,
|
||||||
base_url: &'a ServoUrl,
|
url_data: &'a UrlExtraData,
|
||||||
error_reporter: &'a ParseErrorReporter,
|
error_reporter: &'a ParseErrorReporter)
|
||||||
extra_data: ParserContextExtraData)
|
-> ParserContext<'a> {
|
||||||
-> ParserContext<'a> {
|
|
||||||
ParserContext {
|
ParserContext {
|
||||||
stylesheet_origin: stylesheet_origin,
|
stylesheet_origin: stylesheet_origin,
|
||||||
base_url: base_url,
|
url_data: url_data,
|
||||||
error_reporter: error_reporter,
|
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
|
/// 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)
|
error_reporter: &'a ParseErrorReporter)
|
||||||
-> ParserContext<'a> {
|
-> 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,
|
position: SourcePosition,
|
||||||
message: &str,
|
message: &str,
|
||||||
parsercontext: &ParserContext) {
|
parsercontext: &ParserContext) {
|
||||||
let servo_url = parsercontext.base_url;
|
let url_data = parsercontext.url_data;
|
||||||
parsercontext.error_reporter.report_error(input, position, message, servo_url);
|
parsercontext.error_reporter.report_error(input, position, message, url_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXXManishearth Replace all specified value parse impls with impls of this
|
// XXXManishearth Replace all specified value parse impls with impls of this
|
||||||
|
|
|
@ -9,11 +9,10 @@
|
||||||
use cssparser::{DeclarationListParser, parse_important};
|
use cssparser::{DeclarationListParser, parse_important};
|
||||||
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
|
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
|
||||||
use error_reporting::ParseErrorReporter;
|
use error_reporting::ParseErrorReporter;
|
||||||
use parser::{ParserContext, ParserContextExtraData, log_css_error};
|
use parser::{ParserContext, log_css_error};
|
||||||
use servo_url::ServoUrl;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use stylesheets::Origin;
|
use stylesheets::{Origin, UrlExtraData};
|
||||||
use super::*;
|
use super::*;
|
||||||
#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValueMap;
|
#[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
|
/// A helper to parse the style attribute of an element, in order for this to be
|
||||||
/// shared between Servo and Gecko.
|
/// shared between Servo and Gecko.
|
||||||
pub fn parse_style_attribute(input: &str,
|
pub fn parse_style_attribute(input: &str,
|
||||||
base_url: &ServoUrl,
|
url_data: &UrlExtraData,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter)
|
||||||
extra_data: ParserContextExtraData)
|
|
||||||
-> PropertyDeclarationBlock {
|
-> PropertyDeclarationBlock {
|
||||||
let context = ParserContext::new_with_extra_data(Origin::Author,
|
let context = ParserContext::new(Origin::Author, url_data, error_reporter);
|
||||||
base_url,
|
|
||||||
error_reporter,
|
|
||||||
extra_data);
|
|
||||||
parse_property_declaration_list(&context, &mut Parser::new(input))
|
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
|
/// this does not attempt to parse !important at all
|
||||||
pub fn parse_one_declaration(id: PropertyId,
|
pub fn parse_one_declaration(id: PropertyId,
|
||||||
input: &str,
|
input: &str,
|
||||||
base_url: &ServoUrl,
|
url_data: &UrlExtraData,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter)
|
||||||
extra_data: ParserContextExtraData)
|
|
||||||
-> Result<ParsedDeclaration, ()> {
|
-> Result<ParsedDeclaration, ()> {
|
||||||
let context = ParserContext::new_with_extra_data(Origin::Author,
|
let context = ParserContext::new(Origin::Author, url_data, error_reporter);
|
||||||
base_url,
|
|
||||||
error_reporter,
|
|
||||||
extra_data);
|
|
||||||
Parser::new(input).parse_entirely(|parser| {
|
Parser::new(input).parse_entirely(|parser| {
|
||||||
ParsedDeclaration::parse(id, &context, parser, false)
|
ParsedDeclaration::parse(id, &context, parser, false)
|
||||||
.map_err(|_| ())
|
.map_err(|_| ())
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
|
|
||||||
pub mod single_value {
|
pub mod single_value {
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext, ParserContextExtraData};
|
use parser::{Parse, ParserContext};
|
||||||
use properties::ShorthandId;
|
use properties::ShorthandId;
|
||||||
use values::computed::{Context, ToComputedValue};
|
use values::computed::{Context, ToComputedValue};
|
||||||
use values::{computed, specified};
|
use values::{computed, specified};
|
||||||
|
@ -211,7 +211,7 @@
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
% if not property.derived_from:
|
% if not property.derived_from:
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext, ParserContextExtraData};
|
use parser::{Parse, ParserContext};
|
||||||
use properties::{UnparsedValue, ShorthandId};
|
use properties::{UnparsedValue, ShorthandId};
|
||||||
% endif
|
% endif
|
||||||
use values::{Auto, Either, None_, Normal};
|
use values::{Auto, Either, None_, Normal};
|
||||||
|
@ -368,7 +368,7 @@
|
||||||
Arc::new(UnparsedValue {
|
Arc::new(UnparsedValue {
|
||||||
css: css.into_owned(),
|
css: css.into_owned(),
|
||||||
first_token_type: first_token_type,
|
first_token_type: first_token_type,
|
||||||
base_url: context.base_url.clone(),
|
url_data: context.url_data.clone(),
|
||||||
from_shorthand: None,
|
from_shorthand: None,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
@ -594,7 +594,7 @@
|
||||||
Ok(ParsedDeclaration::${shorthand.camel_case}WithVariables(Arc::new(UnparsedValue {
|
Ok(ParsedDeclaration::${shorthand.camel_case}WithVariables(Arc::new(UnparsedValue {
|
||||||
css: css.into_owned(),
|
css: css.into_owned(),
|
||||||
first_token_type: first_token_type,
|
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}),
|
from_shorthand: Some(ShorthandId::${shorthand.camel_case}),
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -27,13 +27,12 @@ use font_metrics::FontMetricsProvider;
|
||||||
#[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
|
#[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
|
||||||
use logical_geometry::WritingMode;
|
use logical_geometry::WritingMode;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
use parser::{Parse, ParserContext, ParserContextExtraData};
|
use parser::{Parse, ParserContext};
|
||||||
use properties::animated_properties::TransitionProperty;
|
use properties::animated_properties::TransitionProperty;
|
||||||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||||
use servo_url::ServoUrl;
|
|
||||||
use shared_lock::StylesheetGuards;
|
use shared_lock::StylesheetGuards;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use stylesheets::Origin;
|
use stylesheets::{Origin, UrlExtraData};
|
||||||
#[cfg(feature = "servo")] use values::Either;
|
#[cfg(feature = "servo")] use values::Either;
|
||||||
use values::{HasViewportPercentage, computed};
|
use values::{HasViewportPercentage, computed};
|
||||||
use cascade_info::CascadeInfo;
|
use cascade_info::CascadeInfo;
|
||||||
|
@ -296,18 +295,13 @@ impl PropertyDeclarationIdSet {
|
||||||
% endif
|
% endif
|
||||||
{
|
{
|
||||||
if let DeclaredValue::WithVariables(ref with_variables) = *value {
|
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,
|
substitute_variables_${property.ident}_slow(&with_variables.css,
|
||||||
with_variables.first_token_type,
|
with_variables.first_token_type,
|
||||||
&with_variables.base_url,
|
&with_variables.url_data,
|
||||||
with_variables.from_shorthand,
|
with_variables.from_shorthand,
|
||||||
custom_properties,
|
custom_properties,
|
||||||
f,
|
f,
|
||||||
error_reporter,
|
error_reporter);
|
||||||
extra_data);
|
|
||||||
} else {
|
} else {
|
||||||
f(value);
|
f(value);
|
||||||
}
|
}
|
||||||
|
@ -318,12 +312,11 @@ impl PropertyDeclarationIdSet {
|
||||||
fn substitute_variables_${property.ident}_slow<F>(
|
fn substitute_variables_${property.ident}_slow<F>(
|
||||||
css: &String,
|
css: &String,
|
||||||
first_token_type: TokenSerializationType,
|
first_token_type: TokenSerializationType,
|
||||||
base_url: &ServoUrl,
|
url_data: &UrlExtraData,
|
||||||
from_shorthand: Option<ShorthandId>,
|
from_shorthand: Option<ShorthandId>,
|
||||||
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||||
f: F,
|
f: F,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter)
|
||||||
extra_data: ParserContextExtraData)
|
|
||||||
% if property.boxed:
|
% if property.boxed:
|
||||||
where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>)
|
where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>)
|
||||||
% else:
|
% else:
|
||||||
|
@ -337,9 +330,7 @@ impl PropertyDeclarationIdSet {
|
||||||
//
|
//
|
||||||
// FIXME(pcwalton): Cloning the error reporter is slow! But so are custom
|
// FIXME(pcwalton): Cloning the error reporter is slow! But so are custom
|
||||||
// properties, so whatever...
|
// properties, so whatever...
|
||||||
let context = ParserContext::new_with_extra_data(
|
let context = ParserContext::new(Origin::Author, url_data, error_reporter);
|
||||||
::stylesheets::Origin::Author, base_url, error_reporter,
|
|
||||||
extra_data);
|
|
||||||
Parser::new(&css).parse_entirely(|input| {
|
Parser::new(&css).parse_entirely(|input| {
|
||||||
match from_shorthand {
|
match from_shorthand {
|
||||||
None => {
|
None => {
|
||||||
|
@ -652,8 +643,8 @@ pub struct UnparsedValue {
|
||||||
css: String,
|
css: String,
|
||||||
/// The first token type for this serialization.
|
/// The first token type for this serialization.
|
||||||
first_token_type: TokenSerializationType,
|
first_token_type: TokenSerializationType,
|
||||||
/// The base url.
|
/// The url data for resolving url values.
|
||||||
base_url: ServoUrl,
|
url_data: UrlExtraData,
|
||||||
/// The shorthand this came from.
|
/// The shorthand this came from.
|
||||||
from_shorthand: Option<ShorthandId>,
|
from_shorthand: Option<ShorthandId>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl SpecifiedUrl {
|
||||||
context: &ParserContext)
|
context: &ParserContext)
|
||||||
-> Result<Self, ()> {
|
-> Result<Self, ()> {
|
||||||
let serialization = Arc::new(url.into_owned());
|
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 {
|
Ok(SpecifiedUrl {
|
||||||
original: Some(serialization),
|
original: Some(serialization),
|
||||||
resolved: resolved,
|
resolved: resolved,
|
||||||
|
|
|
@ -16,14 +16,19 @@ use font_face::FontFaceRuleData;
|
||||||
use font_face::parse_font_face_block;
|
use font_face::parse_font_face_block;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use gecko::rules::FontFaceRule;
|
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 keyframes::{Keyframe, parse_keyframe_list};
|
||||||
use media_queries::{Device, MediaList, parse_media_query_list};
|
use media_queries::{Device, MediaList, parse_media_query_list};
|
||||||
use parking_lot::RwLock;
|
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 properties::{PropertyDeclarationBlock, parse_property_declaration_list};
|
||||||
use selector_parser::{SelectorImpl, SelectorParser};
|
use selector_parser::{SelectorImpl, SelectorParser};
|
||||||
use selectors::parser::SelectorList;
|
use selectors::parser::SelectorList;
|
||||||
use servo_config::prefs::PREFS;
|
use servo_config::prefs::PREFS;
|
||||||
|
#[cfg(not(feature = "gecko"))]
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use shared_lock::{SharedRwLock, Locked, ToCssWithGuard, SharedRwLockReadGuard};
|
use shared_lock::{SharedRwLock, Locked, ToCssWithGuard, SharedRwLockReadGuard};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -37,6 +42,30 @@ use values::specified::url::SpecifiedUrl;
|
||||||
use viewport::ViewportRule;
|
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.
|
/// Each style rule has an origin, which determines where it enters the cascade.
|
||||||
///
|
///
|
||||||
/// http://dev.w3.org/csswg/css-cascade/#cascading-origins
|
/// http://dev.w3.org/csswg/css-cascade/#cascading-origins
|
||||||
|
@ -106,7 +135,12 @@ impl CssRules {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/cssom/#insert-a-css-rule
|
/// https://drafts.csswg.org/cssom/#insert-a-css-rule
|
||||||
pub fn insert_rule(&mut self, rule: &str, parent_stylesheet: &Stylesheet, index: usize, nested: bool)
|
pub fn insert_rule(&mut self,
|
||||||
|
rule: &str,
|
||||||
|
parent_stylesheet: &Stylesheet,
|
||||||
|
index: usize,
|
||||||
|
nested: bool,
|
||||||
|
loader: Option<&StylesheetLoader>)
|
||||||
-> Result<CssRule, RulesMutateError> {
|
-> Result<CssRule, RulesMutateError> {
|
||||||
// Step 1, 2
|
// Step 1, 2
|
||||||
if index > self.0.len() {
|
if index > self.0.len() {
|
||||||
|
@ -125,8 +159,7 @@ impl CssRules {
|
||||||
// Step 3, 4
|
// Step 3, 4
|
||||||
// XXXManishearth should we also store the namespace map?
|
// XXXManishearth should we also store the namespace map?
|
||||||
let (new_rule, new_state) =
|
let (new_rule, new_state) =
|
||||||
try!(CssRule::parse(&rule, parent_stylesheet,
|
try!(CssRule::parse(&rule, parent_stylesheet, state, loader));
|
||||||
ParserContextExtraData::default(), state));
|
|
||||||
|
|
||||||
// Step 5
|
// Step 5
|
||||||
// Computes the maximum allowed parser state at a given index.
|
// Computes the maximum allowed parser state at a given index.
|
||||||
|
@ -183,8 +216,8 @@ pub struct Stylesheet {
|
||||||
pub media: Arc<Locked<MediaList>>,
|
pub media: Arc<Locked<MediaList>>,
|
||||||
/// The origin of this stylesheet.
|
/// The origin of this stylesheet.
|
||||||
pub origin: Origin,
|
pub origin: Origin,
|
||||||
/// The base url this stylesheet should use.
|
/// The url data this stylesheet should use.
|
||||||
pub base_url: ServoUrl,
|
pub url_data: UrlExtraData,
|
||||||
/// The lock used for objects inside this stylesheet
|
/// The lock used for objects inside this stylesheet
|
||||||
pub shared_lock: SharedRwLock,
|
pub shared_lock: SharedRwLock,
|
||||||
/// The namespaces that apply to this stylesheet.
|
/// The namespaces that apply to this stylesheet.
|
||||||
|
@ -259,7 +292,7 @@ impl ParseErrorReporter for MemoryHoleReporter {
|
||||||
_: &mut Parser,
|
_: &mut Parser,
|
||||||
_: SourcePosition,
|
_: SourcePosition,
|
||||||
_: &str,
|
_: &str,
|
||||||
_: &ServoUrl) {
|
_: &UrlExtraData) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,15 +375,14 @@ impl CssRule {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn parse(css: &str,
|
pub fn parse(css: &str,
|
||||||
parent_stylesheet: &Stylesheet,
|
parent_stylesheet: &Stylesheet,
|
||||||
extra_data: ParserContextExtraData,
|
state: Option<State>,
|
||||||
state: Option<State>)
|
loader: Option<&StylesheetLoader>)
|
||||||
-> Result<(Self, State), SingleRuleParseError> {
|
-> Result<(Self, State), SingleRuleParseError> {
|
||||||
let error_reporter = MemoryHoleReporter;
|
let error_reporter = MemoryHoleReporter;
|
||||||
let mut namespaces = parent_stylesheet.namespaces.write();
|
let mut namespaces = parent_stylesheet.namespaces.write();
|
||||||
let context = ParserContext::new_with_extra_data(parent_stylesheet.origin,
|
let context = ParserContext::new(parent_stylesheet.origin,
|
||||||
&parent_stylesheet.base_url,
|
&parent_stylesheet.url_data,
|
||||||
&error_reporter,
|
&error_reporter);
|
||||||
extra_data);
|
|
||||||
let mut input = Parser::new(css);
|
let mut input = Parser::new(css);
|
||||||
|
|
||||||
// nested rules are in the body state
|
// nested rules are in the body state
|
||||||
|
@ -359,7 +391,7 @@ impl CssRule {
|
||||||
stylesheet_origin: parent_stylesheet.origin,
|
stylesheet_origin: parent_stylesheet.origin,
|
||||||
context: context,
|
context: context,
|
||||||
shared_lock: &parent_stylesheet.shared_lock,
|
shared_lock: &parent_stylesheet.shared_lock,
|
||||||
loader: None,
|
loader: loader,
|
||||||
state: Cell::new(state),
|
state: Cell::new(state),
|
||||||
namespaces: &mut namespaces,
|
namespaces: &mut namespaces,
|
||||||
};
|
};
|
||||||
|
@ -563,13 +595,15 @@ impl Stylesheet {
|
||||||
/// Updates an empty stylesheet from a given string of text.
|
/// Updates an empty stylesheet from a given string of text.
|
||||||
pub fn update_from_str(existing: &Stylesheet,
|
pub fn update_from_str(existing: &Stylesheet,
|
||||||
css: &str,
|
css: &str,
|
||||||
|
url_data: &UrlExtraData,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter) {
|
||||||
extra_data: ParserContextExtraData) {
|
|
||||||
let mut namespaces = Namespaces::default();
|
let mut namespaces = Namespaces::default();
|
||||||
|
// FIXME: we really should update existing.url_data with the given url_data,
|
||||||
|
// otherwise newly inserted rule may not have the right base url.
|
||||||
let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
|
let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
|
||||||
css, &existing.base_url, existing.origin, &mut namespaces, &existing.shared_lock,
|
css, url_data, existing.origin, &mut namespaces,
|
||||||
stylesheet_loader, error_reporter, extra_data,
|
&existing.shared_lock, stylesheet_loader, error_reporter,
|
||||||
);
|
);
|
||||||
|
|
||||||
*existing.namespaces.write() = namespaces;
|
*existing.namespaces.write() = namespaces;
|
||||||
|
@ -582,13 +616,12 @@ impl Stylesheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_rules(css: &str,
|
fn parse_rules(css: &str,
|
||||||
base_url: &ServoUrl,
|
url_data: &UrlExtraData,
|
||||||
origin: Origin,
|
origin: Origin,
|
||||||
namespaces: &mut Namespaces,
|
namespaces: &mut Namespaces,
|
||||||
shared_lock: &SharedRwLock,
|
shared_lock: &SharedRwLock,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter)
|
||||||
extra_data: ParserContextExtraData)
|
|
||||||
-> (Vec<CssRule>, bool) {
|
-> (Vec<CssRule>, bool) {
|
||||||
let mut rules = Vec::new();
|
let mut rules = Vec::new();
|
||||||
let mut input = Parser::new(css);
|
let mut input = Parser::new(css);
|
||||||
|
@ -597,10 +630,7 @@ impl Stylesheet {
|
||||||
namespaces: namespaces,
|
namespaces: namespaces,
|
||||||
shared_lock: shared_lock,
|
shared_lock: shared_lock,
|
||||||
loader: stylesheet_loader,
|
loader: stylesheet_loader,
|
||||||
context: ParserContext::new_with_extra_data(origin,
|
context: ParserContext::new(origin, url_data, error_reporter),
|
||||||
base_url,
|
|
||||||
error_reporter,
|
|
||||||
extra_data),
|
|
||||||
state: Cell::new(State::Start),
|
state: Cell::new(State::Start),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -629,21 +659,20 @@ impl Stylesheet {
|
||||||
/// Effectively creates a new stylesheet and forwards the hard work to
|
/// Effectively creates a new stylesheet and forwards the hard work to
|
||||||
/// `Stylesheet::update_from_str`.
|
/// `Stylesheet::update_from_str`.
|
||||||
pub fn from_str(css: &str,
|
pub fn from_str(css: &str,
|
||||||
base_url: ServoUrl,
|
url_data: UrlExtraData,
|
||||||
origin: Origin,
|
origin: Origin,
|
||||||
media: MediaList,
|
media: MediaList,
|
||||||
shared_lock: SharedRwLock,
|
shared_lock: SharedRwLock,
|
||||||
stylesheet_loader: Option<&StylesheetLoader>,
|
stylesheet_loader: Option<&StylesheetLoader>,
|
||||||
error_reporter: &ParseErrorReporter,
|
error_reporter: &ParseErrorReporter) -> Stylesheet {
|
||||||
extra_data: ParserContextExtraData) -> Stylesheet {
|
|
||||||
let mut namespaces = Namespaces::default();
|
let mut namespaces = Namespaces::default();
|
||||||
let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
|
let (rules, dirty_on_viewport_size_change) = Stylesheet::parse_rules(
|
||||||
css, &base_url, origin, &mut namespaces, &shared_lock,
|
css, &url_data, origin, &mut namespaces,
|
||||||
stylesheet_loader, error_reporter, extra_data,
|
&shared_lock, stylesheet_loader, error_reporter,
|
||||||
);
|
);
|
||||||
Stylesheet {
|
Stylesheet {
|
||||||
origin: origin,
|
origin: origin,
|
||||||
base_url: base_url,
|
url_data: url_data,
|
||||||
namespaces: RwLock::new(namespaces),
|
namespaces: RwLock::new(namespaces),
|
||||||
rules: CssRules::new(rules, &shared_lock),
|
rules: CssRules::new(rules, &shared_lock),
|
||||||
media: Arc::new(shared_lock.wrap(media)),
|
media: Arc::new(shared_lock.wrap(media)),
|
||||||
|
@ -862,7 +891,7 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
|
||||||
media: Arc::new(self.shared_lock.wrap(media)),
|
media: Arc::new(self.shared_lock.wrap(media)),
|
||||||
shared_lock: self.shared_lock.clone(),
|
shared_lock: self.shared_lock.clone(),
|
||||||
origin: self.context.stylesheet_origin,
|
origin: self.context.stylesheet_origin,
|
||||||
base_url: self.context.base_url.clone(),
|
url_data: self.context.url_data.clone(),
|
||||||
namespaces: RwLock::new(Namespaces::default()),
|
namespaces: RwLock::new(Namespaces::default()),
|
||||||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||||
disabled: AtomicBool::new(false),
|
disabled: AtomicBool::new(false),
|
||||||
|
|
|
@ -21,7 +21,6 @@ libc = "0.2"
|
||||||
log = {version = "0.3.5", features = ["release_max_level_info"]}
|
log = {version = "0.3.5", features = ["release_max_level_info"]}
|
||||||
parking_lot = "0.3"
|
parking_lot = "0.3"
|
||||||
selectors = {path = "../../components/selectors"}
|
selectors = {path = "../../components/selectors"}
|
||||||
servo_url = {path = "../../components/url"}
|
|
||||||
style = {path = "../../components/style", features = ["gecko"]}
|
style = {path = "../../components/style", features = ["gecko"]}
|
||||||
style_traits = {path = "../../components/style_traits"}
|
style_traits = {path = "../../components/style_traits"}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ use cssparser::ToCss as ParserToCss;
|
||||||
use env_logger::LogBuilder;
|
use env_logger::LogBuilder;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use selectors::Element;
|
use selectors::Element;
|
||||||
use servo_url::ServoUrl;
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
@ -26,7 +25,6 @@ use style::gecko::global_style_data::GLOBAL_STYLE_DATA;
|
||||||
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
||||||
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
|
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
|
||||||
use style::gecko::traversal::RecalcStyleOnly;
|
use style::gecko::traversal::RecalcStyleOnly;
|
||||||
use style::gecko::wrapper::DUMMY_BASE_URL;
|
|
||||||
use style::gecko::wrapper::GeckoElement;
|
use style::gecko::wrapper::GeckoElement;
|
||||||
use style::gecko_bindings::bindings;
|
use style::gecko_bindings::bindings;
|
||||||
use style::gecko_bindings::bindings::{RawGeckoKeyframeListBorrowed, RawGeckoKeyframeListBorrowedMut};
|
use style::gecko_bindings::bindings::{RawGeckoKeyframeListBorrowed, RawGeckoKeyframeListBorrowedMut};
|
||||||
|
@ -63,11 +61,12 @@ use style::gecko_bindings::structs::nsCSSValueSharedList;
|
||||||
use style::gecko_bindings::structs::nsresult;
|
use style::gecko_bindings::structs::nsresult;
|
||||||
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasFFI, HasArcFFI, HasBoxFFI};
|
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasFFI, HasArcFFI, HasBoxFFI};
|
||||||
use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
|
use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
|
||||||
|
use style::gecko_bindings::sugar::refptr::RefPtr;
|
||||||
use style::gecko_properties::{self, style_structs};
|
use style::gecko_properties::{self, style_structs};
|
||||||
use style::keyframes::KeyframesStepValue;
|
use style::keyframes::KeyframesStepValue;
|
||||||
use style::media_queries::{MediaList, parse_media_query_list};
|
use style::media_queries::{MediaList, parse_media_query_list};
|
||||||
use style::parallel;
|
use style::parallel;
|
||||||
use style::parser::{ParserContext, ParserContextExtraData};
|
use style::parser::ParserContext;
|
||||||
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration};
|
use style::properties::{CascadeFlags, ComputedValues, Importance, ParsedDeclaration};
|
||||||
use style::properties::{PropertyDeclarationBlock, PropertyId};
|
use style::properties::{PropertyDeclarationBlock, PropertyId};
|
||||||
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
||||||
|
@ -97,7 +96,9 @@ use super::stylesheet_loader::StylesheetLoader;
|
||||||
* depend on but good enough for our purposes.
|
* depend on but good enough for our purposes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// A dummy url data for where we don't pass url data in.
|
||||||
|
// We need to get rid of this sooner than later.
|
||||||
|
static mut DUMMY_URL_DATA: Option<*mut URLExtraData> = None;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_Initialize() {
|
pub extern "C" fn Servo_Initialize() {
|
||||||
|
@ -117,12 +118,24 @@ pub extern "C" fn Servo_Initialize() {
|
||||||
|
|
||||||
// Initialize some static data.
|
// Initialize some static data.
|
||||||
gecko_properties::initialize();
|
gecko_properties::initialize();
|
||||||
|
|
||||||
|
// Initialize the dummy url data
|
||||||
|
unsafe {
|
||||||
|
DUMMY_URL_DATA = Some(bindings::Gecko_URLExtraData_CreateDummy());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_Shutdown() {
|
pub extern "C" fn Servo_Shutdown() {
|
||||||
// Clear some static data to avoid shutdown leaks.
|
// Clear some static data to avoid shutdown leaks.
|
||||||
gecko_properties::shutdown();
|
gecko_properties::shutdown();
|
||||||
|
|
||||||
|
// Clear the dummy url data to avoid shutdown leaks.
|
||||||
|
unsafe { RefPtr::from_addrefed(DUMMY_URL_DATA.take().unwrap()) };
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn dummy_url_data() -> &'static RefPtr<URLExtraData> {
|
||||||
|
RefPtr::from_ptr_ref(DUMMY_URL_DATA.as_ref().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_shared_context<'a>(guard: &'a SharedRwLockReadGuard,
|
fn create_shared_context<'a>(guard: &'a SharedRwLockReadGuard,
|
||||||
|
@ -310,8 +323,6 @@ pub extern "C" fn Servo_Element_ClearData(element: RawGeckoElementBorrowed) {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyleSheetStrong {
|
pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyleSheetStrong {
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||||
let url = ServoUrl::parse("about:blank").unwrap();
|
|
||||||
let extra_data = ParserContextExtraData::default();
|
|
||||||
let origin = match mode {
|
let origin = match mode {
|
||||||
SheetParsingMode::eAuthorSheetFeatures => Origin::Author,
|
SheetParsingMode::eAuthorSheetFeatures => Origin::Author,
|
||||||
SheetParsingMode::eUserSheetFeatures => Origin::User,
|
SheetParsingMode::eUserSheetFeatures => Origin::User,
|
||||||
|
@ -319,8 +330,8 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl
|
||||||
};
|
};
|
||||||
let shared_lock = global_style_data.shared_lock.clone();
|
let shared_lock = global_style_data.shared_lock.clone();
|
||||||
Arc::new(Stylesheet::from_str(
|
Arc::new(Stylesheet::from_str(
|
||||||
"", url, origin, Default::default(), shared_lock, None,
|
"", unsafe { dummy_url_data() }.clone(), origin,
|
||||||
&StdoutErrorReporter, extra_data)
|
Default::default(), shared_lock, None, &StdoutErrorReporter)
|
||||||
).into_strong()
|
).into_strong()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +340,6 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
|
||||||
stylesheet: *mut ServoStyleSheet,
|
stylesheet: *mut ServoStyleSheet,
|
||||||
data: *const nsACString,
|
data: *const nsACString,
|
||||||
mode: SheetParsingMode,
|
mode: SheetParsingMode,
|
||||||
base_url: *const nsACString,
|
|
||||||
extra_data: *mut URLExtraData)
|
extra_data: *mut URLExtraData)
|
||||||
-> RawServoStyleSheetStrong {
|
-> RawServoStyleSheetStrong {
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||||
|
@ -341,9 +351,7 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
|
||||||
SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent,
|
SheetParsingMode::eAgentSheetFeatures => Origin::UserAgent,
|
||||||
};
|
};
|
||||||
|
|
||||||
let base_str = unsafe { base_url.as_ref().unwrap().as_str_unchecked() };
|
let url_data = unsafe { RefPtr::from_ptr_ref(&extra_data) };
|
||||||
let url = ServoUrl::parse(base_str).unwrap();
|
|
||||||
let extra_data = unsafe { ParserContextExtraData::new(extra_data) };
|
|
||||||
let loader = if loader.is_null() {
|
let loader = if loader.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -358,8 +366,8 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader,
|
||||||
|
|
||||||
let shared_lock = global_style_data.shared_lock.clone();
|
let shared_lock = global_style_data.shared_lock.clone();
|
||||||
Arc::new(Stylesheet::from_str(
|
Arc::new(Stylesheet::from_str(
|
||||||
input, url, origin, Default::default(), shared_lock, loader,
|
input, url_data.clone(), origin, Default::default(),
|
||||||
&StdoutErrorReporter, extra_data)
|
shared_lock, loader, &StdoutErrorReporter)
|
||||||
).into_strong()
|
).into_strong()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +379,7 @@ pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheet
|
||||||
extra_data: *mut URLExtraData)
|
extra_data: *mut URLExtraData)
|
||||||
{
|
{
|
||||||
let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
let input = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
||||||
let extra_data = unsafe { ParserContextExtraData::new(extra_data) };
|
let url_data = unsafe { RefPtr::from_ptr_ref(&extra_data) };
|
||||||
|
|
||||||
let loader = if loader.is_null() {
|
let loader = if loader.is_null() {
|
||||||
None
|
None
|
||||||
|
@ -386,7 +394,8 @@ pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheet
|
||||||
};
|
};
|
||||||
|
|
||||||
let sheet = Stylesheet::as_arc(&stylesheet);
|
let sheet = Stylesheet::as_arc(&stylesheet);
|
||||||
Stylesheet::update_from_str(&sheet, input, loader, &StdoutErrorReporter, extra_data);
|
Stylesheet::update_from_str(&sheet, input, url_data,
|
||||||
|
loader, &StdoutErrorReporter);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -510,13 +519,24 @@ pub extern "C" fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_CssRules_InsertRule(rules: ServoCssRulesBorrowed, sheet: RawServoStyleSheetBorrowed,
|
pub extern "C" fn Servo_CssRules_InsertRule(rules: ServoCssRulesBorrowed,
|
||||||
rule: *const nsACString, index: u32, nested: bool,
|
sheet: RawServoStyleSheetBorrowed,
|
||||||
|
rule: *const nsACString,
|
||||||
|
index: u32,
|
||||||
|
nested: bool,
|
||||||
|
loader: *mut Loader,
|
||||||
|
gecko_stylesheet: *mut ServoStyleSheet,
|
||||||
rule_type: *mut u16) -> nsresult {
|
rule_type: *mut u16) -> nsresult {
|
||||||
let sheet = Stylesheet::as_arc(&sheet);
|
let sheet = Stylesheet::as_arc(&sheet);
|
||||||
|
let loader = if loader.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(StylesheetLoader::new(loader, gecko_stylesheet))
|
||||||
|
};
|
||||||
|
let loader = loader.as_ref().map(|loader| loader as &StyleStylesheetLoader);
|
||||||
let rule = unsafe { rule.as_ref().unwrap().as_str_unchecked() };
|
let rule = unsafe { rule.as_ref().unwrap().as_str_unchecked() };
|
||||||
write_locked_arc(rules, |rules: &mut CssRules| {
|
write_locked_arc(rules, |rules: &mut CssRules| {
|
||||||
match rules.insert_rule(rule, sheet, index as usize, nested) {
|
match rules.insert_rule(rule, sheet, index as usize, nested, loader) {
|
||||||
Ok(new_rule) => {
|
Ok(new_rule) => {
|
||||||
*unsafe { rule_type.as_mut().unwrap() } = new_rule.rule_type() as u16;
|
*unsafe { rule_type.as_mut().unwrap() } = new_rule.rule_type() as u16;
|
||||||
nsresult::NS_OK
|
nsresult::NS_OK
|
||||||
|
@ -765,20 +785,8 @@ pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) {
|
||||||
let _ = data.into_box::<PerDocumentStyleData>();
|
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]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const nsACString,
|
pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const nsACString,
|
||||||
base: *const nsACString,
|
|
||||||
data: *mut URLExtraData)
|
data: *mut URLExtraData)
|
||||||
-> RawServoDeclarationBlockStrong {
|
-> RawServoDeclarationBlockStrong {
|
||||||
let name = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
let name = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
||||||
|
@ -789,13 +797,9 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const
|
||||||
};
|
};
|
||||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
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 reporter = StdoutErrorReporter;
|
||||||
let context = ParserContext::new_with_extra_data(Origin::Author,
|
let context = ParserContext::new(Origin::Author, url_data, &reporter);
|
||||||
&base_url,
|
|
||||||
&reporter,
|
|
||||||
extra_data);
|
|
||||||
|
|
||||||
match ParsedDeclaration::parse(id, &context, &mut Parser::new(value), false) {
|
match ParsedDeclaration::parse(id, &context, &mut Parser::new(value), false) {
|
||||||
Ok(parsed) => {
|
Ok(parsed) => {
|
||||||
|
@ -810,15 +814,14 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
|
pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
|
||||||
base: *const nsACString,
|
|
||||||
data: *mut URLExtraData,
|
data: *mut URLExtraData,
|
||||||
output: nsTimingFunctionBorrowedMut)
|
output: nsTimingFunctionBorrowedMut)
|
||||||
-> bool {
|
-> bool {
|
||||||
use style::properties::longhands::transition_timing_function;
|
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 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() };
|
let easing = unsafe { (*easing).to_string() };
|
||||||
match transition_timing_function::single_value::parse(&context, &mut Parser::new(&easing)) {
|
match transition_timing_function::single_value::parse(&context, &mut Parser::new(&easing)) {
|
||||||
Ok(parsed_easing) => {
|
Ok(parsed_easing) => {
|
||||||
|
@ -831,14 +834,13 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString,
|
pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString,
|
||||||
base: *const nsACString,
|
|
||||||
raw_extra_data: *mut URLExtraData)
|
raw_extra_data: *mut URLExtraData)
|
||||||
-> RawServoDeclarationBlockStrong {
|
-> RawServoDeclarationBlockStrong {
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||||
let value = unsafe { data.as_ref().unwrap().as_str_unchecked() };
|
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(
|
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]
|
#[no_mangle]
|
||||||
|
@ -951,13 +953,12 @@ pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: Ra
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId,
|
fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId,
|
||||||
value: *const nsACString, is_important: bool,
|
value: *const nsACString, is_important: bool, data: *mut URLExtraData) -> bool {
|
||||||
base: *const nsACString, data: *mut URLExtraData) -> bool {
|
|
||||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
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) };
|
||||||
if let Ok(parsed) = parse_one_declaration(property_id, value, &base_url,
|
if let Ok(parsed) = parse_one_declaration(property_id, value, url_data,
|
||||||
&StdoutErrorReporter, extra_data) {
|
&StdoutErrorReporter) {
|
||||||
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
||||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||||
parsed.expand_set_into(decls, importance)
|
parsed.expand_set_into(decls, importance)
|
||||||
|
@ -971,20 +972,18 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
property: *const nsACString, value: *const nsACString,
|
property: *const nsACString, value: *const nsACString,
|
||||||
is_important: bool,
|
is_important: bool,
|
||||||
base: *const nsACString,
|
|
||||||
data: *mut URLExtraData) -> bool {
|
data: *mut URLExtraData) -> bool {
|
||||||
set_property(declarations, get_property_id_from_property!(property, false),
|
set_property(declarations, get_property_id_from_property!(property, false),
|
||||||
value, is_important, base, data)
|
value, is_important, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoDeclarationBlockBorrowed,
|
pub extern "C" fn Servo_DeclarationBlock_SetPropertyById(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
property: nsCSSPropertyID, value: *const nsACString,
|
property: nsCSSPropertyID, value: *const nsACString,
|
||||||
is_important: bool,
|
is_important: bool,
|
||||||
base: *const nsACString,
|
|
||||||
data: *mut URLExtraData) -> bool {
|
data: *mut URLExtraData) -> bool {
|
||||||
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
|
set_property(declarations, get_property_id_from_nscsspropertyid!(property, false),
|
||||||
value, is_important, base, data)
|
value, is_important, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
fn remove_property(declarations: RawServoDeclarationBlockBorrowed, property_id: PropertyId) {
|
||||||
|
@ -1349,10 +1348,8 @@ pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const
|
||||||
};
|
};
|
||||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||||
|
|
||||||
let base_url = &*DUMMY_BASE_URL;
|
let url_data = unsafe { dummy_url_data() };
|
||||||
let extra_data = ParserContextExtraData::default();
|
parse_one_declaration(id, &value, url_data, &StdoutErrorReporter).is_ok()
|
||||||
|
|
||||||
parse_one_declaration(id, &value, &base_url, &StdoutErrorReporter, extra_data).is_ok()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1361,9 +1358,9 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool {
|
||||||
let mut input = Parser::new(&condition);
|
let mut input = Parser::new(&condition);
|
||||||
let cond = parse_condition_or_declaration(&mut input);
|
let cond = parse_condition_or_declaration(&mut input);
|
||||||
if let Ok(cond) = cond {
|
if let Ok(cond) = cond {
|
||||||
let url = ServoUrl::parse("about:blank").unwrap();
|
let url_data = unsafe { dummy_url_data() };
|
||||||
let reporter = StdoutErrorReporter;
|
let reporter = StdoutErrorReporter;
|
||||||
let context = ParserContext::new_for_cssom(&url, &reporter);
|
let context = ParserContext::new_for_cssom(url_data, &reporter);
|
||||||
cond.eval(&context)
|
cond.eval(&context)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
|
@ -11,7 +11,6 @@ extern crate libc;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate parking_lot;
|
extern crate parking_lot;
|
||||||
extern crate selectors;
|
extern crate selectors;
|
||||||
extern crate servo_url;
|
|
||||||
#[macro_use] extern crate style;
|
#[macro_use] extern crate style;
|
||||||
extern crate style_traits;
|
extern crate style_traits;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use style::gecko_bindings::structs::{Loader, ServoStyleSheet};
|
||||||
use style::gecko_bindings::sugar::ownership::HasArcFFI;
|
use style::gecko_bindings::sugar::ownership::HasArcFFI;
|
||||||
use style::media_queries::MediaList;
|
use style::media_queries::MediaList;
|
||||||
use style::shared_lock::Locked;
|
use style::shared_lock::Locked;
|
||||||
use style::stylesheets::{ImportRule, StylesheetLoader as StyleStylesheetLoader};
|
use style::stylesheets::{ImportRule, Stylesheet, StylesheetLoader as StyleStylesheetLoader};
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
pub struct StylesheetLoader(*mut Loader, *mut ServoStyleSheet);
|
pub struct StylesheetLoader(*mut Loader, *mut ServoStyleSheet);
|
||||||
|
@ -45,17 +45,16 @@ impl StyleStylesheetLoader for StylesheetLoader {
|
||||||
let (spec_bytes, spec_len): (*const u8, usize) = import.url.as_slice_components();
|
let (spec_bytes, spec_len): (*const u8, usize) = import.url.as_slice_components();
|
||||||
|
|
||||||
let base_url_data = import.url.extra_data.get();
|
let base_url_data = import.url.extra_data.get();
|
||||||
let arc = make_arc(import);
|
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_LoadStyleSheet(self.0,
|
Gecko_LoadStyleSheet(self.0,
|
||||||
self.1,
|
self.1,
|
||||||
HasArcFFI::arc_as_borrowed(&arc),
|
Stylesheet::arc_as_borrowed(&import.stylesheet),
|
||||||
base_url_data,
|
base_url_data,
|
||||||
spec_bytes,
|
spec_bytes,
|
||||||
spec_len as u32,
|
spec_len as u32,
|
||||||
media_string.as_bytes().as_ptr(),
|
media_string.as_bytes().as_ptr(),
|
||||||
media_string.len() as u32);
|
media_string.len() as u32);
|
||||||
}
|
}
|
||||||
arc
|
make_arc(import)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ use std::borrow::ToOwned;
|
||||||
use style::Atom;
|
use style::Atom;
|
||||||
use style::error_reporting::ParseErrorReporter;
|
use style::error_reporting::ParseErrorReporter;
|
||||||
use style::media_queries::*;
|
use style::media_queries::*;
|
||||||
use style::parser::ParserContextExtraData;
|
|
||||||
use style::servo::media_queries::*;
|
use style::servo::media_queries::*;
|
||||||
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard};
|
use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard};
|
||||||
use style::stylesheets::{Stylesheet, Origin, CssRule};
|
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 css_str = css.to_owned();
|
||||||
let stylesheet = Stylesheet::from_str(
|
let stylesheet = Stylesheet::from_str(
|
||||||
css, url, Origin::Author, Default::default(), SharedRwLock::new(),
|
css, url, Origin::Author, Default::default(), SharedRwLock::new(),
|
||||||
None, &CSSErrorReporterTest,
|
None, &CSSErrorReporterTest);
|
||||||
ParserContextExtraData::default());
|
|
||||||
let mut rule_count = 0;
|
let mut rule_count = 0;
|
||||||
let guard = stylesheet.shared_lock.read();
|
let guard = stylesheet.shared_lock.read();
|
||||||
media_queries(&guard, &stylesheet.rules.read_with(&guard).0, &mut |mq| {
|
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 url = ServoUrl::parse("http://localhost").unwrap();
|
||||||
let ss = Stylesheet::from_str(
|
let ss = Stylesheet::from_str(
|
||||||
css, url, Origin::Author, Default::default(), SharedRwLock::new(),
|
css, url, Origin::Author, Default::default(), SharedRwLock::new(),
|
||||||
None, &CSSErrorReporterTest,
|
None, &CSSErrorReporterTest);
|
||||||
ParserContextExtraData::default());
|
|
||||||
let mut rule_count = 0;
|
let mut rule_count = 0;
|
||||||
ss.effective_style_rules(device, &ss.shared_lock.read(), |_| rule_count += 1);
|
ss.effective_style_rules(device, &ss.shared_lock.read(), |_| rule_count += 1);
|
||||||
assert!(rule_count == expected_rule_count, css.to_owned());
|
assert!(rule_count == expected_rule_count, css.to_owned());
|
||||||
|
|
|
@ -8,7 +8,6 @@ use servo_url::ServoUrl;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::error_reporting::ParseErrorReporter;
|
use style::error_reporting::ParseErrorReporter;
|
||||||
use style::media_queries::MediaList;
|
use style::media_queries::MediaList;
|
||||||
use style::parser::ParserContextExtraData;
|
|
||||||
use style::properties::{longhands, Importance, PropertyDeclaration, PropertyDeclarationBlock};
|
use style::properties::{longhands, Importance, PropertyDeclaration, PropertyDeclarationBlock};
|
||||||
use style::rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
|
use style::rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
|
||||||
use style::shared_lock::SharedRwLock;
|
use style::shared_lock::SharedRwLock;
|
||||||
|
@ -46,8 +45,7 @@ fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> {
|
||||||
},
|
},
|
||||||
SharedRwLock::new(),
|
SharedRwLock::new(),
|
||||||
None,
|
None,
|
||||||
&ErrorringErrorReporter,
|
&ErrorringErrorReporter);
|
||||||
ParserContextExtraData {});
|
|
||||||
let guard = s.shared_lock.read();
|
let guard = s.shared_lock.read();
|
||||||
let rules = s.rules.read_with(&guard);
|
let rules = s.rules.read_with(&guard);
|
||||||
rules.0.iter().filter_map(|rule| {
|
rules.0.iter().filter_map(|rule| {
|
||||||
|
|
|
@ -15,7 +15,6 @@ use std::sync::Mutex;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use style::error_reporting::ParseErrorReporter;
|
use style::error_reporting::ParseErrorReporter;
|
||||||
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
|
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
|
||||||
use style::parser::ParserContextExtraData;
|
|
||||||
use style::properties::Importance;
|
use style::properties::Importance;
|
||||||
use style::properties::{CSSWideKeyword, DeclaredValueOwned, PropertyDeclaration, PropertyDeclarationBlock};
|
use style::properties::{CSSWideKeyword, DeclaredValueOwned, PropertyDeclaration, PropertyDeclarationBlock};
|
||||||
use style::properties::longhands;
|
use style::properties::longhands;
|
||||||
|
@ -64,8 +63,7 @@ fn test_parse_stylesheet() {
|
||||||
let url = ServoUrl::parse("about::test").unwrap();
|
let url = ServoUrl::parse("about::test").unwrap();
|
||||||
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
||||||
SharedRwLock::new(), None,
|
SharedRwLock::new(), None,
|
||||||
&CSSErrorReporterTest,
|
&CSSErrorReporterTest);
|
||||||
ParserContextExtraData::default());
|
|
||||||
let mut namespaces = Namespaces::default();
|
let mut namespaces = Namespaces::default();
|
||||||
namespaces.default = Some(ns!(html));
|
namespaces.default = Some(ns!(html));
|
||||||
let expected = Stylesheet {
|
let expected = Stylesheet {
|
||||||
|
@ -73,7 +71,7 @@ fn test_parse_stylesheet() {
|
||||||
media: Arc::new(stylesheet.shared_lock.wrap(Default::default())),
|
media: Arc::new(stylesheet.shared_lock.wrap(Default::default())),
|
||||||
shared_lock: stylesheet.shared_lock.clone(),
|
shared_lock: stylesheet.shared_lock.clone(),
|
||||||
namespaces: RwLock::new(namespaces),
|
namespaces: RwLock::new(namespaces),
|
||||||
base_url: url,
|
url_data: url,
|
||||||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||||
disabled: AtomicBool::new(false),
|
disabled: AtomicBool::new(false),
|
||||||
rules: CssRules::new(vec![
|
rules: CssRules::new(vec![
|
||||||
|
@ -327,8 +325,7 @@ fn test_report_error_stylesheet() {
|
||||||
|
|
||||||
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
|
||||||
SharedRwLock::new(), None,
|
SharedRwLock::new(), None,
|
||||||
&error_reporter,
|
&error_reporter);
|
||||||
ParserContextExtraData::default());
|
|
||||||
|
|
||||||
let mut errors = errors.lock().unwrap();
|
let mut errors = errors.lock().unwrap();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use media_queries::CSSErrorReporterTest;
|
||||||
use servo_config::prefs::{PREFS, PrefValue};
|
use servo_config::prefs::{PREFS, PrefValue};
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use style::media_queries::{Device, MediaType};
|
use style::media_queries::{Device, MediaType};
|
||||||
use style::parser::{ParserContext, ParserContextExtraData};
|
use style::parser::ParserContext;
|
||||||
use style::shared_lock::SharedRwLock;
|
use style::shared_lock::SharedRwLock;
|
||||||
use style::stylesheets::{Stylesheet, Origin};
|
use style::stylesheets::{Stylesheet, Origin};
|
||||||
use style::values::specified::LengthOrPercentageOrAuto::{self, Auto};
|
use style::values::specified::LengthOrPercentageOrAuto::{self, Auto};
|
||||||
|
@ -30,8 +30,7 @@ macro_rules! stylesheet {
|
||||||
Default::default(),
|
Default::default(),
|
||||||
$shared_lock,
|
$shared_lock,
|
||||||
None,
|
None,
|
||||||
&$error_reporter,
|
&$error_reporter
|
||||||
ParserContextExtraData::default()
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue