Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: Source/core/css/CSSBasicShapes.cpp

Issue 1225553002: CSSValue Immediates: Make CSSPrimitiveValue a container (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_1
Patch Set: Rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/CSSBasicShapes.h ('k') | Source/core/css/CSSBorderImageSliceValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Pair& offset, const 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 CSSPrimitiveValue buildSerializablePositionOffset(NullableCSSValue offset , CSSValueID defaultSide)
79 { 79 {
80 CSSValueID side = defaultSide; 80 CSSValueID side = defaultSide;
81 RefPtrWillBeRawPtr<CSSPrimitiveValue> amount = nullptr; 81 NullableCSSValue amount;
82 82
83 if (!offset) { 83 if (!offset) {
84 side = CSSValueCenter; 84 side = CSSValueCenter;
85 } else if (offset->isValueID()) { 85 } else if (toCSSPrimitiveValue(*offset).isValueID()) {
86 side = offset->getValueID(); 86 side = toCSSPrimitiveValue(*offset).getValueID();
87 } else if (Pair* pair = offset->getPairValue()) { 87 } else if (Pair* pair = toCSSPrimitiveValue(*offset).getPairValue()) {
88 side = pair->first()->getValueID(); 88 side = toCSSPrimitiveValue(*pair->first()).getValueID();
89 amount = pair->second(); 89 amount = pair->second();
90 } else { 90 } else {
91 amount = offset; 91 amount = offset;
92 } 92 }
93 93
94 if (side == CSSValueCenter) { 94 if (side == CSSValueCenter) {
95 side = defaultSide; 95 side = defaultSide;
96 amount = cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAG E); 96 amount = cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAG E);
97 } else if ((side == CSSValueRight || side == CSSValueBottom) 97 } else if ((side == CSSValueRight || side == CSSValueBottom)
98 && amount->isPercentage()) { 98 && toCSSPrimitiveValue(*amount).isPercentage()) {
99 side = defaultSide; 99 side = defaultSide;
100 amount = cssValuePool().createValue(100 - amount->getFloatValue(), CSSPr imitiveValue::CSS_PERCENTAGE); 100 amount = cssValuePool().createValue(100 - toCSSPrimitiveValue(*amount).g etFloatValue(), CSSPrimitiveValue::CSS_PERCENTAGE);
101 } else if (amount->isLength() && !amount->getFloatValue()) { 101 } else if (toCSSPrimitiveValue(*amount).isLength() && !toCSSPrimitiveValue(* amount).getFloatValue()) {
102 if (side == CSSValueRight || side == CSSValueBottom) 102 if (side == CSSValueRight || side == CSSValueBottom)
103 amount = cssValuePool().createValue(100, CSSPrimitiveValue::CSS_PERC ENTAGE); 103 amount = cssValuePool().createValue(100, CSSPrimitiveValue::CSS_PERC ENTAGE);
104 else 104 else
105 amount = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PERCEN TAGE); 105 amount = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PERCEN TAGE);
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 cssValuePool().createValue(Pair::create(cssValuePool().createValue(si de), toCSSPrimitiveValue(*amount), Pair::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 CSSPrimitiveValue normalizedCX = buildSerializablePositionOffset(m_centerX, CSSValueLeft);
115 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi onOffset(m_centerY, CSSValueTop); 115 CSSPrimitiveValue normalizedCY = buildSerializablePositionOffset(m_centerY, CSSValueTop);
116 116
117 String radius; 117 String radius;
118 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) 118 if (m_radius && toCSSPrimitiveValue(*m_radius).getValueID() != CSSValueClose stSide)
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.getPairValue(), *normalizedCY.getP airValue()),
123 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge tPairValue()), 123 serializePositionOffset(*normalizedCY.getPairValue(), *normalizedCX.getP airValue()),
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 m_centerX == other.m_centerX
134 && compareCSSValuePtr(m_centerY, other.m_centerY) 134 && m_centerY == other.m_centerY
135 && compareCSSValuePtr(m_radius, other.m_radius) 135 && m_radius == other.m_radius
136 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox); 136 && m_referenceBox == other.m_referenceBox;
137 } 137 }
138 138
139 DEFINE_TRACE(CSSBasicShapeCircle) 139 DEFINE_TRACE(CSSBasicShapeCircle)
140 { 140 {
141 visitor->trace(m_centerX); 141 visitor->trace(m_centerX);
142 visitor->trace(m_centerY); 142 visitor->trace(m_centerY);
143 visitor->trace(m_radius); 143 visitor->trace(m_radius);
144 CSSBasicShape::trace(visitor); 144 CSSBasicShape::trace(visitor);
145 } 145 }
146 146
(...skipping 27 matching lines...) Expand all
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 CSSPrimitiveValue normalizedCX = buildSerializablePositionOffset(m_centerX, CSSValueLeft);
185 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi onOffset(m_centerY, CSSValueTop); 185 CSSPrimitiveValue normalizedCY = buildSerializablePositionOffset(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 = toCSSPrimitiveValue(*m_radiusX).getVa lueID() != CSSValueClosestSide;
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 = toCSSPrimitiveValue(*m_radiusY).getVal ueID() != CSSValueClosestSide;
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.getPairValue(), *normalizedCY.getP airValue()),
204 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge tPairValue()), 204 serializePositionOffset(*normalizedCY.getPairValue(), *normalizedCX.getP airValue()),
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 m_centerX == other.m_centerX
215 && compareCSSValuePtr(m_centerY, other.m_centerY) 215 && m_centerY == other.m_centerY
216 && compareCSSValuePtr(m_radiusX, other.m_radiusX) 216 && m_radiusX == other.m_radiusX
217 && compareCSSValuePtr(m_radiusY, other.m_radiusY) 217 && m_radiusY == other.m_radiusY
218 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox); 218 && m_referenceBox == other.m_referenceBox;
219 } 219 }
220 220
221 DEFINE_TRACE(CSSBasicShapeEllipse) 221 DEFINE_TRACE(CSSBasicShapeEllipse)
222 { 222 {
223 visitor->trace(m_centerX); 223 visitor->trace(m_centerX);
224 visitor->trace(m_centerY); 224 visitor->trace(m_centerY);
225 visitor->trace(m_radiusX); 225 visitor->trace(m_radiusX);
226 visitor->trace(m_radiusY); 226 visitor->trace(m_radiusY);
227 CSSBasicShape::trace(visitor); 227 CSSBasicShape::trace(visitor);
228 } 228 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 271
272 return result.toString(); 272 return result.toString();
273 } 273 }
274 274
275 String CSSBasicShapePolygon::cssText() const 275 String CSSBasicShapePolygon::cssText() const
276 { 276 {
277 Vector<String> points; 277 Vector<String> points;
278 points.reserveInitialCapacity(m_values.size()); 278 points.reserveInitialCapacity(m_values.size());
279 279
280 for (size_t i = 0; i < m_values.size(); ++i) 280 for (size_t i = 0; i < m_values.size(); ++i)
281 points.append(m_values.at(i)->cssText()); 281 points.append(m_values.at(i).cssText());
282 282
283 return buildPolygonString(m_windRule, points, m_referenceBox ? m_referenceBo x->cssText() : String()); 283 return buildPolygonString(m_windRule, points, m_referenceBox ? m_referenceBo x->cssText() : String());
284 } 284 }
285 285
286 bool CSSBasicShapePolygon::equals(const CSSBasicShape& shape) const 286 bool CSSBasicShapePolygon::equals(const CSSBasicShape& shape) const
287 { 287 {
288 if (shape.type() != CSSBasicShapePolygonType) 288 if (shape.type() != CSSBasicShapePolygonType)
289 return false; 289 return false;
290 290
291 const CSSBasicShapePolygon& rhs = toCSSBasicShapePolygon(shape); 291 const CSSBasicShapePolygon& rhs = toCSSBasicShapePolygon(shape);
292 292
293 if (!compareCSSValuePtr(m_referenceBox, rhs.m_referenceBox)) 293 if (m_referenceBox != rhs.m_referenceBox)
294 return false; 294 return false;
295 295
296 return compareCSSValueObjectVector(m_values, rhs.m_values); 296 return compareCSSValueVector(m_values, rhs.m_values);
297 } 297 }
298 298
299 DEFINE_TRACE(CSSBasicShapePolygon) 299 DEFINE_TRACE(CSSBasicShapePolygon)
300 { 300 {
301 visitor->trace(m_values); 301 visitor->trace(m_values);
302 CSSBasicShape::trace(visitor); 302 CSSBasicShape::trace(visitor);
303 } 303 }
304 304
305 static bool buildInsetRadii(Vector<String> &radii, const String& topLeftRadius, const String& topRightRadius, const String& bottomRightRadius, const String& bot tomLeftRadius) 305 static bool buildInsetRadii(Vector<String> &radii, const String& topLeftRadius, const String& topRightRadius, const String& bottomRightRadius, const String& bot tomLeftRadius)
306 { 306 {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(NullableCSSValue corner, Str ing& width, String& height)
382 { 382 {
383 if (!corner) 383 if (!corner)
384 return; 384 return;
385 385
386 Pair* radius = corner->getPairValue(); 386 Pair* radius = toCSSPrimitiveValue(*corner).getPairValue();
387 width = radius->first() ? radius->first()->cssText() : String("0"); 387 width = radius->first() ? radius->first()->cssText() : String("0");
388 if (radius->second()) 388 if (radius->second())
389 height = radius->second()->cssText(); 389 height = radius->second()->cssText();
390 } 390 }
391 391
392 String CSSBasicShapeInset::cssText() const 392 String CSSBasicShapeInset::cssText() const
393 { 393 {
394 String topLeftRadiusWidth; 394 String topLeftRadiusWidth;
395 String topLeftRadiusHeight; 395 String topLeftRadiusHeight;
396 String topRightRadiusWidth; 396 String topRightRadiusWidth;
(...skipping 21 matching lines...) Expand all
418 bottomLeftRadiusWidth, 418 bottomLeftRadiusWidth,
419 bottomLeftRadiusHeight); 419 bottomLeftRadiusHeight);
420 } 420 }
421 421
422 bool CSSBasicShapeInset::equals(const CSSBasicShape& shape) const 422 bool CSSBasicShapeInset::equals(const CSSBasicShape& shape) const
423 { 423 {
424 if (shape.type() != CSSBasicShapeInsetType) 424 if (shape.type() != CSSBasicShapeInsetType)
425 return false; 425 return false;
426 426
427 const CSSBasicShapeInset& other = toCSSBasicShapeInset(shape); 427 const CSSBasicShapeInset& other = toCSSBasicShapeInset(shape);
428 return compareCSSValuePtr(m_top, other.m_top) 428 return m_top == other.m_top
429 && compareCSSValuePtr(m_right, other.m_right) 429 && m_right == other.m_right
430 && compareCSSValuePtr(m_bottom, other.m_bottom) 430 && m_bottom == other.m_bottom
431 && compareCSSValuePtr(m_left, other.m_left) 431 && m_left == other.m_left
432 && compareCSSValuePtr(m_topLeftRadius, other.m_topLeftRadius) 432 && m_topLeftRadius == other.m_topLeftRadius
433 && compareCSSValuePtr(m_topRightRadius, other.m_topRightRadius) 433 && m_topRightRadius == other.m_topRightRadius
434 && compareCSSValuePtr(m_bottomRightRadius, other.m_bottomRightRadius) 434 && m_bottomRightRadius == other.m_bottomRightRadius
435 && compareCSSValuePtr(m_bottomLeftRadius, other.m_bottomLeftRadius); 435 && m_bottomLeftRadius == other.m_bottomLeftRadius;
436 } 436 }
437 437
438 DEFINE_TRACE(CSSBasicShapeInset) 438 DEFINE_TRACE(CSSBasicShapeInset)
439 { 439 {
440 visitor->trace(m_top); 440 visitor->trace(m_top);
441 visitor->trace(m_right); 441 visitor->trace(m_right);
442 visitor->trace(m_bottom); 442 visitor->trace(m_bottom);
443 visitor->trace(m_left); 443 visitor->trace(m_left);
444 visitor->trace(m_topLeftRadius); 444 visitor->trace(m_topLeftRadius);
445 visitor->trace(m_topRightRadius); 445 visitor->trace(m_topRightRadius);
446 visitor->trace(m_bottomRightRadius); 446 visitor->trace(m_bottomRightRadius);
447 visitor->trace(m_bottomLeftRadius); 447 visitor->trace(m_bottomLeftRadius);
448 CSSBasicShape::trace(visitor); 448 CSSBasicShape::trace(visitor);
449 } 449 }
450 450
451 } // namespace blink 451 } // namespace blink
452 452
OLDNEW
« no previous file with comments | « Source/core/css/CSSBasicShapes.h ('k') | Source/core/css/CSSBorderImageSliceValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698