summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-04-02 15:41:29 -0400
committerAndreas Kling <kling@serenityos.org>2021-04-03 11:24:33 +0200
commitbd5a91269f27ae1d8aac0027b57d9f2426bec5f4 (patch)
tree1e87887af0e86e52f0875de70397aadf884a2e54
parentfcfeadaffa72c00d7e8b634af4ee49df17455555 (diff)
downloadserenity-bd5a91269f27ae1d8aac0027b57d9f2426bec5f4.zip
LibWeb: Store computed CSS value of background-repeat
-rw-r--r--Userland/Libraries/LibWeb/CSS/ComputedValues.h4
-rw-r--r--Userland/Libraries/LibWeb/CSS/Identifiers.json6
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.cpp24
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.h1
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleResolver.cpp7
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h9
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.cpp4
7 files changed, 55 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h
index 4765507429..6035651bbb 100644
--- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h
+++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h
@@ -45,6 +45,7 @@ public:
static CSS::Display display() { return CSS::Display::Inline; }
static Color color() { return Color::Black; }
static Color background_color() { return Color::Transparent; }
+ static CSS::Repeat background_repeat() { return CSS::Repeat::Repeat; }
static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; }
static CSS::FlexDirection flex_direction() { return CSS::FlexDirection::Row; }
static CSS::Overflow overflow() { return CSS::Overflow::Visible; }
@@ -91,6 +92,7 @@ public:
Color color() const { return m_inherited.color; }
Color background_color() const { return m_noninherited.background_color; }
+ CSS::Repeat background_repeat() const { return m_noninherited.background_repeat; }
CSS::ListStyleType list_style_type() const { return m_inherited.list_style_type; }
@@ -132,6 +134,7 @@ protected:
BorderData border_right;
BorderData border_bottom;
Color background_color { InitialValues::background_color() };
+ CSS::Repeat background_repeat { InitialValues::background_repeat() };
CSS::FlexDirection flex_direction { InitialValues::flex_direction() };
CSS::Overflow overflow_x { InitialValues::overflow() };
CSS::Overflow overflow_y { InitialValues::overflow() };
@@ -146,6 +149,7 @@ public:
void set_color(const Color& color) { m_inherited.color = color; }
void set_cursor(CSS::Cursor cursor) { m_inherited.cursor = cursor; }
void set_background_color(const Color& color) { m_noninherited.background_color = color; }
+ void set_background_repeat(CSS::Repeat repeat) { m_noninherited.background_repeat = repeat; }
void set_float(CSS::Float value) { m_noninherited.float_ = value; }
void set_clear(CSS::Clear value) { m_noninherited.clear = value; }
void set_z_index(Optional<int> value) { m_noninherited.z_index = value; }
diff --git a/Userland/Libraries/LibWeb/CSS/Identifiers.json b/Userland/Libraries/LibWeb/CSS/Identifiers.json
index 9a2380545e..11af8eae41 100644
--- a/Userland/Libraries/LibWeb/CSS/Identifiers.json
+++ b/Userland/Libraries/LibWeb/CSS/Identifiers.json
@@ -108,6 +108,7 @@
"ne-resize",
"nesw-resize",
"no-drop",
+ "no-repeat",
"none",
"normal",
"not-allowed",
@@ -124,8 +125,12 @@
"pre-wrap",
"progress",
"relative",
+ "repeat",
+ "repeat-x",
+ "repeat-y",
"ridge",
"right",
+ "round",
"row",
"row-resize",
"row-reverse",
@@ -134,6 +139,7 @@
"small",
"smaller",
"solid",
+ "space",
"square",
"s-resize",
"static",
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
index b3ce140060..539f1d05ea 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
@@ -612,4 +612,28 @@ Optional<CSS::Overflow> StyleProperties::overflow(CSS::PropertyID property_id) c
}
}
+Optional<CSS::Repeat> StyleProperties::background_repeat() const
+{
+ auto value = property(CSS::PropertyID::BackgroundRepeat);
+ if (!value.has_value())
+ return {};
+
+ switch (value.value()->to_identifier()) {
+ case CSS::ValueID::NoRepeat:
+ return CSS::Repeat::NoRepeat;
+ case CSS::ValueID::Repeat:
+ return CSS::Repeat::Repeat;
+ case CSS::ValueID::RepeatX:
+ return CSS::Repeat::RepeatX;
+ case CSS::ValueID::RepeatY:
+ return CSS::Repeat::RepeatY;
+ case CSS::ValueID::Round:
+ return CSS::Repeat::Round;
+ case CSS::ValueID::Space:
+ return CSS::Repeat::Space;
+ default:
+ return {};
+ }
+}
+
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h
index 4f25e378c4..3bdadf24f1 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h
@@ -73,6 +73,7 @@ public:
Optional<CSS::FlexDirection> flex_direction() const;
Optional<CSS::Overflow> overflow_x() const;
Optional<CSS::Overflow> overflow_y() const;
+ Optional<CSS::Repeat> background_repeat() const;
const Gfx::Font& font() const
{
diff --git a/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp b/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
index c234e42b5f..d8f4dd942d 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
@@ -429,6 +429,8 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
style.set_property(CSS::PropertyID::BackgroundColor, values[0]);
for (auto& value : values) {
+ if (value.is_identifier())
+ set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundRepeat, value, document);
if (!value.is_string())
continue;
auto string = value.to_string();
@@ -456,6 +458,11 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
return;
}
+ if (property_id == CSS::PropertyID::BackgroundRepeat) {
+ style.set_property(CSS::PropertyID::BackgroundRepeat, value);
+ return;
+ }
+
if (property_id == CSS::PropertyID::Margin) {
if (value.is_length()) {
style.set_property(CSS::PropertyID::MarginTop, value);
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 7bacdcb810..aa8997786c 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -189,6 +189,15 @@ enum class Overflow : u8 {
Visible,
};
+enum class Repeat : u8 {
+ NoRepeat,
+ Repeat,
+ RepeatX,
+ RepeatY,
+ Round,
+ Space,
+};
+
class StyleValue : public RefCounted<StyleValue> {
public:
virtual ~StyleValue();
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index b2c1cd4661..44989beba4 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -234,6 +234,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
m_background_image = static_ptr_cast<CSS::ImageStyleValue>(bgimage.value());
}
+ auto background_repeat = specified_style.background_repeat();
+ if (background_repeat.has_value())
+ computed_values.set_background_repeat(background_repeat.value());
+
computed_values.set_display(specified_style.display());
auto flex_direction = specified_style.flex_direction();