Implement the Servo parser for font descriptors Web API.

According to the spec, this parser should follow what we do for
@font_face rule, so we use the same type to parse the input, instead of
using the parser of their specified values.
This commit is contained in:
Boris Chiou 2017-12-05 13:47:36 +08:00
parent 8f30880d36
commit 1e29e64000
3 changed files with 992 additions and 326 deletions

View file

@ -77,6 +77,7 @@ use style::gecko_bindings::bindings::RawServoDeclarationBlockBorrowedOrNull;
use style::gecko_bindings::bindings::RawServoStyleRuleBorrowed;
use style::gecko_bindings::bindings::RawServoStyleSet;
use style::gecko_bindings::bindings::ServoStyleContextBorrowedOrNull;
use style::gecko_bindings::bindings::nsCSSValueBorrowedMut;
use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
@ -85,7 +86,7 @@ use style::gecko_bindings::structs::{CallerType, CSSPseudoElementType, Composite
use style::gecko_bindings::structs::{Loader, LoaderReusableStyleSheets};
use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong, RustString};
use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsAtom, nsCSSPropertyID};
use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule};
use style::gecko_bindings::structs::{nsCSSFontDesc, nsCSSFontFaceRule, nsCSSCounterStyleRule};
use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, PropertyValuePair};
use style::gecko_bindings::structs::AtomArray;
use style::gecko_bindings::structs::IterationCompositeOperation;
@ -4734,6 +4735,81 @@ pub extern "C" fn Servo_ParseTransformIntoMatrix(
true
}
// https://drafts.csswg.org/css-font-loading/#dom-fontface-fontface
#[no_mangle]
pub extern "C" fn Servo_ParseFontDescriptor(
desc_id: nsCSSFontDesc,
value: *const nsAString,
data: *mut URLExtraData,
result: nsCSSValueBorrowedMut,
) -> bool {
use cssparser::UnicodeRange;
use self::nsCSSFontDesc::*;
use style::computed_values::{font_feature_settings, font_stretch, font_style};
use style::font_face::{FontDisplay, FontWeight, Source};
use style::properties::longhands::font_language_override;
use style::values::computed::font::FamilyName;
let string = unsafe { (*value).to_string() };
let mut input = ParserInput::new(&string);
let mut parser = Parser::new(&mut input);
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
let context = ParserContext::new(
Origin::Author,
url_data,
Some(CssRuleType::FontFace),
ParsingMode::DEFAULT,
QuirksMode::NoQuirks,
);
macro_rules! parse_font_desc {
(
valid = [ $( $v_enum_name: ident / $t: ty, )* ]
invalid = [ $( $i_enum_name: ident, )* ]
) => {
match desc_id {
$(
$v_enum_name => {
let f = match parser.parse_entirely(|i| <$t as Parse>::parse(&context, i)) {
Ok(f) => f,
Err(..) => return false,
};
result.set_from(f);
},
)*
$(
$i_enum_name => {
debug_assert!(false, "$i_enum_name is not a valid font descriptor");
return false;
},
)*
}
}
}
// We implement the parser of each arm according to the implementation of @font-face rule.
// see component/style/font_face.rs for more detail.
parse_font_desc!(
valid = [
eCSSFontDesc_Family / FamilyName,
eCSSFontDesc_Style / font_style::T,
eCSSFontDesc_Weight / FontWeight,
eCSSFontDesc_Stretch / font_stretch::T,
eCSSFontDesc_Src / Vec<Source>,
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
eCSSFontDesc_FontFeatureSettings / font_feature_settings::T,
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
eCSSFontDesc_Display / FontDisplay,
]
invalid = [
eCSSFontDesc_UNKNOWN,
eCSSFontDesc_COUNT,
]
);
true
}
#[no_mangle]
pub unsafe extern "C" fn Servo_SourceSizeList_Parse(
value: *const nsACString,