diff --git a/LibHTML/CSS/StyleValue.cpp b/LibHTML/CSS/StyleValue.cpp
index 1d19d602f9..e0d0a1764d 100644
--- a/LibHTML/CSS/StyleValue.cpp
+++ b/LibHTML/CSS/StyleValue.cpp
@@ -8,18 +8,3 @@ StyleValue::StyleValue(Type type)
StyleValue::~StyleValue()
{
}
-
-NonnullRefPtr StyleValue::parse(const StringView& str)
-{
- String string(str);
- bool ok;
- int as_int = string.to_int(ok);
- if (ok)
- return adopt(*new LengthStyleValue(Length(as_int, Length::Type::Absolute)));
- unsigned as_uint = string.to_uint(ok);
- if (ok)
- return adopt(*new LengthStyleValue(Length(as_uint, Length::Type::Absolute)));
- if (string == "auto")
- return adopt(*new LengthStyleValue(Length()));
- return adopt(*new StringStyleValue(str));
-}
diff --git a/LibHTML/CSS/StyleValue.h b/LibHTML/CSS/StyleValue.h
index e195ce0594..574fd8215d 100644
--- a/LibHTML/CSS/StyleValue.h
+++ b/LibHTML/CSS/StyleValue.h
@@ -8,8 +8,6 @@
class StyleValue : public RefCounted {
public:
- static NonnullRefPtr parse(const StringView&);
-
virtual ~StyleValue();
enum class Type {
@@ -33,30 +31,40 @@ private:
class StringStyleValue : public StyleValue {
public:
+ static NonnullRefPtr create(const String& string)
+ {
+ return adopt(*new StringStyleValue(string));
+ }
virtual ~StringStyleValue() override {}
- StringStyleValue(const String& string)
+
+ String to_string() const override { return m_string; }
+
+private:
+ explicit StringStyleValue(const String& string)
: StyleValue(Type::String)
, m_string(string)
{
}
- String to_string() const override { return m_string; }
-
-private:
String m_string;
};
class LengthStyleValue : public StyleValue {
public:
+ static NonnullRefPtr create(const Length& length)
+ {
+ return adopt(*new LengthStyleValue(length));
+ }
virtual ~LengthStyleValue() override {}
- LengthStyleValue(const Length& length)
+
+ String to_string() const override { return m_length.to_string(); }
+
+private:
+ explicit LengthStyleValue(const Length& length)
: StyleValue(Type::Length)
, m_length(length)
{
}
- String to_string() const override { return m_length.to_string(); }
-
-private:
Length m_length;
};
diff --git a/LibHTML/Parser/CSSParser.cpp b/LibHTML/Parser/CSSParser.cpp
index 314895f581..cfc5667884 100644
--- a/LibHTML/Parser/CSSParser.cpp
+++ b/LibHTML/Parser/CSSParser.cpp
@@ -3,6 +3,21 @@
#include
#include
+NonnullRefPtr parse_css_value(const StringView& view)
+{
+ String string(view);
+ bool ok;
+ int as_int = string.to_int(ok);
+ if (ok)
+ return LengthStyleValue::create(Length(as_int, Length::Type::Absolute));
+ unsigned as_uint = string.to_uint(ok);
+ if (ok)
+ return LengthStyleValue::create(Length(as_uint, Length::Type::Absolute));
+ if (string == "auto")
+ return LengthStyleValue::create(Length());
+ return StringStyleValue::create(string);
+}
+
NonnullRefPtr parse_css(const String& css)
{
NonnullRefPtrVector rules;
@@ -108,7 +123,7 @@ NonnullRefPtr parse_css(const String& css)
auto property_value = String::copy(buffer);
buffer.clear();
consume_specific(';');
- current_rule.declarations.append(StyleDeclaration::create(property_name, StyleValue::parse(property_value)));
+ current_rule.declarations.append(StyleDeclaration::create(property_name, parse_css_value(property_value)));
};
auto parse_declarations = [&] {