mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Implement SVGElement.className
This commit is contained in:
parent
59f74b909b
commit
9d1ea4c7e0
Notes:
sideshowbarker
2024-07-17 03:00:02 +09:00
Author: https://github.com/jamierocks Commit: https://github.com/LadybirdBrowser/ladybird/commit/9d1ea4c7e0 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/539
7 changed files with 32 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
svg.className = 'demo class'
|
8
Tests/LibWeb/Text/input/SVG/svg-className-attribute.html
Normal file
8
Tests/LibWeb/Text/input/SVG/svg-className-attribute.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<script src="../include.js"></script>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" id="svg-element" class="demo class"></svg>
|
||||
<script>
|
||||
test(() => {
|
||||
const svgElement = document.getElementById("svg-element");
|
||||
println(`svg.className = '${svgElement.className.baseVal}'`);
|
||||
});
|
||||
</script>
|
|
@ -22,6 +22,9 @@ void initialize_strings()
|
|||
ENUMERATE_SVG_ATTRIBUTES(__ENUMERATE_SVG_ATTRIBUTE)
|
||||
#undef __ENUMERATE_SVG_ATTRIBUTE
|
||||
|
||||
// NOTE: Special cases for C++ keywords.
|
||||
class_ = "class"_fly_string;
|
||||
|
||||
// NOTE: Special case for attributes with ':' in them.
|
||||
xlink_href = "xlink:href"_fly_string;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Web::SVG::AttributeNames {
|
|||
E(baseFrequency) \
|
||||
E(baseProfile) \
|
||||
E(calcMode) \
|
||||
E(class_) \
|
||||
E(clipPathUnits) \
|
||||
E(contentScriptType) \
|
||||
E(contentStyleType) \
|
||||
|
|
|
@ -32,6 +32,7 @@ void SVGElement::visit_edges(Cell::Visitor& visitor)
|
|||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_dataset);
|
||||
visitor.visit(m_class_name_animated_string);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<HTML::DOMStringMap> SVGElement::dataset()
|
||||
|
@ -114,6 +115,16 @@ void SVGElement::blur()
|
|||
dbgln("(STUBBED) SVGElement::blur()");
|
||||
}
|
||||
|
||||
// https://svgwg.org/svg2-draft/types.html#__svg__SVGElement__classNames
|
||||
JS::NonnullGCPtr<SVGAnimatedString> SVGElement::class_name()
|
||||
{
|
||||
// The className IDL attribute reflects the ‘class’ attribute.
|
||||
if (!m_class_name_animated_string)
|
||||
m_class_name_animated_string = SVGAnimatedString::create(realm(), *this, AttributeNames::class_);
|
||||
|
||||
return *m_class_name_animated_string;
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<SVGAnimatedLength> SVGElement::svg_animated_length_for_property(CSS::PropertyID property) const
|
||||
{
|
||||
// FIXME: Create a proper animated value when animations are supported.
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/SVG/SVGAnimatedString.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
||||
|
@ -30,6 +31,8 @@ public:
|
|||
void focus();
|
||||
void blur();
|
||||
|
||||
JS::NonnullGCPtr<SVGAnimatedString> class_name();
|
||||
|
||||
protected:
|
||||
SVGElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
|
@ -48,6 +51,8 @@ private:
|
|||
virtual JS::GCPtr<DOM::EventTarget> global_event_handlers_to_event_target(FlyString const&) override { return *this; }
|
||||
|
||||
virtual bool is_svg_element() const final { return true; }
|
||||
|
||||
JS::GCPtr<SVGAnimatedString> m_class_name_animated_string;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
#import <DOM/Element.idl>
|
||||
#import <HTML/HTMLElement.idl>
|
||||
#import <HTML/DOMStringMap.idl>
|
||||
#import <SVG/SVGAnimatedString.idl>
|
||||
|
||||
// https://svgwg.org/svg2-draft/types.html#InterfaceSVGElement
|
||||
[Exposed=Window]
|
||||
interface SVGElement : Element {
|
||||
|
||||
[SameObject] readonly attribute SVGAnimatedString className;
|
||||
};
|
||||
|
||||
SVGElement includes GlobalEventHandlers;
|
||||
|
|
Loading…
Reference in a new issue