diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-26 17:22:24 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-26 17:51:00 +0200 |
commit | 1b1537c5a6ebc86df9376bf83f7f24b353ae4112 (patch) | |
tree | 236b8a5c2a4c0928d622cddcb2c86ebb9532a720 | |
parent | e0b8b4ac67321a03d037e12fb6d46edfce3a7504 (diff) | |
download | serenity-1b1537c5a6ebc86df9376bf83f7f24b353ae4112.zip |
LibWeb: Simplify type traits for SVGGraphicsElement
-rw-r--r-- | Libraries/LibWeb/DOM/Node.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/SVG/SVGElement.h | 9 | ||||
-rw-r--r-- | 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<Node> append_child(NonnullRefPtr<Node>, bool notify = true); RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> 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<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() |