mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibWeb: Support legacy xlink:href attribute for linked gradients
...and rename the related functions to something more descriptive.
This commit is contained in:
parent
cc8c4266f5
commit
439735fd35
6 changed files with 37 additions and 35 deletions
|
@ -35,8 +35,8 @@ GradientUnits SVGGradientElement::gradient_units() const
|
||||||
{
|
{
|
||||||
if (m_gradient_units.has_value())
|
if (m_gradient_units.has_value())
|
||||||
return *m_gradient_units;
|
return *m_gradient_units;
|
||||||
if (auto href = xlink_href())
|
if (auto gradient = linked_gradient())
|
||||||
return href->gradient_units();
|
return gradient->gradient_units();
|
||||||
return GradientUnits::ObjectBoundingBox;
|
return GradientUnits::ObjectBoundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ Optional<Gfx::AffineTransform> SVGGradientElement::gradient_transform() const
|
||||||
{
|
{
|
||||||
if (m_gradient_transform.has_value())
|
if (m_gradient_transform.has_value())
|
||||||
return m_gradient_transform;
|
return m_gradient_transform;
|
||||||
if (auto href = xlink_href())
|
if (auto gradient = linked_gradient())
|
||||||
return href->gradient_transform();
|
return gradient->gradient_transform();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,11 +78,13 @@ void SVGGradientElement::add_color_stops(Gfx::SVGGradientPaintStyle& paint_style
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::GCPtr<SVGGradientElement const> SVGGradientElement::xlink_href() const
|
JS::GCPtr<SVGGradientElement const> SVGGradientElement::linked_gradient() const
|
||||||
{
|
{
|
||||||
// FIXME: This entire function is an ad-hoc hack!
|
// FIXME: This entire function is an ad-hoc hack!
|
||||||
// It can only resolve #<ids> in the same document.
|
// It can only resolve #<ids> in the same document.
|
||||||
if (auto href = get_attribute("href"); !href.is_empty()) {
|
|
||||||
|
auto link = has_attribute("href") ? get_attribute("href") : get_attribute("xlink:href");
|
||||||
|
if (auto href = link; !href.is_empty()) {
|
||||||
auto url = document().parse_url(href);
|
auto url = document().parse_url(href);
|
||||||
auto id = url.fragment();
|
auto id = url.fragment();
|
||||||
if (id.is_empty())
|
if (id.is_empty())
|
||||||
|
|
|
@ -39,7 +39,7 @@ protected:
|
||||||
|
|
||||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||||
|
|
||||||
JS::GCPtr<SVGGradientElement const> xlink_href() const;
|
JS::GCPtr<SVGGradientElement const> linked_gradient() const;
|
||||||
|
|
||||||
Gfx::AffineTransform gradient_paint_transform(SVGPaintContext const&) const;
|
Gfx::AffineTransform gradient_paint_transform(SVGPaintContext const&) const;
|
||||||
|
|
||||||
|
@ -52,8 +52,8 @@ protected:
|
||||||
callback(stop);
|
callback(stop);
|
||||||
});
|
});
|
||||||
if (!color_stops_found) {
|
if (!color_stops_found) {
|
||||||
if (auto href = xlink_href())
|
if (auto gradient = linked_gradient())
|
||||||
href->for_each_color_stop(callback);
|
gradient->for_each_color_stop(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,8 @@ NumberPercentage SVGLinearGradientElement::start_x() const
|
||||||
{
|
{
|
||||||
if (m_x1.has_value())
|
if (m_x1.has_value())
|
||||||
return *m_x1;
|
return *m_x1;
|
||||||
if (auto href = linear_gradient_xlink_href())
|
if (auto gradient = linked_linear_gradient())
|
||||||
return href->start_x();
|
return gradient->start_x();
|
||||||
// If the attribute is not specified, the effect is as if a value of '0%' were specified.
|
// If the attribute is not specified, the effect is as if a value of '0%' were specified.
|
||||||
return NumberPercentage::create_percentage(0);
|
return NumberPercentage::create_percentage(0);
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,8 @@ NumberPercentage SVGLinearGradientElement::start_y() const
|
||||||
{
|
{
|
||||||
if (m_y1.has_value())
|
if (m_y1.has_value())
|
||||||
return *m_y1;
|
return *m_y1;
|
||||||
if (auto href = linear_gradient_xlink_href())
|
if (auto gradient = linked_linear_gradient())
|
||||||
return href->start_x();
|
return gradient->start_x();
|
||||||
// If the attribute is not specified, the effect is as if a value of '0%' were specified.
|
// If the attribute is not specified, the effect is as if a value of '0%' were specified.
|
||||||
return NumberPercentage::create_percentage(0);
|
return NumberPercentage::create_percentage(0);
|
||||||
}
|
}
|
||||||
|
@ -73,8 +73,8 @@ NumberPercentage SVGLinearGradientElement::end_x() const
|
||||||
{
|
{
|
||||||
if (m_x2.has_value())
|
if (m_x2.has_value())
|
||||||
return *m_x2;
|
return *m_x2;
|
||||||
if (auto href = linear_gradient_xlink_href())
|
if (auto gradient = linked_linear_gradient())
|
||||||
return href->start_x();
|
return gradient->start_x();
|
||||||
// If the attribute is not specified, the effect is as if a value of '100%' were specified.
|
// If the attribute is not specified, the effect is as if a value of '100%' were specified.
|
||||||
return NumberPercentage::create_percentage(100);
|
return NumberPercentage::create_percentage(100);
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,8 @@ NumberPercentage SVGLinearGradientElement::end_y() const
|
||||||
{
|
{
|
||||||
if (m_y2.has_value())
|
if (m_y2.has_value())
|
||||||
return *m_y2;
|
return *m_y2;
|
||||||
if (auto href = linear_gradient_xlink_href())
|
if (auto gradient = linked_linear_gradient())
|
||||||
return href->start_x();
|
return gradient->start_x();
|
||||||
// If the attribute is not specified, the effect is as if a value of '0%' were specified.
|
// If the attribute is not specified, the effect is as if a value of '0%' were specified.
|
||||||
return NumberPercentage::create_percentage(0);
|
return NumberPercentage::create_percentage(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,10 @@ protected:
|
||||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS::GCPtr<SVGLinearGradientElement const> linear_gradient_xlink_href() const
|
JS::GCPtr<SVGLinearGradientElement const> linked_linear_gradient() const
|
||||||
{
|
{
|
||||||
if (auto href = xlink_href(); href && is<SVGLinearGradientElement>(*href))
|
if (auto gradient = linked_gradient(); gradient && is<SVGLinearGradientElement>(*gradient))
|
||||||
return &verify_cast<SVGLinearGradientElement>(*href);
|
return &verify_cast<SVGLinearGradientElement>(*gradient);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,8 @@ NumberPercentage SVGRadialGradientElement::start_circle_x() const
|
||||||
return *m_fx;
|
return *m_fx;
|
||||||
// If the element references an element that specifies a value for 'fx', then the value of 'fx' is
|
// If the element references an element that specifies a value for 'fx', then the value of 'fx' is
|
||||||
// inherited from the referenced element.
|
// inherited from the referenced element.
|
||||||
if (auto href = radial_gradient_xlink_href())
|
if (auto gradient = linked_radial_gradient())
|
||||||
return href->start_circle_x();
|
return gradient->start_circle_x();
|
||||||
// If attribute ‘fx’ is not specified, ‘fx’ will coincide with the presentational value of ‘cx’ for
|
// If attribute ‘fx’ is not specified, ‘fx’ will coincide with the presentational value of ‘cx’ for
|
||||||
// the element whether the value for 'cx' was inherited or not.
|
// the element whether the value for 'cx' was inherited or not.
|
||||||
return end_circle_x();
|
return end_circle_x();
|
||||||
|
@ -71,8 +71,8 @@ NumberPercentage SVGRadialGradientElement::start_circle_y() const
|
||||||
return *m_fy;
|
return *m_fy;
|
||||||
// If the element references an element that specifies a value for 'fy', then the value of 'fy' is
|
// If the element references an element that specifies a value for 'fy', then the value of 'fy' is
|
||||||
// inherited from the referenced element.
|
// inherited from the referenced element.
|
||||||
if (auto href = radial_gradient_xlink_href())
|
if (auto gradient = linked_radial_gradient())
|
||||||
return href->start_circle_y();
|
return gradient->start_circle_y();
|
||||||
// If attribute ‘fy’ is not specified, ‘fy’ will coincide with the presentational value of ‘cy’ for
|
// If attribute ‘fy’ is not specified, ‘fy’ will coincide with the presentational value of ‘cy’ for
|
||||||
// the element whether the value for 'cy' was inherited or not.
|
// the element whether the value for 'cy' was inherited or not.
|
||||||
return end_circle_y();
|
return end_circle_y();
|
||||||
|
@ -86,8 +86,8 @@ NumberPercentage SVGRadialGradientElement::start_circle_radius() const
|
||||||
return *m_fr;
|
return *m_fr;
|
||||||
// if the element references an element that specifies a value for 'fr', then the value of
|
// if the element references an element that specifies a value for 'fr', then the value of
|
||||||
// 'fr' is inherited from the referenced element.
|
// 'fr' is inherited from the referenced element.
|
||||||
if (auto href = radial_gradient_xlink_href())
|
if (auto gradient = linked_radial_gradient())
|
||||||
return href->start_circle_radius();
|
return gradient->start_circle_radius();
|
||||||
// If the attribute is not specified, the effect is as if a value of '0%' were specified.
|
// If the attribute is not specified, the effect is as if a value of '0%' were specified.
|
||||||
return NumberPercentage::create_percentage(0);
|
return NumberPercentage::create_percentage(0);
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,8 @@ NumberPercentage SVGRadialGradientElement::end_circle_x() const
|
||||||
{
|
{
|
||||||
if (m_cx.has_value())
|
if (m_cx.has_value())
|
||||||
return *m_cx;
|
return *m_cx;
|
||||||
if (auto href = radial_gradient_xlink_href())
|
if (auto gradient = linked_radial_gradient())
|
||||||
return href->end_circle_x();
|
return gradient->end_circle_x();
|
||||||
return NumberPercentage::create_percentage(50);
|
return NumberPercentage::create_percentage(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ NumberPercentage SVGRadialGradientElement::end_circle_y() const
|
||||||
{
|
{
|
||||||
if (m_cy.has_value())
|
if (m_cy.has_value())
|
||||||
return *m_cy;
|
return *m_cy;
|
||||||
if (auto href = radial_gradient_xlink_href())
|
if (auto gradient = linked_radial_gradient())
|
||||||
return href->end_circle_y();
|
return gradient->end_circle_y();
|
||||||
return NumberPercentage::create_percentage(50);
|
return NumberPercentage::create_percentage(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ NumberPercentage SVGRadialGradientElement::end_circle_radius() const
|
||||||
// Note: A negative value is an error.
|
// Note: A negative value is an error.
|
||||||
if (m_r.has_value() && m_r->value() >= 0)
|
if (m_r.has_value() && m_r->value() >= 0)
|
||||||
return *m_r;
|
return *m_r;
|
||||||
if (auto href = radial_gradient_xlink_href())
|
if (auto gradient = linked_radial_gradient())
|
||||||
return href->end_circle_radius();
|
return gradient->end_circle_radius();
|
||||||
return NumberPercentage::create_percentage(50);
|
return NumberPercentage::create_percentage(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,10 @@ protected:
|
||||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS::GCPtr<SVGRadialGradientElement const> radial_gradient_xlink_href() const
|
JS::GCPtr<SVGRadialGradientElement const> linked_radial_gradient() const
|
||||||
{
|
{
|
||||||
if (auto href = xlink_href(); href && is<SVGRadialGradientElement>(*href))
|
if (auto gradient = linked_gradient(); gradient && is<SVGRadialGradientElement>(*gradient))
|
||||||
return &verify_cast<SVGRadialGradientElement>(*href);
|
return &verify_cast<SVGRadialGradientElement>(*gradient);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue