mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:57:45 +00:00
LibWeb: Render any specified list-style-image for list items
This commit is contained in:
parent
eb0fb38cac
commit
ef62118c8b
5 changed files with 37 additions and 7 deletions
|
@ -49,13 +49,21 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (m_text.is_null()) {
|
||||
set_width(4);
|
||||
return;
|
||||
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();
|
||||
}
|
||||
|
||||
auto text_width = font().width(m_text);
|
||||
set_width(text_width);
|
||||
if (m_text.is_null()) {
|
||||
set_width(image_width + 4);
|
||||
} else {
|
||||
auto text_width = font().width(m_text);
|
||||
set_width(image_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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue