#pragma once
#include "CascadeLevel.h"
#include "ElementRuleCollector.h"
#include "StyleBuilderState.h"
#include <bitset>
namespace WebCore {
class StyleResolver;
namespace Style {
class PropertyCascade {
WTF_MAKE_FAST_ALLOCATED;
public:
enum IncludedProperties { All, InheritedOnly };
struct Direction {
TextDirection textDirection;
WritingMode writingMode;
};
PropertyCascade(const MatchResult&, OptionSet<CascadeLevel>, IncludedProperties, Direction);
PropertyCascade(const PropertyCascade&, OptionSet<CascadeLevel>);
~PropertyCascade();
struct Property {
CSSPropertyID id;
CascadeLevel level;
ScopeOrdinal styleScopeOrdinal;
CSSValue* cssValue[3]; };
bool hasProperty(CSSPropertyID) const;
const Property& property(CSSPropertyID) const;
bool hasCustomProperty(const String&) const;
Property customProperty(const String&) const;
const Vector<Property, 8>& deferredProperties() const { return m_deferredProperties; }
const HashMap<AtomString, Property>& customProperties() const { return m_customProperties; }
Direction direction() const;
const PropertyCascade* propertyCascadeForRollback(CascadeLevel) const;
private:
void buildCascade(OptionSet<CascadeLevel>);
bool addNormalMatches(CascadeLevel);
void addImportantMatches(CascadeLevel);
bool addMatch(const MatchedProperties&, CascadeLevel, bool important);
void set(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
void setDeferred(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
static void setPropertyInternal(Property&, CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
Direction resolveDirectionAndWritingMode(Direction inheritedDirection) const;
const MatchResult& m_matchResult;
const IncludedProperties m_includedProperties;
mutable Direction m_direction;
mutable bool m_directionIsUnresolved { true };
Property m_properties[numCSSProperties + 2];
std::bitset<numCSSProperties + 2> m_propertyIsPresent;
Vector<Property, 8> m_deferredProperties;
HashMap<AtomString, Property> m_customProperties;
mutable std::unique_ptr<const PropertyCascade> m_authorRollbackCascade;
mutable std::unique_ptr<const PropertyCascade> m_userRollbackCascade;
};
inline bool PropertyCascade::hasProperty(CSSPropertyID id) const
{
ASSERT(id < m_propertyIsPresent.size());
return m_propertyIsPresent[id];
}
inline const PropertyCascade::Property& PropertyCascade::property(CSSPropertyID id) const
{
return m_properties[id];
}
inline bool PropertyCascade::hasCustomProperty(const String& name) const
{
return m_customProperties.contains(name);
}
inline PropertyCascade::Property PropertyCascade::customProperty(const String& name) const
{
return m_customProperties.get(name);
}
}
}