servo: Merge #19489 - add FFI functions for Gecko @counter-style value parsing (from heycam:counter-parse-2); r=upsuper

Trying to land #19441 again.

Source-Repo: https://github.com/servo/servo
Source-Revision: 5bfab782ec862189209931e424fbd4325b8f9172

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 4e3e38ee429faeefb02a6903abd097350a67e1a8
This commit is contained in:
Cameron McCormack 2017-12-04 21:22:50 -06:00
Родитель bac5e97690
Коммит 1d69d9bcb9
6 изменённых файлов: 372 добавлений и 861 удалений

Просмотреть файл

@ -11,7 +11,7 @@ use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser};
use cssparser::{Parser, Token, serialize_identifier, CowRcStr};
use error_reporting::{ContextualParseError, ParseErrorReporter};
#[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors;
#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSCounterDesc;
#[cfg(feature = "gecko")] use gecko_bindings::structs::{ nsCSSCounterDesc, nsCSSValue };
use parser::{ParserContext, ParserErrorContext, Parse};
use selectors::parser::SelectorParseErrorKind;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
@ -22,8 +22,12 @@ use std::ops::Range;
use style_traits::{Comma, OneOrMoreSeparated, ParseError, StyleParseErrorKind, ToCss};
use values::CustomIdent;
/// Parse the prelude of an @counter-style rule
pub fn parse_counter_style_name<'i, 't>(input: &mut Parser<'i, 't>) -> Result<CustomIdent, ParseError<'i>> {
/// Parse a counter style name reference.
///
/// This allows the reserved counter style names "decimal" and "disc".
pub fn parse_counter_style_name<'i, 't>(
input: &mut Parser<'i, 't>
) -> Result<CustomIdent, ParseError<'i>> {
macro_rules! predefined {
($($name: expr,)+) => {
{
@ -41,7 +45,7 @@ pub fn parse_counter_style_name<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Cu
if let Some(&lower_cased) = predefined(&ident) {
Ok(CustomIdent(Atom::from(lower_cased)))
} else {
// https://github.com/w3c/csswg-drafts/issues/1295 excludes "none"
// none is always an invalid <counter-style> value.
CustomIdent::from_ident(location, ident, &["none"])
}
}
@ -50,6 +54,20 @@ pub fn parse_counter_style_name<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Cu
include!("predefined.rs")
}
/// Parse the prelude of an @counter-style rule
pub fn parse_counter_style_name_definition<'i, 't>(
input: &mut Parser<'i, 't>
) -> Result<CustomIdent, ParseError<'i>> {
parse_counter_style_name(input)
.and_then(|ident| {
if ident.0 == atom!("decimal") || ident.0 == atom!("disc") {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
} else {
Ok(ident)
}
})
}
/// Parse the body (inside `{}`) of an @counter-style rule
pub fn parse_counter_style_body<'i, 't, R>(name: CustomIdent,
context: &ParserContext,
@ -225,6 +243,30 @@ macro_rules! counter_style_descriptors {
dest.write_str("}")
}
}
/// Parse a descriptor into an `nsCSSValue`.
#[cfg(feature = "gecko")]
pub fn parse_counter_style_descriptor<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
descriptor: nsCSSCounterDesc,
value: &mut nsCSSValue
) -> Result<(), ParseError<'i>> {
match descriptor {
$(
nsCSSCounterDesc::$gecko_ident => {
let v: $ty =
input.parse_entirely(|i| Parse::parse(context, i))?;
value.set_from(v);
}
)*
nsCSSCounterDesc::eCSSCounterDesc_COUNT |
nsCSSCounterDesc::eCSSCounterDesc_UNKNOWN => {
panic!("invalid counter descriptor");
}
}
Ok(())
}
}
}

Просмотреть файл

@ -564,6 +564,8 @@ cfg_if! {
pub static nsGkAtoms_dateTime: *mut nsStaticAtom;
#[link_name = "_ZN9nsGkAtoms11datasourcesE"]
pub static nsGkAtoms_datasources: *mut nsStaticAtom;
#[link_name = "_ZN9nsGkAtoms4dateE"]
pub static nsGkAtoms_date: *mut nsStaticAtom;
#[link_name = "_ZN9nsGkAtoms8datetimeE"]
pub static nsGkAtoms_datetime: *mut nsStaticAtom;
#[link_name = "_ZN9nsGkAtoms11datetimeboxE"]
@ -5749,6 +5751,8 @@ cfg_if! {
pub static nsGkAtoms_dateTime: *mut nsStaticAtom;
#[link_name = "?datasources@nsGkAtoms@@2PEAVnsStaticAtom@@EA"]
pub static nsGkAtoms_datasources: *mut nsStaticAtom;
#[link_name = "?date@nsGkAtoms@@2PEAVnsStaticAtom@@EA"]
pub static nsGkAtoms_date: *mut nsStaticAtom;
#[link_name = "?datetime@nsGkAtoms@@2PEAVnsStaticAtom@@EA"]
pub static nsGkAtoms_datetime: *mut nsStaticAtom;
#[link_name = "?datetimebox@nsGkAtoms@@2PEAVnsStaticAtom@@EA"]
@ -10934,6 +10938,8 @@ cfg_if! {
pub static nsGkAtoms_dateTime: *mut nsStaticAtom;
#[link_name = "\x01?datasources@nsGkAtoms@@2PAVnsStaticAtom@@A"]
pub static nsGkAtoms_datasources: *mut nsStaticAtom;
#[link_name = "\x01?date@nsGkAtoms@@2PAVnsStaticAtom@@A"]
pub static nsGkAtoms_date: *mut nsStaticAtom;
#[link_name = "\x01?datetime@nsGkAtoms@@2PAVnsStaticAtom@@A"]
pub static nsGkAtoms_datetime: *mut nsStaticAtom;
#[link_name = "\x01?datetimebox@nsGkAtoms@@2PAVnsStaticAtom@@A"]
@ -16122,6 +16128,8 @@ macro_rules! atom {
{{ #[allow(unsafe_code)] #[allow(unused_unsafe)]unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_dateTime as *mut _) } }};
("datasources") =>
{{ #[allow(unsafe_code)] #[allow(unused_unsafe)]unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_datasources as *mut _) } }};
("date") =>
{{ #[allow(unsafe_code)] #[allow(unused_unsafe)]unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_date as *mut _) } }};
("datetime") =>
{{ #[allow(unsafe_code)] #[allow(unused_unsafe)]unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_datetime as *mut _) } }};
("datetimebox") =>

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -5,7 +5,7 @@
//! Parsing of the stylesheet contents.
use {Namespace, Prefix};
use counter_style::{parse_counter_style_body, parse_counter_style_name};
use counter_style::{parse_counter_style_body, parse_counter_style_name_definition};
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
use cssparser::{CowRcStr, SourceLocation, BasicParseError, BasicParseErrorKind};
use error_reporting::{ContextualParseError, ParseErrorReporter};
@ -383,13 +383,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
// Support for this rule is not fully implemented in Servo yet.
return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
}
let name = parse_counter_style_name(input)?;
// ASCII-case-insensitive matches for "decimal" and "disc".
// The name is already lower-cased by `parse_counter_style_name`
// so we can use == here.
if name.0 == atom!("decimal") || name.0 == atom!("disc") {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
let name = parse_counter_style_name_definition(input)?;
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name)))
},
"viewport" => {

Просмотреть файл

@ -18,6 +18,7 @@ use std::ptr;
use style::applicable_declarations::ApplicableDeclarationBlock;
use style::context::{CascadeInputs, QuirksMode, SharedStyleContext, StyleContext};
use style::context::ThreadLocalStyleContext;
use style::counter_style;
use style::data::{ElementStyles, self};
use style::dom::{ShowSubtreeData, TDocument, TElement, TNode};
use style::driver;
@ -104,6 +105,8 @@ use style::gecko_bindings::structs::ServoTraversalFlags;
use style::gecko_bindings::structs::StyleRuleInclusion;
use style::gecko_bindings::structs::URLExtraData;
use style::gecko_bindings::structs::gfxFontFeatureValueSet;
use style::gecko_bindings::structs::nsCSSCounterDesc;
use style::gecko_bindings::structs::nsCSSValue;
use style::gecko_bindings::structs::nsCSSValueSharedList;
use style::gecko_bindings::structs::nsCompatibility;
use style::gecko_bindings::structs::nsIDocument;
@ -4735,3 +4738,49 @@ pub unsafe extern "C" fn Servo_SourceSizeList_Evaluate(
pub unsafe extern "C" fn Servo_SourceSizeList_Drop(list: RawServoSourceSizeListOwned) {
let _ = list.into_box::<SourceSizeList>();
}
#[no_mangle]
pub extern "C" fn Servo_ParseCounterStyleName(
value: *const nsACString,
) -> *mut nsAtom {
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
let mut input = ParserInput::new(&value);
let mut parser = Parser::new(&mut input);
match parser.parse_entirely(counter_style::parse_counter_style_name_definition) {
Ok(name) => name.0.into_addrefed(),
Err(_) => ptr::null_mut(),
}
}
#[no_mangle]
pub extern "C" fn Servo_ParseCounterStyleDescriptor(
descriptor: nsCSSCounterDesc,
value: *const nsACString,
raw_extra_data: *mut URLExtraData,
result: *mut nsCSSValue,
) -> bool {
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
let url_data = unsafe {
if raw_extra_data.is_null() {
dummy_url_data()
} else {
RefPtr::from_ptr_ref(&raw_extra_data)
}
};
let result = unsafe { result.as_mut().unwrap() };
let mut input = ParserInput::new(&value);
let mut parser = Parser::new(&mut input);
let context = ParserContext::new(
Origin::Author,
url_data,
Some(CssRuleType::CounterStyle),
ParsingMode::DEFAULT,
QuirksMode::NoQuirks,
);
counter_style::parse_counter_style_descriptor(
&context,
&mut parser,
descriptor,
result,
).is_ok()
}