浏览代码

LibWeb: Resolve 'inherit' property-value somewhat

This doesn't capture the whole picture as shorthands are not considered
in a careful way.
A very dirty hack is included to not try to resolve 'font' as the amount
of debug spam it generated ("No inital value found for...") was
unhelpful.
Tobias Christiansen 3 年之前
父节点
当前提交
548ebbc233
共有 1 个文件被更改,包括 13 次插入2 次删除
  1. 13 2
      Userland/Libraries/LibWeb/CSS/StyleResolver.cpp

+ 13 - 2
Userland/Libraries/LibWeb/CSS/StyleResolver.cpp

@@ -534,8 +534,8 @@ Optional<StyleProperty> StyleResolver::resolve_custom_property(DOM::Element& ele
 NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(DOM::Element& element) const
 {
     auto style = StyleProperties::create();
-
-    if (auto* parent_style = element.parent_element() ? element.parent_element()->specified_css_values() : nullptr) {
+    auto* parent_style = element.parent_element() ? element.parent_element()->specified_css_values() : nullptr;
+    if (parent_style) {
         parent_style->for_each_property([&](auto property_id, auto& value) {
             if (is_inherited_property(property_id))
                 set_property_expanding_shorthands(style, property_id, value, m_document);
@@ -558,6 +558,17 @@ NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(DOM::Element& elemen
                     property_value = resolved.value().value;
                 }
             }
+            // FIXME: This also captures shorthands of which we ideally want to resolve the long names separately.
+            if (property_value->is_inherit()) {
+                // HACK: Trying to resolve the font property here lead to copious amounts of debug-spam
+                if (property.property_id == CSS::PropertyID::Font)
+                    continue;
+                if (parent_style) {
+                    auto maybe_parent_property_value = parent_style->property(property.property_id);
+                    if (maybe_parent_property_value.has_value())
+                        property_value = maybe_parent_property_value.release_value();
+                }
+            }
             set_property_expanding_shorthands(style, property.property_id, property_value, m_document);
         }
     }