diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-13 01:02:00 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-13 01:03:49 +0100 |
commit | c52dc87a42cb0d02629e85df3682a7af45087ad1 (patch) | |
tree | 151814c253f2884db004d8b632b0ba5c9514f497 | |
parent | 58ce2dd08806fb998d8705868314d25753674f30 (diff) | |
download | serenity-c52dc87a42cb0d02629e85df3682a7af45087ad1.zip |
LibWeb: Don't crash on unknown CSS display types, fall back to inline
This patch also adds CSS::Display::to_string() so we can log the
unimplemented CSS display value (if you have LIBWEB_CSS_DEBUG enabled).
-rw-r--r-- | Userland/Libraries/LibWeb/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Display.cpp | 105 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Display.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Element.cpp | 6 |
4 files changed, 113 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index d77e673046..cec367db00 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -28,6 +28,7 @@ set(SOURCES CSS/CSSSupportsRule.cpp CSS/ResolvedCSSStyleDeclaration.cpp CSS/DefaultStyleSheetSource.cpp + CSS/Display.cpp CSS/Length.cpp CSS/MediaList.cpp CSS/MediaQuery.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Display.cpp b/Userland/Libraries/LibWeb/CSS/Display.cpp new file mode 100644 index 0000000000..3fff2320cd --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/Display.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibWeb/CSS/Display.h> + +namespace Web::CSS { + +String Display::to_string() const +{ + StringBuilder builder; + switch (m_type) { + case Type::OutsideAndInside: + switch (m_value.outside_inside.outside) { + case Outside::Block: + builder.append("block"sv); + break; + case Outside::Inline: + builder.append("inline"sv); + break; + case Outside::RunIn: + builder.append("run-in"sv); + break; + } + builder.append(' '); + switch (m_value.outside_inside.inside) { + case Inside::Flow: + builder.append("flow"sv); + break; + case Inside::FlowRoot: + builder.append("flow-root"sv); + break; + case Inside::Table: + builder.append("table"sv); + break; + case Inside::Flex: + builder.append("flex"sv); + break; + case Inside::Grid: + builder.append("grid"sv); + break; + case Inside::Ruby: + builder.append("ruby"sv); + break; + } + if (m_value.outside_inside.list_item == ListItem::Yes) + builder.append(" list-item"sv); + break; + case Type::Internal: + switch (m_value.internal) { + case Internal::TableRowGroup: + builder.append("table-row-group"sv); + break; + case Internal::TableHeaderGroup: + builder.append("table-header-group"sv); + break; + case Internal::TableFooterGroup: + builder.append("table-footer-group"sv); + break; + case Internal::TableRow: + builder.append("table-row"sv); + break; + case Internal::TableCell: + builder.append("table-cell"sv); + break; + case Internal::TableColumnGroup: + builder.append("table-column-group"sv); + break; + case Internal::TableColumn: + builder.append("table-column"sv); + break; + case Internal::TableCaption: + builder.append("table-caption"sv); + break; + case Internal::RubyBase: + builder.append("ruby-base"sv); + break; + case Internal::RubyText: + builder.append("ruby-text"sv); + break; + case Internal::RubyBaseContainer: + builder.append("ruby-base-container"sv); + break; + case Internal::RubyTextContainer: + builder.append("ruby-text-container"sv); + break; + } + break; + case Type::Box: + switch (m_value.box) { + case Box::Contents: + builder.append("contents"sv); + break; + case Box::None: + builder.append("none"sv); + break; + } + break; + }; + return builder.to_string(); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/Display.h b/Userland/Libraries/LibWeb/CSS/Display.h index 634f92d778..b5c248a66a 100644 --- a/Userland/Libraries/LibWeb/CSS/Display.h +++ b/Userland/Libraries/LibWeb/CSS/Display.h @@ -7,6 +7,7 @@ #pragma once #include <AK/Assertions.h> +#include <AK/String.h> namespace Web::CSS { @@ -15,6 +16,8 @@ public: Display() = default; ~Display() = default; + String to_string() const; + bool operator==(Display const& other) const { if (m_type != other.m_type) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 30e3fb3437..3725aa9818 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #include <AK/AnyOf.h> +#include <AK/Debug.h> #include <AK/StringBuilder.h> #include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/PropertyID.h> @@ -227,7 +228,8 @@ RefPtr<Layout::Node> Element::create_layout_node(NonnullRefPtr<CSS::StylePropert if (display.is_flow_inside()) return adopt_ref(*new Layout::InlineNode(document(), *this, move(style))); - TODO(); + dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Support display: {}", display.to_string()); + return adopt_ref(*new Layout::InlineNode(document(), *this, move(style))); } if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_flex_inside()) |