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
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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue