1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:17:42 +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

@ -78,7 +78,7 @@ NonnullRefPtrVector<StyleRule> StyleResolver::collect_matching_rules(const Eleme
return matching_rules;
}
static bool is_inherited_property(const StringView& name)
bool StyleResolver::is_inherited_property(const StringView& name)
{
static HashTable<String> inherited_properties;
if (inherited_properties.is_empty()) {

View file

@ -22,6 +22,8 @@ public:
NonnullRefPtrVector<StyleRule> collect_matching_rules(const Element&) const;
static bool is_inherited_property(const StringView&);
private:
template<typename Callback>
void for_each_stylesheet(Callback) const;

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;
}

View file

@ -27,6 +27,8 @@ public:
private:
virtual bool is_block() const override { return true; }
NonnullRefPtr<StyleProperties> style_for_anonymous_block() const;
void layout_inline_children();
void layout_block_children();