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

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: Add FAIL test for intermediate result Created 6 years, 9 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 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSVal uePool& pool, const RenderStyle& style, const BasicShapeCenterCoordinate& center ) 43 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSVal uePool& 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 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> basicShapeRadiusToCSSValue(CSSV aluePool& pool, const RenderStyle& style, const BasicShapeRadius& radius) 53 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> basicShapeRadiusToCSSValue(CSSV aluePool& pool, 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 RefPtrWillBeRawPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircl e::create(); 101 RefPtrWillBeRawPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircl e::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 RefPtrWillBeRawPtr<CSSDeprecatedBasicShapeEllipse> ellipseValue = CSSDep recatedBasicShapeEllipse::create(); 111 RefPtrWillBeRawPtr<CSSDeprecatedBasicShapeEllipse> ellipseValue = CSSDep recatedBasicShapeEllipse::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 RefPtrWillBeRawPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEll ipse::create(); 123 RefPtrWillBeRawPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEll ipse::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 RefPtrWillBeRawPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePol ygon::create(); 134 RefPtrWillBeRawPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePol ygon::create();
148 135
149 polygonValue->setWindRule(polygon->windRule()); 136 polygonValue->setWindRule(polygon->windRule());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 { 193 {
207 if (!value) 194 if (!value)
208 return LengthSize(Length(0, Fixed), Length(0, Fixed)); 195 return LengthSize(Length(0, Fixed), Length(0, Fixed));
209 196
210 Pair* pair = value->getPairValue(); 197 Pair* pair = value->getPairValue();
211 return LengthSize(convertToLength(state, pair->first()), convertToLength(sta te, pair->second())); 198 return LengthSize(convertToLength(state, pair->first()), convertToLength(sta te, pair->second()));
212 } 199 }
213 200
214 static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverS tate& state, CSSPrimitiveValue* value) 201 static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverS tate& state, CSSPrimitiveValue* value)
215 { 202 {
216 if (Pair* pair = value->getPairValue()) { 203 BasicShapeCenterCoordinate::Direction direction;
217 BasicShapeCenterCoordinate::Keyword keyword = BasicShapeCenterCoordinate ::None; 204 Length offset = Length(0, Fixed);
218 switch (pair->first()->getValueID()) { 205
219 case CSSValueTop: 206 CSSValueID keyword = CSSValueTop;
220 keyword = BasicShapeCenterCoordinate::Top; 207 if (!value) {
221 break; 208 keyword = CSSValueCenter;
222 case CSSValueRight: 209 } else if (value->isValueID()) {
223 keyword = BasicShapeCenterCoordinate::Right; 210 keyword = value->getValueID();
224 break; 211 } else if (Pair* pair = value->getPairValue()) {
225 case CSSValueBottom: 212 keyword = pair->first()->getValueID();
226 keyword = BasicShapeCenterCoordinate::Bottom; 213 offset = convertToLength(state, pair->second());
227 break; 214 } else {
228 case CSSValueLeft: 215 offset = convertToLength(state, value);
229 keyword = BasicShapeCenterCoordinate::Left;
230 break;
231 default:
232 ASSERT_NOT_REACHED();
233 break;
234 }
235 return BasicShapeCenterCoordinate(keyword, convertToLength(state, pair-> second()));
236 } 216 }
237 217
238 return BasicShapeCenterCoordinate(convertToLength(state, value)); 218 switch (keyword) {
219 case CSSValueTop:
220 case CSSValueLeft:
221 direction = BasicShapeCenterCoordinate::TopLeft;
222 break;
223 case CSSValueRight:
224 case CSSValueBottom:
225 direction = BasicShapeCenterCoordinate::BottomRight;
226 break;
227 case CSSValueCenter:
228 direction = BasicShapeCenterCoordinate::TopLeft;
229 offset = Length(50, Percent);
230 break;
231 default:
232 ASSERT_NOT_REACHED();
233 direction = BasicShapeCenterCoordinate::TopLeft;
234 break;
235 }
236
237 return BasicShapeCenterCoordinate(direction, offset);
239 } 238 }
240 239
241 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta te, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius) 240 static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& sta te, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius)
242 { 241 {
243 if (!radius) 242 if (!radius)
244 return BasicShapeRadius(BasicShapeRadius::ClosestSide); 243 return BasicShapeRadius(BasicShapeRadius::ClosestSide);
245 244
246 if (radius->isValueID()) { 245 if (radius->isValueID()) {
247 switch (radius->getValueID()) { 246 switch (radius->getValueID()) {
248 case CSSValueClosestSide: 247 case CSSValueClosestSide:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 circle->setCenterY(convertToLength(state, circleValue->centerY())); 292 circle->setCenterY(convertToLength(state, circleValue->centerY()));
294 circle->setRadius(convertToLength(state, circleValue->radius())); 293 circle->setRadius(convertToLength(state, circleValue->radius()));
295 294
296 basicShape = circle.release(); 295 basicShape = circle.release();
297 break; 296 break;
298 } 297 }
299 case CSSBasicShape::CSSBasicShapeCircleType: { 298 case CSSBasicShape::CSSBasicShapeCircleType: {
300 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape Circle *>(basicShapeValue); 299 const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShape Circle *>(basicShapeValue);
301 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create(); 300 RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create();
302 301
303 if (circleValue->centerX() && circleValue->centerY()) { 302 circle->setCenterX(convertToCenterCoordinate(state, circleValue->centerX ()));
304 circle->setCenterX(convertToCenterCoordinate(state, circleValue->cen terX())); 303 circle->setCenterY(convertToCenterCoordinate(state, circleValue->centerY ()));
305 circle->setCenterY(convertToCenterCoordinate(state, circleValue->cen terY()));
306 } else {
307 circle->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent)));
308 circle->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent)));
309 }
310 circle->setRadius(cssValueToBasicShapeRadius(state, circleValue->radius( ))); 304 circle->setRadius(cssValueToBasicShapeRadius(state, circleValue->radius( )));
311 305
312 basicShape = circle.release(); 306 basicShape = circle.release();
313 break; 307 break;
314 } 308 }
315 case CSSBasicShape::CSSDeprecatedBasicShapeEllipseType: { 309 case CSSBasicShape::CSSDeprecatedBasicShapeEllipseType: {
316 const CSSDeprecatedBasicShapeEllipse* ellipseValue = static_cast<const C SSDeprecatedBasicShapeEllipse *>(basicShapeValue); 310 const CSSDeprecatedBasicShapeEllipse* ellipseValue = static_cast<const C SSDeprecatedBasicShapeEllipse *>(basicShapeValue);
317 RefPtr<DeprecatedBasicShapeEllipse> ellipse = DeprecatedBasicShapeEllips e::create(); 311 RefPtr<DeprecatedBasicShapeEllipse> ellipse = DeprecatedBasicShapeEllips e::create();
318 312
319 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX())); 313 ellipse->setCenterX(convertToLength(state, ellipseValue->centerX()));
320 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY())); 314 ellipse->setCenterY(convertToLength(state, ellipseValue->centerY()));
321 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX())); 315 ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX()));
322 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY())); 316 ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY()));
323 317
324 basicShape = ellipse.release(); 318 basicShape = ellipse.release();
325 break; 319 break;
326 } 320 }
327 case CSSBasicShape::CSSBasicShapeEllipseType: { 321 case CSSBasicShape::CSSBasicShapeEllipseType: {
328 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha peEllipse *>(basicShapeValue); 322 const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicSha peEllipse *>(basicShapeValue);
329 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create(); 323 RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create();
330 324
331 if (ellipseValue->centerX() && ellipseValue->centerY()) { 325 ellipse->setCenterX(convertToCenterCoordinate(state, ellipseValue->cente rX()));
332 ellipse->setCenterX(convertToCenterCoordinate(state, ellipseValue->c enterX())); 326 ellipse->setCenterY(convertToCenterCoordinate(state, ellipseValue->cente rY()));
333 ellipse->setCenterY(convertToCenterCoordinate(state, ellipseValue->c enterY()));
334 } else {
335 ellipse->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent))) ;
336 ellipse->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent))) ;
337 }
338 ellipse->setRadiusX(cssValueToBasicShapeRadius(state, ellipseValue->radi usX())); 327 ellipse->setRadiusX(cssValueToBasicShapeRadius(state, ellipseValue->radi usX()));
339 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi usY())); 328 ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radi usY()));
340 329
341 basicShape = ellipse.release(); 330 basicShape = ellipse.release();
342 break; 331 break;
343 } 332 }
344 case CSSBasicShape::CSSBasicShapePolygonType: { 333 case CSSBasicShape::CSSBasicShapePolygonType: {
345 const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicSha pePolygon *>(basicShapeValue); 334 const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicSha pePolygon *>(basicShapeValue);
346 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); 335 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create();
347 336
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (basicShapeValue->layoutBox()) 388 if (basicShapeValue->layoutBox())
400 basicShape->setLayoutBox(LayoutBox(*basicShapeValue->layoutBox())); 389 basicShape->setLayoutBox(LayoutBox(*basicShapeValue->layoutBox()));
401 390
402 return basicShape.release(); 391 return basicShape.release();
403 } 392 }
404 393
405 FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente rX, const BasicShapeCenterCoordinate& centerY, FloatSize boxSize) 394 FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente rX, const BasicShapeCenterCoordinate& centerY, FloatSize boxSize)
406 { 395 {
407 FloatPoint p; 396 FloatPoint p;
408 float offset = floatValueForLength(centerX.length(), boxSize.width()); 397 float offset = floatValueForLength(centerX.length(), boxSize.width());
409 switch (centerX.keyword()) { 398 p.setX(centerX.direction() == BasicShapeCenterCoordinate::TopLeft ? offset : boxSize.width() - offset);
410 case BasicShapeCenterCoordinate::None:
411 case BasicShapeCenterCoordinate::Left:
412 p.setX(offset);
413 break;
414 case BasicShapeCenterCoordinate::Right:
415 p.setX(boxSize.width() - offset);
416 break;
417 default:
418 ASSERT_NOT_REACHED();
419 }
420
421 offset = floatValueForLength(centerY.length(), boxSize.height()); 399 offset = floatValueForLength(centerY.length(), boxSize.height());
422 switch (centerY.keyword()) { 400 p.setY(centerY.direction() == BasicShapeCenterCoordinate::TopLeft ? offset : boxSize.height() - offset);
423 case BasicShapeCenterCoordinate::None:
424 case BasicShapeCenterCoordinate::Top:
425 p.setY(offset);
426 break;
427 case BasicShapeCenterCoordinate::Bottom:
428 p.setY(boxSize.height() - offset);
429 break;
430 default:
431 ASSERT_NOT_REACHED();
432 }
433
434 return p; 401 return p;
435 } 402 }
436 403
437 } 404 }
OLDNEW
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | Source/core/rendering/style/BasicShapes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698