mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Add SVGNumber
This commit is contained in:
parent
0dd8e1e6f2
commit
7e869c7816
Notes:
github-actions[bot]
2025-11-09 00:24:28 +00:00
Author: https://github.com/gmta
Commit: 7e869c7816
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6709
9 changed files with 112 additions and 9 deletions
|
|
@ -934,6 +934,7 @@ set(SOURCES
|
|||
SVG/SVGLineElement.cpp
|
||||
SVG/SVGMaskElement.cpp
|
||||
SVG/SVGMetadataElement.cpp
|
||||
SVG/SVGNumber.cpp
|
||||
SVG/SVGPathElement.cpp
|
||||
SVG/SVGPolygonElement.cpp
|
||||
SVG/SVGPolylineElement.cpp
|
||||
|
|
|
|||
|
|
@ -1117,6 +1117,7 @@ class SVGLength;
|
|||
class SVGLineElement;
|
||||
class SVGMaskElement;
|
||||
class SVGMetadataElement;
|
||||
class SVGNumber;
|
||||
class SVGPathElement;
|
||||
class SVGPolygonElement;
|
||||
class SVGPolylineElement;
|
||||
|
|
|
|||
49
Libraries/LibWeb/SVG/SVGNumber.cpp
Normal file
49
Libraries/LibWeb/SVG/SVGNumber.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/SVGNumberPrototype.h>
|
||||
#include <LibWeb/SVG/SVGNumber.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(SVGNumber);
|
||||
|
||||
GC::Ref<SVGNumber> SVGNumber::create(JS::Realm& realm, float value, ReadOnly read_only)
|
||||
{
|
||||
return realm.create<SVGNumber>(realm, value, read_only);
|
||||
}
|
||||
|
||||
SVGNumber::SVGNumber(JS::Realm& realm, float value, ReadOnly read_only)
|
||||
: PlatformObject(realm)
|
||||
, m_value(value)
|
||||
, m_read_only(read_only)
|
||||
{
|
||||
}
|
||||
|
||||
void SVGNumber::initialize(JS::Realm& realm)
|
||||
{
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGNumber);
|
||||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG2/types.html#__svg__SVGNumber__value
|
||||
WebIDL::ExceptionOr<void> SVGNumber::set_value(float value)
|
||||
{
|
||||
// 1. If the SVGNumber is read only, then throw a NoModificationAllowedError.
|
||||
if (m_read_only == ReadOnly::Yes)
|
||||
return WebIDL::NoModificationAllowedError::create(realm(), "Cannot modify value of read-only SVGNumber"_utf16);
|
||||
|
||||
// 2. Set the SVGNumber's value to the value being assigned to the value member.
|
||||
m_value = value;
|
||||
|
||||
// FIXME: 3. If the SVGNumber reflects an element of the base value of a reflected attribute, then reserialize the
|
||||
// reflected attribute.
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
44
Libraries/LibWeb/SVG/SVGNumber.h
Normal file
44
Libraries/LibWeb/SVG/SVGNumber.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
// https://www.w3.org/TR/SVG2/types.html#InterfaceSVGNumber
|
||||
class SVGNumber final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(SVGNumber, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(SVGNumber);
|
||||
|
||||
public:
|
||||
enum class ReadOnly : u8 {
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
|
||||
[[nodiscard]] static GC::Ref<SVGNumber> create(JS::Realm&, float value, ReadOnly);
|
||||
virtual ~SVGNumber() override = default;
|
||||
|
||||
float value() const { return m_value; }
|
||||
WebIDL::ExceptionOr<void> set_value(float value);
|
||||
|
||||
ReadOnly read_only() const { return m_read_only; }
|
||||
|
||||
private:
|
||||
SVGNumber(JS::Realm&, float value, ReadOnly);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
float m_value { 0 };
|
||||
|
||||
// https://www.w3.org/TR/SVG2/types.html#ReadOnlyNumber
|
||||
ReadOnly m_read_only;
|
||||
};
|
||||
|
||||
}
|
||||
5
Libraries/LibWeb/SVG/SVGNumber.idl
Normal file
5
Libraries/LibWeb/SVG/SVGNumber.idl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// https://www.w3.org/TR/SVG2/types.html#InterfaceSVGNumber
|
||||
[Exposed=Window]
|
||||
interface SVGNumber {
|
||||
attribute float value;
|
||||
};
|
||||
|
|
@ -403,6 +403,7 @@ libweb_js_bindings(SVG/SVGLineElement)
|
|||
libweb_js_bindings(SVG/SVGLinearGradientElement)
|
||||
libweb_js_bindings(SVG/SVGMaskElement)
|
||||
libweb_js_bindings(SVG/SVGMetadataElement)
|
||||
libweb_js_bindings(SVG/SVGNumber)
|
||||
libweb_js_bindings(SVG/SVGPathElement)
|
||||
libweb_js_bindings(SVG/SVGPolygonElement)
|
||||
libweb_js_bindings(SVG/SVGPolylineElement)
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ static bool is_platform_object(Type const& type)
|
|||
"ServiceWorkerContainer"sv,
|
||||
"ServiceWorkerRegistration"sv,
|
||||
"SVGAnimationElement"sv,
|
||||
"SVGNumber"sv,
|
||||
"SVGTransform"sv,
|
||||
"ShadowRoot"sv,
|
||||
"SourceBuffer"sv,
|
||||
|
|
|
|||
|
|
@ -397,6 +397,7 @@ SVGLinearGradientElement
|
|||
SVGMaskElement
|
||||
SVGMatrix
|
||||
SVGMetadataElement
|
||||
SVGNumber
|
||||
SVGPathElement
|
||||
SVGPoint
|
||||
SVGPolygonElement
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ Harness status: OK
|
|||
|
||||
Found 1781 tests
|
||||
|
||||
970 Pass
|
||||
811 Fail
|
||||
977 Pass
|
||||
804 Fail
|
||||
Pass idl_test setup
|
||||
Pass idl_test validation
|
||||
Pass Partial interface Document: original interface defined
|
||||
|
|
@ -85,13 +85,13 @@ Fail SVGGeometryElement interface: operation isPointInFill(optional DOMPointInit
|
|||
Fail SVGGeometryElement interface: operation isPointInStroke(optional DOMPointInit)
|
||||
Pass SVGGeometryElement interface: operation getTotalLength()
|
||||
Pass SVGGeometryElement interface: operation getPointAtLength(float)
|
||||
Fail SVGNumber interface: existence and properties of interface object
|
||||
Fail SVGNumber interface object length
|
||||
Fail SVGNumber interface object name
|
||||
Fail SVGNumber interface: existence and properties of interface prototype object
|
||||
Fail SVGNumber interface: existence and properties of interface prototype object's "constructor" property
|
||||
Fail SVGNumber interface: existence and properties of interface prototype object's @@unscopables property
|
||||
Fail SVGNumber interface: attribute value
|
||||
Pass SVGNumber interface: existence and properties of interface object
|
||||
Pass SVGNumber interface object length
|
||||
Pass SVGNumber interface object name
|
||||
Pass SVGNumber interface: existence and properties of interface prototype object
|
||||
Pass SVGNumber interface: existence and properties of interface prototype object's "constructor" property
|
||||
Pass SVGNumber interface: existence and properties of interface prototype object's @@unscopables property
|
||||
Pass SVGNumber interface: attribute value
|
||||
Fail SVGNumber must be primary interface of objects.svg.createSVGNumber()
|
||||
Fail Stringification of objects.svg.createSVGNumber()
|
||||
Fail SVGNumber interface: objects.svg.createSVGNumber() must inherit property "value" with the proper type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue