use super::*;
pub(crate) fn apply_cascaded_declarations_with_inheritance_source_and_parent_ch_advance(
style: &mut ComputedStyle,
declarations: &[CascadedDeclaration<'_>],
inheritance_source: &ComputedStyle,
parent_ch_advance: LayoutLength,
is_document_root: bool,
color_scheme_preference: ColorSchemePreference,
) {
let (direction, writing_mode) =
logical_mapping_context(style, declarations, inheritance_source);
let mut declarations =
declarations_after_css_wide_rollbacks(declarations, direction, writing_mode);
declarations.retain(cascaded_declaration_is_canonical);
apply_cascaded_custom_property_declarations(style, &declarations, inheritance_source);
apply_cascaded_color_scheme_declarations(
style,
&declarations,
inheritance_source,
color_scheme_preference,
);
compute_registered_custom_property_values(style);
let declarations = declarations_after_variable_substitution_and_shorthand_expansion(
&declarations,
&style.custom_properties,
direction,
writing_mode,
);
apply_cascaded_font_size_declarations_with_parent_ch_advance(
style,
&declarations,
inheritance_source,
parent_ch_advance,
);
apply_cascaded_color_declarations(style, &declarations, inheritance_source);
update_dependency_prepass_provenance(style, &declarations, inheritance_source);
let mut parsed_font_component = None;
for (index, declaration) in declarations.iter().enumerate() {
let Some(property) = declaration.property.modeled() else {
continue;
};
let name = property.css_name();
if matches!(
property,
ModeledProperty::Longhand(
ModeledLonghand::ColorScheme | ModeledLonghand::FontSize | ModeledLonghand::Color
) | ModeledProperty::FontComponent(ModeledLonghand::FontSize)
) {
continue;
}
if is_shadowed_by_later_var_declaration(&declarations, index, &declaration.property) {
continue;
}
let resolved_value;
let value = trim_css_value(&declaration.value);
let value = if contains_css_variable_reference(value) {
let Some(resolved) = resolve_css_variables(value, &style.custom_properties) else {
if matches!(
property,
ModeledProperty::Longhand(
ModeledLonghand::AnimationName
| ModeledLonghand::AnimationDuration
| ModeledLonghand::AnimationDelay
)
) {
apply_css_wide_default_keyword(
style,
property,
CssWideDefaultKeyword::Initial,
inheritance_source,
);
}
continue;
};
resolved_value = resolved;
trim_css_value(&resolved_value)
} else {
value
};
if let Some(keyword) = CssWideDefaultKeyword::parse(value) {
apply_css_wide_default_keyword(style, property, keyword, inheritance_source);
for longhand in property.resolve_targets(direction, writing_mode) {
if !matches!(keyword, CssWideDefaultKeyword::Inherit)
&& !(matches!(keyword, CssWideDefaultKeyword::Unset) && longhand.is_inherited())
{
mark_modeled_longhand_specified(style, longhand);
}
}
continue;
}
if let Some(component) = property.font_component() {
let source = (
declaration.stylesheet_index,
declaration.rule_order,
declaration.declaration_order,
);
if parsed_font_component
.as_ref()
.is_none_or(|(cached_source, _)| *cached_source != source)
{
parsed_font_component = parse_font_shorthand_with_line_height_font_size(
value,
inheritance_source.font_size,
parent_ch_advance,
style.font_weight,
Some(style.font_size),
layout_pt(inheritance_source.line_height),
)
.map(|font| (source, font));
}
if let Some((_, font)) = &parsed_font_component {
apply_font_shorthand_component(style, component, font);
mark_modeled_longhand_specified(style, component);
}
continue;
}
parsed_font_component = None;
if is_document_root && value.eq_ignore_ascii_case("match-parent") {
match name {
"text-align" => {
style.text_align = TextAlign::Start;
style.text_align_last = TextAlignLast::Auto;
continue;
}
"text-align-all" => {
style.text_align = TextAlign::Start;
continue;
}
_ => {}
}
}
if apply_cascaded_property(
style,
name,
value,
declaration,
inheritance_source,
parent_ch_advance,
) {
for longhand in property.resolve_targets(direction, writing_mode) {
mark_modeled_longhand_specified(style, longhand);
}
continue;
}
}
normalize_overflow_axes(style);
style.resolve_legacy_webkit_line_clamp();
normalize_background_layers(style);
style
.row_gap
.reduce_math_with_nonnegative_percentage_basis();
style
.column_gap
.reduce_math_with_nonnegative_percentage_basis();
style.effective_zoom =
EffectiveZoom::from_parent_and_local(inheritance_source.effective_zoom, style.zoom);
}
fn canonical_longhand(property: &ModeledProperty) -> Option<ModeledLonghand> {
match property {
ModeledProperty::Longhand(longhand) | ModeledProperty::FontComponent(longhand) => {
Some(*longhand)
}
ModeledProperty::Shorthand(_)
| ModeledProperty::Logical(_)
| ModeledProperty::Alias(_)
| ModeledProperty::All => None,
}
}
fn update_dependency_prepass_provenance(
style: &mut ComputedStyle,
declarations: &[CascadedDeclaration<'_>],
inheritance_source: &ComputedStyle,
) {
for declaration in declarations {
let Some(property) = declaration.property.modeled() else {
continue;
};
let Some(longhand) = canonical_longhand(property) else {
continue;
};
if !matches!(
longhand,
ModeledLonghand::ColorScheme | ModeledLonghand::FontSize | ModeledLonghand::Color
) {
continue;
}
let resolved;
let value = if contains_css_variable_reference(&declaration.value) {
let Some(value) = resolve_css_variables(&declaration.value, &style.custom_properties)
else {
inherit_modeled_longhand_provenance(style, inheritance_source, longhand);
continue;
};
resolved = value;
trim_css_value(&resolved)
} else {
trim_css_value(&declaration.value)
};
if let Some(keyword) = CssWideDefaultKeyword::parse(value) {
if matches!(keyword, CssWideDefaultKeyword::Inherit)
|| (matches!(keyword, CssWideDefaultKeyword::Unset) && longhand.is_inherited())
{
inherit_modeled_longhand_provenance(style, inheritance_source, longhand);
} else {
mark_modeled_longhand_specified(style, longhand);
}
} else if crate::css::parse::cascaded_declaration_is_valid(&declaration.property, value) {
mark_modeled_longhand_specified(style, longhand);
} else if longhand.is_inherited() {
inherit_modeled_longhand_provenance(style, inheritance_source, longhand);
} else {
mark_modeled_longhand_specified(style, longhand);
}
}
}
fn apply_cascaded_property(
style: &mut ComputedStyle,
name: &str,
value: &str,
declaration: &CascadedDeclaration<'_>,
inheritance_source: &ComputedStyle,
parent_ch_advance: LayoutLength,
) -> bool {
if super::super::style::apply_animation_snapshot_longhand(style, name, value) {
return true;
}
if name == "color-scheme" {
return true;
}
apply_cascaded_layout_declaration(
style,
name,
value,
declaration,
inheritance_source,
parent_ch_advance,
) || apply_cascaded_sizing_declaration(
style,
name,
value,
declaration,
inheritance_source,
parent_ch_advance,
) || apply_cascaded_positioning_declaration(
style,
name,
value,
declaration,
inheritance_source,
parent_ch_advance,
) || apply_cascaded_visual_declaration(
style,
name,
value,
declaration,
inheritance_source,
parent_ch_advance,
) || apply_cascaded_text_declaration(
style,
name,
value,
declaration,
inheritance_source,
parent_ch_advance,
)
}
pub(in crate::css) fn apply_cascaded_marker_text_property(
style: &mut ComputedStyle,
name: &str,
value: &str,
declaration: &CascadedDeclaration<'_>,
inheritance_source: &ComputedStyle,
parent_ch_advance: LayoutLength,
) -> bool {
if !matches!(
name,
"direction"
| "unicode-bidi"
| "text-orientation"
| "text-combine-upright"
| "letter-spacing"
| "word-spacing"
| "tab-size"
| "word-break"
| "overflow-wrap"
| "word-wrap"
| "line-break"
| "hyphens"
| "text-decoration"
| "text-decoration-line"
| "text-decoration-style"
| "text-decoration-color"
| "text-decoration-thickness"
| "text-decoration-inset"
| "text-decoration-skip"
| "text-decoration-skip-ink"
| "text-decoration-skip-self"
| "text-decoration-skip-box"
| "text-decoration-skip-spaces"
| "text-underline-offset"
| "text-underline-position"
| "text-emphasis"
| "text-emphasis-style"
| "text-emphasis-color"
| "text-emphasis-position"
| "text-emphasis-skip"
| "text-shadow"
) {
return false;
}
apply_cascaded_property(
style,
name,
value,
declaration,
inheritance_source,
parent_ch_advance,
)
}
pub(in crate::css) fn cascaded_declaration_is_canonical(
declaration: &CascadedDeclaration<'_>,
) -> bool {
if declaration
.property
.modeled()
.is_some_and(|property| property.font_component().is_some())
{
return true;
}
crate::css::parse::cascaded_declaration_is_valid(
&declaration.property,
declaration.value.as_ref(),
)
}
fn normalize_overflow_axes(style: &mut ComputedStyle) {
let x_is_scroll_container = !matches!(style.overflow_x, Overflow::Visible | Overflow::Clip);
let y_is_scroll_container = !matches!(style.overflow_y, Overflow::Visible | Overflow::Clip);
if x_is_scroll_container {
style.overflow_y = match style.overflow_y {
Overflow::Visible => Overflow::Auto,
Overflow::Clip => Overflow::Hidden,
overflow => overflow,
};
}
if y_is_scroll_container {
style.overflow_x = match style.overflow_x {
Overflow::Visible => Overflow::Auto,
Overflow::Clip => Overflow::Hidden,
overflow => overflow,
};
}
}
mod layout;
pub(in crate::css) use self::layout::*;
mod positioning;
pub(in crate::css) use self::positioning::*;
mod sizing;
pub(in crate::css) use self::sizing::*;
mod visual;
pub(in crate::css) use self::visual::*;
mod text;
pub(in crate::css) use self::text::*;