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

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

Issue 220023003: Rename LayoutBox to CSSBoxType (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 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/CSSComputedStyleDeclaration.cpp » ('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 23 matching lines...) Expand all
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 WebCore { 40 namespace WebCore {
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& layoutBox) 44 static String buildCircleString(const String& radius, const String& centerX, con st String& centerY, const String& box)
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 (layoutBox.length()) { 63 if (box.length()) {
64 result.appendLiteral(separator); 64 result.appendLiteral(separator);
65 result.append(layoutBox); 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 ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValue ID() == CSSValueTop)
73 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal ueID() == CSSValueLeft)) 73 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal ueID() == CSSValueLeft))
74 return offset.second()->cssText(); 74 return offset.second()->cssText();
75 return offset.cssText(); 75 return offset.cssText();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<CSSPrimitiveValue> normalizedCX = buildSerializablePositi onOffset(m_centerX, CSSValueLeft);
115 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi onOffset(m_centerY, CSSValueTop); 115 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi onOffset(m_centerY, CSSValueTop);
116 116
117 return buildCircleString(m_radius ? m_radius->cssText() : String(), 117 return buildCircleString(m_radius ? m_radius->cssText() : String(),
118 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge tPairValue()), 118 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge tPairValue()),
119 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge tPairValue()), 119 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge tPairValue()),
120 m_layoutBox ? m_layoutBox->cssText() : String()); 120 m_referenceBox ? m_referenceBox->cssText() : String());
121 } 121 }
122 122
123 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const 123 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const
124 { 124 {
125 if (shape.type() != CSSBasicShapeCircleType) 125 if (shape.type() != CSSBasicShapeCircleType)
126 return false; 126 return false;
127 127
128 const CSSBasicShapeCircle& other = static_cast<const CSSBasicShapeCircle&>(s hape); 128 const CSSBasicShapeCircle& other = static_cast<const CSSBasicShapeCircle&>(s hape);
129 return compareCSSValuePtr(m_centerX, other.m_centerX) 129 return compareCSSValuePtr(m_centerX, other.m_centerX)
130 && compareCSSValuePtr(m_centerY, other.m_centerY) 130 && compareCSSValuePtr(m_centerY, other.m_centerY)
131 && compareCSSValuePtr(m_radius, other.m_radius) 131 && compareCSSValuePtr(m_radius, other.m_radius)
132 && compareCSSValuePtr(m_layoutBox, other.m_layoutBox); 132 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox);
133 } 133 }
134 134
135 void CSSBasicShapeCircle::trace(Visitor* visitor) 135 void CSSBasicShapeCircle::trace(Visitor* visitor)
136 { 136 {
137 visitor->trace(m_centerX); 137 visitor->trace(m_centerX);
138 visitor->trace(m_centerY); 138 visitor->trace(m_centerY);
139 visitor->trace(m_radius); 139 visitor->trace(m_radius);
140 CSSBasicShape::trace(visitor); 140 CSSBasicShape::trace(visitor);
141 } 141 }
142 142
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 String CSSBasicShapeEllipse::cssText() const 178 String CSSBasicShapeEllipse::cssText() const
179 { 179 {
180 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi onOffset(m_centerX, CSSValueLeft); 180 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositi onOffset(m_centerX, CSSValueLeft);
181 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi onOffset(m_centerY, CSSValueTop); 181 RefPtrWillBeRawPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositi onOffset(m_centerY, CSSValueTop);
182 182
183 return buildEllipseString(m_radiusX ? m_radiusX->cssText() : String(), 183 return buildEllipseString(m_radiusX ? m_radiusX->cssText() : String(),
184 m_radiusY ? m_radiusY->cssText() : String(), 184 m_radiusY ? m_radiusY->cssText() : String(),
185 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge tPairValue()), 185 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge tPairValue()),
186 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge tPairValue()), 186 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge tPairValue()),
187 m_layoutBox ? m_layoutBox->cssText() : String()); 187 m_referenceBox ? m_referenceBox->cssText() : String());
188 } 188 }
189 189
190 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const 190 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const
191 { 191 {
192 if (shape.type() != CSSBasicShapeEllipseType) 192 if (shape.type() != CSSBasicShapeEllipseType)
193 return false; 193 return false;
194 194
195 const CSSBasicShapeEllipse& other = static_cast<const CSSBasicShapeEllipse&> (shape); 195 const CSSBasicShapeEllipse& other = static_cast<const CSSBasicShapeEllipse&> (shape);
196 return compareCSSValuePtr(m_centerX, other.m_centerX) 196 return compareCSSValuePtr(m_centerX, other.m_centerX)
197 && compareCSSValuePtr(m_centerY, other.m_centerY) 197 && compareCSSValuePtr(m_centerY, other.m_centerY)
198 && compareCSSValuePtr(m_radiusX, other.m_radiusX) 198 && compareCSSValuePtr(m_radiusX, other.m_radiusX)
199 && compareCSSValuePtr(m_radiusY, other.m_radiusY) 199 && compareCSSValuePtr(m_radiusY, other.m_radiusY)
200 && compareCSSValuePtr(m_layoutBox, other.m_layoutBox); 200 && compareCSSValuePtr(m_referenceBox, other.m_referenceBox);
201 } 201 }
202 202
203 void CSSBasicShapeEllipse::trace(Visitor* visitor) 203 void CSSBasicShapeEllipse::trace(Visitor* visitor)
204 { 204 {
205 visitor->trace(m_centerX); 205 visitor->trace(m_centerX);
206 visitor->trace(m_centerY); 206 visitor->trace(m_centerY);
207 visitor->trace(m_radiusX); 207 visitor->trace(m_radiusX);
208 visitor->trace(m_radiusY); 208 visitor->trace(m_radiusY);
209 CSSBasicShape::trace(visitor); 209 CSSBasicShape::trace(visitor);
210 } 210 }
211 211
212 static String buildPolygonString(const WindRule& windRule, const Vector<String>& points, const String& layoutBox) 212 static String buildPolygonString(const WindRule& windRule, const Vector<String>& points, const String& box)
213 { 213 {
214 ASSERT(!(points.size() % 2)); 214 ASSERT(!(points.size() % 2));
215 215
216 StringBuilder result; 216 StringBuilder result;
217 const char evenOddOpening[] = "polygon(evenodd, "; 217 const char evenOddOpening[] = "polygon(evenodd, ";
218 const char nonZeroOpening[] = "polygon("; 218 const char nonZeroOpening[] = "polygon(";
219 const char commaSeparator[] = ", "; 219 const char commaSeparator[] = ", ";
220 COMPILE_ASSERT(sizeof(evenOddOpening) > sizeof(nonZeroOpening), polygon_stri ng_openings_have_same_length); 220 COMPILE_ASSERT(sizeof(evenOddOpening) > sizeof(nonZeroOpening), polygon_stri ng_openings_have_same_length);
221 221
222 // Compute the required capacity in advance to reduce allocations. 222 // Compute the required capacity in advance to reduce allocations.
223 size_t length = sizeof(evenOddOpening) - 1; 223 size_t length = sizeof(evenOddOpening) - 1;
224 for (size_t i = 0; i < points.size(); i += 2) { 224 for (size_t i = 0; i < points.size(); i += 2) {
225 if (i) 225 if (i)
226 length += (sizeof(commaSeparator) - 1); 226 length += (sizeof(commaSeparator) - 1);
227 // add length of two strings, plus one for the space separator. 227 // add length of two strings, plus one for the space separator.
228 length += points[i].length() + 1 + points[i + 1].length(); 228 length += points[i].length() + 1 + points[i + 1].length();
229 } 229 }
230 if (!layoutBox.isEmpty()) 230 if (!box.isEmpty())
231 length += layoutBox.length() + 1; 231 length += box.length() + 1;
232 result.reserveCapacity(length); 232 result.reserveCapacity(length);
233 233
234 if (windRule == RULE_EVENODD) 234 if (windRule == RULE_EVENODD)
235 result.appendLiteral(evenOddOpening); 235 result.appendLiteral(evenOddOpening);
236 else 236 else
237 result.appendLiteral(nonZeroOpening); 237 result.appendLiteral(nonZeroOpening);
238 238
239 for (size_t i = 0; i < points.size(); i += 2) { 239 for (size_t i = 0; i < points.size(); i += 2) {
240 if (i) 240 if (i)
241 result.appendLiteral(commaSeparator); 241 result.appendLiteral(commaSeparator);
242 result.append(points[i]); 242 result.append(points[i]);
243 result.append(' '); 243 result.append(' ');
244 result.append(points[i + 1]); 244 result.append(points[i + 1]);
245 } 245 }
246 246
247 result.append(')'); 247 result.append(')');
248 248
249 if (!layoutBox.isEmpty()) { 249 if (!box.isEmpty()) {
250 result.append(' '); 250 result.append(' ');
251 result.append(layoutBox); 251 result.append(box);
252 } 252 }
253 253
254 return result.toString(); 254 return result.toString();
255 } 255 }
256 256
257 String CSSBasicShapePolygon::cssText() const 257 String CSSBasicShapePolygon::cssText() const
258 { 258 {
259 Vector<String> points; 259 Vector<String> points;
260 points.reserveInitialCapacity(m_values.size()); 260 points.reserveInitialCapacity(m_values.size());
261 261
262 for (size_t i = 0; i < m_values.size(); ++i) 262 for (size_t i = 0; i < m_values.size(); ++i)
263 points.append(m_values.at(i)->cssText()); 263 points.append(m_values.at(i)->cssText());
264 264
265 return buildPolygonString(m_windRule, points, m_layoutBox ? m_layoutBox->css Text() : String()); 265 return buildPolygonString(m_windRule, points, m_referenceBox ? m_referenceBo x->cssText() : String());
266 } 266 }
267 267
268 bool CSSBasicShapePolygon::equals(const CSSBasicShape& shape) const 268 bool CSSBasicShapePolygon::equals(const CSSBasicShape& shape) const
269 { 269 {
270 if (shape.type() != CSSBasicShapePolygonType) 270 if (shape.type() != CSSBasicShapePolygonType)
271 return false; 271 return false;
272 272
273 const CSSBasicShapePolygon& rhs = static_cast<const CSSBasicShapePolygon&>(s hape); 273 const CSSBasicShapePolygon& rhs = static_cast<const CSSBasicShapePolygon&>(s hape);
274 274
275 if (!compareCSSValuePtr(m_layoutBox, rhs.m_layoutBox)) 275 if (!compareCSSValuePtr(m_referenceBox, rhs.m_referenceBox))
276 return false; 276 return false;
277 277
278 return compareCSSValueVector(m_values, rhs.m_values); 278 return compareCSSValueVector(m_values, rhs.m_values);
279 } 279 }
280 280
281 void CSSBasicShapePolygon::trace(Visitor* visitor) 281 void CSSBasicShapePolygon::trace(Visitor* visitor)
282 { 282 {
283 visitor->trace(m_values); 283 visitor->trace(m_values);
284 CSSBasicShape::trace(visitor); 284 CSSBasicShape::trace(visitor);
285 } 285 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 visitor->trace(m_left); 404 visitor->trace(m_left);
405 visitor->trace(m_topLeftRadius); 405 visitor->trace(m_topLeftRadius);
406 visitor->trace(m_topRightRadius); 406 visitor->trace(m_topRightRadius);
407 visitor->trace(m_bottomRightRadius); 407 visitor->trace(m_bottomRightRadius);
408 visitor->trace(m_bottomLeftRadius); 408 visitor->trace(m_bottomLeftRadius);
409 CSSBasicShape::trace(visitor); 409 CSSBasicShape::trace(visitor);
410 } 410 }
411 411
412 } // namespace WebCore 412 } // namespace WebCore
413 413
OLDNEW
« no previous file with comments | « Source/core/css/CSSBasicShapes.h ('k') | Source/core/css/CSSComputedStyleDeclaration.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698