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 CSSPrimitiveValue valueForCenterCoordinate(CSSValuePool& pool, const Comp
utedStyle& style, const BasicShapeCenterCoordinate& center, EBoxOrient orientati
on) |
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 CSSPrimitiveValue basicShapeRadiusToCSSValue(CSSValuePool& pool, const Co
mputedStyle& 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 pool.createValue(radius.value(), style); |
66 } | 66 } |
67 | 67 |
68 CSSValue valueForBasicShape(const ComputedStyle& style, const BasicShape* basicS
hape) | 68 CSSValue valueForBasicShape(const ComputedStyle& style, const BasicShape* basicS
hape) |
69 { | 69 { |
70 CSSValuePool& pool = cssValuePool(); | 70 CSSValuePool& pool = cssValuePool(); |
71 | 71 |
72 RefPtrWillBeRawPtr<CSSBasicShape> basicShapeValue = nullptr; | 72 RefPtrWillBeRawPtr<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); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 break; | 122 break; |
123 } | 123 } |
124 default: | 124 default: |
125 ASSERT_NOT_REACHED(); | 125 ASSERT_NOT_REACHED(); |
126 break; | 126 break; |
127 } | 127 } |
128 | 128 |
129 return pool.createValue(basicShapeValue.release()); | 129 return pool.createValue(basicShapeValue.release()); |
130 } | 130 } |
131 | 131 |
132 static Length convertToLength(const StyleResolverState& state, CSSPrimitiveValue
* value) | 132 static Length convertToLength(const StyleResolverState& state, NullableCSSValue
value) |
133 { | 133 { |
134 if (!value) | 134 if (!value) |
135 return Length(0, Fixed); | 135 return Length(0, Fixed); |
136 return value->convertToLength(state.cssToLengthConversionData()); | 136 return toCSSPrimitiveValue(*value).convertToLength(state.cssToLengthConversi
onData()); |
137 } | 137 } |
138 | 138 |
139 static LengthSize convertToLengthSize(const StyleResolverState& state, CSSPrimit
iveValue* value) | 139 static LengthSize convertToLengthSize(const StyleResolverState& state, NullableC
SSValue value) |
140 { | 140 { |
141 if (!value) | 141 if (!value) |
142 return LengthSize(Length(0, Fixed), Length(0, Fixed)); | 142 return LengthSize(Length(0, Fixed), Length(0, Fixed)); |
143 | 143 |
144 Pair* pair = value->getPairValue(); | 144 Pair* pair = toCSSPrimitiveValue(*value).getPairValue(); |
145 return LengthSize(convertToLength(state, pair->first()), convertToLength(sta
te, pair->second())); | 145 return LengthSize(convertToLength(state, pair->first()), convertToLength(sta
te, pair->second())); |
146 } | 146 } |
147 | 147 |
148 static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverS
tate& state, CSSPrimitiveValue* value) | 148 static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverS
tate& state, NullableCSSValue value) |
149 { | 149 { |
150 BasicShapeCenterCoordinate::Direction direction; | 150 BasicShapeCenterCoordinate::Direction direction; |
151 Length offset = Length(0, Fixed); | 151 Length offset = Length(0, Fixed); |
152 | 152 |
153 CSSValueID keyword = CSSValueTop; | 153 CSSValueID keyword = CSSValueTop; |
154 if (!value) { | 154 if (!value) { |
155 keyword = CSSValueCenter; | 155 keyword = CSSValueCenter; |
156 } else if (value->isValueID()) { | 156 } else if (toCSSPrimitiveValue(*value).isValueID()) { |
157 keyword = value->getValueID(); | 157 keyword = toCSSPrimitiveValue(*value).getValueID(); |
158 } else if (Pair* pair = value->getPairValue()) { | 158 } else if (Pair* pair = toCSSPrimitiveValue(*value).getPairValue()) { |
159 keyword = pair->first()->getValueID(); | 159 keyword = toCSSPrimitiveValue(*pair->first()).getValueID(); |
160 offset = convertToLength(state, pair->second()); | 160 offset = convertToLength(state, pair->second()); |
161 } else { | 161 } else { |
162 offset = convertToLength(state, value); | 162 offset = convertToLength(state, value); |
163 } | 163 } |
164 | 164 |
165 switch (keyword) { | 165 switch (keyword) { |
166 case CSSValueTop: | 166 case CSSValueTop: |
167 case CSSValueLeft: | 167 case CSSValueLeft: |
168 direction = BasicShapeCenterCoordinate::TopLeft; | 168 direction = BasicShapeCenterCoordinate::TopLeft; |
169 break; | 169 break; |
170 case CSSValueRight: | 170 case CSSValueRight: |
171 case CSSValueBottom: | 171 case CSSValueBottom: |
172 direction = BasicShapeCenterCoordinate::BottomRight; | 172 direction = BasicShapeCenterCoordinate::BottomRight; |
173 break; | 173 break; |
174 case CSSValueCenter: | 174 case CSSValueCenter: |
175 direction = BasicShapeCenterCoordinate::TopLeft; | 175 direction = BasicShapeCenterCoordinate::TopLeft; |
176 offset = Length(50, Percent); | 176 offset = Length(50, Percent); |
177 break; | 177 break; |
178 default: | 178 default: |
179 ASSERT_NOT_REACHED(); | 179 ASSERT_NOT_REACHED(); |
180 direction = BasicShapeCenterCoordinate::TopLeft; | 180 direction = BasicShapeCenterCoordinate::TopLeft; |
181 break; | 181 break; |
182 } | 182 } |
183 | 183 |
184 return BasicShapeCenterCoordinate(direction, offset); | 184 return BasicShapeCenterCoordinate(direction, offset); |
185 } | 185 } |
186 | 186 |
187 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta
te, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius) | 187 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta
te, NullableCSSValue radius) |
188 { | 188 { |
189 if (!radius) | 189 if (!radius) |
190 return BasicShapeRadius(BasicShapeRadius::ClosestSide); | 190 return BasicShapeRadius(BasicShapeRadius::ClosestSide); |
191 | 191 |
192 if (radius->isValueID()) { | 192 if (toCSSPrimitiveValue(*radius).isValueID()) { |
193 switch (radius->getValueID()) { | 193 switch (toCSSPrimitiveValue(*radius).getValueID()) { |
194 case CSSValueClosestSide: | 194 case CSSValueClosestSide: |
195 return BasicShapeRadius(BasicShapeRadius::ClosestSide); | 195 return BasicShapeRadius(BasicShapeRadius::ClosestSide); |
196 case CSSValueFarthestSide: | 196 case CSSValueFarthestSide: |
197 return BasicShapeRadius(BasicShapeRadius::FarthestSide); | 197 return BasicShapeRadius(BasicShapeRadius::FarthestSide); |
198 default: | 198 default: |
199 ASSERT_NOT_REACHED(); | 199 ASSERT_NOT_REACHED(); |
200 break; | 200 break; |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 return BasicShapeRadius(convertToLength(state, radius.get())); | 204 return BasicShapeRadius(convertToLength(state, radius)); |
205 } | 205 } |
206 | 206 |
207 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
CSSBasicShape* basicShapeValue) | 207 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
CSSBasicShape* basicShapeValue) |
208 { | 208 { |
209 RefPtr<BasicShape> basicShape; | 209 RefPtr<BasicShape> basicShape; |
210 | 210 |
211 switch (basicShapeValue->type()) { | 211 switch (basicShapeValue->type()) { |
212 case CSSBasicShape::CSSBasicShapeCircleType: { | 212 case CSSBasicShape::CSSBasicShapeCircleType: { |
213 const CSSBasicShapeCircle* circleValue = toCSSBasicShapeCircle(basicShap
eValue); | 213 const CSSBasicShapeCircle* circleValue = toCSSBasicShapeCircle(basicShap
eValue); |
214 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); | 214 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); |
(...skipping 15 matching lines...) Expand all Loading... |
230 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi
usY())); | 230 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi
usY())); |
231 | 231 |
232 basicShape = ellipse.release(); | 232 basicShape = ellipse.release(); |
233 break; | 233 break; |
234 } | 234 } |
235 case CSSBasicShape::CSSBasicShapePolygonType: { | 235 case CSSBasicShape::CSSBasicShapePolygonType: { |
236 const CSSBasicShapePolygon* polygonValue = toCSSBasicShapePolygon(basicS
hapeValue); | 236 const CSSBasicShapePolygon* polygonValue = toCSSBasicShapePolygon(basicS
hapeValue); |
237 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); | 237 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); |
238 | 238 |
239 polygon->setWindRule(polygonValue->windRule()); | 239 polygon->setWindRule(polygonValue->windRule()); |
240 const WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>>& values =
polygonValue->values(); | 240 const WillBeHeapVector<CSSValue>& values = polygonValue->values(); |
241 for (unsigned i = 0; i < values.size(); i += 2) | 241 for (unsigned i = 0; i < values.size(); i += 2) |
242 polygon->appendPoint(convertToLength(state, values.at(i).get()), con
vertToLength(state, values.at(i + 1).get())); | 242 polygon->appendPoint(convertToLength(state, values.at(i).get()), con
vertToLength(state, values.at(i + 1).get())); |
243 | 243 |
244 basicShape = polygon.release(); | 244 basicShape = polygon.release(); |
245 break; | 245 break; |
246 } | 246 } |
247 case CSSBasicShape::CSSBasicShapeInsetType: { | 247 case CSSBasicShape::CSSBasicShapeInsetType: { |
248 const CSSBasicShapeInset* rectValue = toCSSBasicShapeInset(basicShapeVal
ue); | 248 const CSSBasicShapeInset* rectValue = toCSSBasicShapeInset(basicShapeVal
ue); |
249 RefPtr<BasicShapeInset> rect = BasicShapeInset::create(); | 249 RefPtr<BasicShapeInset> rect = BasicShapeInset::create(); |
250 | 250 |
(...skipping 18 matching lines...) Expand all Loading... |
269 } | 269 } |
270 | 270 |
271 FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente
rX, const BasicShapeCenterCoordinate& centerY, FloatSize boxSize) | 271 FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente
rX, const BasicShapeCenterCoordinate& centerY, FloatSize boxSize) |
272 { | 272 { |
273 float x = floatValueForLength(centerX.computedLength(), boxSize.width()); | 273 float x = floatValueForLength(centerX.computedLength(), boxSize.width()); |
274 float y = floatValueForLength(centerY.computedLength(), boxSize.height()); | 274 float y = floatValueForLength(centerY.computedLength(), boxSize.height()); |
275 return FloatPoint(x, y); | 275 return FloatPoint(x, y); |
276 } | 276 } |
277 | 277 |
278 } | 278 } |
OLD | NEW |