mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
LibWeb: Rename CSS::StyleResolver => StyleComputer
Resolved style is a spec concept that refers to the weird mix of computed style and used style reflected by getComputedStyle(). The purpose of this class is to produce the *computed* style for a given element, so let's call it StyleComputer.
This commit is contained in:
parent
3dc6f0bc47
commit
f8dd3e14ba
22 changed files with 59 additions and 59 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
||||
|
@ -555,7 +555,7 @@ Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID propert
|
|||
const_cast<DOM::Document&>(m_element->document()).ensure_layout();
|
||||
|
||||
if (!m_element->layout_node()) {
|
||||
auto style = m_element->document().style_resolver().resolve_style(const_cast<DOM::Element&>(*m_element));
|
||||
auto style = m_element->document().style_computer().compute_style(const_cast<DOM::Element&>(*m_element));
|
||||
if (auto maybe_property = style->property(property_id); maybe_property.has_value()) {
|
||||
return StyleProperty {
|
||||
.property_id = property_id,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <LibWeb/CSS/CSSStyleRule.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/SelectorEngine.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/CSS/StyleSheet.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
@ -24,12 +24,12 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
StyleResolver::StyleResolver(DOM::Document& document)
|
||||
StyleComputer::StyleComputer(DOM::Document& document)
|
||||
: m_document(document)
|
||||
{
|
||||
}
|
||||
|
||||
StyleResolver::~StyleResolver()
|
||||
StyleComputer::~StyleComputer()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ static StyleSheet& quirks_mode_stylesheet()
|
|||
}
|
||||
|
||||
template<typename Callback>
|
||||
void StyleResolver::for_each_stylesheet(CascadeOrigin cascade_origin, Callback callback) const
|
||||
void StyleComputer::for_each_stylesheet(CascadeOrigin cascade_origin, Callback callback) const
|
||||
{
|
||||
if (cascade_origin == CascadeOrigin::Any || cascade_origin == CascadeOrigin::UserAgent) {
|
||||
callback(default_stylesheet());
|
||||
|
@ -70,7 +70,7 @@ void StyleResolver::for_each_stylesheet(CascadeOrigin cascade_origin, Callback c
|
|||
}
|
||||
}
|
||||
|
||||
Vector<MatchingRule> StyleResolver::collect_matching_rules(DOM::Element const& element, CascadeOrigin declaration_type) const
|
||||
Vector<MatchingRule> StyleComputer::collect_matching_rules(DOM::Element const& element, CascadeOrigin declaration_type) const
|
||||
{
|
||||
Vector<MatchingRule> matching_rules;
|
||||
|
||||
|
@ -94,7 +94,7 @@ Vector<MatchingRule> StyleResolver::collect_matching_rules(DOM::Element const& e
|
|||
return matching_rules;
|
||||
}
|
||||
|
||||
void StyleResolver::sort_matching_rules(Vector<MatchingRule>& matching_rules) const
|
||||
void StyleComputer::sort_matching_rules(Vector<MatchingRule>& matching_rules) const
|
||||
{
|
||||
quick_sort(matching_rules, [&](MatchingRule& a, MatchingRule& b) {
|
||||
auto& a_selector = a.rule->selectors()[a.selector_index];
|
||||
|
@ -473,7 +473,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
style.set_property(property_id, value);
|
||||
}
|
||||
|
||||
StyleResolver::CustomPropertyResolutionTuple StyleResolver::resolve_custom_property_with_specificity(DOM::Element& element, String const& custom_property_name) const
|
||||
StyleComputer::CustomPropertyResolutionTuple StyleComputer::resolve_custom_property_with_specificity(DOM::Element& element, String const& custom_property_name) const
|
||||
{
|
||||
if (auto maybe_property = element.resolve_custom_property(custom_property_name); maybe_property.has_value())
|
||||
return maybe_property.value();
|
||||
|
@ -501,7 +501,7 @@ StyleResolver::CustomPropertyResolutionTuple StyleResolver::resolve_custom_prope
|
|||
return parent_resolved;
|
||||
}
|
||||
|
||||
Optional<StyleProperty> StyleResolver::resolve_custom_property(DOM::Element& element, String const& custom_property_name) const
|
||||
Optional<StyleProperty> StyleComputer::resolve_custom_property(DOM::Element& element, String const& custom_property_name) const
|
||||
{
|
||||
auto resolved_with_specificity = resolve_custom_property_with_specificity(element, custom_property_name);
|
||||
|
||||
|
@ -513,7 +513,7 @@ struct MatchingDeclarations {
|
|||
Vector<MatchingRule> author_rules;
|
||||
};
|
||||
|
||||
void StyleResolver::cascade_declarations(StyleProperties& style, DOM::Element& element, Vector<MatchingRule> const& matching_rules, CascadeOrigin cascade_origin, bool important) const
|
||||
void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& element, Vector<MatchingRule> const& matching_rules, CascadeOrigin cascade_origin, bool important) const
|
||||
{
|
||||
for (auto& match : matching_rules) {
|
||||
for (auto& property : verify_cast<PropertyOwningCSSStyleDeclaration>(match.rule->declaration()).properties()) {
|
||||
|
@ -543,7 +543,7 @@ void StyleResolver::cascade_declarations(StyleProperties& style, DOM::Element& e
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/css-cascade/#cascading
|
||||
void StyleResolver::compute_cascaded_values(StyleProperties& style, DOM::Element& element) const
|
||||
void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element& element) const
|
||||
{
|
||||
// First, we collect all the CSS rules whose selectors match `element`:
|
||||
MatchingRuleSet matching_rule_set;
|
||||
|
@ -596,7 +596,7 @@ static NonnullRefPtr<StyleValue> get_inherit_value(CSS::PropertyID property_id,
|
|||
return *it->value;
|
||||
};
|
||||
|
||||
void StyleResolver::compute_defaulted_property_value(StyleProperties& style, DOM::Element const* element, CSS::PropertyID property_id) const
|
||||
void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM::Element const* element, CSS::PropertyID property_id) const
|
||||
{
|
||||
// FIXME: If we don't know the correct initial value for a property, we fall back to InitialStyleValue.
|
||||
|
||||
|
@ -621,7 +621,7 @@ void StyleResolver::compute_defaulted_property_value(StyleProperties& style, DOM
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/css-cascade/#defaulting
|
||||
void StyleResolver::compute_defaulted_values(StyleProperties& style, DOM::Element const* element) const
|
||||
void StyleComputer::compute_defaulted_values(StyleProperties& style, DOM::Element const* element) const
|
||||
{
|
||||
// Walk the list of all known CSS properties and:
|
||||
// - Add them to `style` if they are missing.
|
||||
|
@ -632,7 +632,7 @@ void StyleResolver::compute_defaulted_values(StyleProperties& style, DOM::Elemen
|
|||
}
|
||||
}
|
||||
|
||||
void StyleResolver::compute_font(StyleProperties& style, DOM::Element const* element) const
|
||||
void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* element) const
|
||||
{
|
||||
// To compute the font, first ensure that we've defaulted the relevant CSS font properties.
|
||||
// FIXME: This should be more sophisticated.
|
||||
|
@ -810,7 +810,7 @@ void StyleResolver::compute_font(StyleProperties& style, DOM::Element const* ele
|
|||
style.set_computed_font(found_font.release_nonnull());
|
||||
}
|
||||
|
||||
void StyleResolver::absolutize_values(StyleProperties& style, DOM::Element const*) const
|
||||
void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const*) const
|
||||
{
|
||||
auto viewport_rect = document().browsing_context()->viewport_rect();
|
||||
auto font_metrics = style.computed_font().metrics('M');
|
||||
|
@ -827,7 +827,7 @@ void StyleResolver::absolutize_values(StyleProperties& style, DOM::Element const
|
|||
}
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleProperties> StyleResolver::create_document_style() const
|
||||
NonnullRefPtr<StyleProperties> StyleComputer::create_document_style() const
|
||||
{
|
||||
auto style = StyleProperties::create();
|
||||
compute_font(style, nullptr);
|
||||
|
@ -836,7 +836,7 @@ NonnullRefPtr<StyleProperties> StyleResolver::create_document_style() const
|
|||
return style;
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(DOM::Element& element) const
|
||||
NonnullRefPtr<StyleProperties> StyleComputer::compute_style(DOM::Element& element) const
|
||||
{
|
||||
auto style = StyleProperties::create();
|
||||
// 1. Perform the cascade. This produces the "specified style"
|
|
@ -22,16 +22,16 @@ struct MatchingRule {
|
|||
u32 specificity { 0 };
|
||||
};
|
||||
|
||||
class StyleResolver {
|
||||
class StyleComputer {
|
||||
public:
|
||||
explicit StyleResolver(DOM::Document&);
|
||||
~StyleResolver();
|
||||
explicit StyleComputer(DOM::Document&);
|
||||
~StyleComputer();
|
||||
|
||||
DOM::Document& document() { return m_document; }
|
||||
DOM::Document const& document() const { return m_document; }
|
||||
|
||||
NonnullRefPtr<StyleProperties> create_document_style() const;
|
||||
NonnullRefPtr<StyleProperties> resolve_style(DOM::Element&) const;
|
||||
NonnullRefPtr<StyleProperties> compute_style(DOM::Element&) const;
|
||||
|
||||
// https://www.w3.org/TR/css-cascade/#origin
|
||||
enum class CascadeOrigin {
|
|
@ -16,9 +16,9 @@ StyleInvalidator::StyleInvalidator(DOM::Document& document)
|
|||
{
|
||||
if (!m_document.should_invalidate_styles_on_attribute_changes())
|
||||
return;
|
||||
auto& style_resolver = m_document.style_resolver();
|
||||
auto& style_computer = m_document.style_computer();
|
||||
m_document.for_each_in_inclusive_subtree_of_type<DOM::Element>([&](auto& element) {
|
||||
m_elements_and_matching_rules_before.set(&element, style_resolver.collect_matching_rules(element));
|
||||
m_elements_and_matching_rules_before.set(&element, style_computer.collect_matching_rules(element));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ StyleInvalidator::~StyleInvalidator()
|
|||
{
|
||||
if (!m_document.should_invalidate_styles_on_attribute_changes())
|
||||
return;
|
||||
auto& style_resolver = m_document.style_resolver();
|
||||
auto& style_computer = m_document.style_computer();
|
||||
m_document.for_each_in_inclusive_subtree_of_type<DOM::Element>([&](auto& element) {
|
||||
auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element);
|
||||
if (!maybe_matching_rules_before.has_value()) {
|
||||
|
@ -35,13 +35,13 @@ StyleInvalidator::~StyleInvalidator()
|
|||
return IterationDecision::Continue;
|
||||
}
|
||||
auto& matching_rules_before = maybe_matching_rules_before.value();
|
||||
auto matching_rules_after = style_resolver.collect_matching_rules(element);
|
||||
auto matching_rules_after = style_computer.collect_matching_rules(element);
|
||||
if (matching_rules_before.size() != matching_rules_after.size()) {
|
||||
element.set_needs_style_update(true);
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
style_resolver.sort_matching_rules(matching_rules_before);
|
||||
style_resolver.sort_matching_rules(matching_rules_after);
|
||||
style_computer.sort_matching_rules(matching_rules_before);
|
||||
style_computer.sort_matching_rules(matching_rules_after);
|
||||
for (size_t i = 0; i < matching_rules_before.size(); ++i) {
|
||||
if (matching_rules_before[i].rule != matching_rules_after[i].rule) {
|
||||
element.set_needs_style_update(true);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
static NonnullRefPtr<Gfx::Font> font_fallback(bool monospace, bool bold);
|
||||
|
||||
private:
|
||||
friend class StyleResolver;
|
||||
friend class StyleComputer;
|
||||
|
||||
HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>> m_property_values;
|
||||
Optional<CSS::Overflow> overflow(CSS::PropertyID) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue