LibWeb: Begin implementing the SVGLength type
There are a few unimplemented features for this type: 1. The value setter should throw a DOMException if it is invoked on an SVGLength that was declared readonly in another IDL file. 2. SVG::AttributeParser does not parse unit types when it parses lengths so all SVGLength will have an "unknown" unit for now. 3. Due to (2), methods which convert between units are unimplemented.
This commit is contained in:
parent
3ebc5cc58e
commit
ebf3829f1c
Notes:
sideshowbarker
2024-07-17 16:58:59 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/ebf3829f1c Pull-request: https://github.com/SerenityOS/serenity/pull/13175
5 changed files with 98 additions and 0 deletions
|
@ -317,6 +317,7 @@ set(SOURCES
|
|||
SVG/SVGPathElement.cpp
|
||||
SVG/SVGCircleElement.cpp
|
||||
SVG/SVGEllipseElement.cpp
|
||||
SVG/SVGLength.cpp
|
||||
SVG/SVGLineElement.cpp
|
||||
SVG/SVGPolygonElement.cpp
|
||||
SVG/SVGPolylineElement.cpp
|
||||
|
@ -575,6 +576,7 @@ libweb_js_wrapper(SVG/SVGGeometryElement)
|
|||
libweb_js_wrapper(SVG/SVGGraphicsElement)
|
||||
libweb_js_wrapper(SVG/SVGCircleElement)
|
||||
libweb_js_wrapper(SVG/SVGEllipseElement)
|
||||
libweb_js_wrapper(SVG/SVGLength)
|
||||
libweb_js_wrapper(SVG/SVGLineElement)
|
||||
libweb_js_wrapper(SVG/SVGPathElement)
|
||||
libweb_js_wrapper(SVG/SVGPolygonElement)
|
||||
|
|
|
@ -291,6 +291,7 @@ class SVGElement;
|
|||
class SVGEllipseElement;
|
||||
class SVGGeometryElement;
|
||||
class SVGGraphicsElement;
|
||||
class SVGLength;
|
||||
class SVGLineElement;
|
||||
class SVGPathElement;
|
||||
class SVGPolygonElement;
|
||||
|
@ -514,6 +515,7 @@ class SVGElementWrapper;
|
|||
class SVGEllipseElementWrapper;
|
||||
class SVGGeometryElementWrapper;
|
||||
class SVGGraphicsElementWrapper;
|
||||
class SVGLengthWrapper;
|
||||
class SVGLineElementWrapper;
|
||||
class SVGPathElementWrapper;
|
||||
class SVGPolygonElementWrapper;
|
||||
|
|
30
Userland/Libraries/LibWeb/SVG/SVGLength.cpp
Normal file
30
Userland/Libraries/LibWeb/SVG/SVGLength.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/SVG/SVGLength.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
NonnullRefPtr<SVGLength> SVGLength::create(u8 unit_type, float value)
|
||||
{
|
||||
return adopt_ref(*new SVGLength(unit_type, value));
|
||||
}
|
||||
|
||||
SVGLength::SVGLength(u8 unit_type, float value)
|
||||
: m_unit_type(unit_type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/types.html#__svg__SVGLength__value
|
||||
DOM::ExceptionOr<void> SVGLength::set_value(float value)
|
||||
{
|
||||
// FIXME: Raise an exception if this <length> is read-only.
|
||||
m_value = value;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
40
Userland/Libraries/LibWeb/SVG/SVGLength.h
Normal file
40
Userland/Libraries/LibWeb/SVG/SVGLength.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
// https://www.w3.org/TR/SVG11/types.html#InterfaceSVGLength
|
||||
class SVGLength
|
||||
: public RefCounted<SVGLength>
|
||||
, public Bindings::Wrappable
|
||||
, public Weakable<SVGLength> {
|
||||
public:
|
||||
using WrapperType = Bindings::SVGLengthWrapper;
|
||||
|
||||
static NonnullRefPtr<SVGLength> create(u8 unit_type, float value);
|
||||
virtual ~SVGLength() = default;
|
||||
|
||||
u8 unit_type() const { return m_unit_type; }
|
||||
|
||||
float value() const { return m_value; }
|
||||
DOM::ExceptionOr<void> set_value(float value);
|
||||
|
||||
private:
|
||||
SVGLength(u8 unit_type, float value);
|
||||
|
||||
u8 m_unit_type { 0 };
|
||||
float m_value { 0 };
|
||||
};
|
||||
|
||||
}
|
24
Userland/Libraries/LibWeb/SVG/SVGLength.idl
Normal file
24
Userland/Libraries/LibWeb/SVG/SVGLength.idl
Normal file
|
@ -0,0 +1,24 @@
|
|||
interface SVGLength {
|
||||
const unsigned short SVG_LENGTHTYPE_UNKNOWN = 0;
|
||||
const unsigned short SVG_LENGTHTYPE_NUMBER = 1;
|
||||
const unsigned short SVG_LENGTHTYPE_PERCENTAGE = 2;
|
||||
const unsigned short SVG_LENGTHTYPE_EMS = 3;
|
||||
const unsigned short SVG_LENGTHTYPE_EXS = 4;
|
||||
const unsigned short SVG_LENGTHTYPE_PX = 5;
|
||||
const unsigned short SVG_LENGTHTYPE_CM = 6;
|
||||
const unsigned short SVG_LENGTHTYPE_MM = 7;
|
||||
const unsigned short SVG_LENGTHTYPE_IN = 8;
|
||||
const unsigned short SVG_LENGTHTYPE_PT = 9;
|
||||
const unsigned short SVG_LENGTHTYPE_PC = 10;
|
||||
|
||||
readonly attribute unsigned short unitType;
|
||||
|
||||
// FIXME: Support setraises().
|
||||
attribute float value; // setraises(DOMException);
|
||||
|
||||
// attribute float valueInSpecifiedUnits setraises(DOMException);
|
||||
// attribute DOMString valueAsString setraises(DOMException);
|
||||
|
||||
// void newValueSpecifiedUnits(in unsigned short unitType, in float valueInSpecifiedUnits) raises(DOMException);
|
||||
// void convertToSpecifiedUnits(in unsigned short unitType) raises(DOMException);
|
||||
};
|
Loading…
Add table
Reference in a new issue