mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Add an FFI which returns computed values for a given declaration block with/without parent_style. r?heycam
The function uses document's default computed values if the parent style is not specified.
This commit is contained in:
parent
39d3c22edc
commit
bd066af640
3 changed files with 52 additions and 1 deletions
|
@ -369,7 +369,7 @@ impl PropertyDeclarationBlock {
|
|||
return false
|
||||
}
|
||||
}
|
||||
self.declarations.iter().any(|&&(ref decl, _)|
|
||||
self.declarations.iter().any(|&(ref decl, _)|
|
||||
decl.id().is_or_is_longhand_of(property) &&
|
||||
decl.get_css_wide_keyword().is_some()
|
||||
)
|
||||
|
|
|
@ -854,6 +854,33 @@ impl Stylist {
|
|||
{
|
||||
self.dependencies.compute_hint(element, snapshot)
|
||||
}
|
||||
|
||||
/// Computes styles for a given declaration with parent_style.
|
||||
pub fn compute_for_declarations(&self,
|
||||
guards: &StylesheetGuards,
|
||||
parent_style: &Arc<ComputedValues>,
|
||||
declarations: Arc<Locked<PropertyDeclarationBlock>>)
|
||||
-> Arc<ComputedValues> {
|
||||
use font_metrics::get_metrics_provider_for_product;
|
||||
|
||||
let v = vec![
|
||||
ApplicableDeclarationBlock::from_declarations(declarations.clone(),
|
||||
CascadeLevel::StyleAttributeNormal)
|
||||
];
|
||||
let rule_node =
|
||||
self.rule_tree.insert_ordered_rules(v.into_iter().map(|a| (a.source, a.level)));
|
||||
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
Arc::new(properties::cascade(&self.device,
|
||||
&rule_node,
|
||||
guards,
|
||||
Some(parent_style),
|
||||
Some(parent_style),
|
||||
None,
|
||||
&StdoutErrorReporter,
|
||||
&metrics,
|
||||
CascadeFlags::empty()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Stylist {
|
||||
|
|
|
@ -2123,3 +2123,27 @@ pub extern "C" fn Servo_StyleSet_GetFontFaceRules(raw_data: RawServoStyleSetBorr
|
|||
dest.mSheetType = src.1.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(raw_data: RawServoStyleSetBorrowed,
|
||||
parent_style_or_null: ServoComputedValuesBorrowedOrNull,
|
||||
declarations: RawServoDeclarationBlockBorrowed)
|
||||
-> ServoComputedValuesStrong
|
||||
{
|
||||
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let guards = StylesheetGuards::same(&guard);
|
||||
|
||||
let parent_style = match ComputedValues::arc_from_borrowed(&parent_style_or_null) {
|
||||
Some(parent) => &parent,
|
||||
None => doc_data.default_computed_values(),
|
||||
};
|
||||
|
||||
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||
|
||||
doc_data.stylist.compute_for_declarations(&guards,
|
||||
parent_style,
|
||||
declarations.clone()).into_strong()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue