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 22 matching lines...) Expand all Loading... |
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/Pair.h" |
37 #include "core/css/resolver/StyleResolverState.h" | 37 #include "core/css/resolver/StyleResolverState.h" |
38 #include "core/style/BasicShapes.h" | 38 #include "core/style/BasicShapes.h" |
39 #include "core/style/ComputedStyle.h" | 39 #include "core/style/ComputedStyle.h" |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSVal
uePool& pool, const ComputedStyle& style, const BasicShapeCenterCoordinate& cent
er, EBoxOrient orientation) | 43 static PassRefPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSValuePool& pool
, const ComputedStyle& style, const BasicShapeCenterCoordinate& center, EBoxOrie
nt orientation) |
44 { | 44 { |
45 if (center.direction() == BasicShapeCenterCoordinate::TopLeft) | 45 if (center.direction() == BasicShapeCenterCoordinate::TopLeft) |
46 return pool.createValue(center.length(), style); | 46 return pool.createValue(center.length(), style); |
47 | 47 |
48 CSSValueID keyword = orientation == HORIZONTAL ? CSSValueRight : CSSValueBot
tom; | 48 CSSValueID keyword = orientation == HORIZONTAL ? CSSValueRight : CSSValueBot
tom; |
49 | 49 |
50 return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), po
ol.createValue(center.length(), style), Pair::DropIdenticalValues)); | 50 return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), po
ol.createValue(center.length(), style), Pair::DropIdenticalValues)); |
51 } | 51 } |
52 | 52 |
53 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> basicShapeRadiusToCSSValue(CSSV
aluePool& pool, const ComputedStyle& style, const BasicShapeRadius& radius) | 53 static PassRefPtr<CSSPrimitiveValue> basicShapeRadiusToCSSValue(CSSValuePool& po
ol, const ComputedStyle& style, const BasicShapeRadius& radius) |
54 { | 54 { |
55 switch (radius.type()) { | 55 switch (radius.type()) { |
56 case BasicShapeRadius::Value: | 56 case BasicShapeRadius::Value: |
57 return pool.createValue(radius.value(), style); | 57 return pool.createValue(radius.value(), style); |
58 case BasicShapeRadius::ClosestSide: | 58 case BasicShapeRadius::ClosestSide: |
59 return pool.createIdentifierValue(CSSValueClosestSide); | 59 return pool.createIdentifierValue(CSSValueClosestSide); |
60 case BasicShapeRadius::FarthestSide: | 60 case BasicShapeRadius::FarthestSide: |
61 return pool.createIdentifierValue(CSSValueFarthestSide); | 61 return pool.createIdentifierValue(CSSValueFarthestSide); |
62 } | 62 } |
63 | 63 |
64 ASSERT_NOT_REACHED(); | 64 ASSERT_NOT_REACHED(); |
65 return nullptr; | 65 return nullptr; |
66 } | 66 } |
67 | 67 |
68 PassRefPtrWillBeRawPtr<CSSValue> valueForBasicShape(const ComputedStyle& style,
const BasicShape* basicShape) | 68 PassRefPtr<CSSValue> valueForBasicShape(const ComputedStyle& style, const BasicS
hape* basicShape) |
69 { | 69 { |
70 CSSValuePool& pool = cssValuePool(); | 70 CSSValuePool& pool = cssValuePool(); |
71 | 71 |
72 RefPtrWillBeRawPtr<CSSBasicShape> basicShapeValue = nullptr; | 72 RefPtr<CSSBasicShape> basicShapeValue = nullptr; |
73 switch (basicShape->type()) { | 73 switch (basicShape->type()) { |
74 case BasicShape::BasicShapeCircleType: { | 74 case BasicShape::BasicShapeCircleType: { |
75 const BasicShapeCircle* circle = toBasicShapeCircle(basicShape); | 75 const BasicShapeCircle* circle = toBasicShapeCircle(basicShape); |
76 RefPtrWillBeRawPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircl
e::create(); | 76 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create(); |
77 | 77 |
78 circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->ce
nterX(), HORIZONTAL)); | 78 circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->ce
nterX(), HORIZONTAL)); |
79 circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->ce
nterY(), VERTICAL)); | 79 circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->ce
nterY(), VERTICAL)); |
80 circleValue->setRadius(basicShapeRadiusToCSSValue(pool, style, circle->r
adius())); | 80 circleValue->setRadius(basicShapeRadiusToCSSValue(pool, style, circle->r
adius())); |
81 basicShapeValue = circleValue.release(); | 81 basicShapeValue = circleValue.release(); |
82 break; | 82 break; |
83 } | 83 } |
84 case BasicShape::BasicShapeEllipseType: { | 84 case BasicShape::BasicShapeEllipseType: { |
85 const BasicShapeEllipse* ellipse = toBasicShapeEllipse(basicShape); | 85 const BasicShapeEllipse* ellipse = toBasicShapeEllipse(basicShape); |
86 RefPtrWillBeRawPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEll
ipse::create(); | 86 RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create
(); |
87 | 87 |
88 ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse->
centerX(), HORIZONTAL)); | 88 ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse->
centerX(), HORIZONTAL)); |
89 ellipseValue->setCenterY(valueForCenterCoordinate(pool, style, ellipse->
centerY(), VERTICAL)); | 89 ellipseValue->setCenterY(valueForCenterCoordinate(pool, style, ellipse->
centerY(), VERTICAL)); |
90 ellipseValue->setRadiusX(basicShapeRadiusToCSSValue(pool, style, ellipse
->radiusX())); | 90 ellipseValue->setRadiusX(basicShapeRadiusToCSSValue(pool, style, ellipse
->radiusX())); |
91 ellipseValue->setRadiusY(basicShapeRadiusToCSSValue(pool, style, ellipse
->radiusY())); | 91 ellipseValue->setRadiusY(basicShapeRadiusToCSSValue(pool, style, ellipse
->radiusY())); |
92 basicShapeValue = ellipseValue.release(); | 92 basicShapeValue = ellipseValue.release(); |
93 break; | 93 break; |
94 } | 94 } |
95 case BasicShape::BasicShapePolygonType: { | 95 case BasicShape::BasicShapePolygonType: { |
96 const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape); | 96 const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape); |
97 RefPtrWillBeRawPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePol
ygon::create(); | 97 RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create
(); |
98 | 98 |
99 polygonValue->setWindRule(polygon->windRule()); | 99 polygonValue->setWindRule(polygon->windRule()); |
100 const Vector<Length>& values = polygon->values(); | 100 const Vector<Length>& values = polygon->values(); |
101 for (unsigned i = 0; i < values.size(); i += 2) | 101 for (unsigned i = 0; i < values.size(); i += 2) |
102 polygonValue->appendPoint(pool.createValue(values.at(i), style), poo
l.createValue(values.at(i + 1), style)); | 102 polygonValue->appendPoint(pool.createValue(values.at(i), style), poo
l.createValue(values.at(i + 1), style)); |
103 | 103 |
104 basicShapeValue = polygonValue.release(); | 104 basicShapeValue = polygonValue.release(); |
105 break; | 105 break; |
106 } | 106 } |
107 case BasicShape::BasicShapeInsetType: { | 107 case BasicShape::BasicShapeInsetType: { |
108 const BasicShapeInset* inset = toBasicShapeInset(basicShape); | 108 const BasicShapeInset* inset = toBasicShapeInset(basicShape); |
109 RefPtrWillBeRawPtr<CSSBasicShapeInset> insetValue = CSSBasicShapeInset::
create(); | 109 RefPtr<CSSBasicShapeInset> insetValue = CSSBasicShapeInset::create(); |
110 | 110 |
111 insetValue->setTop(pool.createValue(inset->top(), style)); | 111 insetValue->setTop(pool.createValue(inset->top(), style)); |
112 insetValue->setRight(pool.createValue(inset->right(), style)); | 112 insetValue->setRight(pool.createValue(inset->right(), style)); |
113 insetValue->setBottom(pool.createValue(inset->bottom(), style)); | 113 insetValue->setBottom(pool.createValue(inset->bottom(), style)); |
114 insetValue->setLeft(pool.createValue(inset->left(), style)); | 114 insetValue->setLeft(pool.createValue(inset->left(), style)); |
115 | 115 |
116 insetValue->setTopLeftRadius(CSSPrimitiveValue::create(inset->topLeftRad
ius(), style)); | 116 insetValue->setTopLeftRadius(CSSPrimitiveValue::create(inset->topLeftRad
ius(), style)); |
117 insetValue->setTopRightRadius(CSSPrimitiveValue::create(inset->topRightR
adius(), style)); | 117 insetValue->setTopRightRadius(CSSPrimitiveValue::create(inset->topRightR
adius(), style)); |
118 insetValue->setBottomRightRadius(CSSPrimitiveValue::create(inset->bottom
RightRadius(), style)); | 118 insetValue->setBottomRightRadius(CSSPrimitiveValue::create(inset->bottom
RightRadius(), style)); |
119 insetValue->setBottomLeftRadius(CSSPrimitiveValue::create(inset->bottomL
eftRadius(), style)); | 119 insetValue->setBottomLeftRadius(CSSPrimitiveValue::create(inset->bottomL
eftRadius(), style)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 break; | 176 break; |
177 default: | 177 default: |
178 ASSERT_NOT_REACHED(); | 178 ASSERT_NOT_REACHED(); |
179 direction = BasicShapeCenterCoordinate::TopLeft; | 179 direction = BasicShapeCenterCoordinate::TopLeft; |
180 break; | 180 break; |
181 } | 181 } |
182 | 182 |
183 return BasicShapeCenterCoordinate(direction, offset); | 183 return BasicShapeCenterCoordinate(direction, offset); |
184 } | 184 } |
185 | 185 |
186 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta
te, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius) | 186 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta
te, PassRefPtr<CSSPrimitiveValue> radius) |
187 { | 187 { |
188 if (!radius) | 188 if (!radius) |
189 return BasicShapeRadius(BasicShapeRadius::ClosestSide); | 189 return BasicShapeRadius(BasicShapeRadius::ClosestSide); |
190 | 190 |
191 if (radius->isValueID()) { | 191 if (radius->isValueID()) { |
192 switch (radius->getValueID()) { | 192 switch (radius->getValueID()) { |
193 case CSSValueClosestSide: | 193 case CSSValueClosestSide: |
194 return BasicShapeRadius(BasicShapeRadius::ClosestSide); | 194 return BasicShapeRadius(BasicShapeRadius::ClosestSide); |
195 case CSSValueFarthestSide: | 195 case CSSValueFarthestSide: |
196 return BasicShapeRadius(BasicShapeRadius::FarthestSide); | 196 return BasicShapeRadius(BasicShapeRadius::FarthestSide); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi
usY())); | 229 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi
usY())); |
230 | 230 |
231 basicShape = ellipse.release(); | 231 basicShape = ellipse.release(); |
232 break; | 232 break; |
233 } | 233 } |
234 case CSSBasicShape::CSSBasicShapePolygonType: { | 234 case CSSBasicShape::CSSBasicShapePolygonType: { |
235 const CSSBasicShapePolygon* polygonValue = toCSSBasicShapePolygon(basicS
hapeValue); | 235 const CSSBasicShapePolygon* polygonValue = toCSSBasicShapePolygon(basicS
hapeValue); |
236 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); | 236 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); |
237 | 237 |
238 polygon->setWindRule(polygonValue->windRule()); | 238 polygon->setWindRule(polygonValue->windRule()); |
239 const WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>>& values =
polygonValue->values(); | 239 const Vector<RefPtr<CSSPrimitiveValue>>& values = polygonValue->values()
; |
240 for (unsigned i = 0; i < values.size(); i += 2) | 240 for (unsigned i = 0; i < values.size(); i += 2) |
241 polygon->appendPoint(convertToLength(state, values.at(i).get()), con
vertToLength(state, values.at(i + 1).get())); | 241 polygon->appendPoint(convertToLength(state, values.at(i).get()), con
vertToLength(state, values.at(i + 1).get())); |
242 | 242 |
243 basicShape = polygon.release(); | 243 basicShape = polygon.release(); |
244 break; | 244 break; |
245 } | 245 } |
246 case CSSBasicShape::CSSBasicShapeInsetType: { | 246 case CSSBasicShape::CSSBasicShapeInsetType: { |
247 const CSSBasicShapeInset* rectValue = toCSSBasicShapeInset(basicShapeVal
ue); | 247 const CSSBasicShapeInset* rectValue = toCSSBasicShapeInset(basicShapeVal
ue); |
248 RefPtr<BasicShapeInset> rect = BasicShapeInset::create(); | 248 RefPtr<BasicShapeInset> rect = BasicShapeInset::create(); |
249 | 249 |
(...skipping 18 matching lines...) Expand all Loading... |
268 } | 268 } |
269 | 269 |
270 FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente
rX, const BasicShapeCenterCoordinate& centerY, FloatSize boxSize) | 270 FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente
rX, const BasicShapeCenterCoordinate& centerY, FloatSize boxSize) |
271 { | 271 { |
272 float x = floatValueForLength(centerX.computedLength(), boxSize.width()); | 272 float x = floatValueForLength(centerX.computedLength(), boxSize.width()); |
273 float y = floatValueForLength(centerY.computedLength(), boxSize.height()); | 273 float y = floatValueForLength(centerY.computedLength(), boxSize.height()); |
274 return FloatPoint(x, y); | 274 return FloatPoint(x, y); |
275 } | 275 } |
276 | 276 |
277 } | 277 } |
OLD | NEW |