Skip to content

Commit

Permalink
LibWeb/SVG: Implement SVGAnimatedInteger type
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed May 8, 2024
1 parent 53314b1 commit 2970ac9
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions Meta/gn/secondary/Userland/Libraries/LibWeb/SVG/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source_set("SVG") {
"AttributeParser.cpp",
"SVGAnimatedBoolean.cpp",
"SVGAnimatedEnumeration.cpp",
"SVGAnimatedInteger.cpp",
"SVGAnimatedLength.cpp",
"SVGAnimatedNumber.cpp",
"SVGAnimatedRect.cpp",
Expand Down
1 change: 1 addition & 0 deletions Meta/gn/secondary/Userland/Libraries/LibWeb/idl_files.gni
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ standard_idl_files = [
"//Userland/Libraries/LibWeb/Streams/WritableStreamDefaultWriter.idl",
"//Userland/Libraries/LibWeb/SVG/SVGAnimatedBoolean.idl",
"//Userland/Libraries/LibWeb/SVG/SVGAnimatedEnumeration.idl",
"//Userland/Libraries/LibWeb/SVG/SVGAnimatedInteger.idl",
"//Userland/Libraries/LibWeb/SVG/SVGAnimatedLength.idl",
"//Userland/Libraries/LibWeb/SVG/SVGAnimatedNumber.idl",
"//Userland/Libraries/LibWeb/SVG/SVGAnimatedRect.idl",
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ set(SOURCES
SVG/AttributeParser.cpp
SVG/SVGAnimatedBoolean.cpp
SVG/SVGAnimatedEnumeration.cpp
SVG/SVGAnimatedInteger.cpp
SVG/SVGAnimatedLength.cpp
SVG/SVGAnimatedNumber.cpp
SVG/SVGAnimatedRect.cpp
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ struct UnderlyingSource;
namespace Web::SVG {
class SVGAnimatedBoolean;
class SVGAnimatedEnumeration;
class SVGAnimatedInteger;
class SVGAnimatedLength;
class SVGAnimatedRect;
class SVGCircleElement;
Expand Down
35 changes: 35 additions & 0 deletions Userland/Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/SVGAnimatedIntegerPrototype.h>
#include <LibWeb/SVG/SVGAnimatedInteger.h>

namespace Web::SVG {

JS_DEFINE_ALLOCATOR(SVGAnimatedInteger);

JS::NonnullGCPtr<SVGAnimatedInteger> SVGAnimatedInteger::create(JS::Realm& realm, u32 base_val, u32 anim_val)
{
return realm.heap().allocate<SVGAnimatedInteger>(realm, realm, base_val, anim_val);
}

SVGAnimatedInteger::SVGAnimatedInteger(JS::Realm& realm, u32 base_val, u32 anim_val)
: PlatformObject(realm)
, m_base_val(base_val)
, m_anim_val(anim_val)
{
}

SVGAnimatedInteger::~SVGAnimatedInteger() = default;

void SVGAnimatedInteger::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGAnimatedInteger);
}

}
36 changes: 36 additions & 0 deletions Userland/Libraries/LibWeb/SVG/SVGAnimatedInteger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibWeb/Bindings/PlatformObject.h>

namespace Web::SVG {

// https://svgwg.org/svg2-draft/types.html#InterfaceSVGAnimatedInteger
class SVGAnimatedInteger final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(SVGAnimatedInteger, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(SVGAnimatedInteger);

public:
[[nodiscard]] static JS::NonnullGCPtr<SVGAnimatedInteger> create(JS::Realm&, u32 base_val, u32 anim_val);
virtual ~SVGAnimatedInteger() override;

u32 base_val() const { return m_base_val; }
u32 anim_val() const { return m_anim_val; }

void set_base_val(u32 base_val) { m_base_val = base_val; }

private:
SVGAnimatedInteger(JS::Realm&, u32 base_val, u32 anim_val);

virtual void initialize(JS::Realm&) override;

u32 m_base_val;
u32 m_anim_val;
};

}
5 changes: 5 additions & 0 deletions Userland/Libraries/LibWeb/SVG/SVGAnimatedInteger.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Exposed=Window]
interface SVGAnimatedInteger {
attribute long baseVal;
readonly attribute long animVal;
};
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/idl_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ libweb_js_bindings(Streams/WritableStreamDefaultController)
libweb_js_bindings(Streams/WritableStreamDefaultWriter)
libweb_js_bindings(SVG/SVGAnimatedBoolean)
libweb_js_bindings(SVG/SVGAnimatedEnumeration)
libweb_js_bindings(SVG/SVGAnimatedInteger)
libweb_js_bindings(SVG/SVGAnimatedLength)
libweb_js_bindings(SVG/SVGAnimatedNumber)
libweb_js_bindings(SVG/SVGAnimatedRect)
Expand Down

0 comments on commit 2970ac9

Please sign in to comment.