LibWeb: Simplify type traits for SVGGraphicsElement

This commit is contained in:
Andreas Kling 2020-07-26 17:22:24 +02:00
parent e0b8b4ac67
commit 1b1537c5a6
Notes: sideshowbarker 2024-07-19 04:36:06 +09:00
3 changed files with 14 additions and 15 deletions

View file

@ -82,6 +82,7 @@ public:
bool is_character_data() const { return type() == NodeType::TEXT_NODE || type() == NodeType::COMMENT_NODE; }
bool is_document_fragment() const { return type() == NodeType::DOCUMENT_FRAGMENT_NODE; }
bool is_parent_node() const { return is_element() || is_document() || is_document_fragment(); }
virtual bool is_svg_element() const { return false; }
RefPtr<Node> append_child(NonnullRefPtr<Node>, bool notify = true);
RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify = true);

View file

@ -33,6 +33,15 @@ namespace Web::SVG {
class SVGElement : public Element {
public:
SVGElement(Document&, const FlyString& tag_name);
virtual bool is_graphics_element() const { return false; }
private:
virtual bool is_svg_element() const final { return true; }
};
}
AK_BEGIN_TYPE_TRAITS(Web::SVG::SVGElement)
static bool is_type(const Web::Node& node) { return node.is_svg_element(); }
AK_END_TYPE_TRAITS()

View file

@ -59,24 +59,13 @@ protected:
Optional<Gfx::Color> m_fill_color;
Optional<Gfx::Color> m_stroke_color;
Optional<float> m_stroke_width;
private:
virtual bool is_graphics_element() const final { return true; }
};
}
AK_BEGIN_TYPE_TRAITS(Web::SVG::SVGGraphicsElement)
static bool is_type(const Web::Node& node)
{
if (!is<Web::Element>(node))
return false;
auto tag_name = downcast<Web::Element>(node).tag_name();
#define __ENUMERATE_SVG_TAG(name) \
if (tag_name == #name) \
return true;
ENUMERATE_SVG_TAGS
#undef ENUMERATE_SVG_TAG
return false;
}
static bool is_type(const Web::Node& node) { return is<Web::SVG::SVGElement>(node) && downcast<Web::SVG::SVGElement>(node).is_graphics_element(); }
AK_END_TYPE_TRAITS()