mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-21 16:32:34 +00:00
While 788d5368a7
took care of better text
marker positioning, this improves graphical marker positioning instead.
By looking at how Firefox and Chrome render markers, it's clear that
there are three parts to positioning a graphical marker:
* The containing space that the marker resides in;
* The marker dimensions;
* The distance between the marker and the start of the list item.
The space that the marker can be contained in, is the area to the left
of the list item with a height of the marker's line-height. The marker
dimensions are relative to the marker's font's pixel size: most of them
are a square at 35% of the font size, but the disclosure markers are
sized at 50% instead. Finally, the marker distance is always gauged at
50% of the font size.
So for example, a list item with `list-style-type: disc` and `font-size:
20px`, has 10px between its start and the right side of the marker, and
the marker's dimensions are 7x7.
The percentages I've chosen closely resemble how Firefox lays out its
list item markers.
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/Layout/Box.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
class ListItemMarkerBox final : public Box {
|
|
GC_CELL(ListItemMarkerBox, Box);
|
|
GC_DECLARE_ALLOCATOR(ListItemMarkerBox);
|
|
|
|
public:
|
|
explicit ListItemMarkerBox(DOM::Document&, CSS::ListStyleType, CSS::ListStylePosition, GC::Ref<DOM::Element>, GC::Ref<CSS::ComputedProperties>);
|
|
virtual ~ListItemMarkerBox() override;
|
|
|
|
Optional<String> text() const;
|
|
|
|
virtual GC::Ptr<Painting::Paintable> create_paintable() const override;
|
|
|
|
CSS::ListStyleType const& list_style_type() const { return m_list_style_type; }
|
|
CSS::ListStylePosition list_style_position() const { return m_list_style_position; }
|
|
|
|
CSSPixels relative_size() const;
|
|
|
|
private:
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
virtual bool is_list_item_marker_box() const final { return true; }
|
|
virtual bool can_have_children() const override { return false; }
|
|
|
|
CSS::ListStyleType m_list_style_type { CSS::CounterStyleNameKeyword::None };
|
|
CSS::ListStylePosition m_list_style_position { CSS::ListStylePosition::Outside };
|
|
GC::Ref<DOM::Element> m_list_item_element;
|
|
};
|
|
|
|
template<>
|
|
inline bool Node::fast_is<ListItemMarkerBox>() const { return is_list_item_marker_box(); }
|
|
|
|
}
|