From 1b1537c5a6ebc86df9376bf83f7f24b353ae4112 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 26 Jul 2020 17:22:24 +0200 Subject: LibWeb: Simplify type traits for SVGGraphicsElement --- Libraries/LibWeb/DOM/Node.h | 1 + Libraries/LibWeb/SVG/SVGElement.h | 9 +++++++++ Libraries/LibWeb/SVG/SVGGraphicsElement.h | 19 ++++--------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index b97c5c6da3..288130a29d 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -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 append_child(NonnullRefPtr, bool notify = true); RefPtr insert_before(NonnullRefPtr node, RefPtr child, bool notify = true); diff --git a/Libraries/LibWeb/SVG/SVGElement.h b/Libraries/LibWeb/SVG/SVGElement.h index 3bd813eb4a..5138a11e93 100644 --- a/Libraries/LibWeb/SVG/SVGElement.h +++ b/Libraries/LibWeb/SVG/SVGElement.h @@ -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() diff --git a/Libraries/LibWeb/SVG/SVGGraphicsElement.h b/Libraries/LibWeb/SVG/SVGGraphicsElement.h index 7862a341ec..be2fbfa8d2 100644 --- a/Libraries/LibWeb/SVG/SVGGraphicsElement.h +++ b/Libraries/LibWeb/SVG/SVGGraphicsElement.h @@ -59,24 +59,13 @@ protected: Optional m_fill_color; Optional m_stroke_color; Optional 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(node)) - return false; - - auto tag_name = downcast(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(node) && downcast(node).is_graphics_element(); } AK_END_TYPE_TRAITS() -- cgit v1.2.3