OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2011 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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "core/css/CSSValuePool.h" | 33 #include "core/css/CSSValuePool.h" |
34 #include "core/css/Pair.h" | 34 #include "core/css/Pair.h" |
35 #include "platform/Length.h" | 35 #include "platform/Length.h" |
36 #include "wtf/text/StringBuilder.h" | 36 #include "wtf/text/StringBuilder.h" |
37 | 37 |
38 using namespace WTF; | 38 using namespace WTF; |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CSSBasicShape) | |
43 | |
44 static String buildCircleString(const String& radius, const String& centerX, con
st String& centerY, const String& box) | 42 static String buildCircleString(const String& radius, const String& centerX, con
st String& centerY, const String& box) |
45 { | 43 { |
46 char at[] = "at"; | 44 char at[] = "at"; |
47 char separator[] = " "; | 45 char separator[] = " "; |
48 StringBuilder result; | 46 StringBuilder result; |
49 result.appendLiteral("circle("); | 47 result.appendLiteral("circle("); |
50 if (!radius.isNull()) | 48 if (!radius.isNull()) |
51 result.append(radius); | 49 result.append(radius); |
52 | 50 |
53 if (!centerX.isNull() || !centerY.isNull()) { | 51 if (!centerX.isNull() || !centerY.isNull()) { |
(...skipping 14 matching lines...) Expand all Loading... |
68 } | 66 } |
69 | 67 |
70 static String serializePositionOffset(const Pair& offset, const Pair& other) | 68 static String serializePositionOffset(const Pair& offset, const Pair& other) |
71 { | 69 { |
72 if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValue
ID() == CSSValueTop) | 70 if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValue
ID() == CSSValueTop) |
73 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal
ueID() == CSSValueLeft)) | 71 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal
ueID() == CSSValueLeft)) |
74 return offset.second()->cssText(); | 72 return offset.second()->cssText(); |
75 return offset.cssText(); | 73 return offset.cssText(); |
76 } | 74 } |
77 | 75 |
78 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> buildSerializablePositionOffset
(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> offset, CSSValueID defaultSide) | 76 static PassRefPtr<CSSPrimitiveValue> buildSerializablePositionOffset(PassRefPtr<
CSSPrimitiveValue> offset, CSSValueID defaultSide) |
79 { | 77 { |
80 CSSValueID side = defaultSide; | 78 CSSValueID side = defaultSide; |
81 RefPtrWillBeRawPtr<CSSPrimitiveValue> amount = nullptr; | 79 RefPtr<CSSPrimitiveValue> amount = nullptr; |
82 | 80 |
83 if (!offset) { | 81 if (!offset) { |
84 side = CSSValueCenter; | 82 side = CSSValueCenter; |
85 } else if (offset->isValueID()) { | 83 } else if (offset->isValueID()) { |
86 side = offset->getValueID(); | 84 side = offset->getValueID(); |
87 } else if (Pair* pair = offset->getPairValue()) { | 85 } else if (Pair* pair = offset->getPairValue()) { |
88 side = pair->first()->getValueID(); | 86 side = pair->first()->getValueID(); |
89 amount = pair->second(); | 87 amount = pair->second(); |
90 } else { | 88 } else { |
91 amount = offset; | 89 amount = offset; |
(...skipping 12 matching lines...) Expand all Loading... |
104 else | 102 else |
105 amount = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::
Percentage); | 103 amount = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::
Percentage); |
106 side = defaultSide; | 104 side = defaultSide; |
107 } | 105 } |
108 | 106 |
109 return cssValuePool().createValue(Pair::create(cssValuePool().createValue(si
de), amount.release(), Pair::KeepIdenticalValues)); | 107 return cssValuePool().createValue(Pair::create(cssValuePool().createValue(si
de), amount.release(), Pair::KeepIdenticalValues)); |
110 } | 108 } |
111 | 109 |
112 String CSSBasicShapeCircle::cssText() const | 110 String CSSBasicShapeCircle::cssText() const |
113 { | 111 { |
114 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); | 112 RefPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_c
enterX, CSSValueLeft); |
115 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); | 113 RefPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_c
enterY, CSSValueTop); |
116 | 114 |
117 String radius; | 115 String radius; |
118 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) | 116 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) |
119 radius = m_radius->cssText(); | 117 radius = m_radius->cssText(); |
120 | 118 |
121 return buildCircleString(radius, | 119 return buildCircleString(radius, |
122 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), | 120 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), |
123 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue()), | 121 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue()), |
124 m_referenceBox ? m_referenceBox->cssText() : String()); | 122 m_referenceBox ? m_referenceBox->cssText() : String()); |
125 } | 123 } |
126 | 124 |
127 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const | 125 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const |
128 { | 126 { |
129 if (shape.type() != CSSBasicShapeCircleType) | 127 if (shape.type() != CSSBasicShapeCircleType) |
130 return false; | 128 return false; |
131 | 129 |
132 const CSSBasicShapeCircle& other = toCSSBasicShapeCircle(shape); | 130 const CSSBasicShapeCircle& other = toCSSBasicShapeCircle(shape); |
133 return compareCSSValuePtr(m_centerX, other.m_centerX) | 131 return compareCSSValuePtr(m_centerX, other.m_centerX) |
134 && compareCSSValuePtr(m_centerY, other.m_centerY) | 132 && compareCSSValuePtr(m_centerY, other.m_centerY) |
135 && compareCSSValuePtr(m_radius, other.m_radius) | 133 && compareCSSValuePtr(m_radius, other.m_radius) |
136 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox); | 134 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox); |
137 } | 135 } |
138 | 136 |
139 DEFINE_TRACE(CSSBasicShapeCircle) | |
140 { | |
141 visitor->trace(m_centerX); | |
142 visitor->trace(m_centerY); | |
143 visitor->trace(m_radius); | |
144 CSSBasicShape::trace(visitor); | |
145 } | |
146 | |
147 static String buildEllipseString(const String& radiusX, const String& radiusY, c
onst String& centerX, const String& centerY, const String& box) | 137 static String buildEllipseString(const String& radiusX, const String& radiusY, c
onst String& centerX, const String& centerY, const String& box) |
148 { | 138 { |
149 char at[] = "at"; | 139 char at[] = "at"; |
150 char separator[] = " "; | 140 char separator[] = " "; |
151 StringBuilder result; | 141 StringBuilder result; |
152 result.appendLiteral("ellipse("); | 142 result.appendLiteral("ellipse("); |
153 bool needsSeparator = false; | 143 bool needsSeparator = false; |
154 if (!radiusX.isNull()) { | 144 if (!radiusX.isNull()) { |
155 result.append(radiusX); | 145 result.append(radiusX); |
156 needsSeparator = true; | 146 needsSeparator = true; |
(...skipping 17 matching lines...) Expand all Loading... |
174 result.append(')'); | 164 result.append(')'); |
175 if (box.length()) { | 165 if (box.length()) { |
176 result.appendLiteral(separator); | 166 result.appendLiteral(separator); |
177 result.append(box); | 167 result.append(box); |
178 } | 168 } |
179 return result.toString(); | 169 return result.toString(); |
180 } | 170 } |
181 | 171 |
182 String CSSBasicShapeEllipse::cssText() const | 172 String CSSBasicShapeEllipse::cssText() const |
183 { | 173 { |
184 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); | 174 RefPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_c
enterX, CSSValueLeft); |
185 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); | 175 RefPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_c
enterY, CSSValueTop); |
186 | 176 |
187 String radiusX; | 177 String radiusX; |
188 String radiusY; | 178 String radiusY; |
189 if (m_radiusX) { | 179 if (m_radiusX) { |
190 bool shouldSerializeRadiusXValue = m_radiusX->getValueID() != CSSValueCl
osestSide; | 180 bool shouldSerializeRadiusXValue = m_radiusX->getValueID() != CSSValueCl
osestSide; |
191 bool shouldSerializeRadiusYValue = false; | 181 bool shouldSerializeRadiusYValue = false; |
192 | 182 |
193 if (m_radiusY) { | 183 if (m_radiusY) { |
194 shouldSerializeRadiusYValue = m_radiusY->getValueID() != CSSValueClo
sestSide; | 184 shouldSerializeRadiusYValue = m_radiusY->getValueID() != CSSValueClo
sestSide; |
195 if (shouldSerializeRadiusYValue) | 185 if (shouldSerializeRadiusYValue) |
(...skipping 15 matching lines...) Expand all Loading... |
211 return false; | 201 return false; |
212 | 202 |
213 const CSSBasicShapeEllipse& other = toCSSBasicShapeEllipse(shape); | 203 const CSSBasicShapeEllipse& other = toCSSBasicShapeEllipse(shape); |
214 return compareCSSValuePtr(m_centerX, other.m_centerX) | 204 return compareCSSValuePtr(m_centerX, other.m_centerX) |
215 && compareCSSValuePtr(m_centerY, other.m_centerY) | 205 && compareCSSValuePtr(m_centerY, other.m_centerY) |
216 && compareCSSValuePtr(m_radiusX, other.m_radiusX) | 206 && compareCSSValuePtr(m_radiusX, other.m_radiusX) |
217 && compareCSSValuePtr(m_radiusY, other.m_radiusY) | 207 && compareCSSValuePtr(m_radiusY, other.m_radiusY) |
218 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox); | 208 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox); |
219 } | 209 } |
220 | 210 |
221 DEFINE_TRACE(CSSBasicShapeEllipse) | |
222 { | |
223 visitor->trace(m_centerX); | |
224 visitor->trace(m_centerY); | |
225 visitor->trace(m_radiusX); | |
226 visitor->trace(m_radiusY); | |
227 CSSBasicShape::trace(visitor); | |
228 } | |
229 | |
230 static String buildPolygonString(const WindRule& windRule, const Vector<String>&
points, const String& box) | 211 static String buildPolygonString(const WindRule& windRule, const Vector<String>&
points, const String& box) |
231 { | 212 { |
232 ASSERT(!(points.size() % 2)); | 213 ASSERT(!(points.size() % 2)); |
233 | 214 |
234 StringBuilder result; | 215 StringBuilder result; |
235 const char evenOddOpening[] = "polygon(evenodd, "; | 216 const char evenOddOpening[] = "polygon(evenodd, "; |
236 const char nonZeroOpening[] = "polygon("; | 217 const char nonZeroOpening[] = "polygon("; |
237 const char commaSeparator[] = ", "; | 218 const char commaSeparator[] = ", "; |
238 static_assert(sizeof(evenOddOpening) > sizeof(nonZeroOpening), "polygon stri
ng openings should be the same length"); | 219 static_assert(sizeof(evenOddOpening) > sizeof(nonZeroOpening), "polygon stri
ng openings should be the same length"); |
239 | 220 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 return false; | 270 return false; |
290 | 271 |
291 const CSSBasicShapePolygon& rhs = toCSSBasicShapePolygon(shape); | 272 const CSSBasicShapePolygon& rhs = toCSSBasicShapePolygon(shape); |
292 | 273 |
293 if (!compareCSSValuePtr(m_referenceBox, rhs.m_referenceBox)) | 274 if (!compareCSSValuePtr(m_referenceBox, rhs.m_referenceBox)) |
294 return false; | 275 return false; |
295 | 276 |
296 return compareCSSValueVector(m_values, rhs.m_values); | 277 return compareCSSValueVector(m_values, rhs.m_values); |
297 } | 278 } |
298 | 279 |
299 DEFINE_TRACE(CSSBasicShapePolygon) | |
300 { | |
301 visitor->trace(m_values); | |
302 CSSBasicShape::trace(visitor); | |
303 } | |
304 | |
305 static bool buildInsetRadii(Vector<String> &radii, const String& topLeftRadius,
const String& topRightRadius, const String& bottomRightRadius, const String& bot
tomLeftRadius) | 280 static bool buildInsetRadii(Vector<String> &radii, const String& topLeftRadius,
const String& topRightRadius, const String& bottomRightRadius, const String& bot
tomLeftRadius) |
306 { | 281 { |
307 bool showBottomLeft = topRightRadius != bottomLeftRadius; | 282 bool showBottomLeft = topRightRadius != bottomLeftRadius; |
308 bool showBottomRight = showBottomLeft || (bottomRightRadius != topLeftRadius
); | 283 bool showBottomRight = showBottomLeft || (bottomRightRadius != topLeftRadius
); |
309 bool showTopRight = showBottomRight || (topRightRadius != topLeftRadius); | 284 bool showTopRight = showBottomRight || (topRightRadius != topLeftRadius); |
310 | 285 |
311 radii.append(topLeftRadius); | 286 radii.append(topLeftRadius); |
312 if (showTopRight) | 287 if (showTopRight) |
313 radii.append(topRightRadius); | 288 radii.append(topRightRadius); |
314 if (showBottomRight) | 289 if (showBottomRight) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 return compareCSSValuePtr(m_top, other.m_top) | 403 return compareCSSValuePtr(m_top, other.m_top) |
429 && compareCSSValuePtr(m_right, other.m_right) | 404 && compareCSSValuePtr(m_right, other.m_right) |
430 && compareCSSValuePtr(m_bottom, other.m_bottom) | 405 && compareCSSValuePtr(m_bottom, other.m_bottom) |
431 && compareCSSValuePtr(m_left, other.m_left) | 406 && compareCSSValuePtr(m_left, other.m_left) |
432 && compareCSSValuePtr(m_topLeftRadius, other.m_topLeftRadius) | 407 && compareCSSValuePtr(m_topLeftRadius, other.m_topLeftRadius) |
433 && compareCSSValuePtr(m_topRightRadius, other.m_topRightRadius) | 408 && compareCSSValuePtr(m_topRightRadius, other.m_topRightRadius) |
434 && compareCSSValuePtr(m_bottomRightRadius, other.m_bottomRightRadius) | 409 && compareCSSValuePtr(m_bottomRightRadius, other.m_bottomRightRadius) |
435 && compareCSSValuePtr(m_bottomLeftRadius, other.m_bottomLeftRadius); | 410 && compareCSSValuePtr(m_bottomLeftRadius, other.m_bottomLeftRadius); |
436 } | 411 } |
437 | 412 |
438 DEFINE_TRACE(CSSBasicShapeInset) | |
439 { | |
440 visitor->trace(m_top); | |
441 visitor->trace(m_right); | |
442 visitor->trace(m_bottom); | |
443 visitor->trace(m_left); | |
444 visitor->trace(m_topLeftRadius); | |
445 visitor->trace(m_topRightRadius); | |
446 visitor->trace(m_bottomRightRadius); | |
447 visitor->trace(m_bottomLeftRadius); | |
448 CSSBasicShape::trace(visitor); | |
449 } | |
450 | |
451 } // namespace blink | 413 } // namespace blink |
452 | 414 |
OLD | NEW |