| 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, const String& box) | 44 static String buildCircleString(const String& radius, const String& centerX, con
st String& centerY, const String& box) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 result.append(centerY); | 60 result.append(centerY); |
| 61 } | 61 } |
| 62 result.append(')'); | 62 result.append(')'); |
| 63 if (box.length()) { | 63 if (box.length()) { |
| 64 result.appendLiteral(separator); | 64 result.appendLiteral(separator); |
| 65 result.append(box); | 65 result.append(box); |
| 66 } | 66 } |
| 67 return result.toString(); | 67 return result.toString(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static String serializePositionOffset(const Pair& offset, const Pair& other) | 70 static String serializePositionOffset(const CSSValuePair& offset, const CSSValue
Pair& other) |
| 71 { | 71 { |
| 72 if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValue
ID() == CSSValueTop) | 72 if ((toCSSPrimitiveValue(offset.first())->getValueID() == CSSValueLeft && to
CSSPrimitiveValue(other.first())->getValueID() == CSSValueTop) |
| 73 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal
ueID() == CSSValueLeft)) | 73 || (toCSSPrimitiveValue(offset.first())->getValueID() == CSSValueTop &&
toCSSPrimitiveValue(other.first())->getValueID() == CSSValueLeft)) |
| 74 return offset.second()->cssText(); | 74 return offset.second()->cssText(); |
| 75 return offset.cssText(); | 75 return offset.cssText(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> buildSerializablePositionOffset
(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> offset, CSSValueID defaultSide) | 78 static PassRefPtrWillBeRawPtr<CSSValuePair> buildSerializablePositionOffset(Pass
RefPtrWillBeRawPtr<CSSValue> offset, CSSValueID defaultSide) |
| 79 { | 79 { |
| 80 CSSValueID side = defaultSide; | 80 CSSValueID side = defaultSide; |
| 81 RefPtrWillBeRawPtr<CSSPrimitiveValue> amount = nullptr; | 81 RefPtrWillBeRawPtr<CSSPrimitiveValue> amount = nullptr; |
| 82 | 82 |
| 83 if (!offset) { | 83 if (!offset) { |
| 84 side = CSSValueCenter; | 84 side = CSSValueCenter; |
| 85 } else if (offset->isValueID()) { | 85 } else if (offset->isPrimitiveValue() && toCSSPrimitiveValue(offset.get())->
isValueID()) { |
| 86 side = offset->getValueID(); | 86 side = toCSSPrimitiveValue(offset.get())->getValueID(); |
| 87 } else if (Pair* pair = offset->getPairValue()) { | 87 } else if (offset->isValuePair()) { |
| 88 side = pair->first()->getValueID(); | 88 side = toCSSPrimitiveValue(toCSSValuePair(offset.get())->first())->getVa
lueID(); |
| 89 amount = pair->second(); | 89 amount = toCSSPrimitiveValue(toCSSValuePair(offset.get())->second()); |
| 90 } else { | 90 } else { |
| 91 amount = offset; | 91 amount = toCSSPrimitiveValue(offset.get()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 if (side == CSSValueCenter) { | 94 if (side == CSSValueCenter) { |
| 95 side = defaultSide; | 95 side = defaultSide; |
| 96 amount = cssValuePool().createValue(50, CSSPrimitiveValue::UnitType::Per
centage); | 96 amount = cssValuePool().createValue(50, CSSPrimitiveValue::UnitType::Per
centage); |
| 97 } else if ((side == CSSValueRight || side == CSSValueBottom) | 97 } else if ((side == CSSValueRight || side == CSSValueBottom) |
| 98 && amount->isPercentage()) { | 98 && amount->isPercentage()) { |
| 99 side = defaultSide; | 99 side = defaultSide; |
| 100 amount = cssValuePool().createValue(100 - amount->getFloatValue(), CSSPr
imitiveValue::UnitType::Percentage); | 100 amount = cssValuePool().createValue(100 - amount->getFloatValue(), CSSPr
imitiveValue::UnitType::Percentage); |
| 101 } else if (amount->isLength() && !amount->getFloatValue()) { | 101 } else if (amount->isLength() && !amount->getFloatValue()) { |
| 102 if (side == CSSValueRight || side == CSSValueBottom) | 102 if (side == CSSValueRight || side == CSSValueBottom) |
| 103 amount = cssValuePool().createValue(100, CSSPrimitiveValue::UnitType
::Percentage); | 103 amount = cssValuePool().createValue(100, CSSPrimitiveValue::UnitType
::Percentage); |
| 104 else | 104 else |
| 105 amount = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::
Percentage); | 105 amount = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::
Percentage); |
| 106 side = defaultSide; | 106 side = defaultSide; |
| 107 } | 107 } |
| 108 | 108 |
| 109 return cssValuePool().createValue(Pair::create(cssValuePool().createValue(si
de), amount.release(), Pair::KeepIdenticalValues)); | 109 return CSSValuePair::create(cssValuePool().createValue(side), amount.release
(), CSSValuePair::KeepIdenticalValues); |
| 110 } | 110 } |
| 111 | 111 |
| 112 String CSSBasicShapeCircle::cssText() const | 112 String CSSBasicShapeCircle::cssText() const |
| 113 { | 113 { |
| 114 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); | 114 RefPtrWillBeRawPtr<CSSValuePair> normalizedCX = buildSerializablePositionOff
set(m_centerX, CSSValueLeft); |
| 115 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); | 115 RefPtrWillBeRawPtr<CSSValuePair> normalizedCY = buildSerializablePositionOff
set(m_centerY, CSSValueTop); |
| 116 | 116 |
| 117 String radius; | 117 String radius; |
| 118 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) | 118 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) |
| 119 radius = m_radius->cssText(); | 119 radius = m_radius->cssText(); |
| 120 | 120 |
| 121 return buildCircleString(radius, | 121 return buildCircleString(radius, |
| 122 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), | 122 serializePositionOffset(*normalizedCX, *normalizedCY), |
| 123 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue()), | 123 serializePositionOffset(*normalizedCY, *normalizedCX), |
| 124 m_referenceBox ? m_referenceBox->cssText() : String()); | 124 m_referenceBox ? m_referenceBox->cssText() : String()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const | 127 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const |
| 128 { | 128 { |
| 129 if (shape.type() != CSSBasicShapeCircleType) | 129 if (shape.type() != CSSBasicShapeCircleType) |
| 130 return false; | 130 return false; |
| 131 | 131 |
| 132 const CSSBasicShapeCircle& other = toCSSBasicShapeCircle(shape); | 132 const CSSBasicShapeCircle& other = toCSSBasicShapeCircle(shape); |
| 133 return compareCSSValuePtr(m_centerX, other.m_centerX) | 133 return compareCSSValuePtr(m_centerX, other.m_centerX) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 result.append(')'); | 174 result.append(')'); |
| 175 if (box.length()) { | 175 if (box.length()) { |
| 176 result.appendLiteral(separator); | 176 result.appendLiteral(separator); |
| 177 result.append(box); | 177 result.append(box); |
| 178 } | 178 } |
| 179 return result.toString(); | 179 return result.toString(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 String CSSBasicShapeEllipse::cssText() const | 182 String CSSBasicShapeEllipse::cssText() const |
| 183 { | 183 { |
| 184 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); | 184 RefPtrWillBeRawPtr<CSSValuePair> normalizedCX = buildSerializablePositionOff
set(m_centerX, CSSValueLeft); |
| 185 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); | 185 RefPtrWillBeRawPtr<CSSValuePair> normalizedCY = buildSerializablePositionOff
set(m_centerY, CSSValueTop); |
| 186 | 186 |
| 187 String radiusX; | 187 String radiusX; |
| 188 String radiusY; | 188 String radiusY; |
| 189 if (m_radiusX) { | 189 if (m_radiusX) { |
| 190 bool shouldSerializeRadiusXValue = m_radiusX->getValueID() != CSSValueCl
osestSide; | 190 bool shouldSerializeRadiusXValue = m_radiusX->getValueID() != CSSValueCl
osestSide; |
| 191 bool shouldSerializeRadiusYValue = false; | 191 bool shouldSerializeRadiusYValue = false; |
| 192 | 192 |
| 193 if (m_radiusY) { | 193 if (m_radiusY) { |
| 194 shouldSerializeRadiusYValue = m_radiusY->getValueID() != CSSValueClo
sestSide; | 194 shouldSerializeRadiusYValue = m_radiusY->getValueID() != CSSValueClo
sestSide; |
| 195 if (shouldSerializeRadiusYValue) | 195 if (shouldSerializeRadiusYValue) |
| 196 radiusY = m_radiusY->cssText(); | 196 radiusY = m_radiusY->cssText(); |
| 197 } | 197 } |
| 198 if (shouldSerializeRadiusXValue || (!shouldSerializeRadiusXValue && shou
ldSerializeRadiusYValue)) | 198 if (shouldSerializeRadiusXValue || (!shouldSerializeRadiusXValue && shou
ldSerializeRadiusYValue)) |
| 199 radiusX = m_radiusX->cssText(); | 199 radiusX = m_radiusX->cssText(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 return buildEllipseString(radiusX, radiusY, | 202 return buildEllipseString(radiusX, radiusY, |
| 203 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), | 203 serializePositionOffset(*normalizedCX, *normalizedCY), |
| 204 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue()), | 204 serializePositionOffset(*normalizedCY, *normalizedCX), |
| 205 m_referenceBox ? m_referenceBox->cssText() : String()); | 205 m_referenceBox ? m_referenceBox->cssText() : String()); |
| 206 } | 206 } |
| 207 | 207 |
| 208 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const | 208 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const |
| 209 { | 209 { |
| 210 if (shape.type() != CSSBasicShapeEllipseType) | 210 if (shape.type() != CSSBasicShapeEllipseType) |
| 211 return false; | 211 return false; |
| 212 | 212 |
| 213 const CSSBasicShapeEllipse& other = toCSSBasicShapeEllipse(shape); | 213 const CSSBasicShapeEllipse& other = toCSSBasicShapeEllipse(shape); |
| 214 return compareCSSValuePtr(m_centerX, other.m_centerX) | 214 return compareCSSValuePtr(m_centerX, other.m_centerX) |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 result.append(verticalRadii[i]); | 371 result.append(verticalRadii[i]); |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 result.append(')'); | 376 result.append(')'); |
| 377 | 377 |
| 378 return result.toString(); | 378 return result.toString(); |
| 379 } | 379 } |
| 380 | 380 |
| 381 static inline void updateCornerRadiusWidthAndHeight(CSSPrimitiveValue* corner, S
tring& width, String& height) | 381 static inline void updateCornerRadiusWidthAndHeight(CSSValuePair* cornerRadius,
String& width, String& height) |
| 382 { | 382 { |
| 383 if (!corner) | 383 if (!cornerRadius) |
| 384 return; | 384 return; |
| 385 | 385 |
| 386 Pair* radius = corner->getPairValue(); | 386 width = cornerRadius->first() ? cornerRadius->first()->cssText() : String("0
"); |
| 387 width = radius->first() ? radius->first()->cssText() : String("0"); | 387 if (cornerRadius->second()) |
| 388 if (radius->second()) | 388 height = cornerRadius->second()->cssText(); |
| 389 height = radius->second()->cssText(); | |
| 390 } | 389 } |
| 391 | 390 |
| 392 String CSSBasicShapeInset::cssText() const | 391 String CSSBasicShapeInset::cssText() const |
| 393 { | 392 { |
| 394 String topLeftRadiusWidth; | 393 String topLeftRadiusWidth; |
| 395 String topLeftRadiusHeight; | 394 String topLeftRadiusHeight; |
| 396 String topRightRadiusWidth; | 395 String topRightRadiusWidth; |
| 397 String topRightRadiusHeight; | 396 String topRightRadiusHeight; |
| 398 String bottomRightRadiusWidth; | 397 String bottomRightRadiusWidth; |
| 399 String bottomRightRadiusHeight; | 398 String bottomRightRadiusHeight; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 visitor->trace(m_left); | 442 visitor->trace(m_left); |
| 444 visitor->trace(m_topLeftRadius); | 443 visitor->trace(m_topLeftRadius); |
| 445 visitor->trace(m_topRightRadius); | 444 visitor->trace(m_topRightRadius); |
| 446 visitor->trace(m_bottomRightRadius); | 445 visitor->trace(m_bottomRightRadius); |
| 447 visitor->trace(m_bottomLeftRadius); | 446 visitor->trace(m_bottomLeftRadius); |
| 448 CSSBasicShape::trace(visitor); | 447 CSSBasicShape::trace(visitor); |
| 449 } | 448 } |
| 450 | 449 |
| 451 } // namespace blink | 450 } // namespace blink |
| 452 | 451 |
| OLD | NEW |