#pragma once
#include "CSSPropertyNames.h"
#include "CSSValue.h"
#include "WritingMode.h"
#include <wtf/RefPtr.h>
namespace WebCore {
struct StylePropertyMetadata {
StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, bool important, bool implicit, bool inherited)
: m_propertyID(propertyID)
, m_isSetFromShorthand(isSetFromShorthand)
, m_indexInShorthandsVector(indexInShorthandsVector)
, m_important(important)
, m_implicit(implicit)
, m_inherited(inherited)
{
}
CSSPropertyID shorthandID() const;
bool operator==(const StylePropertyMetadata& other) const
{
return m_propertyID == other.m_propertyID
&& m_isSetFromShorthand == other.m_isSetFromShorthand
&& m_indexInShorthandsVector == other.m_indexInShorthandsVector
&& m_important == other.m_important
&& m_implicit == other.m_implicit
&& m_inherited == other.m_inherited;
}
uint16_t m_propertyID : 10;
uint16_t m_isSetFromShorthand : 1;
uint16_t m_indexInShorthandsVector : 2; uint16_t m_important : 1;
uint16_t m_implicit : 1; uint16_t m_inherited : 1;
};
class CSSProperty {
public:
CSSProperty(CSSPropertyID propertyID, RefPtr<CSSValue>&& value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false)
: m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, isInheritedProperty(propertyID))
, m_value(WTFMove(value))
{
}
CSSPropertyID id() const { return static_cast<CSSPropertyID>(m_metadata.m_propertyID); }
bool isSetFromShorthand() const { return m_metadata.m_isSetFromShorthand; };
CSSPropertyID shorthandID() const { return m_metadata.shorthandID(); };
bool isImportant() const { return m_metadata.m_important; }
CSSValue* value() const { return m_value.get(); }
void wrapValueInCommaSeparatedList();
static CSSPropertyID resolveDirectionAwareProperty(CSSPropertyID, TextDirection, WritingMode);
static bool isInheritedProperty(CSSPropertyID);
static Vector<String> aliasesForProperty(CSSPropertyID);
static bool isDirectionAwareProperty(CSSPropertyID);
static bool isDescriptorOnly(CSSPropertyID);
static bool isColorProperty(CSSPropertyID);
const StylePropertyMetadata& metadata() const { return m_metadata; }
bool operator==(const CSSProperty& other) const
{
if (!(m_metadata == other.m_metadata))
return false;
if (!m_value && !other.m_value)
return true;
if (!m_value || !other.m_value)
return false;
return m_value->equals(*other.m_value);
}
private:
StylePropertyMetadata m_metadata;
RefPtr<CSSValue> m_value;
};
typedef Vector<CSSProperty, 256> ParsedPropertyVector;
}
namespace WTF {
template <> struct VectorTraits<WebCore::CSSProperty> : VectorTraitsBase<false, WebCore::CSSProperty> {
static const bool canInitializeWithMemset = true;
static const bool canMoveWithMemcpy = true;
};
}