1 /* 2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following 13 * disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_BASIC_SHAPE_VALUES_H_ 31 #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_BASIC_SHAPE_VALUES_H_ 32 33 #include "base/memory/scoped_refptr.h" 34 #include "third_party/blink/renderer/core/css/css_primitive_value.h" 35 #include "third_party/blink/renderer/core/css/css_value.h" 36 #include "third_party/blink/renderer/core/css/css_value_pair.h" 37 #include "third_party/blink/renderer/platform/graphics/graphics_types.h" 38 #include "third_party/blink/renderer/platform/wtf/casting.h" 39 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 40 #include "third_party/blink/renderer/platform/wtf/vector.h" 41 42 namespace blink { 43 namespace cssvalue { 44 45 class CSSBasicShapeCircleValue final : public CSSValue { 46 public: CSSBasicShapeCircleValue()47 CSSBasicShapeCircleValue() : CSSValue(kBasicShapeCircleClass) {} 48 49 String CustomCSSText() const; 50 bool Equals(const CSSBasicShapeCircleValue&) const; 51 CenterX()52 CSSValue* CenterX() const { return center_x_.Get(); } CenterY()53 CSSValue* CenterY() const { return center_y_.Get(); } Radius()54 CSSValue* Radius() const { return radius_.Get(); } 55 56 // TODO(sashab): Remove these and pass them as arguments in the constructor. SetCenterX(CSSValue * center_x)57 void SetCenterX(CSSValue* center_x) { center_x_ = center_x; } SetCenterY(CSSValue * center_y)58 void SetCenterY(CSSValue* center_y) { center_y_ = center_y; } SetRadius(CSSValue * radius)59 void SetRadius(CSSValue* radius) { radius_ = radius; } 60 61 void TraceAfterDispatch(blink::Visitor*) const; 62 63 private: 64 Member<CSSValue> center_x_; 65 Member<CSSValue> center_y_; 66 Member<CSSValue> radius_; 67 }; 68 69 class CSSBasicShapeEllipseValue final : public CSSValue { 70 public: CSSBasicShapeEllipseValue()71 CSSBasicShapeEllipseValue() : CSSValue(kBasicShapeEllipseClass) {} 72 73 String CustomCSSText() const; 74 bool Equals(const CSSBasicShapeEllipseValue&) const; 75 CenterX()76 CSSValue* CenterX() const { return center_x_.Get(); } CenterY()77 CSSValue* CenterY() const { return center_y_.Get(); } RadiusX()78 CSSValue* RadiusX() const { return radius_x_.Get(); } RadiusY()79 CSSValue* RadiusY() const { return radius_y_.Get(); } 80 81 // TODO(sashab): Remove these and pass them as arguments in the constructor. SetCenterX(CSSValue * center_x)82 void SetCenterX(CSSValue* center_x) { center_x_ = center_x; } SetCenterY(CSSValue * center_y)83 void SetCenterY(CSSValue* center_y) { center_y_ = center_y; } SetRadiusX(CSSValue * radius_x)84 void SetRadiusX(CSSValue* radius_x) { radius_x_ = radius_x; } SetRadiusY(CSSValue * radius_y)85 void SetRadiusY(CSSValue* radius_y) { radius_y_ = radius_y; } 86 87 void TraceAfterDispatch(blink::Visitor*) const; 88 89 private: 90 Member<CSSValue> center_x_; 91 Member<CSSValue> center_y_; 92 Member<CSSValue> radius_x_; 93 Member<CSSValue> radius_y_; 94 }; 95 96 class CSSBasicShapePolygonValue final : public CSSValue { 97 public: CSSBasicShapePolygonValue()98 CSSBasicShapePolygonValue() 99 : CSSValue(kBasicShapePolygonClass), wind_rule_(RULE_NONZERO) {} 100 AppendPoint(CSSPrimitiveValue * x,CSSPrimitiveValue * y)101 void AppendPoint(CSSPrimitiveValue* x, CSSPrimitiveValue* y) { 102 values_.push_back(x); 103 values_.push_back(y); 104 } 105 GetXAt(unsigned i)106 CSSPrimitiveValue* GetXAt(unsigned i) const { return values_.at(i * 2); } GetYAt(unsigned i)107 CSSPrimitiveValue* GetYAt(unsigned i) const { return values_.at(i * 2 + 1); } Values()108 const HeapVector<Member<CSSPrimitiveValue>>& Values() const { 109 return values_; 110 } 111 112 // TODO(sashab): Remove this and pass it as an argument in the constructor. SetWindRule(WindRule w)113 void SetWindRule(WindRule w) { wind_rule_ = w; } GetWindRule()114 WindRule GetWindRule() const { return wind_rule_; } 115 116 String CustomCSSText() const; 117 bool Equals(const CSSBasicShapePolygonValue&) const; 118 119 void TraceAfterDispatch(blink::Visitor*) const; 120 121 private: 122 HeapVector<Member<CSSPrimitiveValue>> values_; 123 WindRule wind_rule_; 124 }; 125 126 class CSSBasicShapeInsetValue final : public CSSValue { 127 public: CSSBasicShapeInsetValue()128 CSSBasicShapeInsetValue() : CSSValue(kBasicShapeInsetClass) {} 129 Top()130 CSSPrimitiveValue* Top() const { return top_.Get(); } Right()131 CSSPrimitiveValue* Right() const { return right_.Get(); } Bottom()132 CSSPrimitiveValue* Bottom() const { return bottom_.Get(); } Left()133 CSSPrimitiveValue* Left() const { return left_.Get(); } 134 TopLeftRadius()135 CSSValuePair* TopLeftRadius() const { return top_left_radius_.Get(); } TopRightRadius()136 CSSValuePair* TopRightRadius() const { return top_right_radius_.Get(); } BottomRightRadius()137 CSSValuePair* BottomRightRadius() const { return bottom_right_radius_.Get(); } BottomLeftRadius()138 CSSValuePair* BottomLeftRadius() const { return bottom_left_radius_.Get(); } 139 140 // TODO(sashab): Remove these and pass them as arguments in the constructor. SetTop(CSSPrimitiveValue * top)141 void SetTop(CSSPrimitiveValue* top) { top_ = top; } SetRight(CSSPrimitiveValue * right)142 void SetRight(CSSPrimitiveValue* right) { right_ = right; } SetBottom(CSSPrimitiveValue * bottom)143 void SetBottom(CSSPrimitiveValue* bottom) { bottom_ = bottom; } SetLeft(CSSPrimitiveValue * left)144 void SetLeft(CSSPrimitiveValue* left) { left_ = left; } 145 UpdateShapeSize4Values(CSSPrimitiveValue * top,CSSPrimitiveValue * right,CSSPrimitiveValue * bottom,CSSPrimitiveValue * left)146 void UpdateShapeSize4Values(CSSPrimitiveValue* top, 147 CSSPrimitiveValue* right, 148 CSSPrimitiveValue* bottom, 149 CSSPrimitiveValue* left) { 150 SetTop(top); 151 SetRight(right); 152 SetBottom(bottom); 153 SetLeft(left); 154 } 155 UpdateShapeSize1Value(CSSPrimitiveValue * value1)156 void UpdateShapeSize1Value(CSSPrimitiveValue* value1) { 157 UpdateShapeSize4Values(value1, value1, value1, value1); 158 } 159 UpdateShapeSize2Values(CSSPrimitiveValue * value1,CSSPrimitiveValue * value2)160 void UpdateShapeSize2Values(CSSPrimitiveValue* value1, 161 CSSPrimitiveValue* value2) { 162 UpdateShapeSize4Values(value1, value2, value1, value2); 163 } 164 UpdateShapeSize3Values(CSSPrimitiveValue * value1,CSSPrimitiveValue * value2,CSSPrimitiveValue * value3)165 void UpdateShapeSize3Values(CSSPrimitiveValue* value1, 166 CSSPrimitiveValue* value2, 167 CSSPrimitiveValue* value3) { 168 UpdateShapeSize4Values(value1, value2, value3, value2); 169 } 170 SetTopLeftRadius(CSSValuePair * radius)171 void SetTopLeftRadius(CSSValuePair* radius) { top_left_radius_ = radius; } SetTopRightRadius(CSSValuePair * radius)172 void SetTopRightRadius(CSSValuePair* radius) { top_right_radius_ = radius; } SetBottomRightRadius(CSSValuePair * radius)173 void SetBottomRightRadius(CSSValuePair* radius) { 174 bottom_right_radius_ = radius; 175 } SetBottomLeftRadius(CSSValuePair * radius)176 void SetBottomLeftRadius(CSSValuePair* radius) { 177 bottom_left_radius_ = radius; 178 } 179 180 String CustomCSSText() const; 181 bool Equals(const CSSBasicShapeInsetValue&) const; 182 183 void TraceAfterDispatch(blink::Visitor*) const; 184 185 private: 186 Member<CSSPrimitiveValue> top_; 187 Member<CSSPrimitiveValue> right_; 188 Member<CSSPrimitiveValue> bottom_; 189 Member<CSSPrimitiveValue> left_; 190 191 Member<CSSValuePair> top_left_radius_; 192 Member<CSSValuePair> top_right_radius_; 193 Member<CSSValuePair> bottom_right_radius_; 194 Member<CSSValuePair> bottom_left_radius_; 195 }; 196 197 } // namespace cssvalue 198 199 template <> 200 struct DowncastTraits<cssvalue::CSSBasicShapeCircleValue> { 201 static bool AllowFrom(const CSSValue& value) { 202 return value.IsBasicShapeCircleValue(); 203 } 204 }; 205 206 template <> 207 struct DowncastTraits<cssvalue::CSSBasicShapeEllipseValue> { 208 static bool AllowFrom(const CSSValue& value) { 209 return value.IsBasicShapeEllipseValue(); 210 } 211 }; 212 213 template <> 214 struct DowncastTraits<cssvalue::CSSBasicShapePolygonValue> { 215 static bool AllowFrom(const CSSValue& value) { 216 return value.IsBasicShapePolygonValue(); 217 } 218 }; 219 220 template <> 221 struct DowncastTraits<cssvalue::CSSBasicShapeInsetValue> { 222 static bool AllowFrom(const CSSValue& value) { 223 return value.IsBasicShapeInsetValue(); 224 } 225 }; 226 } // namespace blink 227 228 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_BASIC_SHAPE_VALUES_H_ 229