Skip to content

Commit

Permalink
LibWeb: Setup computed values for SVG geometry properties
Browse files Browse the repository at this point in the history
  • Loading branch information
MacDue authored and awesomekling committed Mar 4, 2024
1 parent b9afea4 commit 4f78ddd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Userland/Libraries/LibWeb/CSS/ComputedValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ class InitialValues {
static CSS::TableLayout table_layout() { return CSS::TableLayout::Auto; }
static QuotesData quotes() { return QuotesData { .type = QuotesData::Type::Auto }; }
static CSS::TransformBox transform_box() { return CSS::TransformBox::ViewBox; }

// https://www.w3.org/TR/SVG/geometry.html
static LengthPercentage cx() { return CSS::Length::make_px(0); }
static LengthPercentage cy() { return CSS::Length::make_px(0); }
static LengthPercentage r() { return CSS::Length::make_px(0); }
static LengthPercentage rx() { return CSS::Length::make_auto(); }
static LengthPercentage ry() { return CSS::Length::make_auto(); }
static LengthPercentage x() { return CSS::Length::make_px(0); }
static LengthPercentage y() { return CSS::Length::make_px(0); }

Expand Down Expand Up @@ -407,6 +414,12 @@ class ComputedValues {
CSS::TextAnchor text_anchor() const { return m_inherited.text_anchor; }
Optional<MaskReference> const& mask() const { return m_noninherited.mask; }
CSS::MaskType mask_type() const { return m_noninherited.mask_type; }

LengthPercentage const& cx() const { return m_noninherited.cx; }
LengthPercentage const& cy() const { return m_noninherited.cy; }
LengthPercentage const& r() const { return m_noninherited.r; }
LengthPercentage const& rx() const { return m_noninherited.ry; }
LengthPercentage const& ry() const { return m_noninherited.ry; }
LengthPercentage const& x() const { return m_noninherited.x; }
LengthPercentage const& y() const { return m_noninherited.y; }

Expand Down Expand Up @@ -566,6 +579,12 @@ class ComputedValues {

Optional<MaskReference> mask;
CSS::MaskType mask_type { InitialValues::mask_type() };

LengthPercentage cx { InitialValues::cx() };
LengthPercentage cy { InitialValues::cy() };
LengthPercentage r { InitialValues::r() };
LengthPercentage rx { InitialValues::rx() };
LengthPercentage ry { InitialValues::ry() };
LengthPercentage x { InitialValues::x() };
LengthPercentage y { InitialValues::x() };

Expand Down Expand Up @@ -694,6 +713,12 @@ class MutableComputedValues final : public ComputedValues {
void set_outline_width(CSS::Length value) { m_noninherited.outline_width = value; }
void set_mask(MaskReference value) { m_noninherited.mask = value; }
void set_mask_type(CSS::MaskType value) { m_noninherited.mask_type = value; }

void set_cx(LengthPercentage cx) { m_noninherited.cx = cx; }
void set_cy(LengthPercentage cy) { m_noninherited.cy = cy; }
void set_r(LengthPercentage r) { m_noninherited.r = r; }
void set_rx(LengthPercentage rx) { m_noninherited.rx = rx; }
void set_ry(LengthPercentage ry) { m_noninherited.ry = ry; }
void set_x(LengthPercentage x) { m_noninherited.x = x; }
void set_y(LengthPercentage y) { m_noninherited.y = y; }

Expand Down
11 changes: 11 additions & 0 deletions Userland/Libraries/LibWeb/Layout/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,21 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
computed_values.set_grid_template_areas(computed_style.grid_template_areas());
computed_values.set_grid_auto_flow(computed_style.grid_auto_flow());

if (auto cx_value = computed_style.length_percentage(CSS::PropertyID::Cx); cx_value.has_value())
computed_values.set_cx(*cx_value);
if (auto cy_value = computed_style.length_percentage(CSS::PropertyID::Cy); cy_value.has_value())
computed_values.set_cy(*cy_value);
if (auto r_value = computed_style.length_percentage(CSS::PropertyID::R); r_value.has_value())
computed_values.set_r(*r_value);
if (auto rx_value = computed_style.length_percentage(CSS::PropertyID::Rx); rx_value.has_value())
computed_values.set_rx(*rx_value);
if (auto ry_value = computed_style.length_percentage(CSS::PropertyID::Ry); ry_value.has_value())
computed_values.set_ry(*ry_value);
if (auto x_value = computed_style.length_percentage(CSS::PropertyID::X); x_value.has_value())
computed_values.set_x(*x_value);
if (auto y_value = computed_style.length_percentage(CSS::PropertyID::Y); y_value.has_value())
computed_values.set_y(*y_value);

auto fill = computed_style.property(CSS::PropertyID::Fill);
if (fill->has_color())
computed_values.set_fill(fill->to_color(*this));
Expand Down

0 comments on commit 4f78ddd

Please sign in to comment.