summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.h1
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp39
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h10
3 files changed, 42 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h
index 16abee4201..be96bc2ea7 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.h
+++ b/Userland/Libraries/LibWeb/CSS/Length.h
@@ -48,6 +48,7 @@ public:
bool is_auto() const { return m_type == Type::Auto; }
bool is_calculated() const { return m_type == Type::Calculated; }
+ bool is_px() const { return m_type == Type::Px; }
bool is_absolute() const
{
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index 6a5451934a..074b2be9ba 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -1193,4 +1193,43 @@ String StyleValueList::to_string() const
return String::join(separator, m_values);
}
+NonnullRefPtr<ColorStyleValue> ColorStyleValue::create(Color color)
+{
+ if (color.value() == 0) {
+ static auto transparent = adopt_ref(*new ColorStyleValue(color));
+ return transparent;
+ }
+
+ if (color == Color::from_rgb(0x000000)) {
+ static auto black = adopt_ref(*new ColorStyleValue(color));
+ return black;
+ }
+
+ if (color == Color::from_rgb(0xffffff)) {
+ static auto white = adopt_ref(*new ColorStyleValue(color));
+ return white;
+ }
+
+ return adopt_ref(*new ColorStyleValue(color));
+}
+
+NonnullRefPtr<LengthStyleValue> LengthStyleValue::create(Length const& length)
+{
+ if (length.is_auto()) {
+ static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_auto()));
+ return value;
+ }
+ if (length.is_px()) {
+ if (length.raw_value() == 0) {
+ static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_px(0)));
+ return value;
+ }
+ if (length.raw_value() == 1) {
+ static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_px(1)));
+ return value;
+ }
+ }
+ return adopt_ref(*new LengthStyleValue(length));
+}
+
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 03bc0c48e6..fdc8f0b65f 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -856,10 +856,7 @@ private:
class ColorStyleValue : public StyleValue {
public:
- static NonnullRefPtr<ColorStyleValue> create(Color color)
- {
- return adopt_ref(*new ColorStyleValue(color));
- }
+ static NonnullRefPtr<ColorStyleValue> create(Color color);
virtual ~ColorStyleValue() override { }
Color color() const { return m_color; }
@@ -1101,10 +1098,7 @@ private:
class LengthStyleValue : public StyleValue {
public:
- static NonnullRefPtr<LengthStyleValue> create(Length const& length)
- {
- return adopt_ref(*new LengthStyleValue(length));
- }
+ static NonnullRefPtr<LengthStyleValue> create(Length const&);
virtual ~LengthStyleValue() override { }
Length const& length() const { return m_length; }