Home | History | Annotate | Download | only in shapes
      1 /*
      2  * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *
      8  * 1. Redistributions of source code must retain the above
      9  *    copyright notice, this list of conditions and the following
     10  *    disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above
     12  *    copyright notice, this list of conditions and the following
     13  *    disclaimer in the documentation and/or other materials
     14  *    provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     20  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     27  * OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include "config.h"
     31 #include "core/rendering/shapes/BoxShape.h"
     32 
     33 #include "wtf/MathExtras.h"
     34 
     35 namespace WebCore {
     36 
     37 LayoutRect BoxShape::shapeMarginLogicalBoundingBox() const
     38 {
     39     FloatRect marginBounds(m_bounds.rect());
     40     if (shapeMargin() > 0)
     41         marginBounds.inflate(shapeMargin());
     42     return static_cast<LayoutRect>(marginBounds);
     43 }
     44 
     45 LayoutRect BoxShape::shapePaddingLogicalBoundingBox() const
     46 {
     47     FloatRect paddingBounds(m_bounds.rect());
     48     if (shapePadding() > 0)
     49         paddingBounds.inflate(-shapePadding());
     50     return static_cast<LayoutRect>(paddingBounds);
     51 }
     52 
     53 FloatRoundedRect BoxShape::shapeMarginBounds() const
     54 {
     55     FloatRoundedRect marginBounds(m_bounds);
     56     if (shapeMargin() > 0) {
     57         marginBounds.inflate(shapeMargin());
     58         marginBounds.expandRadii(shapeMargin());
     59     }
     60     return marginBounds;
     61 }
     62 
     63 FloatRoundedRect BoxShape::shapePaddingBounds() const
     64 {
     65     FloatRoundedRect paddingBounds(m_bounds);
     66     if (shapePadding() > 0) {
     67         paddingBounds.inflate(-shapePadding());
     68         paddingBounds.expandRadii(-shapePadding());
     69     }
     70     return paddingBounds;
     71 }
     72 
     73 void BoxShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList& result) const
     74 {
     75     const FloatRoundedRect& marginBounds = shapeMarginBounds();
     76     if (marginBounds.isEmpty() || !lineOverlapsShapeMarginBounds(logicalTop, logicalHeight))
     77         return;
     78 
     79     float y1 = logicalTop;
     80     float y2 = logicalTop + logicalHeight;
     81     const FloatRect& rect = marginBounds.rect();
     82 
     83     if (!marginBounds.isRounded()) {
     84         result.append(LineSegment(marginBounds.rect().x(), marginBounds.rect().maxX()));
     85         return;
     86     }
     87 
     88     float x1 = rect.maxX();
     89     float x2 = rect.x();
     90     float minXIntercept;
     91     float maxXIntercept;
     92 
     93     if (marginBounds.xInterceptsAtY(y1, minXIntercept, maxXIntercept)) {
     94         x1 = std::min<float>(x1, minXIntercept);
     95         x2 = std::max<float>(x2, maxXIntercept);
     96     }
     97 
     98     if (marginBounds.xInterceptsAtY(y2, minXIntercept, maxXIntercept)) {
     99         x1 = std::min<float>(x1, minXIntercept);
    100         x2 = std::max<float>(x2, maxXIntercept);
    101     }
    102 
    103     ASSERT(x2 >= x1);
    104     result.append(LineSegment(x1, x2));
    105 }
    106 
    107 void BoxShape::getIncludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList& result) const
    108 {
    109     const FloatRoundedRect& paddingBounds = shapePaddingBounds();
    110     if (paddingBounds.isEmpty())
    111         return;
    112 
    113     const FloatRect& rect = paddingBounds.rect();
    114     if (logicalTop < rect.y() || logicalTop + logicalHeight > rect.maxY())
    115         return;
    116 
    117     // FIXME: this method is only a stub, https://bugs.webkit.org/show_bug.cgi?id=124605.
    118 
    119     result.append(LineSegment(rect.x(), rect.maxX()));
    120 }
    121 
    122 bool BoxShape::firstIncludedIntervalLogicalTop(LayoutUnit minLogicalIntervalTop, const LayoutSize&, LayoutUnit& result) const
    123 {
    124     // FIXME: this method is only a stub, https://bugs.webkit.org/show_bug.cgi?id=124606.
    125 
    126     result = minLogicalIntervalTop;
    127     return true;
    128 }
    129 
    130 } // namespace WebCore
    131