OLD | NEW |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 keyword = CSSValueBottom; | 56 keyword = CSSValueBottom; |
57 break; | 57 break; |
58 case BasicShapeCenterCoordinate::Left: | 58 case BasicShapeCenterCoordinate::Left: |
59 keyword = CSSValueLeft; | 59 keyword = CSSValueLeft; |
60 break; | 60 break; |
61 } | 61 } |
62 | 62 |
63 return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), po
ol.createValue(center.length(), style), Pair::DropIdenticalValues)); | 63 return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), po
ol.createValue(center.length(), style), Pair::DropIdenticalValues)); |
64 } | 64 } |
65 | 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 |
66 PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha
pe* basicShape) | 81 PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha
pe* basicShape) |
67 { | 82 { |
68 CSSValuePool& pool = cssValuePool(); | 83 CSSValuePool& pool = cssValuePool(); |
69 | 84 |
70 RefPtr<CSSBasicShape> basicShapeValue; | 85 RefPtr<CSSBasicShape> basicShapeValue; |
71 switch (basicShape->type()) { | 86 switch (basicShape->type()) { |
72 case BasicShape::BasicShapeRectangleType: { | 87 case BasicShape::BasicShapeRectangleType: { |
73 const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRecta
ngle*>(basicShape); | 88 const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRecta
ngle*>(basicShape); |
74 RefPtr<CSSBasicShapeRectangle> rectangleValue = CSSBasicShapeRectangle::
create(); | 89 RefPtr<CSSBasicShapeRectangle> rectangleValue = CSSBasicShapeRectangle::
create(); |
75 | 90 |
(...skipping 17 matching lines...) Expand all Loading... |
93 | 108 |
94 basicShapeValue = circleValue.release(); | 109 basicShapeValue = circleValue.release(); |
95 break; | 110 break; |
96 } | 111 } |
97 case BasicShape::BasicShapeCircleType: { | 112 case BasicShape::BasicShapeCircleType: { |
98 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba
sicShape); | 113 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba
sicShape); |
99 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create(); | 114 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create(); |
100 | 115 |
101 circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->ce
nterX())); | 116 circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->ce
nterX())); |
102 circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->ce
nterY())); | 117 circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->ce
nterY())); |
103 switch (circle->radius().type()) { | 118 circleValue->setRadius(basicShapeRadiusToCSSValue(pool, style, circle->r
adius())); |
104 case BasicShapeRadius::Value: | |
105 circleValue->setRadius(pool.createValue(circle->radius().value(), st
yle)); | |
106 break; | |
107 case BasicShapeRadius::ClosestSide: | |
108 circleValue->setRadius(pool.createIdentifierValue(CSSValueClosestSid
e)); | |
109 break; | |
110 case BasicShapeRadius::FarthestSide: | |
111 circleValue->setRadius(pool.createIdentifierValue(CSSValueFarthestSi
de)); | |
112 break; | |
113 } | |
114 basicShapeValue = circleValue.release(); | 119 basicShapeValue = circleValue.release(); |
115 break; | 120 break; |
116 } | 121 } |
117 case BasicShape::BasicShapeEllipseType: { | 122 case BasicShape::DeprecatedBasicShapeEllipseType: { |
118 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>
(basicShape); | 123 const DeprecatedBasicShapeEllipse* ellipse = static_cast<const Deprecate
dBasicShapeEllipse*>(basicShape); |
119 RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create
(); | 124 RefPtr<CSSDeprecatedBasicShapeEllipse> ellipseValue = CSSDeprecatedBasic
ShapeEllipse::create(); |
120 | 125 |
121 ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style)); | 126 ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style)); |
122 ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style)); | 127 ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style)); |
123 ellipseValue->setRadiusX(pool.createValue(ellipse->radiusX(), style)); | 128 ellipseValue->setRadiusX(pool.createValue(ellipse->radiusX(), style)); |
124 ellipseValue->setRadiusY(pool.createValue(ellipse->radiusY(), style)); | 129 ellipseValue->setRadiusY(pool.createValue(ellipse->radiusY(), style)); |
125 | 130 |
126 basicShapeValue = ellipseValue.release(); | 131 basicShapeValue = ellipseValue.release(); |
127 break; | 132 break; |
128 } | 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 } |
129 case BasicShape::BasicShapePolygonType: { | 145 case BasicShape::BasicShapePolygonType: { |
130 const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*>
(basicShape); | 146 const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*>
(basicShape); |
131 RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create
(); | 147 RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create
(); |
132 | 148 |
133 polygonValue->setWindRule(polygon->windRule()); | 149 polygonValue->setWindRule(polygon->windRule()); |
134 const Vector<Length>& values = polygon->values(); | 150 const Vector<Length>& values = polygon->values(); |
135 for (unsigned i = 0; i < values.size(); i += 2) | 151 for (unsigned i = 0; i < values.size(); i += 2) |
136 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)); |
137 | 153 |
138 basicShapeValue = polygonValue.release(); | 154 basicShapeValue = polygonValue.release(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 default: | 203 default: |
188 ASSERT_NOT_REACHED(); | 204 ASSERT_NOT_REACHED(); |
189 break; | 205 break; |
190 } | 206 } |
191 return BasicShapeCenterCoordinate(keyword, convertToLength(state, pair->
second())); | 207 return BasicShapeCenterCoordinate(keyword, convertToLength(state, pair->
second())); |
192 } | 208 } |
193 | 209 |
194 return BasicShapeCenterCoordinate(convertToLength(state, value)); | 210 return BasicShapeCenterCoordinate(convertToLength(state, value)); |
195 } | 211 } |
196 | 212 |
| 213 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta
te, PassRefPtr<CSSPrimitiveValue> radius) |
| 214 { |
| 215 if (!radius) |
| 216 return BasicShapeRadius(BasicShapeRadius::ClosestSide); |
| 217 |
| 218 if (radius->isValueID()) { |
| 219 switch (radius->getValueID()) { |
| 220 case CSSValueClosestSide: |
| 221 return BasicShapeRadius(BasicShapeRadius::ClosestSide); |
| 222 case CSSValueFarthestSide: |
| 223 return BasicShapeRadius(BasicShapeRadius::FarthestSide); |
| 224 default: |
| 225 ASSERT_NOT_REACHED(); |
| 226 break; |
| 227 } |
| 228 } |
| 229 |
| 230 return BasicShapeRadius(convertToLength(state, radius.get())); |
| 231 } |
| 232 |
197 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
CSSBasicShape* basicShapeValue) | 233 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
CSSBasicShape* basicShapeValue) |
198 { | 234 { |
199 RefPtr<BasicShape> basicShape; | 235 RefPtr<BasicShape> basicShape; |
200 | 236 |
201 switch (basicShapeValue->type()) { | 237 switch (basicShapeValue->type()) { |
202 case CSSBasicShape::CSSBasicShapeRectangleType: { | 238 case CSSBasicShape::CSSBasicShapeRectangleType: { |
203 const CSSBasicShapeRectangle* rectValue = static_cast<const CSSBasicShap
eRectangle *>(basicShapeValue); | 239 const CSSBasicShapeRectangle* rectValue = static_cast<const CSSBasicShap
eRectangle *>(basicShapeValue); |
204 RefPtr<BasicShapeRectangle> rect = BasicShapeRectangle::create(); | 240 RefPtr<BasicShapeRectangle> rect = BasicShapeRectangle::create(); |
205 | 241 |
206 rect->setX(convertToLength(state, rectValue->x())); | 242 rect->setX(convertToLength(state, rectValue->x())); |
(...skipping 29 matching lines...) Expand all Loading... |
236 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape
Circle *>(basicShapeValue); | 272 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape
Circle *>(basicShapeValue); |
237 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); | 273 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); |
238 | 274 |
239 if (circleValue->centerX() && circleValue->centerY()) { | 275 if (circleValue->centerX() && circleValue->centerY()) { |
240 circle->setCenterX(convertToCenterCoordinate(state, circleValue->cen
terX())); | 276 circle->setCenterX(convertToCenterCoordinate(state, circleValue->cen
terX())); |
241 circle->setCenterY(convertToCenterCoordinate(state, circleValue->cen
terY())); | 277 circle->setCenterY(convertToCenterCoordinate(state, circleValue->cen
terY())); |
242 } else { | 278 } else { |
243 circle->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent))); | 279 circle->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent))); |
244 circle->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent))); | 280 circle->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent))); |
245 } | 281 } |
246 if (RefPtr<CSSPrimitiveValue> radius = circleValue->radius()) { | 282 circle->setRadius(cssValueToBasicShapeRadius(state, circleValue->radius(
))); |
247 if (radius->isValueID()) { | |
248 switch (radius->getValueID()) { | |
249 case CSSValueClosestSide: | |
250 circle->setRadius(BasicShapeRadius(BasicShapeRadius::Closest
Side)); | |
251 break; | |
252 case CSSValueFarthestSide: | |
253 circle->setRadius(BasicShapeRadius(BasicShapeRadius::Farthes
tSide)); | |
254 break; | |
255 default: | |
256 ASSERT_NOT_REACHED(); | |
257 break; | |
258 } | |
259 } else { | |
260 circle->setRadius(BasicShapeRadius(convertToLength(state, radius
.get()))); | |
261 } | |
262 } else { | |
263 circle->setRadius(BasicShapeRadius(BasicShapeRadius::ClosestSide)); | |
264 } | |
265 | 283 |
266 basicShape = circle.release(); | 284 basicShape = circle.release(); |
267 break; | 285 break; |
268 } | 286 } |
269 case CSSBasicShape::CSSBasicShapeEllipseType: { | 287 case CSSBasicShape::CSSDeprecatedBasicShapeEllipseType: { |
270 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha
peEllipse *>(basicShapeValue); | 288 const CSSDeprecatedBasicShapeEllipse* ellipseValue = static_cast<const C
SSDeprecatedBasicShapeEllipse *>(basicShapeValue); |
271 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create(); | 289 RefPtr<DeprecatedBasicShapeEllipse> ellipse = DeprecatedBasicShapeEllips
e::create(); |
272 | 290 |
273 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX())); | 291 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX())); |
274 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY())); | 292 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY())); |
275 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX())); | 293 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX())); |
276 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY())); | 294 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY())); |
277 | 295 |
278 basicShape = ellipse.release(); | 296 basicShape = ellipse.release(); |
279 break; | 297 break; |
280 } | 298 } |
| 299 case CSSBasicShape::CSSBasicShapeEllipseType: { |
| 300 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha
peEllipse *>(basicShapeValue); |
| 301 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create(); |
| 302 |
| 303 if (ellipseValue->centerX() && ellipseValue->centerY()) { |
| 304 ellipse->setCenterX(convertToCenterCoordinate(state, ellipseValue->c
enterX())); |
| 305 ellipse->setCenterY(convertToCenterCoordinate(state, ellipseValue->c
enterY())); |
| 306 } else { |
| 307 ellipse->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent)))
; |
| 308 ellipse->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent)))
; |
| 309 } |
| 310 ellipse->setRadiusX(cssValueToBasicShapeRadius(state, ellipseValue->radi
usX())); |
| 311 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi
usY())); |
| 312 |
| 313 basicShape = ellipse.release(); |
| 314 break; |
| 315 } |
281 case CSSBasicShape::CSSBasicShapePolygonType: { | 316 case CSSBasicShape::CSSBasicShapePolygonType: { |
282 const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicSha
pePolygon *>(basicShapeValue); | 317 const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicSha
pePolygon *>(basicShapeValue); |
283 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); | 318 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); |
284 | 319 |
285 polygon->setWindRule(polygonValue->windRule()); | 320 polygon->setWindRule(polygonValue->windRule()); |
286 const Vector<RefPtr<CSSPrimitiveValue> >& values = polygonValue->values(
); | 321 const Vector<RefPtr<CSSPrimitiveValue> >& values = polygonValue->values(
); |
287 for (unsigned i = 0; i < values.size(); i += 2) | 322 for (unsigned i = 0; i < values.size(); i += 2) |
288 polygon->appendPoint(convertToLength(state, values.at(i).get()), con
vertToLength(state, values.at(i + 1).get())); | 323 polygon->appendPoint(convertToLength(state, values.at(i).get()), con
vertToLength(state, values.at(i + 1).get())); |
289 | 324 |
290 basicShape = polygon.release(); | 325 basicShape = polygon.release(); |
(...skipping 24 matching lines...) Expand all Loading... |
315 default: | 350 default: |
316 break; | 351 break; |
317 } | 352 } |
318 | 353 |
319 if (basicShapeValue->layoutBox()) | 354 if (basicShapeValue->layoutBox()) |
320 basicShape->setLayoutBox(LayoutBox(*basicShapeValue->layoutBox())); | 355 basicShape->setLayoutBox(LayoutBox(*basicShapeValue->layoutBox())); |
321 | 356 |
322 return basicShape.release(); | 357 return basicShape.release(); |
323 } | 358 } |
324 } | 359 } |
OLD | NEW |