| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2015 Google Inc. All rights reserved. | 3 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 sign * primitive_value->GetFloatValue() / 100.f * edge_distance; | 764 sign * primitive_value->GetFloatValue() / 100.f * edge_distance; |
| 765 | 765 |
| 766 if (primitive_value->IsCalculatedPercentageWithLength()) | 766 if (primitive_value->IsCalculatedPercentageWithLength()) |
| 767 return origin + sign * primitive_value->CssCalcValue() | 767 return origin + sign * primitive_value->CssCalcValue() |
| 768 ->ToCalcValue(conversion_data) | 768 ->ToCalcValue(conversion_data) |
| 769 ->Evaluate(edge_distance); | 769 ->Evaluate(edge_distance); |
| 770 | 770 |
| 771 return origin + sign * primitive_value->ComputeLength<float>(conversion_data); | 771 return origin + sign * primitive_value->ComputeLength<float>(conversion_data); |
| 772 } | 772 } |
| 773 | 773 |
| 774 FloatPoint CSSGradientValue::ComputeEndPoint( | 774 // Resolve points/radii to front end values. |
| 775 CSSValue* horizontal, | 775 static FloatPoint ComputeEndPoint( |
| 776 CSSValue* vertical, | 776 const CSSValue* horizontal, |
| 777 const CSSValue* vertical, |
| 777 const CSSToLengthConversionData& conversion_data, | 778 const CSSToLengthConversionData& conversion_data, |
| 778 const IntSize& size) { | 779 const IntSize& size) { |
| 779 FloatPoint result; | 780 FloatPoint result; |
| 780 | 781 |
| 781 if (horizontal) | 782 if (horizontal) |
| 782 result.SetX(PositionFromValue(horizontal, conversion_data, size, true)); | 783 result.SetX(PositionFromValue(horizontal, conversion_data, size, true)); |
| 783 | 784 |
| 784 if (vertical) | 785 if (vertical) |
| 785 result.SetY(PositionFromValue(vertical, conversion_data, size, false)); | 786 result.SetY(PositionFromValue(vertical, conversion_data, size, false)); |
| 786 | 787 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 797 | 798 |
| 798 void CSSGradientValue::GetStopColors(Vector<Color>& stop_colors, | 799 void CSSGradientValue::GetStopColors(Vector<Color>& stop_colors, |
| 799 const LayoutObject& object) const { | 800 const LayoutObject& object) const { |
| 800 for (auto& stop : stops_) { | 801 for (auto& stop : stops_) { |
| 801 if (!stop.IsHint()) | 802 if (!stop.IsHint()) |
| 802 stop_colors.push_back(ResolveStopColor(*stop.color_, object)); | 803 stop_colors.push_back(ResolveStopColor(*stop.color_, object)); |
| 803 } | 804 } |
| 804 } | 805 } |
| 805 | 806 |
| 806 DEFINE_TRACE_AFTER_DISPATCH(CSSGradientValue) { | 807 DEFINE_TRACE_AFTER_DISPATCH(CSSGradientValue) { |
| 807 visitor->Trace(first_x_); | |
| 808 visitor->Trace(first_y_); | |
| 809 visitor->Trace(second_x_); | |
| 810 visitor->Trace(second_y_); | |
| 811 visitor->Trace(stops_); | 808 visitor->Trace(stops_); |
| 812 CSSImageGeneratorValue::TraceAfterDispatch(visitor); | 809 CSSImageGeneratorValue::TraceAfterDispatch(visitor); |
| 813 } | 810 } |
| 814 | 811 |
| 815 String CSSLinearGradientValue::CustomCSSText() const { | 812 String CSSLinearGradientValue::CustomCSSText() const { |
| 816 StringBuilder result; | 813 StringBuilder result; |
| 817 if (gradient_type_ == kCSSDeprecatedLinearGradient) { | 814 if (gradient_type_ == kCSSDeprecatedLinearGradient) { |
| 818 result.Append("-webkit-gradient(linear, "); | 815 result.Append("-webkit-gradient(linear, "); |
| 819 result.Append(first_x_->CssText()); | 816 result.Append(first_x_->CssText()); |
| 820 result.Append(' '); | 817 result.Append(' '); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 } else if (first_y_) { | 1058 } else if (first_y_) { |
| 1062 equal_xand_y = DataEquivalent(first_y_, other.first_y_) && !other.first_x_; | 1059 equal_xand_y = DataEquivalent(first_y_, other.first_y_) && !other.first_x_; |
| 1063 } else { | 1060 } else { |
| 1064 equal_xand_y = !other.first_x_ && !other.first_y_; | 1061 equal_xand_y = !other.first_x_ && !other.first_y_; |
| 1065 } | 1062 } |
| 1066 | 1063 |
| 1067 return equal_xand_y && stops_ == other.stops_; | 1064 return equal_xand_y && stops_ == other.stops_; |
| 1068 } | 1065 } |
| 1069 | 1066 |
| 1070 DEFINE_TRACE_AFTER_DISPATCH(CSSLinearGradientValue) { | 1067 DEFINE_TRACE_AFTER_DISPATCH(CSSLinearGradientValue) { |
| 1068 visitor->Trace(first_x_); |
| 1069 visitor->Trace(first_y_); |
| 1070 visitor->Trace(second_x_); |
| 1071 visitor->Trace(second_y_); |
| 1071 visitor->Trace(angle_); | 1072 visitor->Trace(angle_); |
| 1072 CSSGradientValue::TraceAfterDispatch(visitor); | 1073 CSSGradientValue::TraceAfterDispatch(visitor); |
| 1073 } | 1074 } |
| 1074 | 1075 |
| 1075 void CSSGradientValue::AppendCSSTextForColorStops( | 1076 void CSSGradientValue::AppendCSSTextForColorStops( |
| 1076 StringBuilder& result, | 1077 StringBuilder& result, |
| 1077 bool requires_separator) const { | 1078 bool requires_separator) const { |
| 1078 const CSSValue* prev_color = nullptr; | 1079 const CSSValue* prev_color = nullptr; |
| 1079 | 1080 |
| 1080 for (const auto& stop : stops_) { | 1081 for (const auto& stop : stops_) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 wrote_something |= | 1220 wrote_something |= |
| 1220 AppendPosition(result, first_x_, first_y_, wrote_something); | 1221 AppendPosition(result, first_x_, first_y_, wrote_something); |
| 1221 | 1222 |
| 1222 AppendCSSTextForColorStops(result, wrote_something); | 1223 AppendCSSTextForColorStops(result, wrote_something); |
| 1223 } | 1224 } |
| 1224 | 1225 |
| 1225 result.Append(')'); | 1226 result.Append(')'); |
| 1226 return result.ToString(); | 1227 return result.ToString(); |
| 1227 } | 1228 } |
| 1228 | 1229 |
| 1229 float CSSRadialGradientValue::ResolveRadius( | 1230 namespace { |
| 1230 CSSPrimitiveValue* radius, | 1231 |
| 1231 const CSSToLengthConversionData& conversion_data, | 1232 // Resolve points/radii to front end values. |
| 1232 float* width_or_height) { | 1233 float ResolveRadius(const CSSPrimitiveValue* radius, |
| 1234 const CSSToLengthConversionData& conversion_data, |
| 1235 float* width_or_height = nullptr) { |
| 1233 float result = 0; | 1236 float result = 0; |
| 1234 if (radius->IsNumber()) | 1237 if (radius->IsNumber()) |
| 1235 result = radius->GetFloatValue() * conversion_data.Zoom(); | 1238 result = radius->GetFloatValue() * conversion_data.Zoom(); |
| 1236 else if (width_or_height && radius->IsPercentage()) | 1239 else if (width_or_height && radius->IsPercentage()) |
| 1237 result = *width_or_height * radius->GetFloatValue() / 100; | 1240 result = *width_or_height * radius->GetFloatValue() / 100; |
| 1238 else | 1241 else |
| 1239 result = radius->ComputeLength<float>(conversion_data); | 1242 result = radius->ComputeLength<float>(conversion_data); |
| 1240 | 1243 |
| 1241 return clampTo<float>(std::max(result, 0.0f)); | 1244 return clampTo<float>(std::max(result, 0.0f)); |
| 1242 } | 1245 } |
| 1243 | 1246 |
| 1244 namespace { | |
| 1245 | |
| 1246 enum EndShapeType { kCircleEndShape, kEllipseEndShape }; | 1247 enum EndShapeType { kCircleEndShape, kEllipseEndShape }; |
| 1247 | 1248 |
| 1248 // Compute the radius to the closest/farthest side (depending on the compare | 1249 // Compute the radius to the closest/farthest side (depending on the compare |
| 1249 // functor). | 1250 // functor). |
| 1250 FloatSize RadiusToSide(const FloatPoint& point, | 1251 FloatSize RadiusToSide(const FloatPoint& point, |
| 1251 const FloatSize& size, | 1252 const FloatSize& size, |
| 1252 EndShapeType shape, | 1253 EndShapeType shape, |
| 1253 bool (*compare)(float, float)) { | 1254 bool (*compare)(float, float)) { |
| 1254 float dx1 = clampTo<float>(fabs(point.X())); | 1255 float dx1 = clampTo<float>(fabs(point.X())); |
| 1255 float dy1 = clampTo<float>(fabs(point.Y())); | 1256 float dy1 = clampTo<float>(fabs(point.Y())); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 equal_shape = !other.shape_; | 1452 equal_shape = !other.shape_; |
| 1452 equal_sizing_behavior = !other.sizing_behavior_; | 1453 equal_sizing_behavior = !other.sizing_behavior_; |
| 1453 equal_horizontal_and_vertical_size = | 1454 equal_horizontal_and_vertical_size = |
| 1454 !other.end_horizontal_size_ && !other.end_vertical_size_; | 1455 !other.end_horizontal_size_ && !other.end_vertical_size_; |
| 1455 } | 1456 } |
| 1456 return equal_shape && equal_sizing_behavior && | 1457 return equal_shape && equal_sizing_behavior && |
| 1457 equal_horizontal_and_vertical_size && stops_ == other.stops_; | 1458 equal_horizontal_and_vertical_size && stops_ == other.stops_; |
| 1458 } | 1459 } |
| 1459 | 1460 |
| 1460 DEFINE_TRACE_AFTER_DISPATCH(CSSRadialGradientValue) { | 1461 DEFINE_TRACE_AFTER_DISPATCH(CSSRadialGradientValue) { |
| 1462 visitor->Trace(first_x_); |
| 1463 visitor->Trace(first_y_); |
| 1464 visitor->Trace(second_x_); |
| 1465 visitor->Trace(second_y_); |
| 1461 visitor->Trace(first_radius_); | 1466 visitor->Trace(first_radius_); |
| 1462 visitor->Trace(second_radius_); | 1467 visitor->Trace(second_radius_); |
| 1463 visitor->Trace(shape_); | 1468 visitor->Trace(shape_); |
| 1464 visitor->Trace(sizing_behavior_); | 1469 visitor->Trace(sizing_behavior_); |
| 1465 visitor->Trace(end_horizontal_size_); | 1470 visitor->Trace(end_horizontal_size_); |
| 1466 visitor->Trace(end_vertical_size_); | 1471 visitor->Trace(end_vertical_size_); |
| 1467 CSSGradientValue::TraceAfterDispatch(visitor); | 1472 CSSGradientValue::TraceAfterDispatch(visitor); |
| 1468 } | 1473 } |
| 1469 | 1474 |
| 1470 String CSSConicGradientValue::CustomCSSText() const { | 1475 String CSSConicGradientValue::CustomCSSText() const { |
| 1471 StringBuilder result; | 1476 StringBuilder result; |
| 1472 | 1477 |
| 1473 if (repeating_) | 1478 if (repeating_) |
| 1474 result.Append("repeating-"); | 1479 result.Append("repeating-"); |
| 1475 result.Append("conic-gradient("); | 1480 result.Append("conic-gradient("); |
| 1476 | 1481 |
| 1477 bool wrote_something = false; | 1482 bool wrote_something = false; |
| 1478 | 1483 |
| 1479 if (from_angle_) { | 1484 if (from_angle_) { |
| 1480 result.Append("from "); | 1485 result.Append("from "); |
| 1481 result.Append(from_angle_->CssText()); | 1486 result.Append(from_angle_->CssText()); |
| 1482 wrote_something = true; | 1487 wrote_something = true; |
| 1483 } | 1488 } |
| 1484 | 1489 |
| 1485 wrote_something |= | 1490 wrote_something |= AppendPosition(result, x_, y_, wrote_something); |
| 1486 AppendPosition(result, first_x_, first_y_, wrote_something); | |
| 1487 | 1491 |
| 1488 AppendCSSTextForColorStops(result, wrote_something); | 1492 AppendCSSTextForColorStops(result, wrote_something); |
| 1489 | 1493 |
| 1490 result.Append(')'); | 1494 result.Append(')'); |
| 1491 return result.ToString(); | 1495 return result.ToString(); |
| 1492 } | 1496 } |
| 1493 | 1497 |
| 1494 PassRefPtr<Gradient> CSSConicGradientValue::CreateGradient( | 1498 PassRefPtr<Gradient> CSSConicGradientValue::CreateGradient( |
| 1495 const CSSToLengthConversionData& conversion_data, | 1499 const CSSToLengthConversionData& conversion_data, |
| 1496 const IntSize& size, | 1500 const IntSize& size, |
| 1497 const LayoutObject& object) { | 1501 const LayoutObject& object) { |
| 1498 DCHECK(!size.IsEmpty()); | 1502 DCHECK(!size.IsEmpty()); |
| 1499 | 1503 |
| 1500 const float angle = from_angle_ ? from_angle_->ComputeDegrees() : 0; | 1504 const float angle = from_angle_ ? from_angle_->ComputeDegrees() : 0; |
| 1501 | 1505 |
| 1502 const FloatPoint position( | 1506 const FloatPoint position( |
| 1503 first_x_ ? PositionFromValue(first_x_, conversion_data, size, true) | 1507 x_ ? PositionFromValue(x_, conversion_data, size, true) |
| 1504 : size.Width() / 2, | 1508 : size.Width() / 2, |
| 1505 first_y_ ? PositionFromValue(first_y_, conversion_data, size, false) | 1509 y_ ? PositionFromValue(y_, conversion_data, size, false) |
| 1506 : size.Height() / 2); | 1510 : size.Height() / 2); |
| 1507 | 1511 |
| 1508 GradientDesc desc(position, position, | 1512 GradientDesc desc(position, position, |
| 1509 repeating_ ? kSpreadMethodRepeat : kSpreadMethodPad); | 1513 repeating_ ? kSpreadMethodRepeat : kSpreadMethodPad); |
| 1510 AddStops(desc, conversion_data, object); | 1514 AddStops(desc, conversion_data, object); |
| 1511 | 1515 |
| 1512 RefPtr<Gradient> gradient = Gradient::CreateConic( | 1516 RefPtr<Gradient> gradient = Gradient::CreateConic( |
| 1513 position, angle, Gradient::ColorInterpolation::kPremultiplied); | 1517 position, angle, Gradient::ColorInterpolation::kPremultiplied); |
| 1514 gradient->AddColorStops(desc.stops); | 1518 gradient->AddColorStops(desc.stops); |
| 1515 | 1519 |
| 1516 return gradient.Release(); | 1520 return gradient.Release(); |
| 1517 } | 1521 } |
| 1518 | 1522 |
| 1519 bool CSSConicGradientValue::Equals(const CSSConicGradientValue& other) const { | 1523 bool CSSConicGradientValue::Equals(const CSSConicGradientValue& other) const { |
| 1520 return repeating_ == other.repeating_ && | 1524 return repeating_ == other.repeating_ && DataEquivalent(x_, other.x_) && |
| 1521 DataEquivalent(first_x_, other.first_x_) && | 1525 DataEquivalent(y_, other.y_) && |
| 1522 DataEquivalent(first_y_, other.first_y_) && | |
| 1523 DataEquivalent(from_angle_, other.from_angle_) && | 1526 DataEquivalent(from_angle_, other.from_angle_) && |
| 1524 stops_ == other.stops_; | 1527 stops_ == other.stops_; |
| 1525 } | 1528 } |
| 1526 | 1529 |
| 1527 DEFINE_TRACE_AFTER_DISPATCH(CSSConicGradientValue) { | 1530 DEFINE_TRACE_AFTER_DISPATCH(CSSConicGradientValue) { |
| 1531 visitor->Trace(x_); |
| 1532 visitor->Trace(y_); |
| 1528 visitor->Trace(from_angle_); | 1533 visitor->Trace(from_angle_); |
| 1529 CSSGradientValue::TraceAfterDispatch(visitor); | 1534 CSSGradientValue::TraceAfterDispatch(visitor); |
| 1530 } | 1535 } |
| 1531 | 1536 |
| 1532 } // namespace blink | 1537 } // namespace blink |
| OLD | NEW |