mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:37:34 +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:
parent
958b395418
commit
48f43a7429
4 changed files with 19 additions and 2 deletions
|
@ -78,7 +78,7 @@ NonnullRefPtrVector<StyleRule> StyleResolver::collect_matching_rules(const Eleme
|
||||||
return matching_rules;
|
return matching_rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_inherited_property(const StringView& name)
|
bool StyleResolver::is_inherited_property(const StringView& name)
|
||||||
{
|
{
|
||||||
static HashTable<String> inherited_properties;
|
static HashTable<String> inherited_properties;
|
||||||
if (inherited_properties.is_empty()) {
|
if (inherited_properties.is_empty()) {
|
||||||
|
|
|
@ -22,6 +22,8 @@ public:
|
||||||
|
|
||||||
NonnullRefPtrVector<StyleRule> collect_matching_rules(const Element&) const;
|
NonnullRefPtrVector<StyleRule> collect_matching_rules(const Element&) const;
|
||||||
|
|
||||||
|
static bool is_inherited_property(const StringView&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void for_each_stylesheet(Callback) const;
|
void for_each_stylesheet(Callback) const;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <LibGUI/GPainter.h>
|
#include <LibGUI/GPainter.h>
|
||||||
|
#include <LibHTML/CSS/StyleResolver.h>
|
||||||
#include <LibHTML/DOM/Element.h>
|
#include <LibHTML/DOM/Element.h>
|
||||||
#include <LibHTML/Layout/LayoutBlock.h>
|
#include <LibHTML/Layout/LayoutBlock.h>
|
||||||
#include <LibHTML/Layout/LayoutInline.h>
|
#include <LibHTML/Layout/LayoutInline.h>
|
||||||
|
@ -15,7 +16,7 @@ LayoutBlock::~LayoutBlock()
|
||||||
LayoutNode& LayoutBlock::inline_wrapper()
|
LayoutNode& LayoutBlock::inline_wrapper()
|
||||||
{
|
{
|
||||||
if (!last_child() || !last_child()->is_block() || last_child()->node() != nullptr) {
|
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();
|
return *last_child();
|
||||||
}
|
}
|
||||||
|
@ -236,3 +237,15 @@ HitTestResult LayoutBlock::hit_test(const Point& position) const
|
||||||
}
|
}
|
||||||
return {};
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual bool is_block() const override { return true; }
|
virtual bool is_block() const override { return true; }
|
||||||
|
|
||||||
|
NonnullRefPtr<StyleProperties> style_for_anonymous_block() const;
|
||||||
|
|
||||||
void layout_inline_children();
|
void layout_inline_children();
|
||||||
void layout_block_children();
|
void layout_block_children();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue