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

LibWeb: Convert images to common AbstractImageStyleValue base

This commit moves both the ImageStyleValue and LinearGradientStyleValue
to a common base class of AbstractImageStyleValue. This abstracts
getting the natural_width/height, loading/resolving, and painting
the image.

Now for 'free' you get:

 - Linear gradients working with the various background sizing/repeat
   properties.
 - Linear gradients working as list-markers :^) -- best feature ever!

P.s. This commit is a little large as it's tricky to make this change
incrementally without breaking things.
This commit is contained in:
MacDue 2022-07-31 01:11:59 +01:00 committed by Andreas Kling
parent 264543b90a
commit 6a6475673f
13 changed files with 140 additions and 70 deletions

View file

@ -765,9 +765,9 @@ void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_ite
int image_width = 0;
int image_height = 0;
if (auto const* list_style_image = marker.list_style_image_bitmap()) {
image_width = list_style_image->rect().width();
image_height = list_style_image->rect().height();
if (auto const* list_style_image = marker.list_style_image()) {
image_width = list_style_image->natural_width().value_or(0);
image_height = list_style_image->natural_height().value_or(0);
}
int default_marker_width = max(4, marker.font().glyph_height() - 4);

View file

@ -51,11 +51,6 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType
ListItemMarkerBox::~ListItemMarkerBox() = default;
Gfx::Bitmap const* ListItemMarkerBox::list_style_image_bitmap() const
{
return list_style_image() ? list_style_image()->bitmap() : nullptr;
}
RefPtr<Painting::Paintable> ListItemMarkerBox::create_paintable() const
{
return Painting::MarkerPaintable::create(*this);

View file

@ -16,7 +16,6 @@ public:
explicit ListItemMarkerBox(DOM::Document&, CSS::ListStyleType, size_t index, NonnullRefPtr<CSS::StyleProperties>);
virtual ~ListItemMarkerBox() override;
Gfx::Bitmap const* list_style_image_bitmap() const;
String const& text() const { return m_text; }
virtual RefPtr<Painting::Paintable> create_paintable() const override;

View file

@ -248,11 +248,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
CSS::BackgroundLayerData layer;
if (auto image_value = value_for_layer(images, layer_index); image_value) {
if (image_value->is_image()) {
image_value->as_image().load_bitmap(document());
layer.background_image = image_value;
} else if (image_value->is_linear_gradient()) {
layer.background_image = image_value;
if (image_value->is_abstract_image()) {
layer.background_image = image_value->as_abstract_image();
layer.background_image->load_any_resources(document());
}
}
@ -461,9 +459,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
computed_values.set_list_style_type(list_style_type.value());
auto list_style_image = computed_style.property(CSS::PropertyID::ListStyleImage);
if (list_style_image->is_image()) {
m_list_style_image = list_style_image->as_image();
m_list_style_image->load_bitmap(document());
if (list_style_image->is_abstract_image()) {
m_list_style_image = list_style_image->as_abstract_image();
m_list_style_image->load_any_resources(document());
}
computed_values.set_color(computed_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));

View file

@ -166,7 +166,7 @@ public:
Gfx::Font const& font() const { return *m_font; }
float line_height() const { return m_line_height; }
Vector<CSS::BackgroundLayerData> const& background_layers() const { return computed_values().background_layers(); }
const CSS::ImageStyleValue* list_style_image() const { return m_list_style_image; }
const CSS::AbstractImageStyleValue* list_style_image() const { return m_list_style_image; }
NonnullRefPtr<NodeWithStyle> create_anonymous_wrapper() const;
@ -180,7 +180,7 @@ private:
CSS::ComputedValues m_computed_values;
RefPtr<Gfx::Font> m_font;
float m_line_height { 0 };
RefPtr<CSS::ImageStyleValue> m_list_style_image;
RefPtr<CSS::AbstractImageStyleValue> m_list_style_image;
};
class NodeWithStyleAndBoxModelMetrics : public NodeWithStyle {