mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibWeb: Add SVGAnimatedEnumeration
This commit is contained in:
parent
1aa50ac34a
commit
aeef179668
Notes:
github-actions[bot]
2025-02-22 09:15:33 +00:00
Author: https://github.com/gmta
Commit: aeef179668
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3657
8 changed files with 115 additions and 0 deletions
67
Libraries/LibWeb/SVG/SVGAnimatedEnumeration.cpp
Normal file
67
Libraries/LibWeb/SVG/SVGAnimatedEnumeration.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/SVGAnimatedEnumerationPrototype.h>
|
||||
#include <LibWeb/SVG/SVGAnimatedEnumeration.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(SVGAnimatedEnumeration);
|
||||
|
||||
GC::Ref<SVGAnimatedEnumeration> SVGAnimatedEnumeration::create(JS::Realm& realm, u16 value)
|
||||
{
|
||||
return realm.create<SVGAnimatedEnumeration>(realm, value);
|
||||
}
|
||||
|
||||
SVGAnimatedEnumeration::SVGAnimatedEnumeration(JS::Realm& realm, u16 value)
|
||||
: PlatformObject(realm)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
SVGAnimatedEnumeration::~SVGAnimatedEnumeration() = default;
|
||||
|
||||
// https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedEnumeration__baseVal
|
||||
WebIDL::ExceptionOr<void> SVGAnimatedEnumeration::set_base_val(u16 base_val)
|
||||
{
|
||||
// 1. Let value be the value being assigned to baseVal.
|
||||
auto value = base_val;
|
||||
|
||||
// FIXME: 2. If value is 0 or is not the numeric type value for any value of the reflected attribute, then throw a
|
||||
// TypeError.
|
||||
if (value == 0)
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "invalid value for baseVal"sv };
|
||||
|
||||
// FIXME: 3. Otherwise, if the reflecting IDL attribute is orientType and value is SVG_MARKER_ORIENT_ANGLE, then set the
|
||||
// reflected attribute to the string "0".
|
||||
|
||||
// FIXME: 4. Otherwise, value is the numeric type value for a specific, single keyword value for the reflected attribute.
|
||||
// Set the reflected attribute to that value.
|
||||
m_value = value;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void SVGAnimatedEnumeration::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGAnimatedEnumeration);
|
||||
}
|
||||
|
||||
// https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedEnumeration__baseVal
|
||||
u16 SVGAnimatedEnumeration::base_or_anim_value() const
|
||||
{
|
||||
// FIXME: 1. Let value be the value of the reflected attribute (using the attribute's initial value if it is not present or
|
||||
// invalid).
|
||||
|
||||
// FIXME: 2. Return the numeric type value for value, according to the reflecting IDL attribute's definition.
|
||||
|
||||
return m_value;
|
||||
}
|
||||
|
||||
}
|
37
Libraries/LibWeb/SVG/SVGAnimatedEnumeration.h
Normal file
37
Libraries/LibWeb/SVG/SVGAnimatedEnumeration.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
// https://svgwg.org/svg2-draft/types.html#InterfaceSVGAnimatedEnumeration
|
||||
class SVGAnimatedEnumeration final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(SVGAnimatedEnumeration, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(SVGAnimatedEnumeration);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static GC::Ref<SVGAnimatedEnumeration> create(JS::Realm&, u16 value);
|
||||
virtual ~SVGAnimatedEnumeration() override;
|
||||
|
||||
u16 base_val() const { return base_or_anim_value(); }
|
||||
WebIDL::ExceptionOr<void> set_base_val(u16);
|
||||
|
||||
u16 anim_val() const { return base_or_anim_value(); }
|
||||
|
||||
private:
|
||||
SVGAnimatedEnumeration(JS::Realm&, u16 value);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
u16 base_or_anim_value() const;
|
||||
|
||||
u16 m_value;
|
||||
};
|
||||
|
||||
}
|
6
Libraries/LibWeb/SVG/SVGAnimatedEnumeration.idl
Normal file
6
Libraries/LibWeb/SVG/SVGAnimatedEnumeration.idl
Normal file
|
@ -0,0 +1,6 @@
|
|||
// https://svgwg.org/svg2-draft/types.html#InterfaceSVGAnimatedEnumeration
|
||||
[Exposed=Window]
|
||||
interface SVGAnimatedEnumeration {
|
||||
attribute unsigned short baseVal;
|
||||
readonly attribute unsigned short animVal;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue