From 5b942b519c2fbbab10d61af7f09e5449019cce89 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 29 Sep 2019 12:24:58 +0200 Subject: [PATCH] LibHTML: Add HTMLHeadingElement for

through

--- Libraries/LibHTML/DOM/HTMLHeadingElement.cpp | 10 ++++++++++ Libraries/LibHTML/DOM/HTMLHeadingElement.h | 9 +++++++++ Libraries/LibHTML/Makefile.shared | 1 + Libraries/LibHTML/Parser/HTMLParser.cpp | 12 +++++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Libraries/LibHTML/DOM/HTMLHeadingElement.cpp create mode 100644 Libraries/LibHTML/DOM/HTMLHeadingElement.h diff --git a/Libraries/LibHTML/DOM/HTMLHeadingElement.cpp b/Libraries/LibHTML/DOM/HTMLHeadingElement.cpp new file mode 100644 index 00000000000..9b949a8381f --- /dev/null +++ b/Libraries/LibHTML/DOM/HTMLHeadingElement.cpp @@ -0,0 +1,10 @@ +#include + +HTMLHeadingElement::HTMLHeadingElement(Document& document, const String& tag_name) + : HTMLElement(document, tag_name) +{ +} + +HTMLHeadingElement::~HTMLHeadingElement() +{ +} diff --git a/Libraries/LibHTML/DOM/HTMLHeadingElement.h b/Libraries/LibHTML/DOM/HTMLHeadingElement.h new file mode 100644 index 00000000000..38daa335682 --- /dev/null +++ b/Libraries/LibHTML/DOM/HTMLHeadingElement.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +class HTMLHeadingElement : public HTMLElement { +public: + HTMLHeadingElement(Document&, const String& tag_name); + virtual ~HTMLHeadingElement() override; +}; diff --git a/Libraries/LibHTML/Makefile.shared b/Libraries/LibHTML/Makefile.shared index bb2e2ed0b43..efa0f8ccd3d 100644 --- a/Libraries/LibHTML/Makefile.shared +++ b/Libraries/LibHTML/Makefile.shared @@ -4,6 +4,7 @@ LIBHTML_OBJS = \ DOM/Element.o \ DOM/HTMLElement.o \ DOM/HTMLAnchorElement.o \ + DOM/HTMLHeadingElement.o \ DOM/Document.o \ DOM/Text.o \ CSS/Selector.o \ diff --git a/Libraries/LibHTML/Parser/HTMLParser.cpp b/Libraries/LibHTML/Parser/HTMLParser.cpp index 0e31bda194a..d01df0c1dea 100644 --- a/Libraries/LibHTML/Parser/HTMLParser.cpp +++ b/Libraries/LibHTML/Parser/HTMLParser.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -9,8 +10,17 @@ static NonnullRefPtr create_element(Document& document, const String& tag_name) { - if (tag_name.to_lowercase() == "a") + auto lowercase_tag_name = tag_name.to_lowercase(); + if (lowercase_tag_name == "a") return adopt(*new HTMLAnchorElement(document, tag_name)); + if (lowercase_tag_name == "h1" + || lowercase_tag_name == "h2" + || lowercase_tag_name == "h3" + || lowercase_tag_name == "h4" + || lowercase_tag_name == "h5" + || lowercase_tag_name == "h6") { + return adopt(*new HTMLHeadingElement(document, tag_name)); + } return adopt(*new Element(document, tag_name)); }