Chromium Code Reviews| Index: Source/core/rendering/style/BasicShapes.cpp |
| diff --git a/Source/core/rendering/style/BasicShapes.cpp b/Source/core/rendering/style/BasicShapes.cpp |
| index c8ddf8ccca9dc176fbcdc152c237c5e102901d08..51389c39cfb04f1f70229384f0642d23d7f65926 100644 |
| --- a/Source/core/rendering/style/BasicShapes.cpp |
| +++ b/Source/core/rendering/style/BasicShapes.cpp |
| @@ -28,8 +28,9 @@ |
| */ |
| #include "config.h" |
| - |
| #include "core/rendering/style/BasicShapes.h" |
| + |
| +#include "core/css/BasicShapeFunctions.h" |
| #include "platform/LengthFunctions.h" |
| #include "platform/geometry/FloatRect.h" |
| #include "platform/graphics/Path.h" |
| @@ -47,6 +48,16 @@ bool BasicShape::canBlend(const BasicShape* other) const |
| && static_cast<const BasicShapePolygon*>(this)->values().size() != static_cast<const BasicShapePolygon*>(other)->values().size()) |
| return false; |
| + // Circles with keywords for radii or center coordinates cannot be animated. |
| + if (type() == BasicShape::BasicShapeCircleType) { |
| + const BasicShapeCircle* thisCircle = static_cast<const BasicShapeCircle*>(this); |
| + const BasicShapeCircle* otherCircle = static_cast<const BasicShapeCircle*>(other); |
|
eseidel
2014/01/07 19:47:16
How do we know that "other" is OK to static_cast?
|
| + if (!thisCircle->radius().canBlend(otherCircle->radius()) |
| + || !thisCircle->centerX().canBlend(otherCircle->centerX()) |
| + || !thisCircle->centerY().canBlend(otherCircle->centerY())) |
| + return false; |
| + } |
| + |
| return true; |
| } |
| @@ -133,21 +144,27 @@ bool BasicShapeCircle::operator==(const BasicShape& o) const |
| return m_centerX == other.m_centerX && m_centerY == other.m_centerY && m_radius == other.m_radius; |
| } |
| +float BasicShapeCircle::floatValueForRadiusInBox(float boxWidth, float boxHeight) const |
|
leviw_travelin_and_unemployed
2014/01/07 19:41:34
Why not FloatSize?
|
| +{ |
| + if (m_radius.type() == BasicShapeRadius::Value) |
| + return floatValueForLength(m_radius.value(), sqrtf((boxWidth * boxWidth + boxHeight * boxHeight) / 2)); |
|
eseidel
2014/01/07 19:47:16
I wonder if we have a hypotenuse() function somewh
leviw_travelin_and_unemployed
2014/01/07 19:51:56
cmath has hypot and hypotf
|
| + |
| + float centerX = floatValueForCenterCoordinate(m_centerX, boxWidth); |
| + float centerY = floatValueForCenterCoordinate(m_centerY, boxHeight); |
| + |
| + if (m_radius.type() == BasicShapeRadius::ClosestSide) |
| + return std::min(std::min(centerX, boxWidth - centerX), std::min(centerY, boxHeight - centerY)); |
| + |
| + // If radius.type() == BasicShapeRadius::FarthestSide. |
| + return std::max(std::max(centerX, boxWidth - centerX), std::max(centerY, boxHeight - centerY)); |
| +} |
| + |
| void BasicShapeCircle::path(Path& path, const FloatRect& boundingBox) |
| { |
| ASSERT(path.isEmpty()); |
| - // FIXME Complete implementation of path. |
| - // Compute closest-side and farthest-side from boundingBox. |
| - // Compute top, left, bottom, right from boundingBox. |
| - if (m_radius.type() != BasicShapeRadius::Value) |
| - return; |
| - if (m_centerX.keyword() != BasicShapeCenterCoordinate::None || m_centerY.keyword() != BasicShapeCenterCoordinate::None) |
| - return; |
| - |
| - float diagonal = sqrtf((boundingBox.width() * boundingBox.width() + boundingBox.height() * boundingBox.height()) / 2); |
| - float centerX = floatValueForLength(m_centerX.length(), boundingBox.width()); |
| - float centerY = floatValueForLength(m_centerY.length(), boundingBox.height()); |
| - float radius = floatValueForLength(m_radius.value(), diagonal); |
| + float centerX = floatValueForCenterCoordinate(m_centerX, boundingBox.width()); |
| + float centerY = floatValueForCenterCoordinate(m_centerY, boundingBox.height()); |
| + float radius = floatValueForRadiusInBox(boundingBox.width(), boundingBox.height()); |
| path.addEllipse(FloatRect( |
| centerX - radius + boundingBox.x(), |
| centerY - radius + boundingBox.y(), |
| @@ -162,13 +179,6 @@ PassRefPtr<BasicShape> BasicShapeCircle::blend(const BasicShape* other, double p |
| const BasicShapeCircle* o = static_cast<const BasicShapeCircle*>(other); |
| RefPtr<BasicShapeCircle> result = BasicShapeCircle::create(); |
| - if (m_radius.type() != BasicShapeRadius::Value || o->radius().type() != BasicShapeRadius::Value) { |
| - result->setCenterX(o->centerX()); |
| - result->setCenterY(o->centerY()); |
| - result->setRadius(o->radius()); |
| - return result; |
| - } |
| - |
| result->setCenterX(m_centerX.blend(o->centerX(), progress)); |
| result->setCenterY(m_centerY.blend(o->centerY(), progress)); |
| result->setRadius(m_radius.blend(o->radius(), progress)); |