mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Factor out common part of Servo_ParseProperty() and set_property().
This commit is contained in:
parent
15f3db5abf
commit
7ebdf95a3d
1 changed files with 28 additions and 26 deletions
|
@ -1117,24 +1117,32 @@ pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) {
|
||||||
let _ = data.into_box::<PerDocumentStyleData>();
|
let _ = data.into_box::<PerDocumentStyleData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_property(property_id: PropertyId,
|
||||||
|
value: *const nsACString,
|
||||||
|
data: *mut URLExtraData,
|
||||||
|
length_parsing_mode: structs::LengthParsingMode) -> Result<ParsedDeclaration, ()> {
|
||||||
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||||
|
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
||||||
|
let length_parsing_mode = match length_parsing_mode {
|
||||||
|
structs::LengthParsingMode::Default => LengthParsingMode::Default,
|
||||||
|
structs::LengthParsingMode::SVG => LengthParsingMode::SVG,
|
||||||
|
};
|
||||||
|
|
||||||
|
parse_one_declaration(property_id,
|
||||||
|
value,
|
||||||
|
url_data,
|
||||||
|
&RustLogReporter,
|
||||||
|
length_parsing_mode,
|
||||||
|
QuirksMode::NoQuirks)
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ParseProperty(property: nsCSSPropertyID, value: *const nsACString,
|
pub extern "C" fn Servo_ParseProperty(property: nsCSSPropertyID, value: *const nsACString,
|
||||||
data: *mut URLExtraData)
|
data: *mut URLExtraData)
|
||||||
-> RawServoDeclarationBlockStrong {
|
-> RawServoDeclarationBlockStrong {
|
||||||
let id = get_property_id_from_nscsspropertyid!(property,
|
let id = get_property_id_from_nscsspropertyid!(property,
|
||||||
RawServoDeclarationBlockStrong::null());
|
RawServoDeclarationBlockStrong::null());
|
||||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
match parse_property(id, value, data, structs::LengthParsingMode::Default) {
|
||||||
|
|
||||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
|
||||||
let reporter = RustLogReporter;
|
|
||||||
let context = ParserContext::new(Origin::Author,
|
|
||||||
url_data,
|
|
||||||
&reporter,
|
|
||||||
Some(CssRuleType::Style),
|
|
||||||
LengthParsingMode::Default,
|
|
||||||
QuirksMode::NoQuirks);
|
|
||||||
|
|
||||||
match ParsedDeclaration::parse(id, &context, &mut Parser::new(value)) {
|
|
||||||
Ok(parsed) => {
|
Ok(parsed) => {
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||||
let mut block = PropertyDeclarationBlock::new();
|
let mut block = PropertyDeclarationBlock::new();
|
||||||
|
@ -1293,20 +1301,14 @@ 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, data: *mut URLExtraData,
|
value: *const nsACString, is_important: bool, data: *mut URLExtraData,
|
||||||
length_parsing_mode: structs::LengthParsingMode) -> bool {
|
length_parsing_mode: structs::LengthParsingMode) -> bool {
|
||||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
match parse_property(property_id, value, data, length_parsing_mode) {
|
||||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
Ok(parsed) => {
|
||||||
let length_parsing_mode = match length_parsing_mode {
|
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
||||||
structs::LengthParsingMode::Default => LengthParsingMode::Default,
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||||
structs::LengthParsingMode::SVG => LengthParsingMode::SVG,
|
parsed.expand_set_into(decls, importance)
|
||||||
};
|
})
|
||||||
if let Ok(parsed) = parse_one_declaration(property_id, value, url_data, &RustLogReporter,
|
},
|
||||||
length_parsing_mode, QuirksMode::NoQuirks) {
|
Err(_) => false,
|
||||||
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
|
||||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
|
||||||
parsed.expand_set_into(decls, importance)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue