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

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

Issue 144373002: [CSS Shapes] Basic shapes' computed position should be a horizontal and vertical offset (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Try to fix tests Created 6 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 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 22 matching lines...) Expand all
33 #include "core/css/CSSBasicShapes.h" 33 #include "core/css/CSSBasicShapes.h"
34 #include "core/css/CSSPrimitiveValueMappings.h" 34 #include "core/css/CSSPrimitiveValueMappings.h"
35 #include "core/css/CSSValuePool.h" 35 #include "core/css/CSSValuePool.h"
36 #include "core/css/Pair.h" 36 #include "core/css/Pair.h"
37 #include "core/css/resolver/StyleResolverState.h" 37 #include "core/css/resolver/StyleResolverState.h"
38 #include "core/rendering/style/BasicShapes.h" 38 #include "core/rendering/style/BasicShapes.h"
39 #include "core/rendering/style/RenderStyle.h" 39 #include "core/rendering/style/RenderStyle.h"
40 40
41 namespace WebCore { 41 namespace WebCore {
42 42
43 static PassRefPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSValuePool& pool , const RenderStyle& style, const BasicShapeCenterCoordinate& center) 43 static PassRefPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSValuePool& pool , const RenderStyle& style, const BasicShapeCenterCoordinate& center, EBoxOrient orientation)
44 { 44 {
45 CSSValueID keyword = CSSValueInvalid; 45 if (center.direction() == BasicShapeCenterCoordinate::TopLeft)
46 switch (center.keyword()) {
47 case BasicShapeCenterCoordinate::None:
48 return pool.createValue(center.length(), style); 46 return pool.createValue(center.length(), style);
49 case BasicShapeCenterCoordinate::Top: 47
50 keyword = CSSValueTop; 48 CSSValueID keyword = orientation == HORIZONTAL ? CSSValueRight : CSSValueBot tom;
51 break;
52 case BasicShapeCenterCoordinate::Right:
53 keyword = CSSValueRight;
54 break;
55 case BasicShapeCenterCoordinate::Bottom:
56 keyword = CSSValueBottom;
57 break;
58 case BasicShapeCenterCoordinate::Left:
59 keyword = CSSValueLeft;
60 break;
61 }
62 49
63 return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), po ol.createValue(center.length(), style), Pair::DropIdenticalValues)); 50 return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), po ol.createValue(center.length(), style), Pair::DropIdenticalValues));
64 } 51 }
65 52
66 static PassRefPtr<CSSPrimitiveValue> basicShapeRadiusToCSSValue(CSSValuePool& po ol, const RenderStyle& style, const BasicShapeRadius& radius) 53 static PassRefPtr<CSSPrimitiveValue> basicShapeRadiusToCSSValue(CSSValuePool& po ol, const RenderStyle& style, const BasicShapeRadius& radius)
67 { 54 {
68 switch (radius.type()) { 55 switch (radius.type()) {
69 case BasicShapeRadius::Value: 56 case BasicShapeRadius::Value:
70 return pool.createValue(radius.value(), style); 57 return pool.createValue(radius.value(), style);
71 case BasicShapeRadius::ClosestSide: 58 case BasicShapeRadius::ClosestSide:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 circleValue->setCenterY(pool.createValue(circle->centerY(), style)); 93 circleValue->setCenterY(pool.createValue(circle->centerY(), style));
107 circleValue->setRadius(pool.createValue(circle->radius(), style)); 94 circleValue->setRadius(pool.createValue(circle->radius(), style));
108 95
109 basicShapeValue = circleValue.release(); 96 basicShapeValue = circleValue.release();
110 break; 97 break;
111 } 98 }
112 case BasicShape::BasicShapeCircleType: { 99 case BasicShape::BasicShapeCircleType: {
113 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba sicShape); 100 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba sicShape);
114 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create(); 101 RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create();
115 102
116 circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->ce nterX())); 103 circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->ce nterX(), HORIZONTAL));
117 circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->ce nterY())); 104 circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->ce nterY(), VERTICAL));
118 circleValue->setRadius(basicShapeRadiusToCSSValue(pool, style, circle->r adius())); 105 circleValue->setRadius(basicShapeRadiusToCSSValue(pool, style, circle->r adius()));
119 basicShapeValue = circleValue.release(); 106 basicShapeValue = circleValue.release();
120 break; 107 break;
121 } 108 }
122 case BasicShape::DeprecatedBasicShapeEllipseType: { 109 case BasicShape::DeprecatedBasicShapeEllipseType: {
123 const DeprecatedBasicShapeEllipse* ellipse = static_cast<const Deprecate dBasicShapeEllipse*>(basicShape); 110 const DeprecatedBasicShapeEllipse* ellipse = static_cast<const Deprecate dBasicShapeEllipse*>(basicShape);
124 RefPtr<CSSDeprecatedBasicShapeEllipse> ellipseValue = CSSDeprecatedBasic ShapeEllipse::create(); 111 RefPtr<CSSDeprecatedBasicShapeEllipse> ellipseValue = CSSDeprecatedBasic ShapeEllipse::create();
125 112
126 ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style)); 113 ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style));
127 ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style)); 114 ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style));
128 ellipseValue->setRadiusX(pool.createValue(ellipse->radiusX(), style)); 115 ellipseValue->setRadiusX(pool.createValue(ellipse->radiusX(), style));
129 ellipseValue->setRadiusY(pool.createValue(ellipse->radiusY(), style)); 116 ellipseValue->setRadiusY(pool.createValue(ellipse->radiusY(), style));
130 117
131 basicShapeValue = ellipseValue.release(); 118 basicShapeValue = ellipseValue.release();
132 break; 119 break;
133 } 120 }
134 case BasicShape::BasicShapeEllipseType: { 121 case BasicShape::BasicShapeEllipseType: {
135 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*> (basicShape); 122 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*> (basicShape);
136 RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create (); 123 RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create ();
137 124
138 ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse-> centerX())); 125 ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse-> centerX(), HORIZONTAL));
139 ellipseValue->setCenterY(valueForCenterCoordinate(pool, style, ellipse-> centerY())); 126 ellipseValue->setCenterY(valueForCenterCoordinate(pool, style, ellipse-> centerY(), VERTICAL));
140 ellipseValue->setRadiusX(basicShapeRadiusToCSSValue(pool, style, ellipse ->radiusX())); 127 ellipseValue->setRadiusX(basicShapeRadiusToCSSValue(pool, style, ellipse ->radiusX()));
141 ellipseValue->setRadiusY(basicShapeRadiusToCSSValue(pool, style, ellipse ->radiusY())); 128 ellipseValue->setRadiusY(basicShapeRadiusToCSSValue(pool, style, ellipse ->radiusY()));
142 basicShapeValue = ellipseValue.release(); 129 basicShapeValue = ellipseValue.release();
143 break; 130 break;
144 } 131 }
145 case BasicShape::BasicShapePolygonType: { 132 case BasicShape::BasicShapePolygonType: {
146 const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*> (basicShape); 133 const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*> (basicShape);
147 RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create (); 134 RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create ();
148 135
149 polygonValue->setWindRule(polygon->windRule()); 136 polygonValue->setWindRule(polygon->windRule());
(...skipping 28 matching lines...) Expand all
178 return pool.createValue(basicShapeValue.release()); 165 return pool.createValue(basicShapeValue.release());
179 } 166 }
180 167
181 static Length convertToLength(const StyleResolverState& state, CSSPrimitiveValue * value) 168 static Length convertToLength(const StyleResolverState& state, CSSPrimitiveValue * value)
182 { 169 {
183 return value->convertToLength<FixedConversion | PercentConversion>(state.css ToLengthConversionData()); 170 return value->convertToLength<FixedConversion | PercentConversion>(state.css ToLengthConversionData());
184 } 171 }
185 172
186 static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverS tate& state, CSSPrimitiveValue* value) 173 static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverS tate& state, CSSPrimitiveValue* value)
187 { 174 {
188 if (Pair* pair = value->getPairValue()) { 175 BasicShapeCenterCoordinate::Direction direction;
189 BasicShapeCenterCoordinate::Keyword keyword = BasicShapeCenterCoordinate ::None; 176 Length offset = Length(0, Fixed);
190 switch (pair->first()->getValueID()) { 177
191 case CSSValueTop: 178 CSSValueID keyword = CSSValueTop;
192 keyword = BasicShapeCenterCoordinate::Top; 179 if (!value) {
193 break; 180 keyword = CSSValueCenter;
194 case CSSValueRight: 181 } else if (value->isValueID()) {
195 keyword = BasicShapeCenterCoordinate::Right; 182 keyword = value->getValueID();
196 break; 183 } else if (Pair* pair = value->getPairValue()) {
197 case CSSValueBottom: 184 keyword = pair->first()->getValueID();
198 keyword = BasicShapeCenterCoordinate::Bottom; 185 offset = convertToLength(state, pair->second());
199 break; 186 } else {
200 case CSSValueLeft: 187 offset = convertToLength(state, value);
201 keyword = BasicShapeCenterCoordinate::Left;
202 break;
203 default:
204 ASSERT_NOT_REACHED();
205 break;
206 }
207 return BasicShapeCenterCoordinate(keyword, convertToLength(state, pair-> second()));
208 } 188 }
209 189
210 return BasicShapeCenterCoordinate(convertToLength(state, value)); 190 switch (keyword) {
191 case CSSValueTop:
192 case CSSValueLeft:
193 direction = BasicShapeCenterCoordinate::TopLeft;
194 break;
195 case CSSValueRight:
196 case CSSValueBottom:
197 direction = BasicShapeCenterCoordinate::BottomRight;
198 break;
199 case CSSValueCenter:
200 direction = BasicShapeCenterCoordinate::TopLeft;
201 offset = Length(50, Percent);
202 break;
203 default:
204 ASSERT_NOT_REACHED();
205 direction = BasicShapeCenterCoordinate::TopLeft;
206 break;
207 }
208
209 return BasicShapeCenterCoordinate(direction, offset);
211 } 210 }
212 211
213 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta te, PassRefPtr<CSSPrimitiveValue> radius) 212 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta te, PassRefPtr<CSSPrimitiveValue> radius)
214 { 213 {
215 if (!radius) 214 if (!radius)
216 return BasicShapeRadius(BasicShapeRadius::ClosestSide); 215 return BasicShapeRadius(BasicShapeRadius::ClosestSide);
217 216
218 if (radius->isValueID()) { 217 if (radius->isValueID()) {
219 switch (radius->getValueID()) { 218 switch (radius->getValueID()) {
220 case CSSValueClosestSide: 219 case CSSValueClosestSide:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 circle->setCenterY(convertToLength(state, circleValue->centerY())); 264 circle->setCenterY(convertToLength(state, circleValue->centerY()));
266 circle->setRadius(convertToLength(state, circleValue->radius())); 265 circle->setRadius(convertToLength(state, circleValue->radius()));
267 266
268 basicShape = circle.release(); 267 basicShape = circle.release();
269 break; 268 break;
270 } 269 }
271 case CSSBasicShape::CSSBasicShapeCircleType: { 270 case CSSBasicShape::CSSBasicShapeCircleType: {
272 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape Circle *>(basicShapeValue); 271 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape Circle *>(basicShapeValue);
273 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); 272 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create();
274 273
275 if (circleValue->centerX() && circleValue->centerY()) { 274 circle->setCenterX(convertToCenterCoordinate(state, circleValue->centerX ()));
276 circle->setCenterX(convertToCenterCoordinate(state, circleValue->cen terX())); 275 circle->setCenterY(convertToCenterCoordinate(state, circleValue->centerY ()));
277 circle->setCenterY(convertToCenterCoordinate(state, circleValue->cen terY()));
278 } else {
279 circle->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent)));
280 circle->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent)));
281 }
282 circle->setRadius(cssValueToBasicShapeRadius(state, circleValue->radius( ))); 276 circle->setRadius(cssValueToBasicShapeRadius(state, circleValue->radius( )));
283 277
284 basicShape = circle.release(); 278 basicShape = circle.release();
285 break; 279 break;
286 } 280 }
287 case CSSBasicShape::CSSDeprecatedBasicShapeEllipseType: { 281 case CSSBasicShape::CSSDeprecatedBasicShapeEllipseType: {
288 const CSSDeprecatedBasicShapeEllipse* ellipseValue = static_cast<const C SSDeprecatedBasicShapeEllipse *>(basicShapeValue); 282 const CSSDeprecatedBasicShapeEllipse* ellipseValue = static_cast<const C SSDeprecatedBasicShapeEllipse *>(basicShapeValue);
289 RefPtr<DeprecatedBasicShapeEllipse> ellipse = DeprecatedBasicShapeEllips e::create(); 283 RefPtr<DeprecatedBasicShapeEllipse> ellipse = DeprecatedBasicShapeEllips e::create();
290 284
291 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX())); 285 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX()));
292 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY())); 286 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY()));
293 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX())); 287 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX()));
294 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY())); 288 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY()));
295 289
296 basicShape = ellipse.release(); 290 basicShape = ellipse.release();
297 break; 291 break;
298 } 292 }
299 case CSSBasicShape::CSSBasicShapeEllipseType: { 293 case CSSBasicShape::CSSBasicShapeEllipseType: {
300 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha peEllipse *>(basicShapeValue); 294 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha peEllipse *>(basicShapeValue);
301 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create(); 295 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create();
302 296
303 if (ellipseValue->centerX() && ellipseValue->centerY()) { 297 ellipse->setCenterX(convertToCenterCoordinate(state, ellipseValue->cente rX()));
304 ellipse->setCenterX(convertToCenterCoordinate(state, ellipseValue->c enterX())); 298 ellipse->setCenterY(convertToCenterCoordinate(state, ellipseValue->cente rY()));
305 ellipse->setCenterY(convertToCenterCoordinate(state, ellipseValue->c enterY()));
306 } else {
307 ellipse->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent))) ;
308 ellipse->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent))) ;
309 }
310 ellipse->setRadiusX(cssValueToBasicShapeRadius(state, ellipseValue->radi usX())); 299 ellipse->setRadiusX(cssValueToBasicShapeRadius(state, ellipseValue->radi usX()));
311 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi usY())); 300 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi usY()));
312 301
313 basicShape = ellipse.release(); 302 basicShape = ellipse.release();
314 break; 303 break;
315 } 304 }
316 case CSSBasicShape::CSSBasicShapePolygonType: { 305 case CSSBasicShape::CSSBasicShapePolygonType: {
317 const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicSha pePolygon *>(basicShapeValue); 306 const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicSha pePolygon *>(basicShapeValue);
318 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); 307 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create();
319 308
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (basicShapeValue->layoutBox()) 343 if (basicShapeValue->layoutBox())
355 basicShape->setLayoutBox(LayoutBox(*basicShapeValue->layoutBox())); 344 basicShape->setLayoutBox(LayoutBox(*basicShapeValue->layoutBox()));
356 345
357 return basicShape.release(); 346 return basicShape.release();
358 } 347 }
359 348
360 FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente rX, const BasicShapeCenterCoordinate& centerY, FloatSize boxSize) 349 FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente rX, const BasicShapeCenterCoordinate& centerY, FloatSize boxSize)
361 { 350 {
362 FloatPoint p; 351 FloatPoint p;
363 float offset = floatValueForLength(centerX.length(), boxSize.width()); 352 float offset = floatValueForLength(centerX.length(), boxSize.width());
364 switch (centerX.keyword()) { 353 if (centerX.direction() == BasicShapeCenterCoordinate::TopLeft)
Bear Travis 2014/01/23 22:04:42 As a nit, this method feels like it's a little too
365 case BasicShapeCenterCoordinate::None:
366 case BasicShapeCenterCoordinate::Left:
367 p.setX(offset); 354 p.setX(offset);
368 break; 355 else
369 case BasicShapeCenterCoordinate::Right:
370 p.setX(boxSize.width() - offset); 356 p.setX(boxSize.width() - offset);
371 break;
372 default:
373 ASSERT_NOT_REACHED();
374 }
375 357
376 offset = floatValueForLength(centerY.length(), boxSize.height()); 358 offset = floatValueForLength(centerY.length(), boxSize.height());
377 switch (centerY.keyword()) { 359 if (centerY.direction() == BasicShapeCenterCoordinate::TopLeft)
378 case BasicShapeCenterCoordinate::None:
379 case BasicShapeCenterCoordinate::Top:
380 p.setY(offset); 360 p.setY(offset);
381 break; 361 else
382 case BasicShapeCenterCoordinate::Bottom:
383 p.setY(boxSize.height() - offset); 362 p.setY(boxSize.height() - offset);
384 break;
385 default:
386 ASSERT_NOT_REACHED();
387 }
388 363
389 return p; 364 return p;
390 } 365 }
391 366
392 } 367 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698