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)#include "config.h" 31a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "core/rendering/shapes/BoxShape.h" 32a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 33a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "wtf/MathExtras.h" 34a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 35c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 36a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)LayoutRect BoxShape::shapeMarginLogicalBoundingBox() const 38a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) FloatRect marginBounds(m_bounds.rect()); 4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (shapeMargin() > 0) 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) marginBounds.inflate(shapeMargin()); 4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return static_cast<LayoutRect>(marginBounds); 4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)FloatRoundedRect BoxShape::shapeMarginBounds() const 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) FloatRoundedRect marginBounds(m_bounds); 4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (shapeMargin() > 0) { 4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) marginBounds.inflate(shapeMargin()); 5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) marginBounds.expandRadii(shapeMargin()); 51a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return marginBounds; 5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 55e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)LineSegment BoxShape::getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const 56a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const FloatRoundedRect& marginBounds = shapeMarginBounds(); 5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (marginBounds.isEmpty() || !lineOverlapsShapeMarginBounds(logicalTop, logicalHeight)) 59e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) return LineSegment(); 60a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 6143e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) float y1 = logicalTop.toFloat(); 6243e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) float y2 = (logicalTop + logicalHeight).toFloat(); 6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const FloatRect& rect = marginBounds.rect(); 64a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 65e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) if (!marginBounds.isRounded()) 66e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) return LineSegment(marginBounds.rect().x(), marginBounds.rect().maxX()); 6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) float topCornerMaxY = std::max<float>(marginBounds.topLeftCorner().maxY(), marginBounds.topRightCorner().maxY()); 6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) float bottomCornerMinY = std::min<float>(marginBounds.bottomLeftCorner().y(), marginBounds.bottomRightCorner().y()); 70a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 71e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) if (topCornerMaxY <= bottomCornerMinY && y1 <= topCornerMaxY && y2 >= bottomCornerMinY) 72e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) return LineSegment(rect.x(), rect.maxX()); 73a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 74a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) float x1 = rect.maxX(); 75a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) float x2 = rect.x(); 76a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) float minXIntercept; 77a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) float maxXIntercept; 78a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 796f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch if (y1 <= marginBounds.topLeftCorner().maxY() && y2 >= marginBounds.bottomLeftCorner().y()) 806f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch x1 = rect.x(); 816f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch 826f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch if (y1 <= marginBounds.topRightCorner().maxY() && y2 >= marginBounds.bottomRightCorner().y()) 836f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch x2 = rect.maxX(); 846f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch 8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (marginBounds.xInterceptsAtY(y1, minXIntercept, maxXIntercept)) { 86a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) x1 = std::min<float>(x1, minXIntercept); 87a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) x2 = std::max<float>(x2, maxXIntercept); 88a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 89a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 9009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (marginBounds.xInterceptsAtY(y2, minXIntercept, maxXIntercept)) { 91a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) x1 = std::min<float>(x1, minXIntercept); 92a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) x2 = std::max<float>(x2, maxXIntercept); 93a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 94a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 95a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) ASSERT(x2 >= x1); 96e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) return LineSegment(x1, x2); 97a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 98a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 99323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)void BoxShape::buildDisplayPaths(DisplayPaths& paths) const 100323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles){ 101323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) paths.shape.addRoundedRect(m_bounds.rect(), m_bounds.radii().topLeft(), m_bounds.radii().topRight(), m_bounds.radii().bottomLeft(), m_bounds.radii().bottomRight()); 102323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) if (shapeMargin()) 103323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) paths.marginShape.addRoundedRect(shapeMarginBounds().rect(), shapeMarginBounds().radii().topLeft(), shapeMarginBounds().radii().topRight(), shapeMarginBounds().radii().bottomLeft(), shapeMarginBounds().radii().bottomRight()); 104323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)} 105323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) 106c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 107