From 10851d87a2071d22e49fecb5a3fd19f7157c392a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 7 Jun 2020 23:10:45 +0200 Subject: [PATCH] LibWeb: Add (stub) HTMLTable{,Cell,Row}Element C++ classes We'll need a place to implement the various presentational attributes for table parts, and more stuff. --- Libraries/LibWeb/CMakeLists.txt | 3 ++ Libraries/LibWeb/DOM/ElementFactory.cpp | 11 +++++ Libraries/LibWeb/DOM/HTMLTableCellElement.cpp | 40 +++++++++++++++++ Libraries/LibWeb/DOM/HTMLTableCellElement.h | 45 +++++++++++++++++++ Libraries/LibWeb/DOM/HTMLTableElement.cpp | 40 +++++++++++++++++ Libraries/LibWeb/DOM/HTMLTableElement.h | 45 +++++++++++++++++++ Libraries/LibWeb/DOM/HTMLTableRowElement.cpp | 40 +++++++++++++++++ Libraries/LibWeb/DOM/HTMLTableRowElement.h | 45 +++++++++++++++++++ 8 files changed, 269 insertions(+) create mode 100644 Libraries/LibWeb/DOM/HTMLTableCellElement.cpp create mode 100644 Libraries/LibWeb/DOM/HTMLTableCellElement.h create mode 100644 Libraries/LibWeb/DOM/HTMLTableElement.cpp create mode 100644 Libraries/LibWeb/DOM/HTMLTableElement.h create mode 100644 Libraries/LibWeb/DOM/HTMLTableRowElement.cpp create mode 100644 Libraries/LibWeb/DOM/HTMLTableRowElement.h diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 3ba2a05983b..aac8fde6054 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -55,6 +55,9 @@ set(SOURCES DOM/HTMLLinkElement.cpp DOM/HTMLScriptElement.cpp DOM/HTMLStyleElement.cpp + DOM/HTMLTableElement.cpp + DOM/HTMLTableCellElement.cpp + DOM/HTMLTableRowElement.cpp DOM/HTMLTitleElement.cpp DOM/ImageData.cpp DOM/Node.cpp diff --git a/Libraries/LibWeb/DOM/ElementFactory.cpp b/Libraries/LibWeb/DOM/ElementFactory.cpp index 38fe0f40483..04874247a00 100644 --- a/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -42,6 +42,9 @@ #include #include #include +#include +#include +#include #include namespace Web { @@ -79,6 +82,14 @@ NonnullRefPtr create_element(Document& document, const FlyString& tag_n return adopt(*new HTMLBRElement(document, lowercase_tag_name)); if (lowercase_tag_name == "iframe") return adopt(*new HTMLIFrameElement(document, lowercase_tag_name)); + if (lowercase_tag_name == "table") + return adopt(*new HTMLTableElement(document, lowercase_tag_name)); + if (lowercase_tag_name == "tr") + return adopt(*new HTMLTableRowElement(document, lowercase_tag_name)); + if (lowercase_tag_name == "td" || lowercase_tag_name == "th") + return adopt(*new HTMLTableCellElement(document, lowercase_tag_name)); + if (lowercase_tag_name == "iframe") + return adopt(*new HTMLIFrameElement(document, lowercase_tag_name)); if (lowercase_tag_name == "h1" || lowercase_tag_name == "h2" || lowercase_tag_name == "h3" diff --git a/Libraries/LibWeb/DOM/HTMLTableCellElement.cpp b/Libraries/LibWeb/DOM/HTMLTableCellElement.cpp new file mode 100644 index 00000000000..19e3fcf95ae --- /dev/null +++ b/Libraries/LibWeb/DOM/HTMLTableCellElement.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +namespace Web { + +HTMLTableCellElement::HTMLTableCellElement(Document& document, const FlyString& tag_name) + : HTMLElement(document, tag_name) +{ +} + +HTMLTableCellElement::~HTMLTableCellElement() +{ +} + +} diff --git a/Libraries/LibWeb/DOM/HTMLTableCellElement.h b/Libraries/LibWeb/DOM/HTMLTableCellElement.h new file mode 100644 index 00000000000..486c2e698f4 --- /dev/null +++ b/Libraries/LibWeb/DOM/HTMLTableCellElement.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +namespace Web { + +class HTMLTableCellElement : public HTMLElement { +public: + HTMLTableCellElement(Document&, const FlyString& tag_name); + virtual ~HTMLTableCellElement() override; +}; + +template<> +inline bool is(const Node& node) +{ + return is(node) && to(node).tag_name().is_one_of("td", "th"); +} + +} diff --git a/Libraries/LibWeb/DOM/HTMLTableElement.cpp b/Libraries/LibWeb/DOM/HTMLTableElement.cpp new file mode 100644 index 00000000000..0a00448d709 --- /dev/null +++ b/Libraries/LibWeb/DOM/HTMLTableElement.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +namespace Web { + +HTMLTableElement::HTMLTableElement(Document& document, const FlyString& tag_name) + : HTMLElement(document, tag_name) +{ +} + +HTMLTableElement::~HTMLTableElement() +{ +} + +} diff --git a/Libraries/LibWeb/DOM/HTMLTableElement.h b/Libraries/LibWeb/DOM/HTMLTableElement.h new file mode 100644 index 00000000000..423345f9ce5 --- /dev/null +++ b/Libraries/LibWeb/DOM/HTMLTableElement.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +namespace Web { + +class HTMLTableElement : public HTMLElement { +public: + HTMLTableElement(Document&, const FlyString& tag_name); + virtual ~HTMLTableElement() override; +}; + +template<> +inline bool is(const Node& node) +{ + return is(node) && to(node).tag_name().equals_ignoring_case("table"); +} + +} diff --git a/Libraries/LibWeb/DOM/HTMLTableRowElement.cpp b/Libraries/LibWeb/DOM/HTMLTableRowElement.cpp new file mode 100644 index 00000000000..b14464d33d5 --- /dev/null +++ b/Libraries/LibWeb/DOM/HTMLTableRowElement.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +namespace Web { + +HTMLTableRowElement::HTMLTableRowElement(Document& document, const FlyString& tag_name) + : HTMLElement(document, tag_name) +{ +} + +HTMLTableRowElement::~HTMLTableRowElement() +{ +} + +} diff --git a/Libraries/LibWeb/DOM/HTMLTableRowElement.h b/Libraries/LibWeb/DOM/HTMLTableRowElement.h new file mode 100644 index 00000000000..f3b3870bf20 --- /dev/null +++ b/Libraries/LibWeb/DOM/HTMLTableRowElement.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +namespace Web { + +class HTMLTableRowElement : public HTMLElement { +public: + HTMLTableRowElement(Document&, const FlyString& tag_name); + virtual ~HTMLTableRowElement() override; +}; + +template<> +inline bool is(const Node& node) +{ + return is(node) && to(node).tag_name().equals_ignoring_case("tr"); +} + +}