Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: Source/core/css/BasicShapeFunctions.cpp

Issue 103413006: Implement parsing of the new ellipse shape syntax. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 15 matching lines...) Expand all
26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 */ 28 */
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "core/css/BasicShapeFunctions.h" 31 #include "core/css/BasicShapeFunctions.h"
32 32
33 #include "core/css/CSSBasicShapes.h" 33 #include "core/css/CSSBasicShapes.h"
34 #include "core/css/CSSPrimitiveValueMappings.h" 34 #include "core/css/CSSPrimitiveValueMappings.h"
35 #include "core/css/CSSValuePool.h" 35 #include "core/css/CSSValuePool.h"
36 #include "core/css/Pair.h"
36 #include "core/css/resolver/StyleResolverState.h" 37 #include "core/css/resolver/StyleResolverState.h"
37 #include "core/rendering/style/BasicShapes.h" 38 #include "core/rendering/style/BasicShapes.h"
38 #include "core/rendering/style/RenderStyle.h" 39 #include "core/rendering/style/RenderStyle.h"
39 40
40 namespace WebCore { 41 namespace WebCore {
41 42
43 static PassRefPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSValuePool& pool , const RenderStyle& style, const BasicShapeCenterCoordinate& center)
44 {
45 CSSValueID keyword = CSSValueInvalid;
46 switch (center.keyword()) {
47 case BasicShapeCenterCoordinate::None:
48 return pool.createValue(center.length(), style);
49 case BasicShapeCenterCoordinate::Top:
50 keyword = CSSValueTop;
51 break;
52 case BasicShapeCenterCoordinate::Right:
53 keyword = CSSValueRight;
54 break;
55 case BasicShapeCenterCoordinate::Bottom:
56 keyword = CSSValueBottom;
57 break;
58 case BasicShapeCenterCoordinate::Left:
59 keyword = CSSValueLeft;
60 break;
61 }
62
63 return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), po ol.createValue(center.length(), style), Pair::DropIdenticalValues));
64 }
65
66 static PassRefPtr<CSSPrimitiveValue> basicShapeRadiusToCSSValue(CSSValuePool& po ol, const RenderStyle& style, const BasicShapeRadius& radius)
67 {
68 switch (radius.type()) {
69 case BasicShapeRadius::Value:
70 return pool.createValue(radius.value(), style);
71 case BasicShapeRadius::ClosestSide:
72 return pool.createIdentifierValue(CSSValueClosestSide);
73 case BasicShapeRadius::FarthestSide:
74 return pool.createIdentifierValue(CSSValueFarthestSide);
75 }
76
77 ASSERT_NOT_REACHED();
78 return 0;
79 }
80
42 PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha pe* basicShape) 81 PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha pe* basicShape)
43 { 82 {
44 CSSValuePool& pool = cssValuePool(); 83 CSSValuePool& pool = cssValuePool();
45 84
46 RefPtr<CSSBasicShape> basicShapeValue; 85 RefPtr<CSSBasicShape> basicShapeValue;
47 switch (basicShape->type()) { 86 switch (basicShape->type()) {
48 case BasicShape::BasicShapeRectangleType: { 87 case BasicShape::BasicShapeRectangleType: {
49 const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRecta ngle*>(basicShape); 88 const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRecta ngle*>(basicShape);
50 RefPtr<CSSBasicShapeRectangle> rectangleValue = CSSBasicShapeRectangle:: create(); 89 RefPtr<CSSBasicShapeRectangle> rectangleValue = CSSBasicShapeRectangle:: create();
51 90
52 rectangleValue->setX(pool.createValue(rectangle->x(), style)); 91 rectangleValue->setX(pool.createValue(rectangle->x(), style));
53 rectangleValue->setY(pool.createValue(rectangle->y(), style)); 92 rectangleValue->setY(pool.createValue(rectangle->y(), style));
54 rectangleValue->setWidth(pool.createValue(rectangle->width(), style)); 93 rectangleValue->setWidth(pool.createValue(rectangle->width(), style));
55 rectangleValue->setHeight(pool.createValue(rectangle->height(), style)); 94 rectangleValue->setHeight(pool.createValue(rectangle->height(), style));
56 rectangleValue->setRadiusX(pool.createValue(rectangle->cornerRadiusX(), style)); 95 rectangleValue->setRadiusX(pool.createValue(rectangle->cornerRadiusX(), style));
57 rectangleValue->setRadiusY(pool.createValue(rectangle->cornerRadiusY(), style)); 96 rectangleValue->setRadiusY(pool.createValue(rectangle->cornerRadiusY(), style));
58 97
59 basicShapeValue = rectangleValue.release(); 98 basicShapeValue = rectangleValue.release();
60 break; 99 break;
61 } 100 }
62 case BasicShape::BasicShapeCircleType: { 101 case BasicShape::DeprecatedBasicShapeCircleType: {
63 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba sicShape); 102 const DeprecatedBasicShapeCircle* circle = static_cast<const DeprecatedB asicShapeCircle*>(basicShape);
64 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create(); 103 RefPtr<CSSDeprecatedBasicShapeCircle> circleValue = CSSDeprecatedBasicSh apeCircle::create();
65 104
66 circleValue->setCenterX(pool.createValue(circle->centerX(), style)); 105 circleValue->setCenterX(pool.createValue(circle->centerX(), style));
67 circleValue->setCenterY(pool.createValue(circle->centerY(), style)); 106 circleValue->setCenterY(pool.createValue(circle->centerY(), style));
68 circleValue->setRadius(pool.createValue(circle->radius(), style)); 107 circleValue->setRadius(pool.createValue(circle->radius(), style));
69 108
70 basicShapeValue = circleValue.release(); 109 basicShapeValue = circleValue.release();
71 break; 110 break;
72 } 111 }
73 case BasicShape::BasicShapeEllipseType: { 112 case BasicShape::BasicShapeCircleType: {
74 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*> (basicShape); 113 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba sicShape);
75 RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create (); 114 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create();
115
116 circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->ce nterX()));
117 circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->ce nterY()));
118 circleValue->setRadius(basicShapeRadiusToCSSValue(pool, style, circle->r adius()));
119 basicShapeValue = circleValue.release();
120 break;
121 }
122 case BasicShape::DeprecatedBasicShapeEllipseType: {
123 const DeprecatedBasicShapeEllipse* ellipse = static_cast<const Deprecate dBasicShapeEllipse*>(basicShape);
124 RefPtr<CSSDeprecatedBasicShapeEllipse> ellipseValue = CSSDeprecatedBasic ShapeEllipse::create();
76 125
77 ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style)); 126 ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style));
78 ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style)); 127 ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style));
79 ellipseValue->setRadiusX(pool.createValue(ellipse->radiusX(), style)); 128 ellipseValue->setRadiusX(pool.createValue(ellipse->radiusX(), style));
80 ellipseValue->setRadiusY(pool.createValue(ellipse->radiusY(), style)); 129 ellipseValue->setRadiusY(pool.createValue(ellipse->radiusY(), style));
81 130
82 basicShapeValue = ellipseValue.release(); 131 basicShapeValue = ellipseValue.release();
83 break; 132 break;
84 } 133 }
134 case BasicShape::BasicShapeEllipseType: {
135 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*> (basicShape);
136 RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create ();
137
138 ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse-> centerX()));
139 ellipseValue->setCenterY(valueForCenterCoordinate(pool, style, ellipse-> centerY()));
140 ellipseValue->setRadiusX(basicShapeRadiusToCSSValue(pool, style, ellipse ->radiusX()));
141 ellipseValue->setRadiusY(basicShapeRadiusToCSSValue(pool, style, ellipse ->radiusY()));
142 basicShapeValue = ellipseValue.release();
143 break;
144 }
85 case BasicShape::BasicShapePolygonType: { 145 case BasicShape::BasicShapePolygonType: {
86 const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*> (basicShape); 146 const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*> (basicShape);
87 RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create (); 147 RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create ();
88 148
89 polygonValue->setWindRule(polygon->windRule()); 149 polygonValue->setWindRule(polygon->windRule());
90 const Vector<Length>& values = polygon->values(); 150 const Vector<Length>& values = polygon->values();
91 for (unsigned i = 0; i < values.size(); i += 2) 151 for (unsigned i = 0; i < values.size(); i += 2)
92 polygonValue->appendPoint(pool.createValue(values.at(i), style), poo l.createValue(values.at(i + 1), style)); 152 polygonValue->appendPoint(pool.createValue(values.at(i), style), poo l.createValue(values.at(i + 1), style));
93 153
94 basicShapeValue = polygonValue.release(); 154 basicShapeValue = polygonValue.release();
(...skipping 17 matching lines...) Expand all
112 break; 172 break;
113 } 173 }
114 return pool.createValue(basicShapeValue.release()); 174 return pool.createValue(basicShapeValue.release());
115 } 175 }
116 176
117 static Length convertToLength(const StyleResolverState& state, CSSPrimitiveValue * value) 177 static Length convertToLength(const StyleResolverState& state, CSSPrimitiveValue * value)
118 { 178 {
119 return value->convertToLength<FixedConversion | PercentConversion>(state.css ToLengthConversionData()); 179 return value->convertToLength<FixedConversion | PercentConversion>(state.css ToLengthConversionData());
120 } 180 }
121 181
182 static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverS tate& state, CSSPrimitiveValue* value)
183 {
184 if (Pair* pair = value->getPairValue()) {
185 BasicShapeCenterCoordinate::Keyword keyword = BasicShapeCenterCoordinate ::None;
186 switch (pair->first()->getValueID()) {
187 case CSSValueTop:
188 keyword = BasicShapeCenterCoordinate::Top;
189 break;
190 case CSSValueRight:
191 keyword = BasicShapeCenterCoordinate::Right;
192 break;
193 case CSSValueBottom:
194 keyword = BasicShapeCenterCoordinate::Bottom;
195 break;
196 case CSSValueLeft:
197 keyword = BasicShapeCenterCoordinate::Left;
198 break;
199 default:
200 ASSERT_NOT_REACHED();
201 break;
202 }
203 return BasicShapeCenterCoordinate(keyword, convertToLength(state, pair-> second()));
204 }
205
206 return BasicShapeCenterCoordinate(convertToLength(state, value));
207 }
208
209 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta te, PassRefPtr<CSSPrimitiveValue> radius)
210 {
211 if (!radius)
212 return BasicShapeRadius(BasicShapeRadius::ClosestSide);
213
214 if (radius->isValueID()) {
215 switch (radius->getValueID()) {
216 case CSSValueClosestSide:
217 return BasicShapeRadius(BasicShapeRadius::ClosestSide);
218 case CSSValueFarthestSide:
219 return BasicShapeRadius(BasicShapeRadius::FarthestSide);
220 default:
221 ASSERT_NOT_REACHED();
222 break;
223 }
224 }
225
226 return BasicShapeRadius(convertToLength(state, radius.get()));
227 }
228
122 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const CSSBasicShape* basicShapeValue) 229 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const CSSBasicShape* basicShapeValue)
123 { 230 {
124 RefPtr<BasicShape> basicShape; 231 RefPtr<BasicShape> basicShape;
125 232
126 switch (basicShapeValue->type()) { 233 switch (basicShapeValue->type()) {
127 case CSSBasicShape::CSSBasicShapeRectangleType: { 234 case CSSBasicShape::CSSBasicShapeRectangleType: {
128 const CSSBasicShapeRectangle* rectValue = static_cast<const CSSBasicShap eRectangle *>(basicShapeValue); 235 const CSSBasicShapeRectangle* rectValue = static_cast<const CSSBasicShap eRectangle *>(basicShapeValue);
129 RefPtr<BasicShapeRectangle> rect = BasicShapeRectangle::create(); 236 RefPtr<BasicShapeRectangle> rect = BasicShapeRectangle::create();
130 237
131 rect->setX(convertToLength(state, rectValue->x())); 238 rect->setX(convertToLength(state, rectValue->x()));
132 rect->setY(convertToLength(state, rectValue->y())); 239 rect->setY(convertToLength(state, rectValue->y()));
133 rect->setWidth(convertToLength(state, rectValue->width())); 240 rect->setWidth(convertToLength(state, rectValue->width()));
134 rect->setHeight(convertToLength(state, rectValue->height())); 241 rect->setHeight(convertToLength(state, rectValue->height()));
135 if (rectValue->radiusX()) { 242 if (rectValue->radiusX()) {
136 Length radiusX = convertToLength(state, rectValue->radiusX()); 243 Length radiusX = convertToLength(state, rectValue->radiusX());
137 rect->setCornerRadiusX(radiusX); 244 rect->setCornerRadiusX(radiusX);
138 if (rectValue->radiusY()) 245 if (rectValue->radiusY())
139 rect->setCornerRadiusY(convertToLength(state, rectValue->radiusY ())); 246 rect->setCornerRadiusY(convertToLength(state, rectValue->radiusY ()));
140 else 247 else
141 rect->setCornerRadiusY(radiusX); 248 rect->setCornerRadiusY(radiusX);
142 } else { 249 } else {
143 rect->setCornerRadiusX(Length(0, Fixed)); 250 rect->setCornerRadiusX(Length(0, Fixed));
144 rect->setCornerRadiusY(Length(0, Fixed)); 251 rect->setCornerRadiusY(Length(0, Fixed));
145 } 252 }
146 basicShape = rect.release(); 253 basicShape = rect.release();
147 break; 254 break;
148 } 255 }
149 case CSSBasicShape::CSSBasicShapeCircleType: { 256 case CSSBasicShape::CSSDeprecatedBasicShapeCircleType: {
150 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape Circle *>(basicShapeValue); 257 const CSSDeprecatedBasicShapeCircle* circleValue = static_cast<const CSS DeprecatedBasicShapeCircle *>(basicShapeValue);
151 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); 258 RefPtr<DeprecatedBasicShapeCircle> circle = DeprecatedBasicShapeCircle:: create();
152 259
153 circle->setCenterX(convertToLength(state, circleValue->centerX())); 260 circle->setCenterX(convertToLength(state, circleValue->centerX()));
154 circle->setCenterY(convertToLength(state, circleValue->centerY())); 261 circle->setCenterY(convertToLength(state, circleValue->centerY()));
155 circle->setRadius(convertToLength(state, circleValue->radius())); 262 circle->setRadius(convertToLength(state, circleValue->radius()));
156 263
157 basicShape = circle.release(); 264 basicShape = circle.release();
158 break; 265 break;
159 } 266 }
160 case CSSBasicShape::CSSBasicShapeEllipseType: { 267 case CSSBasicShape::CSSBasicShapeCircleType: {
161 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha peEllipse *>(basicShapeValue); 268 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape Circle *>(basicShapeValue);
162 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create(); 269 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create();
270
271 if (circleValue->centerX() && circleValue->centerY()) {
272 circle->setCenterX(convertToCenterCoordinate(state, circleValue->cen terX()));
273 circle->setCenterY(convertToCenterCoordinate(state, circleValue->cen terY()));
274 } else {
275 circle->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent)));
276 circle->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent)));
277 }
278 circle->setRadius(cssValueToBasicShapeRadius(state, circleValue->radius( )));
279
280 basicShape = circle.release();
281 break;
282 }
283 case CSSBasicShape::CSSDeprecatedBasicShapeEllipseType: {
284 const CSSDeprecatedBasicShapeEllipse* ellipseValue = static_cast<const C SSDeprecatedBasicShapeEllipse *>(basicShapeValue);
285 RefPtr<DeprecatedBasicShapeEllipse> ellipse = DeprecatedBasicShapeEllips e::create();
163 286
164 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX())); 287 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX()));
165 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY())); 288 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY()));
166 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX())); 289 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX()));
167 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY())); 290 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY()));
168 291
169 basicShape = ellipse.release(); 292 basicShape = ellipse.release();
170 break; 293 break;
171 } 294 }
295 case CSSBasicShape::CSSBasicShapeEllipseType: {
296 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha peEllipse *>(basicShapeValue);
297 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create();
298
299 if (ellipseValue->centerX() && ellipseValue->centerY()) {
300 ellipse->setCenterX(convertToCenterCoordinate(state, ellipseValue->c enterX()));
301 ellipse->setCenterY(convertToCenterCoordinate(state, ellipseValue->c enterY()));
302 } else {
303 ellipse->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent))) ;
304 ellipse->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent))) ;
305 }
306 ellipse->setRadiusX(cssValueToBasicShapeRadius(state, ellipseValue->radi usX()));
307 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi usY()));
308
309 basicShape = ellipse.release();
310 break;
311 }
172 case CSSBasicShape::CSSBasicShapePolygonType: { 312 case CSSBasicShape::CSSBasicShapePolygonType: {
173 const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicSha pePolygon *>(basicShapeValue); 313 const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicSha pePolygon *>(basicShapeValue);
174 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); 314 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create();
175 315
176 polygon->setWindRule(polygonValue->windRule()); 316 polygon->setWindRule(polygonValue->windRule());
177 const Vector<RefPtr<CSSPrimitiveValue> >& values = polygonValue->values( ); 317 const Vector<RefPtr<CSSPrimitiveValue> >& values = polygonValue->values( );
178 for (unsigned i = 0; i < values.size(); i += 2) 318 for (unsigned i = 0; i < values.size(); i += 2)
179 polygon->appendPoint(convertToLength(state, values.at(i).get()), con vertToLength(state, values.at(i + 1).get())); 319 polygon->appendPoint(convertToLength(state, values.at(i).get()), con vertToLength(state, values.at(i + 1).get()));
180 320
181 basicShape = polygon.release(); 321 basicShape = polygon.release();
(...skipping 20 matching lines...) Expand all
202 } 342 }
203 basicShape = rect.release(); 343 basicShape = rect.release();
204 break; 344 break;
205 } 345 }
206 default: 346 default:
207 break; 347 break;
208 } 348 }
209 return basicShape.release(); 349 return basicShape.release();
210 } 350 }
211 } 351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698