summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-10-29 09:00:30 -0400
committerAndreas Kling <kling@serenityos.org>2021-10-29 22:06:49 +0200
commitef62118c8b1707a4835035ebd04b5891bda9ec13 (patch)
tree832f1240ce71a4e0fde02b7305cef0e6b6384e6e /Userland/Libraries
parenteb0fb38caca5f77e323d1745b6974cd7d6946634 (diff)
downloadserenity-ef62118c8b1707a4835035ebd04b5891bda9ec13.zip
LibWeb: Render any specified list-style-image for list items
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Layout/ListItemBox.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp29
-rw-r--r--Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h1
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.h2
5 files changed, 36 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/ListItemBox.cpp b/Userland/Libraries/LibWeb/Layout/ListItemBox.cpp
index 9f0e121f36..0102d44a6a 100644
--- a/Userland/Libraries/LibWeb/Layout/ListItemBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/ListItemBox.cpp
@@ -40,7 +40,9 @@ void ListItemBox::layout_marker()
}
m_marker->set_offset(-(m_marker->width() + 4), 0);
- m_marker->set_height(line_height());
+
+ if (m_marker->height() > height())
+ set_height(m_marker->height());
}
}
diff --git a/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp b/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp
index 4aca039ed5..efe7efac8c 100644
--- a/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp
@@ -49,13 +49,21 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType
VERIFY_NOT_REACHED();
}
+ int image_width = 0;
+ int image_height = 0;
+ if (auto const* list_style_image = list_style_image_bitmap()) {
+ image_width = list_style_image->rect().width();
+ image_height = list_style_image->rect().height();
+ }
+
if (m_text.is_null()) {
- set_width(4);
- return;
+ set_width(image_width + 4);
+ } else {
+ auto text_width = font().width(m_text);
+ set_width(image_width + text_width);
}
- auto text_width = font().width(m_text);
- set_width(text_width);
+ set_height(max(image_height, line_height()));
}
ListItemMarkerBox::~ListItemMarkerBox()
@@ -67,10 +75,16 @@ void ListItemMarkerBox::paint(PaintContext& context, PaintPhase phase)
if (phase != PaintPhase::Foreground)
return;
+ auto enclosing = enclosing_int_rect(absolute_rect());
+
+ if (auto const* list_style_image = list_style_image_bitmap()) {
+ context.painter().blit(enclosing.location(), *list_style_image, list_style_image->rect());
+ return;
+ }
+
// FIXME: It would be nicer to not have to go via the parent here to get our inherited style.
auto color = parent()->computed_values().color();
- auto enclosing = enclosing_int_rect(absolute_rect());
int marker_width = (int)enclosing.height() / 2;
Gfx::IntRect marker_rect { 0, 0, marker_width, marker_width };
marker_rect.center_within(enclosing);
@@ -110,4 +124,9 @@ void ListItemMarkerBox::paint(PaintContext& context, PaintPhase phase)
}
}
+Gfx::Bitmap const* ListItemMarkerBox::list_style_image_bitmap() const
+{
+ return list_style_image() ? list_style_image()->bitmap() : nullptr;
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h b/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h
index e452d57aca..85e79ef869 100644
--- a/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h
+++ b/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h
@@ -20,6 +20,7 @@ public:
private:
virtual bool can_have_children() const override { return false; }
+ Gfx::Bitmap const* list_style_image_bitmap() const;
CSS::ListStyleType m_list_style_type { CSS::ListStyleType::None };
size_t m_index;
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index 755fa2c36a..6df55962dd 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -320,6 +320,12 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
if (auto list_style_type = specified_style.list_style_type(); list_style_type.has_value())
computed_values.set_list_style_type(list_style_type.value());
+ auto list_style_image = specified_style.property(CSS::PropertyID::ListStyleImage);
+ if (list_style_image.has_value() && list_style_image.value()->is_image()) {
+ m_list_style_image = list_style_image.value()->as_image();
+ m_list_style_image->load_bitmap(document());
+ }
+
computed_values.set_color(specified_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
computed_values.set_background_color(specified_style.color_or_fallback(CSS::PropertyID::BackgroundColor, *this, CSS::InitialValues::background_color()));
diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h
index 014db131d4..0215ecff36 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.h
+++ b/Userland/Libraries/LibWeb/Layout/Node.h
@@ -206,6 +206,7 @@ public:
float line_height() const { return m_line_height; }
float font_size() const { return m_font_size; }
const CSS::ImageStyleValue* background_image() const { return m_background_image; }
+ const CSS::ImageStyleValue* list_style_image() const { return m_list_style_image; }
NonnullRefPtr<NodeWithStyle> create_anonymous_wrapper() const;
@@ -222,6 +223,7 @@ private:
float m_line_height { 0 };
float m_font_size { 0 };
RefPtr<CSS::ImageStyleValue> m_background_image;
+ RefPtr<CSS::ImageStyleValue> m_list_style_image;
bool m_has_definite_height { false };
bool m_has_definite_width { false };