mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
style: Rewrite get*Style using StyleResolverForElement.
Removing the ugly. MozReview-Commit-ID: BvahbMKS7QU
This commit is contained in:
parent
b4c8ba3029
commit
0ad2d39c30
4 changed files with 126 additions and 178 deletions
|
@ -37,7 +37,7 @@ use style::selector_parser::PseudoElement;
|
|||
use style_traits::ToCss;
|
||||
use style_traits::cursor::Cursor;
|
||||
use webrender_traits::ClipId;
|
||||
use wrapper::{LayoutNodeHelpers, LayoutNodeLayoutData};
|
||||
use wrapper::LayoutNodeLayoutData;
|
||||
|
||||
/// Mutable data belonging to the LayoutThread.
|
||||
///
|
||||
|
@ -680,7 +680,9 @@ pub fn process_resolved_style_request<'a, N>(context: &LayoutContext,
|
|||
layout_root: &mut Flow) -> String
|
||||
where N: LayoutNode,
|
||||
{
|
||||
use style::stylist::RuleInclusion;
|
||||
use style::traversal::resolve_style;
|
||||
|
||||
let element = node.as_element().unwrap();
|
||||
|
||||
// We call process_resolved_style_request after performing a whole-document
|
||||
|
@ -689,30 +691,43 @@ pub fn process_resolved_style_request<'a, N>(context: &LayoutContext,
|
|||
return process_resolved_style_request_internal(node, pseudo, property, layout_root);
|
||||
}
|
||||
|
||||
// However, the element may be in a display:none subtree. The style system
|
||||
// has a mechanism to give us that within a defined scope (after which point
|
||||
// it's cleared to maintained style system invariants).
|
||||
// In a display: none subtree. No pseudo-element exists.
|
||||
if pseudo.is_some() {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
let mut tlc = ThreadLocalStyleContext::new(&context.style_context);
|
||||
let mut context = StyleContext {
|
||||
shared: &context.style_context,
|
||||
thread_local: &mut tlc,
|
||||
};
|
||||
let mut result = None;
|
||||
let ensure = |el: N::ConcreteElement| el.as_node().initialize_data();
|
||||
let clear = |el: N::ConcreteElement| el.as_node().clear_data();
|
||||
resolve_style(&mut context, element, &ensure, &clear, |_: &_| {
|
||||
let s = process_resolved_style_request_internal(node, pseudo, property, layout_root);
|
||||
result = Some(s);
|
||||
});
|
||||
result.unwrap()
|
||||
|
||||
let styles = resolve_style(&mut context, element, RuleInclusion::All);
|
||||
let style = styles.primary();
|
||||
let longhand_id = match *property {
|
||||
PropertyId::Longhand(id) => id,
|
||||
// Firefox returns blank strings for the computed value of shorthands,
|
||||
// so this should be web-compatible.
|
||||
PropertyId::Shorthand(_) => return String::new(),
|
||||
PropertyId::Custom(ref name) => {
|
||||
return style.computed_value_to_string(PropertyDeclarationId::Custom(name))
|
||||
}
|
||||
};
|
||||
|
||||
// No need to care about used values here, since we're on a display: none
|
||||
// subtree, use the resolved value.
|
||||
style.computed_value_to_string(PropertyDeclarationId::Longhand(longhand_id))
|
||||
}
|
||||
|
||||
/// The primary resolution logic, which assumes that the element is styled.
|
||||
fn process_resolved_style_request_internal<'a, N>(requested_node: N,
|
||||
pseudo: &Option<PseudoElement>,
|
||||
property: &PropertyId,
|
||||
layout_root: &mut Flow) -> String
|
||||
where N: LayoutNode,
|
||||
fn process_resolved_style_request_internal<'a, N>(
|
||||
requested_node: N,
|
||||
pseudo: &Option<PseudoElement>,
|
||||
property: &PropertyId,
|
||||
layout_root: &mut Flow,
|
||||
) -> String
|
||||
where
|
||||
N: LayoutNode,
|
||||
{
|
||||
let layout_el = requested_node.to_threadsafe().as_element().unwrap();
|
||||
let layout_el = match *pseudo {
|
||||
|
@ -721,6 +736,8 @@ fn process_resolved_style_request_internal<'a, N>(requested_node: N,
|
|||
Some(PseudoElement::DetailsSummary) |
|
||||
Some(PseudoElement::DetailsContent) |
|
||||
Some(PseudoElement::Selection) => None,
|
||||
// FIXME(emilio): What about the other pseudos? Probably they shouldn't
|
||||
// just return the element's style!
|
||||
_ => Some(layout_el)
|
||||
};
|
||||
|
||||
|
@ -735,7 +752,6 @@ fn process_resolved_style_request_internal<'a, N>(requested_node: N,
|
|||
};
|
||||
|
||||
let style = &*layout_el.resolved_style();
|
||||
|
||||
let longhand_id = match *property {
|
||||
PropertyId::Longhand(id) => id,
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue