15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * disclaimer. 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * disclaimer in the documentation and/or other materials 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * provided with the distribution. 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SUCH DAMAGE. 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h" 3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/style/BasicShapes.h" 3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/css/BasicShapeFunctions.h" 34d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "platform/CalculationValue.h" 35bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "platform/LengthFunctions.h" 361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/FloatRect.h" 37a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/Path.h" 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 39c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 40d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 41926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)bool BasicShape::canBlend(const BasicShape* other) const 42926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 43926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) // FIXME: Support animations between different shapes in the future. 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!other || !isSameType(*other)) 45926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return false; 46926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 47926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) // Just polygons with same number of vertices can be animated. 485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) if (type() == BasicShape::BasicShapePolygonType 49197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch && (toBasicShapePolygon(this)->values().size() != toBasicShapePolygon(other)->values().size() 50197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch || toBasicShapePolygon(this)->windRule() != toBasicShapePolygon(other)->windRule())) 51926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return false; 52926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Circles with keywords for radii or center coordinates cannot be animated. 5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (type() == BasicShape::BasicShapeCircleType) { 55197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (!toBasicShapeCircle(this)->radius().canBlend(toBasicShapeCircle(other)->radius())) 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Ellipses with keywords for radii or center coordinates cannot be animated. 6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (type() != BasicShape::BasicShapeEllipseType) 6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return true; 6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 63197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return (toBasicShapeEllipse(this)->radiusX().canBlend(toBasicShapeEllipse(other)->radiusX()) 64197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch && toBasicShapeEllipse(this)->radiusY().canBlend(toBasicShapeEllipse(other)->radiusY())); 65926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 66926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool BasicShapeCircle::operator==(const BasicShape& o) const 6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!isSameType(o)) 7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 7109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const BasicShapeCircle& other = toBasicShapeCircle(o); 7209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return m_centerX == other.m_centerX && m_centerY == other.m_centerY && m_radius == other.m_radius; 7309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 7409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)float BasicShapeCircle::floatValueForRadiusInBox(FloatSize boxSize) const 7609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 7709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (m_radius.type() == BasicShapeRadius::Value) 7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return floatValueForLength(m_radius.value(), hypotf(boxSize.width(), boxSize.height()) / sqrtf(2)); 7909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 8009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) FloatPoint center = floatPointForCenterCoordinate(m_centerX, m_centerY, boxSize); 8109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (m_radius.type() == BasicShapeRadius::ClosestSide) 8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return std::min(std::min(center.x(), boxSize.width() - center.x()), std::min(center.y(), boxSize.height() - center.y())); 8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // If radius.type() == BasicShapeRadius::FarthestSide. 8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return std::max(std::max(center.x(), boxSize.width() - center.x()), std::max(center.y(), boxSize.height() - center.y())); 8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 8809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 8909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void BasicShapeCircle::path(Path& path, const FloatRect& boundingBox) 9009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 9109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(path.isEmpty()); 9209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) FloatPoint center = floatPointForCenterCoordinate(m_centerX, m_centerY, boundingBox.size()); 9309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) float radius = floatValueForRadiusInBox(boundingBox.size()); 9409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) path.addEllipse(FloatRect( 9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) center.x() - radius + boundingBox.x(), 9609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) center.y() - radius + boundingBox.y(), 9709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) radius * 2, 9809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) radius * 2 9909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) )); 10009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 10109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 10209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)PassRefPtr<BasicShape> BasicShapeCircle::blend(const BasicShape* other, double progress) const 10309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 10409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(type() == other->type()); 105197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch const BasicShapeCircle* o = toBasicShapeCircle(other); 10609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RefPtr<BasicShapeCircle> result = BasicShapeCircle::create(); 10709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 10809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setCenterX(m_centerX.blend(o->centerX(), progress)); 10909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setCenterY(m_centerY.blend(o->centerY(), progress)); 11009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setRadius(m_radius.blend(o->radius(), progress)); 11109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return result.release(); 11209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 11309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 11409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool BasicShapeEllipse::operator==(const BasicShape& o) const 11509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 11609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!isSameType(o)) 11709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 11809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const BasicShapeEllipse& other = toBasicShapeEllipse(o); 11909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return m_centerX == other.m_centerX && m_centerY == other.m_centerY && m_radiusX == other.m_radiusX && m_radiusY == other.m_radiusY; 12009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 12109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 12209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)float BasicShapeEllipse::floatValueForRadiusInBox(const BasicShapeRadius& radius, float center, float boxWidthOrHeight) const 12309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 12409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (radius.type() == BasicShapeRadius::Value) 12509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return floatValueForLength(radius.value(), boxWidthOrHeight); 12609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 12709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (radius.type() == BasicShapeRadius::ClosestSide) 12809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return std::min(center, boxWidthOrHeight - center); 12909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 13009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(radius.type() == BasicShapeRadius::FarthestSide); 13109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return std::max(center, boxWidthOrHeight - center); 13209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 13309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 13409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void BasicShapeEllipse::path(Path& path, const FloatRect& boundingBox) 13509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 13609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(path.isEmpty()); 13709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) FloatPoint center = floatPointForCenterCoordinate(m_centerX, m_centerY, boundingBox.size()); 13809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) float radiusX = floatValueForRadiusInBox(m_radiusX, center.x(), boundingBox.width()); 13909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) float radiusY = floatValueForRadiusInBox(m_radiusY, center.y(), boundingBox.height()); 14009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) path.addEllipse(FloatRect( 14109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) center.x() - radiusX + boundingBox.x(), 14209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) center.y() - radiusY + boundingBox.y(), 14309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) radiusX * 2, 14409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) radiusY * 2 14509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) )); 14609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 14709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 14809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)PassRefPtr<BasicShape> BasicShapeEllipse::blend(const BasicShape* other, double progress) const 14909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 15009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(type() == other->type()); 151197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch const BasicShapeEllipse* o = toBasicShapeEllipse(other); 15209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RefPtr<BasicShapeEllipse> result = BasicShapeEllipse::create(); 15309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 15409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (m_radiusX.type() != BasicShapeRadius::Value || o->radiusX().type() != BasicShapeRadius::Value 15509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) || m_radiusY.type() != BasicShapeRadius::Value || o->radiusY().type() != BasicShapeRadius::Value) { 15609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setCenterX(o->centerX()); 15709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setCenterY(o->centerY()); 15809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setRadiusX(o->radiusX()); 15909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setRadiusY(o->radiusY()); 16009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return result; 16109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 16209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 16309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setCenterX(m_centerX.blend(o->centerX(), progress)); 16409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setCenterY(m_centerY.blend(o->centerY(), progress)); 16509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setRadiusX(m_radiusX.blend(o->radiusX(), progress)); 16609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) result->setRadiusY(m_radiusY.blend(o->radiusY(), progress)); 16709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return result.release(); 16809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 16909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void BasicShapePolygon::path(Path& path, const FloatRect& boundingBox) 1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ASSERT(path.isEmpty()); 1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ASSERT(!(m_values.size() % 2)); 1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) size_t length = m_values.size(); 17502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 1765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!length) 1775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return; 1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) path.moveTo(FloatPoint(floatValueForLength(m_values.at(0), boundingBox.width()) + boundingBox.x(), 1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) floatValueForLength(m_values.at(1), boundingBox.height()) + boundingBox.y())); 1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) for (size_t i = 2; i < length; i = i + 2) { 1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) path.addLineTo(FloatPoint(floatValueForLength(m_values.at(i), boundingBox.width()) + boundingBox.x(), 1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) floatValueForLength(m_values.at(i + 1), boundingBox.height()) + boundingBox.y())); 1845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) path.closeSubpath(); 1865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 187926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 188926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)PassRefPtr<BasicShape> BasicShapePolygon::blend(const BasicShape* other, double progress) const 189926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 19009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(other && isSameType(*other)); 191926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 192197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch const BasicShapePolygon* o = toBasicShapePolygon(other); 193926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) ASSERT(m_values.size() == o->values().size()); 194926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) ASSERT(!(m_values.size() % 2)); 195926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 196926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) size_t length = m_values.size(); 197926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) RefPtr<BasicShapePolygon> result = BasicShapePolygon::create(); 198926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) if (!length) 199926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return result.release(); 200926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 201926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) result->setWindRule(o->windRule()); 202926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 203926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) for (size_t i = 0; i < length; i = i + 2) { 2041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) result->appendPoint(m_values.at(i).blend(o->values().at(i), progress, ValueRangeAll), 2051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) m_values.at(i + 1).blend(o->values().at(i + 1), progress, ValueRangeAll)); 206926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) } 207926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 208926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return result.release(); 209926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 2105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 21109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool BasicShapePolygon::operator==(const BasicShape& o) const 21209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 21309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!isSameType(o)) 21409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 21509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const BasicShapePolygon& other = toBasicShapePolygon(o); 21609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return m_windRule == other.m_windRule && m_values == other.m_values; 21709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 21809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 21909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)static FloatSize floatSizeForLengthSize(const LengthSize& lengthSize, const FloatRect& boundingBox) 22009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 22109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return FloatSize(floatValueForLength(lengthSize.width(), boundingBox.width()), 22209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) floatValueForLength(lengthSize.height(), boundingBox.height())); 22309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 22409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 22509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void BasicShapeInset::path(Path& path, const FloatRect& boundingBox) 22609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 22709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(path.isEmpty()); 22809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) float left = floatValueForLength(m_left, boundingBox.width()); 22909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) float top = floatValueForLength(m_top, boundingBox.height()); 23009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) path.addRoundedRect( 23109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) FloatRect( 23209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) left + boundingBox.x(), 23309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) top + boundingBox.y(), 23409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) std::max<float>(boundingBox.width() - left - floatValueForLength(m_right, boundingBox.width()), 0), 23509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) std::max<float>(boundingBox.height() - top - floatValueForLength(m_bottom, boundingBox.height()), 0) 23609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ), 23709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) floatSizeForLengthSize(m_topLeftRadius, boundingBox), 23809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) floatSizeForLengthSize(m_topRightRadius, boundingBox), 23909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) floatSizeForLengthSize(m_bottomLeftRadius, boundingBox), 24009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) floatSizeForLengthSize(m_bottomRightRadius, boundingBox) 24109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ); 24209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 24309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 24409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)PassRefPtr<BasicShape> BasicShapeInset::blend(const BasicShape* other, double) const 24509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 24609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(type() == other->type()); 24709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // FIXME: Implement blend for BasicShapeInset. 248d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return nullptr; 24909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 25009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 25109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool BasicShapeInset::operator==(const BasicShape& o) const 25209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 25309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!isSameType(o)) 25409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 25509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const BasicShapeInset& other = toBasicShapeInset(o); 25609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return m_right == other.m_right 25709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) && m_top == other.m_top 25809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) && m_bottom == other.m_bottom 25909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) && m_left == other.m_left 26009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) && m_topLeftRadius == other.m_topLeftRadius 26109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) && m_topRightRadius == other.m_topRightRadius 26209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) && m_bottomRightRadius == other.m_bottomRightRadius 26309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) && m_bottomLeftRadius == other.m_bottomLeftRadius; 26409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 26509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 2665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 267