Files
ladybird/Libraries/LibWeb/CSS/CascadedProperties.h
Callum Law 99c06675cf LibWeb: Combine cascaded property lookups during computation
Previously we would do two cascaded property lookups per property during
style computation - the first to get the value of the property and the
second to check whether it was marked as important. We now do this as a
single lookup to save some unnecessary work.
2026-01-11 14:10:37 +01:00

52 lines
1.6 KiB
C++

/*
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGC/CellAllocator.h>
#include <LibJS/Heap/Cell.h>
#include <LibWeb/CSS/CascadeOrigin.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/CSS/StyleProperty.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {
class CascadedProperties final : public JS::Cell {
GC_CELL(CascadedProperties, JS::Cell);
GC_DECLARE_ALLOCATOR(CascadedProperties);
public:
virtual ~CascadedProperties() override;
[[nodiscard]] RefPtr<StyleValue const> property(PropertyID) const;
[[nodiscard]] GC::Ptr<CSSStyleDeclaration const> property_source(PropertyID) const;
[[nodiscard]] Optional<StyleProperty> style_property(PropertyID) const;
void set_property(PropertyID, NonnullRefPtr<StyleValue const>, Important, CascadeOrigin, Optional<FlyString> layer_name, GC::Ptr<CSS::CSSStyleDeclaration const> source);
void set_property_from_presentational_hint(PropertyID, NonnullRefPtr<StyleValue const>);
void revert_property(PropertyID, Important, CascadeOrigin);
void revert_layer_property(PropertyID, Important, Optional<FlyString> layer_name);
void resolve_unresolved_properties(DOM::AbstractElement);
private:
CascadedProperties();
virtual void visit_edges(Visitor&) override;
struct Entry {
StyleProperty property;
CascadeOrigin origin;
Optional<FlyString> layer_name;
GC::Ptr<CSS::CSSStyleDeclaration const> source;
};
HashMap<PropertyID, Vector<Entry>> m_properties;
};
}