diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-03-21 14:34:02 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-21 21:04:39 +0100 |
commit | 57296393eda84e866a26c1ce85be1e9fc5fbf731 (patch) | |
tree | 28bc97fd9d77ee5a84a66b8e40c302d8565f77d9 /Userland/Libraries/LibWeb/SVG | |
parent | 7a6b4e33bae79182e9d9a9951b1714985d449765 (diff) | |
download | serenity-57296393eda84e866a26c1ce85be1e9fc5fbf731.zip |
LibWeb: Begin implementing SVGRectElement's SVGAnimatedLength attributes
Diffstat (limited to 'Userland/Libraries/LibWeb/SVG')
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp | 62 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGRectElement.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGRectElement.idl | 13 |
3 files changed, 76 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp index 3822a66689..eeefaac8a8 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp @@ -7,6 +7,8 @@ #include "SVGRectElement.h" #include <LibWeb/SVG/AttributeNames.h> #include <LibWeb/SVG/AttributeParser.h> +#include <LibWeb/SVG/SVGAnimatedLength.h> +#include <LibWeb/SVG/SVGLength.h> namespace Web::SVG { @@ -150,4 +152,64 @@ Gfx::FloatPoint SVGRectElement::calculate_used_corner_radius_values() return Gfx::FloatPoint { rx, ry }; } +// https://www.w3.org/TR/SVG11/shapes.html#RectElementXAttribute +NonnullRefPtr<SVGAnimatedLength> SVGRectElement::x() const +{ + // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). + // FIXME: Create a proper animated value when animations are supported. + auto base_length = SVGLength::create(0, m_x.value_or(0)); + auto anim_length = SVGLength::create(0, m_x.value_or(0)); + return SVGAnimatedLength::create(move(base_length), move(anim_length)); +} + +// https://www.w3.org/TR/SVG11/shapes.html#RectElementYAttribute +NonnullRefPtr<SVGAnimatedLength> SVGRectElement::y() const +{ + // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). + // FIXME: Create a proper animated value when animations are supported. + auto base_length = SVGLength::create(0, m_y.value_or(0)); + auto anim_length = SVGLength::create(0, m_y.value_or(0)); + return SVGAnimatedLength::create(move(base_length), move(anim_length)); +} + +// https://www.w3.org/TR/SVG11/shapes.html#RectElementWidthAttribute +NonnullRefPtr<SVGAnimatedLength> SVGRectElement::width() const +{ + // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). + // FIXME: Create a proper animated value when animations are supported. + auto base_length = SVGLength::create(0, m_width.value_or(0)); + auto anim_length = SVGLength::create(0, m_width.value_or(0)); + return SVGAnimatedLength::create(move(base_length), move(anim_length)); +} + +// https://www.w3.org/TR/SVG11/shapes.html#RectElementHeightAttribute +NonnullRefPtr<SVGAnimatedLength> SVGRectElement::height() const +{ + // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). + // FIXME: Create a proper animated value when animations are supported. + auto base_length = SVGLength::create(0, m_height.value_or(0)); + auto anim_length = SVGLength::create(0, m_height.value_or(0)); + return SVGAnimatedLength::create(move(base_length), move(anim_length)); +} + +// https://www.w3.org/TR/SVG11/shapes.html#RectElementRXAttribute +NonnullRefPtr<SVGAnimatedLength> SVGRectElement::rx() const +{ + // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). + // FIXME: Create a proper animated value when animations are supported. + auto base_length = SVGLength::create(0, m_radius_x.value_or(0)); + auto anim_length = SVGLength::create(0, m_radius_x.value_or(0)); + return SVGAnimatedLength::create(move(base_length), move(anim_length)); +} + +// https://www.w3.org/TR/SVG11/shapes.html#RectElementRYAttribute +NonnullRefPtr<SVGAnimatedLength> SVGRectElement::ry() const +{ + // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). + // FIXME: Create a proper animated value when animations are supported. + auto base_length = SVGLength::create(0, m_radius_y.value_or(0)); + auto anim_length = SVGLength::create(0, m_radius_y.value_or(0)); + return SVGAnimatedLength::create(move(base_length), move(anim_length)); +} + } diff --git a/Userland/Libraries/LibWeb/SVG/SVGRectElement.h b/Userland/Libraries/LibWeb/SVG/SVGRectElement.h index e180deca57..22f6726b7f 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGRectElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGRectElement.h @@ -22,6 +22,13 @@ public: virtual Gfx::Path& get_path() override; + NonnullRefPtr<SVGAnimatedLength> x() const; + NonnullRefPtr<SVGAnimatedLength> y() const; + NonnullRefPtr<SVGAnimatedLength> width() const; + NonnullRefPtr<SVGAnimatedLength> height() const; + NonnullRefPtr<SVGAnimatedLength> rx() const; + NonnullRefPtr<SVGAnimatedLength> ry() const; + private: Gfx::FloatPoint calculate_used_corner_radius_values(); diff --git a/Userland/Libraries/LibWeb/SVG/SVGRectElement.idl b/Userland/Libraries/LibWeb/SVG/SVGRectElement.idl index 801742b95d..be89d154fd 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGRectElement.idl +++ b/Userland/Libraries/LibWeb/SVG/SVGRectElement.idl @@ -1,11 +1,12 @@ +#import <SVG/SVGAnimatedLength.idl> #import <SVG/SVGGeometryElement.idl> [Exposed=Window] interface SVGRectElement : SVGGeometryElement { - // [SameObject] readonly attribute SVGAnimatedLength x; - // [SameObject] readonly attribute SVGAnimatedLength y; - // [SameObject] readonly attribute SVGAnimatedLength width; - // [SameObject] readonly attribute SVGAnimatedLength height; - // [SameObject] readonly attribute SVGAnimatedLength rx; - // [SameObject] readonly attribute SVGAnimatedLength ry; + [SameObject] readonly attribute SVGAnimatedLength x; + [SameObject] readonly attribute SVGAnimatedLength y; + [SameObject] readonly attribute SVGAnimatedLength width; + [SameObject] readonly attribute SVGAnimatedLength height; + [SameObject] readonly attribute SVGAnimatedLength rx; + [SameObject] readonly attribute SVGAnimatedLength ry; }; |