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 12 matching lines...) Expand all Loading... |
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
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/CSSBasicShapes.h" | 31 #include "core/css/CSSBasicShapes.h" |
32 | 32 |
| 33 #include "core/css/CSSValuePair.h" |
33 #include "core/css/CSSValuePool.h" | 34 #include "core/css/CSSValuePool.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) | 42 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CSSBasicShape) |
43 | 43 |
44 static String buildCircleString(const String& radius, const String& centerX, con
st String& centerY) | 44 static String buildCircleString(const String& radius, const String& centerX, con
st String& centerY) |
(...skipping 11 matching lines...) Expand all Loading... |
56 result.append(at); | 56 result.append(at); |
57 result.appendLiteral(separator); | 57 result.appendLiteral(separator); |
58 result.append(centerX); | 58 result.append(centerX); |
59 result.appendLiteral(separator); | 59 result.appendLiteral(separator); |
60 result.append(centerY); | 60 result.append(centerY); |
61 } | 61 } |
62 result.append(')'); | 62 result.append(')'); |
63 return result.toString(); | 63 return result.toString(); |
64 } | 64 } |
65 | 65 |
66 static String serializePositionOffset(const Pair& offset, const Pair& other) | 66 static String serializePositionOffset(const CSSValuePair& offset, const CSSValue
Pair& other) |
67 { | 67 { |
68 if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValue
ID() == CSSValueTop) | 68 if ((toCSSPrimitiveValue(offset.first())->getValueID() == CSSValueLeft && to
CSSPrimitiveValue(other.first())->getValueID() == CSSValueTop) |
69 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal
ueID() == CSSValueLeft)) | 69 || (toCSSPrimitiveValue(offset.first())->getValueID() == CSSValueTop &&
toCSSPrimitiveValue(other.first())->getValueID() == CSSValueLeft)) |
70 return offset.second()->cssText(); | 70 return offset.second()->cssText(); |
71 return offset.cssText(); | 71 return offset.cssText(); |
72 } | 72 } |
73 | 73 |
74 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> buildSerializablePositionOffset
(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> offset, CSSValueID defaultSide) | 74 static PassRefPtrWillBeRawPtr<CSSValuePair> buildSerializablePositionOffset(Pass
RefPtrWillBeRawPtr<CSSValue> offset, CSSValueID defaultSide) |
75 { | 75 { |
76 CSSValueID side = defaultSide; | 76 CSSValueID side = defaultSide; |
77 RefPtrWillBeRawPtr<CSSPrimitiveValue> amount = nullptr; | 77 RefPtrWillBeRawPtr<CSSPrimitiveValue> amount = nullptr; |
78 | 78 |
79 if (!offset) { | 79 if (!offset) { |
80 side = CSSValueCenter; | 80 side = CSSValueCenter; |
81 } else if (offset->isValueID()) { | 81 } else if (offset->isPrimitiveValue() && toCSSPrimitiveValue(offset.get())->
isValueID()) { |
82 side = offset->getValueID(); | 82 side = toCSSPrimitiveValue(offset.get())->getValueID(); |
83 } else if (Pair* pair = offset->getPairValue()) { | 83 } else if (offset->isValuePair()) { |
84 side = pair->first()->getValueID(); | 84 side = toCSSPrimitiveValue(toCSSValuePair(offset.get())->first())->getVa
lueID(); |
85 amount = pair->second(); | 85 amount = toCSSPrimitiveValue(toCSSValuePair(offset.get())->second()); |
86 } else { | 86 } else { |
87 amount = offset; | 87 amount = toCSSPrimitiveValue(offset.get()); |
88 } | 88 } |
89 | 89 |
90 if (side == CSSValueCenter) { | 90 if (side == CSSValueCenter) { |
91 side = defaultSide; | 91 side = defaultSide; |
92 amount = cssValuePool().createValue(50, CSSPrimitiveValue::UnitType::Per
centage); | 92 amount = cssValuePool().createValue(50, CSSPrimitiveValue::UnitType::Per
centage); |
93 } else if ((side == CSSValueRight || side == CSSValueBottom) | 93 } else if ((side == CSSValueRight || side == CSSValueBottom) |
94 && amount->isPercentage()) { | 94 && amount->isPercentage()) { |
95 side = defaultSide; | 95 side = defaultSide; |
96 amount = cssValuePool().createValue(100 - amount->getFloatValue(), CSSPr
imitiveValue::UnitType::Percentage); | 96 amount = cssValuePool().createValue(100 - amount->getFloatValue(), CSSPr
imitiveValue::UnitType::Percentage); |
97 } else if (amount->isLength() && !amount->getFloatValue()) { | 97 } else if (amount->isLength() && !amount->getFloatValue()) { |
98 if (side == CSSValueRight || side == CSSValueBottom) | 98 if (side == CSSValueRight || side == CSSValueBottom) |
99 amount = cssValuePool().createValue(100, CSSPrimitiveValue::UnitType
::Percentage); | 99 amount = cssValuePool().createValue(100, CSSPrimitiveValue::UnitType
::Percentage); |
100 else | 100 else |
101 amount = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::
Percentage); | 101 amount = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::
Percentage); |
102 side = defaultSide; | 102 side = defaultSide; |
103 } | 103 } |
104 | 104 |
105 return cssValuePool().createValue(Pair::create(cssValuePool().createValue(si
de), amount.release(), Pair::KeepIdenticalValues)); | 105 return CSSValuePair::create(cssValuePool().createValue(side), amount.release
(), CSSValuePair::KeepIdenticalValues); |
106 } | 106 } |
107 | 107 |
108 String CSSBasicShapeCircle::cssText() const | 108 String CSSBasicShapeCircle::cssText() const |
109 { | 109 { |
110 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); | 110 RefPtrWillBeRawPtr<CSSValuePair> normalizedCX = buildSerializablePositionOff
set(m_centerX, CSSValueLeft); |
111 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); | 111 RefPtrWillBeRawPtr<CSSValuePair> normalizedCY = buildSerializablePositionOff
set(m_centerY, CSSValueTop); |
112 | 112 |
113 String radius; | 113 String radius; |
114 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) | 114 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) |
115 radius = m_radius->cssText(); | 115 radius = m_radius->cssText(); |
116 | 116 |
117 return buildCircleString(radius, | 117 return buildCircleString(radius, |
118 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), | 118 serializePositionOffset(*normalizedCX, *normalizedCY), |
119 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue())); | 119 serializePositionOffset(*normalizedCY, *normalizedCX)); |
120 } | 120 } |
121 | 121 |
122 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const | 122 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const |
123 { | 123 { |
124 if (shape.type() != CSSBasicShapeCircleType) | 124 if (shape.type() != CSSBasicShapeCircleType) |
125 return false; | 125 return false; |
126 | 126 |
127 const CSSBasicShapeCircle& other = toCSSBasicShapeCircle(shape); | 127 const CSSBasicShapeCircle& other = toCSSBasicShapeCircle(shape); |
128 return compareCSSValuePtr(m_centerX, other.m_centerX) | 128 return compareCSSValuePtr(m_centerX, other.m_centerX) |
129 && compareCSSValuePtr(m_centerY, other.m_centerY) | 129 && compareCSSValuePtr(m_centerY, other.m_centerY) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 result.append(centerX); | 164 result.append(centerX); |
165 result.appendLiteral(separator); | 165 result.appendLiteral(separator); |
166 result.append(centerY); | 166 result.append(centerY); |
167 } | 167 } |
168 result.append(')'); | 168 result.append(')'); |
169 return result.toString(); | 169 return result.toString(); |
170 } | 170 } |
171 | 171 |
172 String CSSBasicShapeEllipse::cssText() const | 172 String CSSBasicShapeEllipse::cssText() const |
173 { | 173 { |
174 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); | 174 RefPtrWillBeRawPtr<CSSValuePair> normalizedCX = buildSerializablePositionOff
set(m_centerX, CSSValueLeft); |
175 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); | 175 RefPtrWillBeRawPtr<CSSValuePair> normalizedCY = buildSerializablePositionOff
set(m_centerY, CSSValueTop); |
176 | 176 |
177 String radiusX; | 177 String radiusX; |
178 String radiusY; | 178 String radiusY; |
179 if (m_radiusX) { | 179 if (m_radiusX) { |
180 bool shouldSerializeRadiusXValue = m_radiusX->getValueID() != CSSValueCl
osestSide; | 180 bool shouldSerializeRadiusXValue = m_radiusX->getValueID() != CSSValueCl
osestSide; |
181 bool shouldSerializeRadiusYValue = false; | 181 bool shouldSerializeRadiusYValue = false; |
182 | 182 |
183 if (m_radiusY) { | 183 if (m_radiusY) { |
184 shouldSerializeRadiusYValue = m_radiusY->getValueID() != CSSValueClo
sestSide; | 184 shouldSerializeRadiusYValue = m_radiusY->getValueID() != CSSValueClo
sestSide; |
185 if (shouldSerializeRadiusYValue) | 185 if (shouldSerializeRadiusYValue) |
186 radiusY = m_radiusY->cssText(); | 186 radiusY = m_radiusY->cssText(); |
187 } | 187 } |
188 if (shouldSerializeRadiusXValue || (!shouldSerializeRadiusXValue && shou
ldSerializeRadiusYValue)) | 188 if (shouldSerializeRadiusXValue || (!shouldSerializeRadiusXValue && shou
ldSerializeRadiusYValue)) |
189 radiusX = m_radiusX->cssText(); | 189 radiusX = m_radiusX->cssText(); |
190 } | 190 } |
191 | 191 |
192 return buildEllipseString(radiusX, radiusY, | 192 return buildEllipseString(radiusX, radiusY, |
193 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), | 193 serializePositionOffset(*normalizedCX, *normalizedCY), |
194 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue())); | 194 serializePositionOffset(*normalizedCY, *normalizedCX)); |
195 } | 195 } |
196 | 196 |
197 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const | 197 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const |
198 { | 198 { |
199 if (shape.type() != CSSBasicShapeEllipseType) | 199 if (shape.type() != CSSBasicShapeEllipseType) |
200 return false; | 200 return false; |
201 | 201 |
202 const CSSBasicShapeEllipse& other = toCSSBasicShapeEllipse(shape); | 202 const CSSBasicShapeEllipse& other = toCSSBasicShapeEllipse(shape); |
203 return compareCSSValuePtr(m_centerX, other.m_centerX) | 203 return compareCSSValuePtr(m_centerX, other.m_centerX) |
204 && compareCSSValuePtr(m_centerY, other.m_centerY) | 204 && compareCSSValuePtr(m_centerY, other.m_centerY) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 result.append(verticalRadii[i]); | 347 result.append(verticalRadii[i]); |
348 } | 348 } |
349 } | 349 } |
350 } | 350 } |
351 } | 351 } |
352 result.append(')'); | 352 result.append(')'); |
353 | 353 |
354 return result.toString(); | 354 return result.toString(); |
355 } | 355 } |
356 | 356 |
357 static inline void updateCornerRadiusWidthAndHeight(CSSPrimitiveValue* corner, S
tring& width, String& height) | 357 static inline void updateCornerRadiusWidthAndHeight(CSSValuePair* cornerRadius,
String& width, String& height) |
358 { | 358 { |
359 if (!corner) | 359 if (!cornerRadius) |
360 return; | 360 return; |
361 | 361 |
362 Pair* radius = corner->getPairValue(); | 362 width = cornerRadius->first() ? cornerRadius->first()->cssText() : String("0
"); |
363 width = radius->first() ? radius->first()->cssText() : String("0"); | 363 if (cornerRadius->second()) |
364 if (radius->second()) | 364 height = cornerRadius->second()->cssText(); |
365 height = radius->second()->cssText(); | |
366 } | 365 } |
367 | 366 |
368 String CSSBasicShapeInset::cssText() const | 367 String CSSBasicShapeInset::cssText() const |
369 { | 368 { |
370 String topLeftRadiusWidth; | 369 String topLeftRadiusWidth; |
371 String topLeftRadiusHeight; | 370 String topLeftRadiusHeight; |
372 String topRightRadiusWidth; | 371 String topRightRadiusWidth; |
373 String topRightRadiusHeight; | 372 String topRightRadiusHeight; |
374 String bottomRightRadiusWidth; | 373 String bottomRightRadiusWidth; |
375 String bottomRightRadiusHeight; | 374 String bottomRightRadiusHeight; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 visitor->trace(m_left); | 418 visitor->trace(m_left); |
420 visitor->trace(m_topLeftRadius); | 419 visitor->trace(m_topLeftRadius); |
421 visitor->trace(m_topRightRadius); | 420 visitor->trace(m_topRightRadius); |
422 visitor->trace(m_bottomRightRadius); | 421 visitor->trace(m_bottomRightRadius); |
423 visitor->trace(m_bottomLeftRadius); | 422 visitor->trace(m_bottomLeftRadius); |
424 CSSBasicShape::trace(visitor); | 423 CSSBasicShape::trace(visitor); |
425 } | 424 } |
426 | 425 |
427 } // namespace blink | 426 } // namespace blink |
428 | 427 |
OLD | NEW |