summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML/Parser
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-18 11:12:58 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-18 11:48:41 +0100
commite6e41e4fb888918a3d75e6c112a3f5c996bb3393 (patch)
tree34f81cf93e703f63c1cd19b335e4f98452229137 /Libraries/LibHTML/Parser
parentdcd10149feac4c17247a5e06cf850df6ed8e4aab (diff)
downloadserenity-e6e41e4fb888918a3d75e6c112a3f5c996bb3393.zip
LibHTML: Start building a simple code generator for CSS properties
Code for parsing and stringifying CSS properties is now generated based on LibHTML/CSS/Properties.json At the moment, the file tells us three things: - The name of a property - Its initial value - Whether it's inherited Also, for shorthand properties, it provides a list of all the longhand properties it may expand too. This is not actually used in the engine yet though. This *finally* makes layout tree dumps show the names of CSS properties in effect, instead of "CSS::PropertyID(32)" and such. :^)
Diffstat (limited to 'Libraries/LibHTML/Parser')
-rw-r--r--Libraries/LibHTML/Parser/CSSParser.cpp53
1 files changed, 3 insertions, 50 deletions
diff --git a/Libraries/LibHTML/Parser/CSSParser.cpp b/Libraries/LibHTML/Parser/CSSParser.cpp
index 4d8e8e0f3f..97ec907304 100644
--- a/Libraries/LibHTML/Parser/CSSParser.cpp
+++ b/Libraries/LibHTML/Parser/CSSParser.cpp
@@ -1,4 +1,5 @@
#include <AK/HashMap.h>
+#include <LibHTML/CSS/PropertyID.h>
#include <LibHTML/CSS/StyleSheet.h>
#include <LibHTML/Parser/CSSParser.h>
#include <ctype.h>
@@ -48,55 +49,6 @@ NonnullRefPtr<StyleValue> parse_css_value(const StringView& view)
return StringStyleValue::create(string);
}
-static CSS::PropertyID parse_css_property_id(const StringView& string)
-{
- static HashMap<String, CSS::PropertyID> map;
- if (map.is_empty()) {
- map.set("background-color", CSS::PropertyID::BackgroundColor);
- map.set("border-bottom-style", CSS::PropertyID::BorderBottomStyle);
- map.set("border-bottom-width", CSS::PropertyID::BorderBottomWidth);
- map.set("border-collapse", CSS::PropertyID::BorderCollapse);
- map.set("border-left-style", CSS::PropertyID::BorderLeftStyle);
- map.set("border-left-width", CSS::PropertyID::BorderLeftWidth);
- map.set("border-right-style", CSS::PropertyID::BorderRightStyle);
- map.set("border-right-width", CSS::PropertyID::BorderRightWidth);
- map.set("border-spacing", CSS::PropertyID::BorderSpacing);
- map.set("border-top-style", CSS::PropertyID::BorderTopStyle);
- map.set("border-top-width", CSS::PropertyID::BorderTopWidth);
- map.set("color", CSS::PropertyID::Color);
- map.set("display", CSS::PropertyID::Display);
- map.set("font-family", CSS::PropertyID::FontFamily);
- map.set("font-size", CSS::PropertyID::FontSize);
- map.set("font-style", CSS::PropertyID::FontStyle);
- map.set("font-variant", CSS::PropertyID::FontVariant);
- map.set("font-weight", CSS::PropertyID::FontWeight);
- map.set("height", CSS::PropertyID::Height);
- map.set("letter-spacing", CSS::PropertyID::LetterSpacing);
- map.set("line-height", CSS::PropertyID::LineHeight);
- map.set("list-style", CSS::PropertyID::ListStyle);
- map.set("list-style-image", CSS::PropertyID::ListStyleImage);
- map.set("list-style-position", CSS::PropertyID::ListStylePosition);
- map.set("list-style-type", CSS::PropertyID::ListStyleType);
- map.set("margin-bottom", CSS::PropertyID::MarginBottom);
- map.set("margin-left", CSS::PropertyID::MarginLeft);
- map.set("margin-right", CSS::PropertyID::MarginRight);
- map.set("margin-top", CSS::PropertyID::MarginTop);
- map.set("padding-bottom", CSS::PropertyID::PaddingBottom);
- map.set("padding-left", CSS::PropertyID::PaddingLeft);
- map.set("padding-right", CSS::PropertyID::PaddingRight);
- map.set("padding-top", CSS::PropertyID::PaddingTop);
- map.set("text-align", CSS::PropertyID::TextAlign);
- map.set("text-decoration", CSS::PropertyID::TextDecoration);
- map.set("text-indent", CSS::PropertyID::TextIndent);
- map.set("text-transform", CSS::PropertyID::TextTransform);
- map.set("visibility", CSS::PropertyID::Visibility);
- map.set("white-space", CSS::PropertyID::WhiteSpace);
- map.set("width", CSS::PropertyID::Width);
- map.set("word-spacing", CSS::PropertyID::WordSpacing);
- }
- return map.get(string).value_or(CSS::PropertyID::Invalid);
-}
-
class CSSParser {
public:
CSSParser(const StringView& input)
@@ -331,7 +283,8 @@ public:
if (peek() && peek() != '}')
consume_specific(';');
- return StyleProperty { parse_css_property_id(property_name), parse_css_value(property_value), is_important };
+ auto property_id = CSS::property_id_from_string(property_name);
+ return StyleProperty { property_id, parse_css_value(property_value), is_important };
}
void parse_declaration()