| 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 23 matching lines...) Expand all Loading... |
| 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) | 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) |
| 45 { | 45 { |
| 46 char at[] = "at"; | 46 char at[] = "at"; |
| 47 char separator[] = " "; | 47 char separator[] = " "; |
| 48 StringBuilder result; | 48 StringBuilder result; |
| 49 result.appendLiteral("circle("); | 49 result.appendLiteral("circle("); |
| 50 if (!radius.isNull()) | 50 if (!radius.isNull()) |
| 51 result.append(radius); | 51 result.append(radius); |
| 52 | 52 |
| 53 if (!centerX.isNull() || !centerY.isNull()) { | 53 if (!centerX.isNull() || !centerY.isNull()) { |
| 54 if (!radius.isNull()) | 54 if (!radius.isNull()) |
| 55 result.appendLiteral(separator); | 55 result.appendLiteral(separator); |
| 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 if (box.length()) { | |
| 64 result.appendLiteral(separator); | |
| 65 result.append(box); | |
| 66 } | |
| 67 return result.toString(); | 63 return result.toString(); |
| 68 } | 64 } |
| 69 | 65 |
| 70 static String serializePositionOffset(const Pair& offset, const Pair& other) | 66 static String serializePositionOffset(const Pair& offset, const Pair& other) |
| 71 { | 67 { |
| 72 if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValue
ID() == CSSValueTop) | 68 if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValue
ID() == CSSValueTop) |
| 73 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal
ueID() == CSSValueLeft)) | 69 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal
ueID() == CSSValueLeft)) |
| 74 return offset.second()->cssText(); | 70 return offset.second()->cssText(); |
| 75 return offset.cssText(); | 71 return offset.cssText(); |
| 76 } | 72 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 { | 109 { |
| 114 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); | 110 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); |
| 115 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); | 111 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); |
| 116 | 112 |
| 117 String radius; | 113 String radius; |
| 118 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) | 114 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) |
| 119 radius = m_radius->cssText(); | 115 radius = m_radius->cssText(); |
| 120 | 116 |
| 121 return buildCircleString(radius, | 117 return buildCircleString(radius, |
| 122 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), | 118 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), |
| 123 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue()), | 119 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue())); |
| 124 m_referenceBox ? m_referenceBox->cssText() : String()); | |
| 125 } | 120 } |
| 126 | 121 |
| 127 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const | 122 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const |
| 128 { | 123 { |
| 129 if (shape.type() != CSSBasicShapeCircleType) | 124 if (shape.type() != CSSBasicShapeCircleType) |
| 130 return false; | 125 return false; |
| 131 | 126 |
| 132 const CSSBasicShapeCircle& other = toCSSBasicShapeCircle(shape); | 127 const CSSBasicShapeCircle& other = toCSSBasicShapeCircle(shape); |
| 133 return compareCSSValuePtr(m_centerX, other.m_centerX) | 128 return compareCSSValuePtr(m_centerX, other.m_centerX) |
| 134 && compareCSSValuePtr(m_centerY, other.m_centerY) | 129 && compareCSSValuePtr(m_centerY, other.m_centerY) |
| 135 && compareCSSValuePtr(m_radius, other.m_radius) | 130 && compareCSSValuePtr(m_radius, other.m_radius); |
| 136 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox); | |
| 137 } | 131 } |
| 138 | 132 |
| 139 DEFINE_TRACE(CSSBasicShapeCircle) | 133 DEFINE_TRACE(CSSBasicShapeCircle) |
| 140 { | 134 { |
| 141 visitor->trace(m_centerX); | 135 visitor->trace(m_centerX); |
| 142 visitor->trace(m_centerY); | 136 visitor->trace(m_centerY); |
| 143 visitor->trace(m_radius); | 137 visitor->trace(m_radius); |
| 144 CSSBasicShape::trace(visitor); | 138 CSSBasicShape::trace(visitor); |
| 145 } | 139 } |
| 146 | 140 |
| 147 static String buildEllipseString(const String& radiusX, const String& radiusY, c
onst String& centerX, const String& centerY, const String& box) | 141 static String buildEllipseString(const String& radiusX, const String& radiusY, c
onst String& centerX, const String& centerY) |
| 148 { | 142 { |
| 149 char at[] = "at"; | 143 char at[] = "at"; |
| 150 char separator[] = " "; | 144 char separator[] = " "; |
| 151 StringBuilder result; | 145 StringBuilder result; |
| 152 result.appendLiteral("ellipse("); | 146 result.appendLiteral("ellipse("); |
| 153 bool needsSeparator = false; | 147 bool needsSeparator = false; |
| 154 if (!radiusX.isNull()) { | 148 if (!radiusX.isNull()) { |
| 155 result.append(radiusX); | 149 result.append(radiusX); |
| 156 needsSeparator = true; | 150 needsSeparator = true; |
| 157 } | 151 } |
| 158 if (!radiusY.isNull()) { | 152 if (!radiusY.isNull()) { |
| 159 if (needsSeparator) | 153 if (needsSeparator) |
| 160 result.appendLiteral(separator); | 154 result.appendLiteral(separator); |
| 161 result.append(radiusY); | 155 result.append(radiusY); |
| 162 needsSeparator = true; | 156 needsSeparator = true; |
| 163 } | 157 } |
| 164 | 158 |
| 165 if (!centerX.isNull() || !centerY.isNull()) { | 159 if (!centerX.isNull() || !centerY.isNull()) { |
| 166 if (needsSeparator) | 160 if (needsSeparator) |
| 167 result.appendLiteral(separator); | 161 result.appendLiteral(separator); |
| 168 result.appendLiteral(at); | 162 result.appendLiteral(at); |
| 169 result.appendLiteral(separator); | 163 result.appendLiteral(separator); |
| 170 result.append(centerX); | 164 result.append(centerX); |
| 171 result.appendLiteral(separator); | 165 result.appendLiteral(separator); |
| 172 result.append(centerY); | 166 result.append(centerY); |
| 173 } | 167 } |
| 174 result.append(')'); | 168 result.append(')'); |
| 175 if (box.length()) { | |
| 176 result.appendLiteral(separator); | |
| 177 result.append(box); | |
| 178 } | |
| 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 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi
onOffset(m_centerX, CSSValueLeft); |
| 185 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, CSSValueTop); | 175 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi
onOffset(m_centerY, 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) |
| 196 radiusY = m_radiusY->cssText(); | 186 radiusY = m_radiusY->cssText(); |
| 197 } | 187 } |
| 198 if (shouldSerializeRadiusXValue || (!shouldSerializeRadiusXValue && shou
ldSerializeRadiusYValue)) | 188 if (shouldSerializeRadiusXValue || (!shouldSerializeRadiusXValue && shou
ldSerializeRadiusYValue)) |
| 199 radiusX = m_radiusX->cssText(); | 189 radiusX = m_radiusX->cssText(); |
| 200 } | 190 } |
| 201 | 191 |
| 202 return buildEllipseString(radiusX, radiusY, | 192 return buildEllipseString(radiusX, radiusY, |
| 203 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), | 193 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), |
| 204 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue()), | 194 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue())); |
| 205 m_referenceBox ? m_referenceBox->cssText() : String()); | |
| 206 } | 195 } |
| 207 | 196 |
| 208 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const | 197 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const |
| 209 { | 198 { |
| 210 if (shape.type() != CSSBasicShapeEllipseType) | 199 if (shape.type() != CSSBasicShapeEllipseType) |
| 211 return false; | 200 return false; |
| 212 | 201 |
| 213 const CSSBasicShapeEllipse& other = toCSSBasicShapeEllipse(shape); | 202 const CSSBasicShapeEllipse& other = toCSSBasicShapeEllipse(shape); |
| 214 return compareCSSValuePtr(m_centerX, other.m_centerX) | 203 return compareCSSValuePtr(m_centerX, other.m_centerX) |
| 215 && compareCSSValuePtr(m_centerY, other.m_centerY) | 204 && compareCSSValuePtr(m_centerY, other.m_centerY) |
| 216 && compareCSSValuePtr(m_radiusX, other.m_radiusX) | 205 && compareCSSValuePtr(m_radiusX, other.m_radiusX) |
| 217 && compareCSSValuePtr(m_radiusY, other.m_radiusY) | 206 && compareCSSValuePtr(m_radiusY, other.m_radiusY); |
| 218 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox); | |
| 219 } | 207 } |
| 220 | 208 |
| 221 DEFINE_TRACE(CSSBasicShapeEllipse) | 209 DEFINE_TRACE(CSSBasicShapeEllipse) |
| 222 { | 210 { |
| 223 visitor->trace(m_centerX); | 211 visitor->trace(m_centerX); |
| 224 visitor->trace(m_centerY); | 212 visitor->trace(m_centerY); |
| 225 visitor->trace(m_radiusX); | 213 visitor->trace(m_radiusX); |
| 226 visitor->trace(m_radiusY); | 214 visitor->trace(m_radiusY); |
| 227 CSSBasicShape::trace(visitor); | 215 CSSBasicShape::trace(visitor); |
| 228 } | 216 } |
| 229 | 217 |
| 230 static String buildPolygonString(const WindRule& windRule, const Vector<String>&
points, const String& box) | 218 static String buildPolygonString(const WindRule& windRule, const Vector<String>&
points) |
| 231 { | 219 { |
| 232 ASSERT(!(points.size() % 2)); | 220 ASSERT(!(points.size() % 2)); |
| 233 | 221 |
| 234 StringBuilder result; | 222 StringBuilder result; |
| 235 const char evenOddOpening[] = "polygon(evenodd, "; | 223 const char evenOddOpening[] = "polygon(evenodd, "; |
| 236 const char nonZeroOpening[] = "polygon("; | 224 const char nonZeroOpening[] = "polygon("; |
| 237 const char commaSeparator[] = ", "; | 225 const char commaSeparator[] = ", "; |
| 238 static_assert(sizeof(evenOddOpening) > sizeof(nonZeroOpening), "polygon stri
ng openings should be the same length"); | 226 static_assert(sizeof(evenOddOpening) > sizeof(nonZeroOpening), "polygon stri
ng openings should be the same length"); |
| 239 | 227 |
| 240 // Compute the required capacity in advance to reduce allocations. | 228 // Compute the required capacity in advance to reduce allocations. |
| 241 size_t length = sizeof(evenOddOpening) - 1; | 229 size_t length = sizeof(evenOddOpening) - 1; |
| 242 for (size_t i = 0; i < points.size(); i += 2) { | 230 for (size_t i = 0; i < points.size(); i += 2) { |
| 243 if (i) | 231 if (i) |
| 244 length += (sizeof(commaSeparator) - 1); | 232 length += (sizeof(commaSeparator) - 1); |
| 245 // add length of two strings, plus one for the space separator. | 233 // add length of two strings, plus one for the space separator. |
| 246 length += points[i].length() + 1 + points[i + 1].length(); | 234 length += points[i].length() + 1 + points[i + 1].length(); |
| 247 } | 235 } |
| 248 if (!box.isEmpty()) | |
| 249 length += box.length() + 1; | |
| 250 result.reserveCapacity(length); | 236 result.reserveCapacity(length); |
| 251 | 237 |
| 252 if (windRule == RULE_EVENODD) | 238 if (windRule == RULE_EVENODD) |
| 253 result.appendLiteral(evenOddOpening); | 239 result.appendLiteral(evenOddOpening); |
| 254 else | 240 else |
| 255 result.appendLiteral(nonZeroOpening); | 241 result.appendLiteral(nonZeroOpening); |
| 256 | 242 |
| 257 for (size_t i = 0; i < points.size(); i += 2) { | 243 for (size_t i = 0; i < points.size(); i += 2) { |
| 258 if (i) | 244 if (i) |
| 259 result.appendLiteral(commaSeparator); | 245 result.appendLiteral(commaSeparator); |
| 260 result.append(points[i]); | 246 result.append(points[i]); |
| 261 result.append(' '); | 247 result.append(' '); |
| 262 result.append(points[i + 1]); | 248 result.append(points[i + 1]); |
| 263 } | 249 } |
| 264 | 250 |
| 265 result.append(')'); | 251 result.append(')'); |
| 266 | |
| 267 if (!box.isEmpty()) { | |
| 268 result.append(' '); | |
| 269 result.append(box); | |
| 270 } | |
| 271 | |
| 272 return result.toString(); | 252 return result.toString(); |
| 273 } | 253 } |
| 274 | 254 |
| 275 String CSSBasicShapePolygon::cssText() const | 255 String CSSBasicShapePolygon::cssText() const |
| 276 { | 256 { |
| 277 Vector<String> points; | 257 Vector<String> points; |
| 278 points.reserveInitialCapacity(m_values.size()); | 258 points.reserveInitialCapacity(m_values.size()); |
| 279 | 259 |
| 280 for (size_t i = 0; i < m_values.size(); ++i) | 260 for (size_t i = 0; i < m_values.size(); ++i) |
| 281 points.append(m_values.at(i)->cssText()); | 261 points.append(m_values.at(i)->cssText()); |
| 282 | 262 |
| 283 return buildPolygonString(m_windRule, points, m_referenceBox ? m_referenceBo
x->cssText() : String()); | 263 return buildPolygonString(m_windRule, points); |
| 284 } | 264 } |
| 285 | 265 |
| 286 bool CSSBasicShapePolygon::equals(const CSSBasicShape& shape) const | 266 bool CSSBasicShapePolygon::equals(const CSSBasicShape& shape) const |
| 287 { | 267 { |
| 288 if (shape.type() != CSSBasicShapePolygonType) | 268 if (shape.type() != CSSBasicShapePolygonType) |
| 289 return false; | 269 return false; |
| 290 | 270 |
| 291 const CSSBasicShapePolygon& rhs = toCSSBasicShapePolygon(shape); | 271 const CSSBasicShapePolygon& rhs = toCSSBasicShapePolygon(shape); |
| 292 | |
| 293 if (!compareCSSValuePtr(m_referenceBox, rhs.m_referenceBox)) | |
| 294 return false; | |
| 295 | |
| 296 return compareCSSValueVector(m_values, rhs.m_values); | 272 return compareCSSValueVector(m_values, rhs.m_values); |
| 297 } | 273 } |
| 298 | 274 |
| 299 DEFINE_TRACE(CSSBasicShapePolygon) | 275 DEFINE_TRACE(CSSBasicShapePolygon) |
| 300 { | 276 { |
| 301 visitor->trace(m_values); | 277 visitor->trace(m_values); |
| 302 CSSBasicShape::trace(visitor); | 278 CSSBasicShape::trace(visitor); |
| 303 } | 279 } |
| 304 | 280 |
| 305 static bool buildInsetRadii(Vector<String> &radii, const String& topLeftRadius,
const String& topRightRadius, const String& bottomRightRadius, const String& bot
tomLeftRadius) | 281 static bool buildInsetRadii(Vector<String> &radii, const String& topLeftRadius,
const String& topRightRadius, const String& bottomRightRadius, const String& bot
tomLeftRadius) |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 visitor->trace(m_left); | 419 visitor->trace(m_left); |
| 444 visitor->trace(m_topLeftRadius); | 420 visitor->trace(m_topLeftRadius); |
| 445 visitor->trace(m_topRightRadius); | 421 visitor->trace(m_topRightRadius); |
| 446 visitor->trace(m_bottomRightRadius); | 422 visitor->trace(m_bottomRightRadius); |
| 447 visitor->trace(m_bottomLeftRadius); | 423 visitor->trace(m_bottomLeftRadius); |
| 448 CSSBasicShape::trace(visitor); | 424 CSSBasicShape::trace(visitor); |
| 449 } | 425 } |
| 450 | 426 |
| 451 } // namespace blink | 427 } // namespace blink |
| 452 | 428 |
| OLD | NEW |