Skip to content

Commit

Permalink
Add an FFI which returns computed values for a given declaration bloc…
Browse files Browse the repository at this point in the history
…k with/without parent_style. r?heycam

The function uses document's default computed values if the parent style
is not specified.
  • Loading branch information
Hiroyuki Ikezoe committed Apr 15, 2017
1 parent 39d3c22 commit bd066af
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/style/properties/declaration_block.rs
Expand Up @@ -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()
)
Expand Down
27 changes: 27 additions & 0 deletions components/style/stylist.rs
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions ports/geckolib/glue.rs
Expand Up @@ -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()
}

0 comments on commit bd066af

Please sign in to comment.