#ifndef CSSValue_h
#define CSSValue_h
#include "core/dom/ExceptionCode.h"
#include "heap/Handle.h"
#include "platform/weborigin/KURL.h"
#include "wtf/HashMap.h"
#include "wtf/ListHashSet.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
namespace WebCore {
class ExceptionState;
class StyleSheetContents;
enum CSSTextFormattingFlags { QuoteCSSStringIfNeeded, AlwaysQuoteCSSString };
class CSSValue : public RefCountedWillBeRefCountedGarbageCollected<CSSValue> {
public:
enum Type {
CSS_INHERIT = 0,
CSS_PRIMITIVE_VALUE = 1,
CSS_VALUE_LIST = 2,
CSS_CUSTOM = 3,
CSS_INITIAL = 4
};
#if !ENABLE(OILPAN)
void deref()
{
if (derefBase())
destroy();
}
#endif
Type cssValueType() const;
String cssText() const;
void setCSSText(const String&, ExceptionState&) { }
bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
bool isValueList() const { return m_classType >= ValueListClass; }
bool isBaseValueList() const { return m_classType == ValueListClass; }
bool isAspectRatioValue() const { return m_classType == AspectRatioClass; }
bool isBorderImageSliceValue() const { return m_classType == BorderImageSliceClass; }
bool isCanvasValue() const { return m_classType == CanvasClass; }
bool isCursorImageValue() const { return m_classType == CursorImageClass; }
bool isCrossfadeValue() const { return m_classType == CrossfadeClass; }
bool isFontFeatureValue() const { return m_classType == FontFeatureClass; }
bool isFontValue() const { return m_classType == FontClass; }
bool isFontFaceSrcValue() const { return m_classType == FontFaceSrcClass; }
bool isFunctionValue() const { return m_classType == FunctionClass; }
bool isImageGeneratorValue() const { return m_classType >= CanvasClass && m_classType <= RadialGradientClass; }
bool isGradientValue() const { return m_classType >= LinearGradientClass && m_classType <= RadialGradientClass; }
bool isImageSetValue() const { return m_classType == ImageSetClass; }
bool isImageValue() const { return m_classType == ImageClass; }
bool isImplicitInitialValue() const;
bool isInheritedValue() const { return m_classType == InheritedClass; }
bool isInitialValue() const { return m_classType == InitialClass; }
bool isLinearGradientValue() const { return m_classType == LinearGradientClass; }
bool isRadialGradientValue() const { return m_classType == RadialGradientClass; }
bool isReflectValue() const { return m_classType == ReflectClass; }
bool isShadowValue() const { return m_classType == ShadowClass; }
bool isTextCloneCSSValue() const { return m_isTextClone; }
bool isCubicBezierTimingFunctionValue() const { return m_classType == CubicBezierTimingFunctionClass; }
bool isStepsTimingFunctionValue() const { return m_classType == StepsTimingFunctionClass; }
bool isTransformValue() const { return m_classType == CSSTransformClass; }
bool isLineBoxContainValue() const { return m_classType == LineBoxContainClass; }
bool isCalcValue() const {return m_classType == CalculationClass; }
bool isFilterValue() const { return m_classType == CSSFilterClass; }
bool isArrayFunctionValue() const { return m_classType == CSSArrayFunctionValueClass; }
bool isGridTemplateAreasValue() const { return m_classType == GridTemplateAreasClass; }
bool isSVGPaint() const { return m_classType == SVGPaintClass; }
bool isSVGDocumentValue() const { return m_classType == CSSSVGDocumentClass; }
bool isUnicodeRangeValue() const { return m_classType == UnicodeRangeClass; }
bool isGridLineNamesValue() const { return m_classType == GridLineNamesClass; }
bool isCSSOMSafe() const { return m_isCSSOMSafe; }
bool isSubtypeExposedToCSSOM() const
{
return isPrimitiveValue() || isSVGPaint() || isValueList();
}
PassRefPtrWillBeRawPtr<CSSValue> cloneForCSSOM() const;
bool hasFailedOrCanceledSubresources() const;
bool equals(const CSSValue&) const;
void finalizeGarbageCollectedObject();
void traceAfterDispatch(Visitor*) { }
void trace(Visitor*);
protected:
static const size_t ClassTypeBits = 6;
enum ClassType {
PrimitiveClass,
ImageClass,
CursorImageClass,
CanvasClass,
CrossfadeClass,
LinearGradientClass,
RadialGradientClass,
CubicBezierTimingFunctionClass,
StepsTimingFunctionClass,
AspectRatioClass,
BorderImageSliceClass,
FontFeatureClass,
FontClass,
FontFaceSrcClass,
FunctionClass,
InheritedClass,
InitialClass,
ReflectClass,
ShadowClass,
UnicodeRangeClass,
LineBoxContainClass,
CalculationClass,
GridTemplateAreasClass,
SVGPaintClass,
CSSSVGDocumentClass,
ValueListClass,
ImageSetClass,
CSSFilterClass,
CSSArrayFunctionValueClass,
CSSTransformClass,
GridLineNamesClass,
};
static const size_t ValueListSeparatorBits = 2;
enum ValueListSeparator {
SpaceSeparator,
CommaSeparator,
SlashSeparator
};
ClassType classType() const { return static_cast<ClassType>(m_classType); }
explicit CSSValue(ClassType classType, bool isCSSOMSafe = false)
: m_isCSSOMSafe(isCSSOMSafe)
, m_isTextClone(false)
, m_primitiveUnitType(0)
, m_hasCachedCSSText(false)
, m_isQuirkValue(false)
, m_valueListSeparator(SpaceSeparator)
, m_classType(classType)
{
}
~CSSValue() { }
private:
void destroy();
protected:
unsigned m_isCSSOMSafe : 1;
unsigned m_isTextClone : 1;
unsigned m_primitiveUnitType : 7;
mutable unsigned m_hasCachedCSSText : 1;
unsigned m_isQuirkValue : 1;
unsigned m_valueListSeparator : ValueListSeparatorBits;
private:
unsigned m_classType : ClassTypeBits;
};
template<typename CSSValueType, size_t inlineCapacity>
inline bool compareCSSValueVector(const WillBeHeapVector<RefPtrWillBeMember<CSSValueType>, inlineCapacity>& firstVector, const WillBeHeapVector<RefPtrWillBeMember<CSSValueType>, inlineCapacity>& secondVector)
{
size_t size = firstVector.size();
if (size != secondVector.size())
return false;
for (size_t i = 0; i < size; i++) {
const RefPtrWillBeMember<CSSValueType>& firstPtr = firstVector[i];
const RefPtrWillBeMember<CSSValueType>& secondPtr = secondVector[i];
if (firstPtr == secondPtr || (firstPtr && secondPtr && firstPtr->equals(*secondPtr)))
continue;
return false;
}
return true;
}
template<typename CSSValueType>
inline bool compareCSSValuePtr(const RefPtr<CSSValueType>& first, const RefPtr<CSSValueType>& second)
{
return first ? second && first->equals(*second) : !second;
}
template<typename CSSValueType>
inline bool compareCSSValuePtr(const RawPtr<CSSValueType>& first, const RawPtr<CSSValueType>& second)
{
return first ? second && first->equals(*second) : !second;
}
template<typename CSSValueType>
inline bool compareCSSValuePtr(const Member<CSSValueType>& first, const Member<CSSValueType>& second)
{
return first ? second && first->equals(*second) : !second;
}
#define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \
DEFINE_TYPE_CASTS(thisType, CSSValue, value, value->predicate, value.predicate)
}
#endif