Home | History | Annotate | Download | only in shapes
      1 /*
      2  * Copyright (C) 2012 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 HOLDER "AS IS" AND ANY
     17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
     20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     25  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
     26  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 #ifndef ShapeInsideInfo_h
     31 #define ShapeInsideInfo_h
     32 
     33 #include "core/rendering/shapes/ShapeInfo.h"
     34 #include "wtf/PassOwnPtr.h"
     35 #include "wtf/Vector.h"
     36 
     37 namespace WebCore {
     38 
     39 class InlineIterator;
     40 class RenderBlock;
     41 class RenderObject;
     42 
     43 struct LineSegmentIterator {
     44     RenderObject* root;
     45     RenderObject* object;
     46     unsigned offset;
     47     LineSegmentIterator(RenderObject* root, RenderObject* object, unsigned offset)
     48         : root(root)
     49         , object(object)
     50         , offset(offset)
     51     {
     52     }
     53 };
     54 
     55 struct LineSegmentRange {
     56     LineSegmentIterator start;
     57     LineSegmentIterator end;
     58     LineSegmentRange(const InlineIterator& start, const InlineIterator& end);
     59 };
     60 
     61 typedef Vector<LineSegmentRange> SegmentRangeList;
     62 
     63 class ShapeInsideInfo : public ShapeInfo<RenderBlock, &RenderStyle::resolvedShapeInside, &Shape::getIncludedIntervals> {
     64 public:
     65     static PassOwnPtr<ShapeInsideInfo> createInfo(const RenderBlock* renderer) { return adoptPtr(new ShapeInsideInfo(renderer)); }
     66 
     67     static bool isEnabledFor(const RenderBlock* renderer);
     68 
     69     virtual bool computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) OVERRIDE
     70     {
     71         m_segmentRanges.clear();
     72         return ShapeInfo<RenderBlock, &RenderStyle::resolvedShapeInside, &Shape::getIncludedIntervals>::computeSegmentsForLine(lineTop, lineHeight);
     73     }
     74 
     75     bool hasSegments() const
     76     {
     77         return lineOverlapsShapeBounds() && m_segments.size();
     78     }
     79     const SegmentList& segments() const
     80     {
     81         ASSERT(hasSegments());
     82         return m_segments;
     83     }
     84     SegmentRangeList& segmentRanges() { return m_segmentRanges; }
     85     const SegmentRangeList& segmentRanges() const { return m_segmentRanges; }
     86     const LineSegment* currentSegment() const
     87     {
     88         if (!hasSegments())
     89             return 0;
     90         ASSERT(m_segmentRanges.size() < m_segments.size());
     91         return &m_segments[m_segmentRanges.size()];
     92     }
     93     bool adjustLogicalLineTop(float minSegmentWidth);
     94 
     95     void setNeedsLayout(bool value) { m_needsLayout = value; }
     96     bool needsLayout() { return m_needsLayout; }
     97 
     98 protected:
     99     virtual LayoutRect computedShapeLogicalBoundingBox() const OVERRIDE { return computedShape()->shapePaddingLogicalBoundingBox(); }
    100 
    101 private:
    102     ShapeInsideInfo(const RenderBlock* renderer)
    103     : ShapeInfo<RenderBlock, &RenderStyle::resolvedShapeInside, &Shape::getIncludedIntervals> (renderer)
    104     , m_needsLayout(false)
    105     { }
    106 
    107     SegmentRangeList m_segmentRanges;
    108     bool m_needsLayout;
    109 };
    110 
    111 }
    112 #endif
    113