mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
LibWeb: Add list-style-type: disclosure-{closed,open}
These markers are rendered as equilateral triangles pointing right and down respectively. As we currently don't implement writing-mode the closed marker does not respect it.
This commit is contained in:
parent
ad899b179f
commit
5e3e9b2f61
4 changed files with 41 additions and 0 deletions
|
@ -179,6 +179,8 @@
|
||||||
"decimal",
|
"decimal",
|
||||||
"decimal-leading-zero",
|
"decimal-leading-zero",
|
||||||
"disc",
|
"disc",
|
||||||
|
"disclosure-closed",
|
||||||
|
"disclosure-open",
|
||||||
"lower-alpha",
|
"lower-alpha",
|
||||||
"lower-latin",
|
"lower-latin",
|
||||||
"lower-roman",
|
"lower-roman",
|
||||||
|
|
|
@ -108,6 +108,8 @@
|
||||||
"decimal-leading-zero",
|
"decimal-leading-zero",
|
||||||
"default",
|
"default",
|
||||||
"disc",
|
"disc",
|
||||||
|
"disclosure-closed",
|
||||||
|
"disclosure-open",
|
||||||
"distribute",
|
"distribute",
|
||||||
"dotted",
|
"dotted",
|
||||||
"double",
|
"double",
|
||||||
|
|
|
@ -19,6 +19,8 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType
|
||||||
case CSS::ListStyleType::Square:
|
case CSS::ListStyleType::Square:
|
||||||
case CSS::ListStyleType::Circle:
|
case CSS::ListStyleType::Circle:
|
||||||
case CSS::ListStyleType::Disc:
|
case CSS::ListStyleType::Disc:
|
||||||
|
case CSS::ListStyleType::DisclosureClosed:
|
||||||
|
case CSS::ListStyleType::DisclosureOpen:
|
||||||
break;
|
break;
|
||||||
case CSS::ListStyleType::Decimal:
|
case CSS::ListStyleType::Decimal:
|
||||||
m_text = DeprecatedString::formatted("{}.", m_index);
|
m_text = DeprecatedString::formatted("{}.", m_index);
|
||||||
|
|
|
@ -26,6 +26,8 @@ Layout::ListItemMarkerBox const& MarkerPaintable::layout_box() const
|
||||||
return static_cast<Layout::ListItemMarkerBox const&>(layout_node());
|
return static_cast<Layout::ListItemMarkerBox const&>(layout_node());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr float sin_60_deg = 0.866025403f;
|
||||||
|
|
||||||
void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const
|
void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||||
{
|
{
|
||||||
if (phase != PaintPhase::Foreground)
|
if (phase != PaintPhase::Foreground)
|
||||||
|
@ -55,6 +57,11 @@ void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||||
marker_rect.center_within(enclosing);
|
marker_rect.center_within(enclosing);
|
||||||
auto device_marker_rect = context.enclosing_device_rect(marker_rect);
|
auto device_marker_rect = context.enclosing_device_rect(marker_rect);
|
||||||
|
|
||||||
|
float left = device_marker_rect.x().value();
|
||||||
|
float right = left + device_marker_rect.width().value();
|
||||||
|
float top = device_marker_rect.y().value();
|
||||||
|
float bottom = top + device_marker_rect.height().value();
|
||||||
|
|
||||||
auto color = computed_values().color();
|
auto color = computed_values().color();
|
||||||
|
|
||||||
Gfx::AntiAliasingPainter aa_painter { context.painter() };
|
Gfx::AntiAliasingPainter aa_painter { context.painter() };
|
||||||
|
@ -69,6 +76,34 @@ void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||||
case CSS::ListStyleType::Disc:
|
case CSS::ListStyleType::Disc:
|
||||||
aa_painter.fill_ellipse(device_marker_rect.to_type<int>(), color);
|
aa_painter.fill_ellipse(device_marker_rect.to_type<int>(), color);
|
||||||
break;
|
break;
|
||||||
|
case CSS::ListStyleType::DisclosureClosed: {
|
||||||
|
// https://drafts.csswg.org/css-counter-styles-3/#disclosure-closed
|
||||||
|
// For the disclosure-open and disclosure-closed counter styles, the marker must be an image or character suitable for indicating the open and closed states of a disclosure widget, such as HTML’s details element.
|
||||||
|
// FIXME: If the image is directional, it must respond to the writing mode of the element, similar to the bidi-sensitive images feature of the Images 4 module.
|
||||||
|
|
||||||
|
// Draw an equilateral triangle pointing right.
|
||||||
|
auto path = Gfx::Path();
|
||||||
|
path.move_to({ left, top });
|
||||||
|
path.line_to({ left + sin_60_deg * (right - left), (top + bottom) / 2 });
|
||||||
|
path.line_to({ left, bottom });
|
||||||
|
path.close();
|
||||||
|
aa_painter.fill_path(path, color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CSS::ListStyleType::DisclosureOpen: {
|
||||||
|
// https://drafts.csswg.org/css-counter-styles-3/#disclosure-open
|
||||||
|
// For the disclosure-open and disclosure-closed counter styles, the marker must be an image or character suitable for indicating the open and closed states of a disclosure widget, such as HTML’s details element.
|
||||||
|
// FIXME: If the image is directional, it must respond to the writing mode of the element, similar to the bidi-sensitive images feature of the Images 4 module.
|
||||||
|
|
||||||
|
// Draw an equilateral triangle pointing down.
|
||||||
|
auto path = Gfx::Path();
|
||||||
|
path.move_to({ left, top });
|
||||||
|
path.line_to({ right, top });
|
||||||
|
path.line_to({ (left + right) / 2, top + sin_60_deg * (bottom - top) });
|
||||||
|
path.close();
|
||||||
|
aa_painter.fill_path(path, color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case CSS::ListStyleType::Decimal:
|
case CSS::ListStyleType::Decimal:
|
||||||
case CSS::ListStyleType::DecimalLeadingZero:
|
case CSS::ListStyleType::DecimalLeadingZero:
|
||||||
case CSS::ListStyleType::LowerAlpha:
|
case CSS::ListStyleType::LowerAlpha:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue