From bd066af64015a5bc668a727152ca9cd610e83627 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 14 Apr 2017 23:39:16 +0900 Subject: [PATCH] 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. --- .../style/properties/declaration_block.rs | 2 +- components/style/stylist.rs | 27 +++++++++++++++++++ ports/geckolib/glue.rs | 24 +++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 045a95e53e2..b1b03f9a7ef 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -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() ) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 5987dd74e44..d91a4b6250d 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -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, + declarations: Arc>) + -> Arc { + 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 { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index d9d1a0c2299..ee848c90ffb 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -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::::as_arc(&declarations); + + doc_data.stylist.compute_for_declarations(&guards, + parent_style, + declarations.clone()).into_strong() +} +