| OLD | NEW |
| 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 14 matching lines...) Expand all Loading... |
| 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 * SUCH DAMAGE. | 27 * SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "core/css/BasicShapeFunctions.h" | 30 #include "core/css/BasicShapeFunctions.h" |
| 31 | 31 |
| 32 #include "core/css/CSSBasicShapeValues.h" | 32 #include "core/css/CSSBasicShapeValues.h" |
| 33 #include "core/css/CSSIdentifierValue.h" | 33 #include "core/css/CSSIdentifierValue.h" |
| 34 #include "core/css/CSSPrimitiveValueMappings.h" | 34 #include "core/css/CSSPrimitiveValueMappings.h" |
| 35 #include "core/css/CSSRayValue.h" |
| 35 #include "core/css/CSSValuePair.h" | 36 #include "core/css/CSSValuePair.h" |
| 36 #include "core/css/resolver/StyleResolverState.h" | 37 #include "core/css/resolver/StyleResolverState.h" |
| 37 #include "core/style/BasicShapes.h" | 38 #include "core/style/BasicShapes.h" |
| 38 #include "core/style/ComputedStyle.h" | 39 #include "core/style/ComputedStyle.h" |
| 40 #include "core/style/StyleRay.h" |
| 39 | 41 |
| 40 namespace blink { | 42 namespace blink { |
| 41 | 43 |
| 44 static StyleRay::RaySize KeywordToRaySize(CSSValueID id) { |
| 45 switch (id) { |
| 46 case CSSValueClosestSide: |
| 47 return StyleRay::RaySize::kClosestSide; |
| 48 case CSSValueClosestCorner: |
| 49 return StyleRay::RaySize::kClosestCorner; |
| 50 case CSSValueFarthestSide: |
| 51 return StyleRay::RaySize::kFarthestSide; |
| 52 case CSSValueFarthestCorner: |
| 53 return StyleRay::RaySize::kFarthestCorner; |
| 54 case CSSValueSides: |
| 55 return StyleRay::RaySize::kSides; |
| 56 default: |
| 57 NOTREACHED(); |
| 58 return StyleRay::RaySize::kClosestSide; |
| 59 } |
| 60 } |
| 61 |
| 62 static CSSValueID RaySizeToKeyword(StyleRay::RaySize size) { |
| 63 switch (size) { |
| 64 case StyleRay::RaySize::kClosestSide: |
| 65 return CSSValueClosestSide; |
| 66 case StyleRay::RaySize::kClosestCorner: |
| 67 return CSSValueClosestCorner; |
| 68 case StyleRay::RaySize::kFarthestSide: |
| 69 return CSSValueFarthestSide; |
| 70 case StyleRay::RaySize::kFarthestCorner: |
| 71 return CSSValueFarthestCorner; |
| 72 case StyleRay::RaySize::kSides: |
| 73 return CSSValueSides; |
| 74 } |
| 75 NOTREACHED(); |
| 76 return CSSValueInvalid; |
| 77 } |
| 78 |
| 42 static CSSValue* ValueForCenterCoordinate( | 79 static CSSValue* ValueForCenterCoordinate( |
| 43 const ComputedStyle& style, | 80 const ComputedStyle& style, |
| 44 const BasicShapeCenterCoordinate& center, | 81 const BasicShapeCenterCoordinate& center, |
| 45 EBoxOrient orientation) { | 82 EBoxOrient orientation) { |
| 46 if (center.GetDirection() == BasicShapeCenterCoordinate::kTopLeft) | 83 if (center.GetDirection() == BasicShapeCenterCoordinate::kTopLeft) |
| 47 return CSSValue::Create(center.length(), style.EffectiveZoom()); | 84 return CSSValue::Create(center.length(), style.EffectiveZoom()); |
| 48 | 85 |
| 49 CSSValueID keyword = | 86 CSSValueID keyword = |
| 50 orientation == HORIZONTAL ? CSSValueRight : CSSValueBottom; | 87 orientation == HORIZONTAL ? CSSValueRight : CSSValueBottom; |
| 51 | 88 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 74 return CSSIdentifierValue::Create(CSSValueFarthestSide); | 111 return CSSIdentifierValue::Create(CSSValueFarthestSide); |
| 75 } | 112 } |
| 76 | 113 |
| 77 NOTREACHED(); | 114 NOTREACHED(); |
| 78 return nullptr; | 115 return nullptr; |
| 79 } | 116 } |
| 80 | 117 |
| 81 CSSValue* ValueForBasicShape(const ComputedStyle& style, | 118 CSSValue* ValueForBasicShape(const ComputedStyle& style, |
| 82 const BasicShape* basic_shape) { | 119 const BasicShape* basic_shape) { |
| 83 switch (basic_shape->GetType()) { | 120 switch (basic_shape->GetType()) { |
| 121 case BasicShape::kStyleRayType: { |
| 122 const StyleRay& ray = ToStyleRay(*basic_shape); |
| 123 return CSSRayValue::Create( |
| 124 *CSSPrimitiveValue::Create(ray.Angle(), |
| 125 CSSPrimitiveValue::UnitType::kDegrees), |
| 126 *CSSIdentifierValue::Create(RaySizeToKeyword(ray.Size())), |
| 127 (ray.Contain() ? CSSIdentifierValue::Create(CSSValueContain) |
| 128 : nullptr)); |
| 129 } |
| 130 |
| 131 case BasicShape::kStylePathType: |
| 132 return ToStylePath(basic_shape)->ComputedCSSValue(); |
| 133 |
| 84 case BasicShape::kBasicShapeCircleType: { | 134 case BasicShape::kBasicShapeCircleType: { |
| 85 const BasicShapeCircle* circle = ToBasicShapeCircle(basic_shape); | 135 const BasicShapeCircle* circle = ToBasicShapeCircle(basic_shape); |
| 86 CSSBasicShapeCircleValue* circle_value = | 136 CSSBasicShapeCircleValue* circle_value = |
| 87 CSSBasicShapeCircleValue::Create(); | 137 CSSBasicShapeCircleValue::Create(); |
| 88 | 138 |
| 89 circle_value->SetCenterX( | 139 circle_value->SetCenterX( |
| 90 ValueForCenterCoordinate(style, circle->CenterX(), HORIZONTAL)); | 140 ValueForCenterCoordinate(style, circle->CenterX(), HORIZONTAL)); |
| 91 circle_value->SetCenterY( | 141 circle_value->SetCenterY( |
| 92 ValueForCenterCoordinate(style, circle->CenterY(), VERTICAL)); | 142 ValueForCenterCoordinate(style, circle->CenterY(), VERTICAL)); |
| 93 circle_value->SetRadius( | 143 circle_value->SetRadius( |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 rect->SetTopLeftRadius( | 338 rect->SetTopLeftRadius( |
| 289 ConvertToLengthSize(state, rect_value.TopLeftRadius())); | 339 ConvertToLengthSize(state, rect_value.TopLeftRadius())); |
| 290 rect->SetTopRightRadius( | 340 rect->SetTopRightRadius( |
| 291 ConvertToLengthSize(state, rect_value.TopRightRadius())); | 341 ConvertToLengthSize(state, rect_value.TopRightRadius())); |
| 292 rect->SetBottomRightRadius( | 342 rect->SetBottomRightRadius( |
| 293 ConvertToLengthSize(state, rect_value.BottomRightRadius())); | 343 ConvertToLengthSize(state, rect_value.BottomRightRadius())); |
| 294 rect->SetBottomLeftRadius( | 344 rect->SetBottomLeftRadius( |
| 295 ConvertToLengthSize(state, rect_value.BottomLeftRadius())); | 345 ConvertToLengthSize(state, rect_value.BottomLeftRadius())); |
| 296 | 346 |
| 297 basic_shape = std::move(rect); | 347 basic_shape = std::move(rect); |
| 348 } else if (basic_shape_value.IsRayValue()) { |
| 349 const CSSRayValue& ray_value = ToCSSRayValue(basic_shape_value); |
| 350 float angle = ray_value.Angle().ComputeDegrees(); |
| 351 StyleRay::RaySize size = KeywordToRaySize(ray_value.Size().GetValueID()); |
| 352 bool contain = !!ray_value.Contain(); |
| 353 basic_shape = StyleRay::Create(angle, size, contain); |
| 298 } else { | 354 } else { |
| 299 NOTREACHED(); | 355 NOTREACHED(); |
| 300 } | 356 } |
| 301 | 357 |
| 302 return basic_shape.Release(); | 358 return basic_shape.Release(); |
| 303 } | 359 } |
| 304 | 360 |
| 305 FloatPoint FloatPointForCenterCoordinate( | 361 FloatPoint FloatPointForCenterCoordinate( |
| 306 const BasicShapeCenterCoordinate& center_x, | 362 const BasicShapeCenterCoordinate& center_x, |
| 307 const BasicShapeCenterCoordinate& center_y, | 363 const BasicShapeCenterCoordinate& center_y, |
| 308 FloatSize box_size) { | 364 FloatSize box_size) { |
| 309 float x = FloatValueForLength(center_x.ComputedLength(), box_size.Width()); | 365 float x = FloatValueForLength(center_x.ComputedLength(), box_size.Width()); |
| 310 float y = FloatValueForLength(center_y.ComputedLength(), box_size.Height()); | 366 float y = FloatValueForLength(center_y.ComputedLength(), box_size.Height()); |
| 311 return FloatPoint(x, y); | 367 return FloatPoint(x, y); |
| 312 } | 368 } |
| 313 | 369 |
| 314 } // namespace blink | 370 } // namespace blink |
| OLD | NEW |