1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +00:00

LibHTML: Anonymous blocks *should* inherit some properties

Okay, I got that a bit wrong. Here's what CSS 2.1 says:

"The properties of anonymous boxes are inherited from the enclosing
non-anonymous box. Non-inherited properties have their initial value."

This patch implements a better behavior by only copying the inherited
properties from the parent style.
This commit is contained in:
Andreas Kling 2019-10-05 23:47:06 +02:00
parent 958b395418
commit 48f43a7429
4 changed files with 19 additions and 2 deletions

View file

@ -1,4 +1,5 @@
#include <LibGUI/GPainter.h>
#include <LibHTML/CSS/StyleResolver.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/Layout/LayoutBlock.h>
#include <LibHTML/Layout/LayoutInline.h>
@ -15,7 +16,7 @@ LayoutBlock::~LayoutBlock()
LayoutNode& LayoutBlock::inline_wrapper()
{
if (!last_child() || !last_child()->is_block() || last_child()->node() != nullptr) {
append_child(adopt(*new LayoutBlock(nullptr, StyleProperties::create())));
append_child(adopt(*new LayoutBlock(nullptr, style_for_anonymous_block())));
}
return *last_child();
}
@ -236,3 +237,15 @@ HitTestResult LayoutBlock::hit_test(const Point& position) const
}
return {};
}
NonnullRefPtr<StyleProperties> LayoutBlock::style_for_anonymous_block() const
{
auto new_style = StyleProperties::create();
style().for_each_property([&](auto& name, auto& value) {
if (StyleResolver::is_inherited_property(name))
new_style->set_property(name, value);
});
return new_style;
}