CSSGradientValue.h [plain text]
#ifndef CSSGradientValue_h
#define CSSGradientValue_h
#include "CSSImageGeneratorValue.h"
#include "CSSPrimitiveValue.h"
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class FloatPoint;
class Gradient;
enum CSSGradientType { CSSLinearGradient, CSSRadialGradient };
enum CSSGradientRepeat { NonRepeating, Repeating };
struct CSSGradientColorStop {
RefPtr<CSSPrimitiveValue> m_position; RefPtr<CSSPrimitiveValue> m_color;
};
class CSSGradientValue : public CSSImageGeneratorValue {
public:
virtual PassRefPtr<Image> image(RenderObject*, const IntSize&);
void setFirstX(PassRefPtr<CSSPrimitiveValue> val) { m_firstX = val; }
void setFirstY(PassRefPtr<CSSPrimitiveValue> val) { m_firstY = val; }
void setSecondX(PassRefPtr<CSSPrimitiveValue> val) { m_secondX = val; }
void setSecondY(PassRefPtr<CSSPrimitiveValue> val) { m_secondY = val; }
void addStop(const CSSGradientColorStop& stop) { m_stops.append(stop); }
Vector<CSSGradientColorStop>& stops() { return m_stops; }
void sortStopsIfNeeded();
virtual bool isLinearGradient() const { return false; }
virtual bool isRadialGradient() const { return false; }
bool isRepeating() const { return m_repeating; }
bool deprecatedType() const { return m_deprecatedType; }
protected:
CSSGradientValue(CSSGradientRepeat repeat, bool deprecatedType = false)
: m_stopsSorted(false)
, m_deprecatedType(deprecatedType)
, m_repeating(repeat == Repeating)
{
}
void addStops(Gradient*, RenderObject*, RenderStyle* rootStyle, float maxLengthForRepeat = 0);
virtual PassRefPtr<Gradient> createGradient(RenderObject*, const IntSize&) = 0;
FloatPoint computeEndPoint(CSSPrimitiveValue*, CSSPrimitiveValue*, RenderStyle*, RenderStyle* rootStyle, const IntSize&);
bool isCacheable() const;
RefPtr<CSSPrimitiveValue> m_firstX;
RefPtr<CSSPrimitiveValue> m_firstY;
RefPtr<CSSPrimitiveValue> m_secondX;
RefPtr<CSSPrimitiveValue> m_secondY;
Vector<CSSGradientColorStop> m_stops;
bool m_stopsSorted;
bool m_deprecatedType; bool m_repeating;
};
class CSSLinearGradientValue : public CSSGradientValue {
public:
static PassRefPtr<CSSLinearGradientValue> create(CSSGradientRepeat repeat, bool deprecatedType = false)
{
return adoptRef(new CSSLinearGradientValue(repeat, deprecatedType));
}
void setAngle(PassRefPtr<CSSPrimitiveValue> val) { m_angle = val; }
virtual String cssText() const;
private:
CSSLinearGradientValue(CSSGradientRepeat repeat, bool deprecatedType = false)
: CSSGradientValue(repeat, deprecatedType)
{
}
virtual bool isLinearGradient() const { return true; }
virtual PassRefPtr<Gradient> createGradient(RenderObject*, const IntSize&);
RefPtr<CSSPrimitiveValue> m_angle; };
class CSSRadialGradientValue : public CSSGradientValue {
public:
static PassRefPtr<CSSRadialGradientValue> create(CSSGradientRepeat repeat, bool deprecatedType = false)
{
return adoptRef(new CSSRadialGradientValue(repeat, deprecatedType));
}
virtual String cssText() const;
void setFirstRadius(PassRefPtr<CSSPrimitiveValue> val) { m_firstRadius = val; }
void setSecondRadius(PassRefPtr<CSSPrimitiveValue> val) { m_secondRadius = val; }
void setShape(PassRefPtr<CSSPrimitiveValue> val) { m_shape = val; }
void setSizingBehavior(PassRefPtr<CSSPrimitiveValue> val) { m_sizingBehavior = val; }
void setEndHorizontalSize(PassRefPtr<CSSPrimitiveValue> val) { m_endHorizontalSize = val; }
void setEndVerticalSize(PassRefPtr<CSSPrimitiveValue> val) { m_endVerticalSize = val; }
private:
CSSRadialGradientValue(CSSGradientRepeat repeat, bool deprecatedType = false)
: CSSGradientValue(repeat, deprecatedType)
{
}
virtual bool isRadialGradient() const { return true; }
virtual PassRefPtr<Gradient> createGradient(RenderObject*, const IntSize&);
float resolveRadius(CSSPrimitiveValue*, RenderStyle*, RenderStyle* rootStyle, float* widthOrHeight = 0);
RefPtr<CSSPrimitiveValue> m_firstRadius;
RefPtr<CSSPrimitiveValue> m_secondRadius;
RefPtr<CSSPrimitiveValue> m_shape;
RefPtr<CSSPrimitiveValue> m_sizingBehavior;
RefPtr<CSSPrimitiveValue> m_endHorizontalSize;
RefPtr<CSSPrimitiveValue> m_endVerticalSize;
};
}
#endif // CSSGradientValue_h