1a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)/* 2a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 3a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * 4a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 5a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * modification, are permitted provided that the following conditions 6a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * are met: 7a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * 8a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * 1. Redistributions of source code must retain the above 9a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * copyright notice, this list of conditions and the following 10a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * disclaimer. 11a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above 12a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * copyright notice, this list of conditions and the following 13a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * disclaimer in the documentation and/or other materials 14a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * provided with the distribution. 15a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * 16a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 19a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 20a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 27a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * OF THE POSSIBILITY OF SUCH DAMAGE. 28a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) */ 29a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 30a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#ifndef FloatRoundedRect_h 31a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define FloatRoundedRect_h 32a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 33a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/geometry/FloatRect.h" 34a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/geometry/FloatSize.h" 3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/geometry/RoundedRect.h" 36a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 37c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 38a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 39a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class PLATFORM_EXPORT FloatRoundedRect { 40a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)public: 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) class PLATFORM_EXPORT Radii { 42a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) public: 43a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) Radii() { } 44a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) Radii(const FloatSize& topLeft, const FloatSize& topRight, const FloatSize& bottomLeft, const FloatSize& bottomRight) 45a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) : m_topLeft(topLeft) 46a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) , m_topRight(topRight) 47a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) , m_bottomLeft(bottomLeft) 48a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) , m_bottomRight(bottomRight) 49a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) { 50a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 51a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) Radii(const RoundedRect::Radii& intRadii) 5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) : m_topLeft(intRadii.topLeft()) 5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) , m_topRight(intRadii.topRight()) 5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) , m_bottomLeft(intRadii.bottomLeft()) 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) , m_bottomRight(intRadii.bottomRight()) 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) { 5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 60a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setTopLeft(const FloatSize& size) { m_topLeft = size; } 61a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setTopRight(const FloatSize& size) { m_topRight = size; } 62a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setBottomLeft(const FloatSize& size) { m_bottomLeft = size; } 63a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setBottomRight(const FloatSize& size) { m_bottomRight = size; } 64a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) const FloatSize& topLeft() const { return m_topLeft; } 65a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) const FloatSize& topRight() const { return m_topRight; } 66a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) const FloatSize& bottomLeft() const { return m_bottomLeft; } 67a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) const FloatSize& bottomRight() const { return m_bottomRight; } 68a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 69a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) bool isZero() const; 70a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 71a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void scale(float factor); 72a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void expand(float topWidth, float bottomWidth, float leftWidth, float rightWidth); 73a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void expand(float size) { expand(size, size, size, size); } 74a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void shrink(float topWidth, float bottomWidth, float leftWidth, float rightWidth) { expand(-topWidth, -bottomWidth, -leftWidth, -rightWidth); } 75a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void shrink(float size) { shrink(size, size, size, size); } 76a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 77a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) private: 78a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatSize m_topLeft; 79a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatSize m_topRight; 80a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatSize m_bottomLeft; 81a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatSize m_bottomRight; 82a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) }; 83a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 84a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) explicit FloatRoundedRect(const FloatRect&, const Radii& = Radii()); 85a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatRoundedRect(float x, float y, float width, float height); 86a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatRoundedRect(const FloatRect&, const FloatSize& topLeft, const FloatSize& topRight, const FloatSize& bottomLeft, const FloatSize& bottomRight); 87a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 88a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) const FloatRect& rect() const { return m_rect; } 89a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) const Radii& radii() const { return m_radii; } 90a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) bool isRounded() const { return !m_radii.isZero(); } 91a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) bool isEmpty() const { return m_rect.isEmpty(); } 92a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 93a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setRect(const FloatRect& rect) { m_rect = rect; } 94a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setRadii(const Radii& radii) { m_radii = radii; } 95a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 96a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void move(const FloatSize& size) { m_rect.move(size); } 97a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void inflate(float size) { m_rect.inflate(size); } 98a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void expandRadii(float size) { m_radii.expand(size); } 99a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void shrinkRadii(float size) { m_radii.shrink(size); } 100a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 101a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatRect topLeftCorner() const 102a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) { 103a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return FloatRect(m_rect.x(), m_rect.y(), m_radii.topLeft().width(), m_radii.topLeft().height()); 104a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 105a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatRect topRightCorner() const 106a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) { 107a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return FloatRect(m_rect.maxX() - m_radii.topRight().width(), m_rect.y(), m_radii.topRight().width(), m_radii.topRight().height()); 108a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 109a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatRect bottomLeftCorner() const 110a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) { 111a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return FloatRect(m_rect.x(), m_rect.maxY() - m_radii.bottomLeft().height(), m_radii.bottomLeft().width(), m_radii.bottomLeft().height()); 112a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 113a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatRect bottomRightCorner() const 114a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) { 115a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return FloatRect(m_rect.maxX() - m_radii.bottomRight().width(), m_rect.maxY() - m_radii.bottomRight().height(), m_radii.bottomRight().width(), m_radii.bottomRight().height()); 116a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 117a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 118a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) bool xInterceptsAtY(float y, float& minXIntercept, float& maxXIntercept) const; 119a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 120a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)private: 121a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) FloatRect m_rect; 122a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) Radii m_radii; 123a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}; 124a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 125a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)inline bool operator==(const FloatRoundedRect::Radii& a, const FloatRoundedRect::Radii& b) 126a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 127a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return a.topLeft() == b.topLeft() && a.topRight() == b.topRight() && a.bottomLeft() == b.bottomLeft() && a.bottomRight() == b.bottomRight(); 128a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 129a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 130a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)inline bool operator==(const FloatRoundedRect& a, const FloatRoundedRect& b) 131a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 132a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return a.rect() == b.rect() && a.radii() == b.radii(); 133a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 134a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 135c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 136a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 137a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#endif // FloatRoundedRect_h 138