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 15 matching lines...) Expand all Loading... |
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 |
42 PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha
pe* basicShape) | 66 PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha
pe* basicShape) |
43 { | 67 { |
44 CSSValuePool& pool = cssValuePool(); | 68 CSSValuePool& pool = cssValuePool(); |
45 | 69 |
46 RefPtr<CSSBasicShape> basicShapeValue; | 70 RefPtr<CSSBasicShape> basicShapeValue; |
47 switch (basicShape->type()) { | 71 switch (basicShape->type()) { |
48 case BasicShape::BasicShapeRectangleType: { | 72 case BasicShape::BasicShapeRectangleType: { |
49 const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRecta
ngle*>(basicShape); | 73 const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRecta
ngle*>(basicShape); |
50 RefPtr<CSSBasicShapeRectangle> rectangleValue = CSSBasicShapeRectangle::
create(); | 74 RefPtr<CSSBasicShapeRectangle> rectangleValue = CSSBasicShapeRectangle::
create(); |
51 | 75 |
52 rectangleValue->setX(pool.createValue(rectangle->x(), style)); | 76 rectangleValue->setX(pool.createValue(rectangle->x(), style)); |
53 rectangleValue->setY(pool.createValue(rectangle->y(), style)); | 77 rectangleValue->setY(pool.createValue(rectangle->y(), style)); |
54 rectangleValue->setWidth(pool.createValue(rectangle->width(), style)); | 78 rectangleValue->setWidth(pool.createValue(rectangle->width(), style)); |
55 rectangleValue->setHeight(pool.createValue(rectangle->height(), style)); | 79 rectangleValue->setHeight(pool.createValue(rectangle->height(), style)); |
56 rectangleValue->setRadiusX(pool.createValue(rectangle->cornerRadiusX(),
style)); | 80 rectangleValue->setRadiusX(pool.createValue(rectangle->cornerRadiusX(),
style)); |
57 rectangleValue->setRadiusY(pool.createValue(rectangle->cornerRadiusY(),
style)); | 81 rectangleValue->setRadiusY(pool.createValue(rectangle->cornerRadiusY(),
style)); |
58 | 82 |
59 basicShapeValue = rectangleValue.release(); | 83 basicShapeValue = rectangleValue.release(); |
60 break; | 84 break; |
61 } | 85 } |
62 case BasicShape::BasicShapeCircleType: { | 86 case BasicShape::DeprecatedBasicShapeCircleType: { |
63 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba
sicShape); | 87 const DeprecatedBasicShapeCircle* circle = static_cast<const DeprecatedB
asicShapeCircle*>(basicShape); |
64 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create(); | 88 RefPtr<CSSDeprecatedBasicShapeCircle> circleValue = CSSDeprecatedBasicSh
apeCircle::create(); |
65 | 89 |
66 circleValue->setCenterX(pool.createValue(circle->centerX(), style)); | 90 circleValue->setCenterX(pool.createValue(circle->centerX(), style)); |
67 circleValue->setCenterY(pool.createValue(circle->centerY(), style)); | 91 circleValue->setCenterY(pool.createValue(circle->centerY(), style)); |
68 circleValue->setRadius(pool.createValue(circle->radius(), style)); | 92 circleValue->setRadius(pool.createValue(circle->radius(), style)); |
69 | 93 |
70 basicShapeValue = circleValue.release(); | 94 basicShapeValue = circleValue.release(); |
71 break; | 95 break; |
72 } | 96 } |
| 97 case BasicShape::BasicShapeCircleType: { |
| 98 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba
sicShape); |
| 99 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create(); |
| 100 |
| 101 circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->ce
nterX())); |
| 102 circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->ce
nterY())); |
| 103 switch (circle->radius().type()) { |
| 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(); |
| 115 break; |
| 116 } |
73 case BasicShape::BasicShapeEllipseType: { | 117 case BasicShape::BasicShapeEllipseType: { |
74 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>
(basicShape); | 118 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>
(basicShape); |
75 RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create
(); | 119 RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create
(); |
76 | 120 |
77 ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style)); | 121 ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style)); |
78 ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style)); | 122 ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style)); |
79 ellipseValue->setRadiusX(pool.createValue(ellipse->radiusX(), style)); | 123 ellipseValue->setRadiusX(pool.createValue(ellipse->radiusX(), style)); |
80 ellipseValue->setRadiusY(pool.createValue(ellipse->radiusY(), style)); | 124 ellipseValue->setRadiusY(pool.createValue(ellipse->radiusY(), style)); |
81 | 125 |
82 basicShapeValue = ellipseValue.release(); | 126 basicShapeValue = ellipseValue.release(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 basicShapeValue->setLayoutBox(pool.createValue(basicShape->layoutBox()))
; | 160 basicShapeValue->setLayoutBox(pool.createValue(basicShape->layoutBox()))
; |
117 | 161 |
118 return pool.createValue(basicShapeValue.release()); | 162 return pool.createValue(basicShapeValue.release()); |
119 } | 163 } |
120 | 164 |
121 static Length convertToLength(const StyleResolverState& state, CSSPrimitiveValue
* value) | 165 static Length convertToLength(const StyleResolverState& state, CSSPrimitiveValue
* value) |
122 { | 166 { |
123 return value->convertToLength<FixedConversion | PercentConversion>(state.css
ToLengthConversionData()); | 167 return value->convertToLength<FixedConversion | PercentConversion>(state.css
ToLengthConversionData()); |
124 } | 168 } |
125 | 169 |
| 170 static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverS
tate& state, CSSPrimitiveValue* value) |
| 171 { |
| 172 if (Pair* pair = value->getPairValue()) { |
| 173 BasicShapeCenterCoordinate::Keyword keyword = BasicShapeCenterCoordinate
::None; |
| 174 switch (pair->first()->getValueID()) { |
| 175 case CSSValueTop: |
| 176 keyword = BasicShapeCenterCoordinate::Top; |
| 177 break; |
| 178 case CSSValueRight: |
| 179 keyword = BasicShapeCenterCoordinate::Right; |
| 180 break; |
| 181 case CSSValueBottom: |
| 182 keyword = BasicShapeCenterCoordinate::Bottom; |
| 183 break; |
| 184 case CSSValueLeft: |
| 185 keyword = BasicShapeCenterCoordinate::Left; |
| 186 break; |
| 187 default: |
| 188 ASSERT_NOT_REACHED(); |
| 189 break; |
| 190 } |
| 191 return BasicShapeCenterCoordinate(keyword, convertToLength(state, pair->
second())); |
| 192 } |
| 193 |
| 194 return BasicShapeCenterCoordinate(convertToLength(state, value)); |
| 195 } |
| 196 |
126 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
CSSBasicShape* basicShapeValue) | 197 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
CSSBasicShape* basicShapeValue) |
127 { | 198 { |
128 RefPtr<BasicShape> basicShape; | 199 RefPtr<BasicShape> basicShape; |
129 | 200 |
130 switch (basicShapeValue->type()) { | 201 switch (basicShapeValue->type()) { |
131 case CSSBasicShape::CSSBasicShapeRectangleType: { | 202 case CSSBasicShape::CSSBasicShapeRectangleType: { |
132 const CSSBasicShapeRectangle* rectValue = static_cast<const CSSBasicShap
eRectangle *>(basicShapeValue); | 203 const CSSBasicShapeRectangle* rectValue = static_cast<const CSSBasicShap
eRectangle *>(basicShapeValue); |
133 RefPtr<BasicShapeRectangle> rect = BasicShapeRectangle::create(); | 204 RefPtr<BasicShapeRectangle> rect = BasicShapeRectangle::create(); |
134 | 205 |
135 rect->setX(convertToLength(state, rectValue->x())); | 206 rect->setX(convertToLength(state, rectValue->x())); |
136 rect->setY(convertToLength(state, rectValue->y())); | 207 rect->setY(convertToLength(state, rectValue->y())); |
137 rect->setWidth(convertToLength(state, rectValue->width())); | 208 rect->setWidth(convertToLength(state, rectValue->width())); |
138 rect->setHeight(convertToLength(state, rectValue->height())); | 209 rect->setHeight(convertToLength(state, rectValue->height())); |
139 if (rectValue->radiusX()) { | 210 if (rectValue->radiusX()) { |
140 Length radiusX = convertToLength(state, rectValue->radiusX()); | 211 Length radiusX = convertToLength(state, rectValue->radiusX()); |
141 rect->setCornerRadiusX(radiusX); | 212 rect->setCornerRadiusX(radiusX); |
142 if (rectValue->radiusY()) | 213 if (rectValue->radiusY()) |
143 rect->setCornerRadiusY(convertToLength(state, rectValue->radiusY
())); | 214 rect->setCornerRadiusY(convertToLength(state, rectValue->radiusY
())); |
144 else | 215 else |
145 rect->setCornerRadiusY(radiusX); | 216 rect->setCornerRadiusY(radiusX); |
146 } else { | 217 } else { |
147 rect->setCornerRadiusX(Length(0, Fixed)); | 218 rect->setCornerRadiusX(Length(0, Fixed)); |
148 rect->setCornerRadiusY(Length(0, Fixed)); | 219 rect->setCornerRadiusY(Length(0, Fixed)); |
149 } | 220 } |
150 basicShape = rect.release(); | 221 basicShape = rect.release(); |
151 break; | 222 break; |
152 } | 223 } |
153 case CSSBasicShape::CSSBasicShapeCircleType: { | 224 case CSSBasicShape::CSSDeprecatedBasicShapeCircleType: { |
154 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape
Circle *>(basicShapeValue); | 225 const CSSDeprecatedBasicShapeCircle* circleValue = static_cast<const CSS
DeprecatedBasicShapeCircle *>(basicShapeValue); |
155 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); | 226 RefPtr<DeprecatedBasicShapeCircle> circle = DeprecatedBasicShapeCircle::
create(); |
156 | 227 |
157 circle->setCenterX(convertToLength(state, circleValue->centerX())); | 228 circle->setCenterX(convertToLength(state, circleValue->centerX())); |
158 circle->setCenterY(convertToLength(state, circleValue->centerY())); | 229 circle->setCenterY(convertToLength(state, circleValue->centerY())); |
159 circle->setRadius(convertToLength(state, circleValue->radius())); | 230 circle->setRadius(convertToLength(state, circleValue->radius())); |
160 | 231 |
161 basicShape = circle.release(); | 232 basicShape = circle.release(); |
162 break; | 233 break; |
163 } | 234 } |
| 235 case CSSBasicShape::CSSBasicShapeCircleType: { |
| 236 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape
Circle *>(basicShapeValue); |
| 237 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); |
| 238 |
| 239 if (circleValue->centerX() && circleValue->centerY()) { |
| 240 circle->setCenterX(convertToCenterCoordinate(state, circleValue->cen
terX())); |
| 241 circle->setCenterY(convertToCenterCoordinate(state, circleValue->cen
terY())); |
| 242 } else { |
| 243 circle->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent))); |
| 244 circle->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent))); |
| 245 } |
| 246 if (RefPtr<CSSPrimitiveValue> radius = 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 |
| 266 basicShape = circle.release(); |
| 267 break; |
| 268 } |
164 case CSSBasicShape::CSSBasicShapeEllipseType: { | 269 case CSSBasicShape::CSSBasicShapeEllipseType: { |
165 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha
peEllipse *>(basicShapeValue); | 270 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha
peEllipse *>(basicShapeValue); |
166 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create(); | 271 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create(); |
167 | 272 |
168 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX())); | 273 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX())); |
169 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY())); | 274 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY())); |
170 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX())); | 275 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX())); |
171 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY())); | 276 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY())); |
172 | 277 |
173 basicShape = ellipse.release(); | 278 basicShape = ellipse.release(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 default: | 315 default: |
211 break; | 316 break; |
212 } | 317 } |
213 | 318 |
214 if (basicShapeValue->layoutBox()) | 319 if (basicShapeValue->layoutBox()) |
215 basicShape->setLayoutBox(LayoutBox(*basicShapeValue->layoutBox())); | 320 basicShape->setLayoutBox(LayoutBox(*basicShapeValue->layoutBox())); |
216 | 321 |
217 return basicShape.release(); | 322 return basicShape.release(); |
218 } | 323 } |
219 } | 324 } |
OLD | NEW |