1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:37:34 +00:00

LibWeb: Store computed CSS value of background-repeat

This commit is contained in:
Timothy Flynn 2021-04-02 15:41:29 -04:00 committed by Andreas Kling
parent fcfeadaffa
commit bd5a91269f
7 changed files with 55 additions and 0 deletions

View file

@ -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; }

View file

@ -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",

View file

@ -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 {};
}
}
}

View file

@ -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
{

View file

@ -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);

View file

@ -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();

View file

@ -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();