1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibWeb: Rename "specified_style" to "computed_style" in Layout::Node

The specified style was turned into computed style long before it
arrived here (StyleComputer took care of that.)
This commit is contained in:
Andreas Kling 2022-03-24 17:38:05 +01:00
parent 40af665a49
commit 30b1772eeb

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -175,11 +175,11 @@ bool Node::is_fixed_position() const
return position == CSS::Position::Fixed;
}
NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> specified_style)
NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> computed_style)
: Node(document, node)
{
m_has_style = true;
apply_style(*specified_style);
apply_style(*computed_style);
}
NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
@ -227,28 +227,28 @@ void NodeWithStyle::did_insert_into_layout_tree(CSS::StyleProperties const& styl
m_has_definite_height = is_definite_size(CSS::PropertyID::Height, false);
}
void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
{
auto& computed_values = static_cast<CSS::MutableComputedValues&>(m_computed_values);
// NOTE: We have to be careful that font-related properties get set in the right order.
// m_font is used by Length::to_px() when resolving sizes against this layout node.
// That's why it has to be set before everything else.
m_font = specified_style.computed_font();
computed_values.set_font_size(specified_style.property(CSS::PropertyID::FontSize).value()->to_length().to_px(*this));
computed_values.set_font_weight(specified_style.property(CSS::PropertyID::FontWeight).value()->to_integer());
m_line_height = specified_style.line_height(*this);
m_font = computed_style.computed_font();
computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize).value()->to_length().to_px(*this));
computed_values.set_font_weight(computed_style.property(CSS::PropertyID::FontWeight).value()->to_integer());
m_line_height = computed_style.line_height(*this);
computed_values.set_vertical_align(specified_style.vertical_align());
computed_values.set_vertical_align(computed_style.vertical_align());
{
auto attachments = specified_style.property(CSS::PropertyID::BackgroundAttachment);
auto clips = specified_style.property(CSS::PropertyID::BackgroundClip);
auto images = specified_style.property(CSS::PropertyID::BackgroundImage);
auto origins = specified_style.property(CSS::PropertyID::BackgroundOrigin);
auto positions = specified_style.property(CSS::PropertyID::BackgroundPosition);
auto repeats = specified_style.property(CSS::PropertyID::BackgroundRepeat);
auto sizes = specified_style.property(CSS::PropertyID::BackgroundSize);
auto attachments = computed_style.property(CSS::PropertyID::BackgroundAttachment);
auto clips = computed_style.property(CSS::PropertyID::BackgroundClip);
auto images = computed_style.property(CSS::PropertyID::BackgroundImage);
auto origins = computed_style.property(CSS::PropertyID::BackgroundOrigin);
auto positions = computed_style.property(CSS::PropertyID::BackgroundPosition);
auto repeats = computed_style.property(CSS::PropertyID::BackgroundRepeat);
auto sizes = computed_style.property(CSS::PropertyID::BackgroundSize);
auto count_layers = [](auto maybe_style_value) -> size_t {
if (maybe_style_value.has_value() && maybe_style_value.value()->is_value_list())
@ -361,173 +361,173 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
computed_values.set_background_layers(move(layers));
}
computed_values.set_background_color(specified_style.color_or_fallback(CSS::PropertyID::BackgroundColor, *this, CSS::InitialValues::background_color()));
computed_values.set_background_color(computed_style.color_or_fallback(CSS::PropertyID::BackgroundColor, *this, CSS::InitialValues::background_color()));
computed_values.set_box_sizing(specified_style.box_sizing());
computed_values.set_box_sizing(computed_style.box_sizing());
if (auto maybe_font_variant = specified_style.font_variant(); maybe_font_variant.has_value())
if (auto maybe_font_variant = computed_style.font_variant(); maybe_font_variant.has_value())
computed_values.set_font_variant(maybe_font_variant.release_value());
// FIXME: BorderXRadius properties are now BorderRadiusStyleValues, so make use of that.
auto border_bottom_left_radius = specified_style.property(CSS::PropertyID::BorderBottomLeftRadius);
auto border_bottom_left_radius = computed_style.property(CSS::PropertyID::BorderBottomLeftRadius);
if (border_bottom_left_radius.has_value() && border_bottom_left_radius.value()->is_border_radius())
computed_values.set_border_bottom_left_radius(border_bottom_left_radius.value()->as_border_radius().horizontal_radius());
auto border_bottom_right_radius = specified_style.property(CSS::PropertyID::BorderBottomRightRadius);
auto border_bottom_right_radius = computed_style.property(CSS::PropertyID::BorderBottomRightRadius);
if (border_bottom_right_radius.has_value() && border_bottom_right_radius.value()->is_border_radius())
computed_values.set_border_bottom_right_radius(border_bottom_right_radius.value()->as_border_radius().horizontal_radius());
auto border_top_left_radius = specified_style.property(CSS::PropertyID::BorderTopLeftRadius);
auto border_top_left_radius = computed_style.property(CSS::PropertyID::BorderTopLeftRadius);
if (border_top_left_radius.has_value() && border_top_left_radius.value()->is_border_radius())
computed_values.set_border_top_left_radius(border_top_left_radius.value()->as_border_radius().horizontal_radius());
auto border_top_right_radius = specified_style.property(CSS::PropertyID::BorderTopRightRadius);
auto border_top_right_radius = computed_style.property(CSS::PropertyID::BorderTopRightRadius);
if (border_top_right_radius.has_value() && border_top_right_radius.value()->is_border_radius())
computed_values.set_border_top_right_radius(border_top_right_radius.value()->as_border_radius().horizontal_radius());
computed_values.set_display(specified_style.display());
computed_values.set_display(computed_style.display());
auto flex_direction = specified_style.flex_direction();
auto flex_direction = computed_style.flex_direction();
if (flex_direction.has_value())
computed_values.set_flex_direction(flex_direction.value());
auto flex_wrap = specified_style.flex_wrap();
auto flex_wrap = computed_style.flex_wrap();
if (flex_wrap.has_value())
computed_values.set_flex_wrap(flex_wrap.value());
auto flex_basis = specified_style.flex_basis();
auto flex_basis = computed_style.flex_basis();
if (flex_basis.has_value())
computed_values.set_flex_basis(flex_basis.value());
computed_values.set_flex_grow(specified_style.flex_grow());
computed_values.set_flex_shrink(specified_style.flex_shrink());
computed_values.set_flex_grow(computed_style.flex_grow());
computed_values.set_flex_shrink(computed_style.flex_shrink());
auto justify_content = specified_style.justify_content();
auto justify_content = computed_style.justify_content();
if (justify_content.has_value())
computed_values.set_justify_content(justify_content.value());
auto align_items = specified_style.align_items();
auto align_items = computed_style.align_items();
if (align_items.has_value())
computed_values.set_align_items(align_items.value());
auto position = specified_style.position();
auto position = computed_style.position();
if (position.has_value())
computed_values.set_position(position.value());
auto text_align = specified_style.text_align();
auto text_align = computed_style.text_align();
if (text_align.has_value())
computed_values.set_text_align(text_align.value());
auto text_justify = specified_style.text_justify();
auto text_justify = computed_style.text_justify();
if (text_align.has_value())
computed_values.set_text_justify(text_justify.value());
auto white_space = specified_style.white_space();
auto white_space = computed_style.white_space();
if (white_space.has_value())
computed_values.set_white_space(white_space.value());
auto float_ = specified_style.float_();
auto float_ = computed_style.float_();
if (float_.has_value())
computed_values.set_float(float_.value());
auto clear = specified_style.clear();
auto clear = computed_style.clear();
if (clear.has_value())
computed_values.set_clear(clear.value());
auto overflow_x = specified_style.overflow_x();
auto overflow_x = computed_style.overflow_x();
if (overflow_x.has_value())
computed_values.set_overflow_x(overflow_x.value());
auto overflow_y = specified_style.overflow_y();
auto overflow_y = computed_style.overflow_y();
if (overflow_y.has_value())
computed_values.set_overflow_y(overflow_y.value());
auto cursor = specified_style.cursor();
auto cursor = computed_style.cursor();
if (cursor.has_value())
computed_values.set_cursor(cursor.value());
auto image_rendering = specified_style.image_rendering();
auto image_rendering = computed_style.image_rendering();
if (image_rendering.has_value())
computed_values.set_image_rendering(image_rendering.value());
auto pointer_events = specified_style.pointer_events();
auto pointer_events = computed_style.pointer_events();
if (pointer_events.has_value())
computed_values.set_pointer_events(pointer_events.value());
auto text_decoration_line = specified_style.text_decoration_line();
auto text_decoration_line = computed_style.text_decoration_line();
if (text_decoration_line.has_value())
computed_values.set_text_decoration_line(text_decoration_line.value());
auto text_decoration_style = specified_style.text_decoration_style();
auto text_decoration_style = computed_style.text_decoration_style();
if (text_decoration_style.has_value())
computed_values.set_text_decoration_style(text_decoration_style.value());
auto text_transform = specified_style.text_transform();
auto text_transform = computed_style.text_transform();
if (text_transform.has_value())
computed_values.set_text_transform(text_transform.value());
if (auto list_style_type = specified_style.list_style_type(); list_style_type.has_value())
if (auto list_style_type = computed_style.list_style_type(); list_style_type.has_value())
computed_values.set_list_style_type(list_style_type.value());
auto list_style_image = specified_style.property(CSS::PropertyID::ListStyleImage);
auto list_style_image = computed_style.property(CSS::PropertyID::ListStyleImage);
if (list_style_image.has_value() && list_style_image.value()->is_image()) {
m_list_style_image = list_style_image.value()->as_image();
m_list_style_image->load_bitmap(document());
}
computed_values.set_color(specified_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
computed_values.set_color(computed_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
// FIXME: The default text decoration color value is `currentcolor`, but since we can't resolve that easily,
// we just manually grab the value from `color`. This makes it dependent on `color` being
// specified first, so it's far from ideal.
computed_values.set_text_decoration_color(specified_style.color_or_fallback(CSS::PropertyID::TextDecorationColor, *this, computed_values.color()));
if (auto maybe_text_decoration_thickness = specified_style.length_percentage(CSS::PropertyID::TextDecorationThickness); maybe_text_decoration_thickness.has_value())
computed_values.set_text_decoration_color(computed_style.color_or_fallback(CSS::PropertyID::TextDecorationColor, *this, computed_values.color()));
if (auto maybe_text_decoration_thickness = computed_style.length_percentage(CSS::PropertyID::TextDecorationThickness); maybe_text_decoration_thickness.has_value())
computed_values.set_text_decoration_thickness(maybe_text_decoration_thickness.release_value());
computed_values.set_text_shadow(specified_style.text_shadow());
computed_values.set_text_shadow(computed_style.text_shadow());
computed_values.set_z_index(specified_style.z_index());
computed_values.set_opacity(specified_style.opacity());
computed_values.set_z_index(computed_style.z_index());
computed_values.set_opacity(computed_style.opacity());
if (auto maybe_visibility = specified_style.visibility(); maybe_visibility.has_value())
if (auto maybe_visibility = computed_style.visibility(); maybe_visibility.has_value())
computed_values.set_visibility(maybe_visibility.release_value());
if (computed_values.opacity() == 0 || computed_values.visibility() != CSS::Visibility::Visible)
m_visible = false;
if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::Width); maybe_length_percentage.has_value())
if (auto maybe_length_percentage = computed_style.length_percentage(CSS::PropertyID::Width); maybe_length_percentage.has_value())
computed_values.set_width(maybe_length_percentage.release_value());
if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::MinWidth); maybe_length_percentage.has_value())
if (auto maybe_length_percentage = computed_style.length_percentage(CSS::PropertyID::MinWidth); maybe_length_percentage.has_value())
computed_values.set_min_width(maybe_length_percentage.release_value());
if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::MaxWidth); maybe_length_percentage.has_value())
if (auto maybe_length_percentage = computed_style.length_percentage(CSS::PropertyID::MaxWidth); maybe_length_percentage.has_value())
computed_values.set_max_width(maybe_length_percentage.release_value());
if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::Height); maybe_length_percentage.has_value())
if (auto maybe_length_percentage = computed_style.length_percentage(CSS::PropertyID::Height); maybe_length_percentage.has_value())
computed_values.set_height(maybe_length_percentage.release_value());
if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::MinHeight); maybe_length_percentage.has_value())
if (auto maybe_length_percentage = computed_style.length_percentage(CSS::PropertyID::MinHeight); maybe_length_percentage.has_value())
computed_values.set_min_height(maybe_length_percentage.release_value());
if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::MaxHeight); maybe_length_percentage.has_value())
if (auto maybe_length_percentage = computed_style.length_percentage(CSS::PropertyID::MaxHeight); maybe_length_percentage.has_value())
computed_values.set_max_height(maybe_length_percentage.release_value());
computed_values.set_offset(specified_style.length_box(CSS::PropertyID::Left, CSS::PropertyID::Top, CSS::PropertyID::Right, CSS::PropertyID::Bottom, CSS::Length::make_auto()));
computed_values.set_margin(specified_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom, CSS::Length::make_px(0)));
computed_values.set_padding(specified_style.length_box(CSS::PropertyID::PaddingLeft, CSS::PropertyID::PaddingTop, CSS::PropertyID::PaddingRight, CSS::PropertyID::PaddingBottom, CSS::Length::make_px(0)));
computed_values.set_offset(computed_style.length_box(CSS::PropertyID::Left, CSS::PropertyID::Top, CSS::PropertyID::Right, CSS::PropertyID::Bottom, CSS::Length::make_auto()));
computed_values.set_margin(computed_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom, CSS::Length::make_px(0)));
computed_values.set_padding(computed_style.length_box(CSS::PropertyID::PaddingLeft, CSS::PropertyID::PaddingTop, CSS::PropertyID::PaddingRight, CSS::PropertyID::PaddingBottom, CSS::Length::make_px(0)));
computed_values.set_box_shadow(specified_style.box_shadow());
computed_values.set_box_shadow(computed_style.box_shadow());
computed_values.set_transformations(specified_style.transformations());
computed_values.set_transform_origin(specified_style.transform_origin());
computed_values.set_transformations(computed_style.transformations());
computed_values.set_transform_origin(computed_style.transform_origin());
auto do_border_style = [&](CSS::BorderData& border, CSS::PropertyID width_property, CSS::PropertyID color_property, CSS::PropertyID style_property) {
// FIXME: The default border color value is `currentcolor`, but since we can't resolve that easily,
// we just manually grab the value from `color`. This makes it dependent on `color` being
// specified first, so it's far from ideal.
border.color = specified_style.color_or_fallback(color_property, *this, computed_values.color());
border.line_style = specified_style.line_style(style_property).value_or(CSS::LineStyle::None);
border.color = computed_style.color_or_fallback(color_property, *this, computed_values.color());
border.line_style = computed_style.line_style(style_property).value_or(CSS::LineStyle::None);
if (border.line_style == CSS::LineStyle::None)
border.width = 0;
else
border.width = specified_style.length_or_fallback(width_property, CSS::Length::make_px(0)).to_px(*this);
border.width = computed_style.length_or_fallback(width_property, CSS::Length::make_px(0)).to_px(*this);
};
do_border_style(computed_values.border_left(), CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor, CSS::PropertyID::BorderLeftStyle);
@ -535,13 +535,13 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
do_border_style(computed_values.border_right(), CSS::PropertyID::BorderRightWidth, CSS::PropertyID::BorderRightColor, CSS::PropertyID::BorderRightStyle);
do_border_style(computed_values.border_bottom(), CSS::PropertyID::BorderBottomWidth, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomStyle);
computed_values.set_content(specified_style.content());
computed_values.set_content(computed_style.content());
if (auto fill = specified_style.property(CSS::PropertyID::Fill); fill.has_value())
if (auto fill = computed_style.property(CSS::PropertyID::Fill); fill.has_value())
computed_values.set_fill(fill.value()->to_color(*this));
if (auto stroke = specified_style.property(CSS::PropertyID::Stroke); stroke.has_value())
if (auto stroke = computed_style.property(CSS::PropertyID::Stroke); stroke.has_value())
computed_values.set_stroke(stroke.value()->to_color(*this));
if (auto stroke_width = specified_style.property(CSS::PropertyID::StrokeWidth); stroke_width.has_value()) {
if (auto stroke_width = computed_style.property(CSS::PropertyID::StrokeWidth); stroke_width.has_value()) {
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
if (stroke_width.value()->is_numeric())