blob: 534e43c6f29870a8f6efd080b57dd57c5bb83960 [file] [log] [blame]
/*
* Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef CSSBasicShapeValues_h
#define CSSBasicShapeValues_h
#include "base/memory/scoped_refptr.h"
#include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSValue.h"
#include "core/css/CSSValuePair.h"
#include "platform/graphics/GraphicsTypes.h"
#include "platform/wtf/Vector.h"
#include "platform/wtf/text/WTFString.h"
namespace blink {
class CSSBasicShapeCircleValue final : public CSSValue {
public:
static CSSBasicShapeCircleValue* Create() {
return new CSSBasicShapeCircleValue;
}
String CustomCSSText() const;
bool Equals(const CSSBasicShapeCircleValue&) const;
CSSValue* CenterX() const { return center_x_.Get(); }
CSSValue* CenterY() const { return center_y_.Get(); }
CSSValue* Radius() const { return radius_.Get(); }
// TODO(sashab): Remove these and pass them as arguments in the constructor.
void SetCenterX(CSSValue* center_x) { center_x_ = center_x; }
void SetCenterY(CSSValue* center_y) { center_y_ = center_y; }
void SetRadius(CSSValue* radius) { radius_ = radius; }
void TraceAfterDispatch(blink::Visitor*);
private:
CSSBasicShapeCircleValue() : CSSValue(kBasicShapeCircleClass) {}
Member<CSSValue> center_x_;
Member<CSSValue> center_y_;
Member<CSSValue> radius_;
};
class CSSBasicShapeEllipseValue final : public CSSValue {
public:
static CSSBasicShapeEllipseValue* Create() {
return new CSSBasicShapeEllipseValue;
}
String CustomCSSText() const;
bool Equals(const CSSBasicShapeEllipseValue&) const;
CSSValue* CenterX() const { return center_x_.Get(); }
CSSValue* CenterY() const { return center_y_.Get(); }
CSSValue* RadiusX() const { return radius_x_.Get(); }
CSSValue* RadiusY() const { return radius_y_.Get(); }
// TODO(sashab): Remove these and pass them as arguments in the constructor.
void SetCenterX(CSSValue* center_x) { center_x_ = center_x; }
void SetCenterY(CSSValue* center_y) { center_y_ = center_y; }
void SetRadiusX(CSSValue* radius_x) { radius_x_ = radius_x; }
void SetRadiusY(CSSValue* radius_y) { radius_y_ = radius_y; }
void TraceAfterDispatch(blink::Visitor*);
private:
CSSBasicShapeEllipseValue() : CSSValue(kBasicShapeEllipseClass) {}
Member<CSSValue> center_x_;
Member<CSSValue> center_y_;
Member<CSSValue> radius_x_;
Member<CSSValue> radius_y_;
};
class CSSBasicShapePolygonValue final : public CSSValue {
public:
static CSSBasicShapePolygonValue* Create() {
return new CSSBasicShapePolygonValue;
}
void AppendPoint(CSSPrimitiveValue* x, CSSPrimitiveValue* y) {
values_.push_back(x);
values_.push_back(y);
}
CSSPrimitiveValue* GetXAt(unsigned i) const { return values_.at(i * 2); }
CSSPrimitiveValue* GetYAt(unsigned i) const { return values_.at(i * 2 + 1); }
const HeapVector<Member<CSSPrimitiveValue>>& Values() const {
return values_;
}
// TODO(sashab): Remove this and pass it as an argument in the constructor.
void SetWindRule(WindRule w) { wind_rule_ = w; }
WindRule GetWindRule() const { return wind_rule_; }
String CustomCSSText() const;
bool Equals(const CSSBasicShapePolygonValue&) const;
void TraceAfterDispatch(blink::Visitor*);
private:
CSSBasicShapePolygonValue()
: CSSValue(kBasicShapePolygonClass), wind_rule_(RULE_NONZERO) {}
HeapVector<Member<CSSPrimitiveValue>> values_;
WindRule wind_rule_;
};
class CSSBasicShapeInsetValue final : public CSSValue {
public:
static CSSBasicShapeInsetValue* Create() {
return new CSSBasicShapeInsetValue;
}
CSSPrimitiveValue* Top() const { return top_.Get(); }
CSSPrimitiveValue* Right() const { return right_.Get(); }
CSSPrimitiveValue* Bottom() const { return bottom_.Get(); }
CSSPrimitiveValue* Left() const { return left_.Get(); }
CSSValuePair* TopLeftRadius() const { return top_left_radius_.Get(); }
CSSValuePair* TopRightRadius() const { return top_right_radius_.Get(); }
CSSValuePair* BottomRightRadius() const { return bottom_right_radius_.Get(); }
CSSValuePair* BottomLeftRadius() const { return bottom_left_radius_.Get(); }
// TODO(sashab): Remove these and pass them as arguments in the constructor.
void SetTop(CSSPrimitiveValue* top) { top_ = top; }
void SetRight(CSSPrimitiveValue* right) { right_ = right; }
void SetBottom(CSSPrimitiveValue* bottom) { bottom_ = bottom; }
void SetLeft(CSSPrimitiveValue* left) { left_ = left; }
void UpdateShapeSize4Values(CSSPrimitiveValue* top,
CSSPrimitiveValue* right,
CSSPrimitiveValue* bottom,
CSSPrimitiveValue* left) {
SetTop(top);
SetRight(right);
SetBottom(bottom);
SetLeft(left);
}
void UpdateShapeSize1Value(CSSPrimitiveValue* value1) {
UpdateShapeSize4Values(value1, value1, value1, value1);
}
void UpdateShapeSize2Values(CSSPrimitiveValue* value1,
CSSPrimitiveValue* value2) {
UpdateShapeSize4Values(value1, value2, value1, value2);
}
void UpdateShapeSize3Values(CSSPrimitiveValue* value1,
CSSPrimitiveValue* value2,
CSSPrimitiveValue* value3) {
UpdateShapeSize4Values(value1, value2, value3, value2);
}
void SetTopLeftRadius(CSSValuePair* radius) { top_left_radius_ = radius; }
void SetTopRightRadius(CSSValuePair* radius) { top_right_radius_ = radius; }
void SetBottomRightRadius(CSSValuePair* radius) {
bottom_right_radius_ = radius;
}
void SetBottomLeftRadius(CSSValuePair* radius) {
bottom_left_radius_ = radius;
}
String CustomCSSText() const;
bool Equals(const CSSBasicShapeInsetValue&) const;
void TraceAfterDispatch(blink::Visitor*);
private:
CSSBasicShapeInsetValue() : CSSValue(kBasicShapeInsetClass) {}
Member<CSSPrimitiveValue> top_;
Member<CSSPrimitiveValue> right_;
Member<CSSPrimitiveValue> bottom_;
Member<CSSPrimitiveValue> left_;
Member<CSSValuePair> top_left_radius_;
Member<CSSValuePair> top_right_radius_;
Member<CSSValuePair> bottom_right_radius_;
Member<CSSValuePair> bottom_left_radius_;
};
DEFINE_CSS_VALUE_TYPE_CASTS(CSSBasicShapeCircleValue,
IsBasicShapeCircleValue());
DEFINE_CSS_VALUE_TYPE_CASTS(CSSBasicShapeEllipseValue,
IsBasicShapeEllipseValue());
DEFINE_CSS_VALUE_TYPE_CASTS(CSSBasicShapePolygonValue,
IsBasicShapePolygonValue());
DEFINE_CSS_VALUE_TYPE_CASTS(CSSBasicShapeInsetValue, IsBasicShapeInsetValue());
} // namespace blink
#endif // CSSBasicShapeValues_h