LibWeb: Resolve text-decoration-thickness
during layout commit
Refactoring towards stop resolving CSS lengths during paintable commands recording.
This commit is contained in:
parent
d5e3158cfe
commit
0d76a9da17
Notes:
sideshowbarker
2024-07-17 09:49:33 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/0d76a9da17 Pull-request: https://github.com/SerenityOS/serenity/pull/22939 Reviewed-by: https://github.com/awesomekling
3 changed files with 22 additions and 10 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <LibWeb/Layout/Viewport.h>
|
#include <LibWeb/Layout/Viewport.h>
|
||||||
#include <LibWeb/Painting/InlinePaintable.h>
|
#include <LibWeb/Painting/InlinePaintable.h>
|
||||||
#include <LibWeb/Painting/SVGPathPaintable.h>
|
#include <LibWeb/Painting/SVGPathPaintable.h>
|
||||||
|
#include <LibWeb/Painting/TextPaintable.h>
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
|
|
||||||
|
@ -507,8 +508,20 @@ void LayoutState::commit(Box& root)
|
||||||
paintable_with_lines.set_fragments(move(fragments_with_inline_paintables_removed));
|
paintable_with_lines.set_fragments(move(fragments_with_inline_paintables_removed));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto* text_node : text_nodes)
|
for (auto* text_node : text_nodes) {
|
||||||
text_node->set_paintable(text_node->create_paintable());
|
text_node->set_paintable(text_node->create_paintable());
|
||||||
|
auto* paintable = text_node->paintable();
|
||||||
|
auto const& font = text_node->first_available_font();
|
||||||
|
auto const glyph_height = CSSPixels::nearest_value_for(font.pixel_size());
|
||||||
|
auto const css_line_thickness = [&] {
|
||||||
|
auto computed_thickness = text_node->computed_values().text_decoration_thickness().resolved(*text_node, CSS::Length(1, CSS::Length::Type::Em).to_px(*text_node));
|
||||||
|
if (computed_thickness.is_auto())
|
||||||
|
return max(glyph_height.scaled(0.1), 1);
|
||||||
|
return computed_thickness.to_px(*text_node);
|
||||||
|
}();
|
||||||
|
auto& text_paintable = static_cast<Painting::TextPaintable&>(*paintable);
|
||||||
|
text_paintable.set_text_decoration_thickness(css_line_thickness);
|
||||||
|
}
|
||||||
|
|
||||||
build_paint_tree(root);
|
build_paint_tree(root);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <LibWeb/Painting/FilterPainting.h>
|
#include <LibWeb/Painting/FilterPainting.h>
|
||||||
#include <LibWeb/Painting/PaintableBox.h>
|
#include <LibWeb/Painting/PaintableBox.h>
|
||||||
#include <LibWeb/Painting/StackingContext.h>
|
#include <LibWeb/Painting/StackingContext.h>
|
||||||
|
#include <LibWeb/Painting/TextPaintable.h>
|
||||||
#include <LibWeb/Painting/ViewportPaintable.h>
|
#include <LibWeb/Painting/ViewportPaintable.h>
|
||||||
#include <LibWeb/Platform/FontPlugin.h>
|
#include <LibWeb/Platform/FontPlugin.h>
|
||||||
|
|
||||||
|
@ -508,15 +509,8 @@ void paint_text_decoration(PaintContext& context, Layout::Node const& text_node,
|
||||||
auto baseline = fragment.baseline();
|
auto baseline = fragment.baseline();
|
||||||
|
|
||||||
auto line_color = text_node.computed_values().text_decoration_color();
|
auto line_color = text_node.computed_values().text_decoration_color();
|
||||||
|
auto const& text_paintable = static_cast<TextPaintable const&>(fragment.paintable());
|
||||||
CSSPixels css_line_thickness = [&] {
|
auto device_line_thickness = context.rounded_device_pixels(text_paintable.text_decoration_thickness());
|
||||||
CSS::Length computed_thickness = text_node.computed_values().text_decoration_thickness().resolved(text_node, CSS::Length(1, CSS::Length::Type::Em).to_px(text_node));
|
|
||||||
if (computed_thickness.is_auto())
|
|
||||||
return max(glyph_height.scaled(0.1), 1);
|
|
||||||
|
|
||||||
return computed_thickness.to_px(text_node);
|
|
||||||
}();
|
|
||||||
auto device_line_thickness = context.rounded_device_pixels(css_line_thickness);
|
|
||||||
|
|
||||||
auto text_decoration_lines = text_node.computed_values().text_decoration_line();
|
auto text_decoration_lines = text_node.computed_values().text_decoration_line();
|
||||||
for (auto line : text_decoration_lines) {
|
for (auto line : text_decoration_lines) {
|
||||||
|
|
|
@ -24,8 +24,13 @@ public:
|
||||||
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
||||||
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
||||||
|
|
||||||
|
void set_text_decoration_thickness(CSSPixels thickness) { m_text_decoration_thickness = thickness; }
|
||||||
|
CSSPixels text_decoration_thickness() const { return m_text_decoration_thickness; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit TextPaintable(Layout::TextNode const&);
|
explicit TextPaintable(Layout::TextNode const&);
|
||||||
|
|
||||||
|
CSSPixels m_text_decoration_thickness { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue