use crate::style::{ComputedStyle, Content, ImportantMask, Rule, RuleOrigin, TuiStyle, Value};
pub(super) fn resolve_content_on<F>(
working: &ComputedStyle,
sorted_by_spec: &[&Rule],
inline: Option<&TuiStyle>,
attr_lookup: &F,
) -> Option<Option<String>>
where
F: Fn(&str) -> Option<String>,
{
let mut declared: Option<Content> = None;
let mut apply_from = |style: &TuiStyle, important_prop_match: bool| {
if let Some(v) = &style.content {
let is_imp = style.important.contains(ImportantMask::CONTENT);
if is_imp == important_prop_match {
declared = match v {
Value::Specified(c) => Some(c.clone()),
Value::Inherit => declared.clone(),
Value::Initial => Some(Content::None),
};
}
}
};
for r in sorted_by_spec {
if r.origin == RuleOrigin::UserAgent {
apply_from(&r.style, false);
}
}
for r in sorted_by_spec {
if r.origin == RuleOrigin::Author {
apply_from(&r.style, false);
}
}
if let Some(s) = inline {
apply_from(s, false);
}
if let Some(s) = inline {
apply_from(s, true);
}
for r in sorted_by_spec {
if r.origin == RuleOrigin::Author {
apply_from(&r.style, true);
}
}
for r in sorted_by_spec {
if r.origin == RuleOrigin::UserAgent {
apply_from(&r.style, true);
}
}
declared.map(|c| c.resolve(&working.vars, attr_lookup))
}