• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
LineSegmentIteratorLineSegmentIterator47     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 FINAL : public ShapeInfo<RenderBlock> {
64 public:
createInfo(const RenderBlock * renderer)65     static PassOwnPtr<ShapeInsideInfo> createInfo(const RenderBlock* renderer) { return adoptPtr(new ShapeInsideInfo(renderer)); }
66 
67     static bool isEnabledFor(const RenderBlock* renderer);
68 
69     bool updateSegmentsForLine(LayoutSize lineOffset, LayoutUnit lineHeight);
70     bool updateSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight);
71 
hasSegments()72     bool hasSegments() const
73     {
74         return lineOverlapsShapeBounds() && m_segments.size();
75     }
segments()76     const SegmentList& segments() const
77     {
78         ASSERT(hasSegments());
79         return m_segments;
80     }
segmentRanges()81     SegmentRangeList& segmentRanges() { return m_segmentRanges; }
segmentRanges()82     const SegmentRangeList& segmentRanges() const { return m_segmentRanges; }
currentSegment()83     const LineSegment* currentSegment() const
84     {
85         if (!hasSegments())
86             return 0;
87         ASSERT(m_segmentRanges.size() < m_segments.size());
88         return &m_segments[m_segmentRanges.size()];
89     }
clearSegments()90     void clearSegments() { m_segments.clear(); }
91     bool adjustLogicalLineTop(float minSegmentWidth);
92     LayoutUnit computeFirstFitPositionForFloat(const LayoutSize) const;
93 
setNeedsLayout(bool value)94     void setNeedsLayout(bool value) { m_needsLayout = value; }
needsLayout()95     bool needsLayout() { return m_needsLayout; }
96 
lineOverlapsShapeBounds()97     virtual bool lineOverlapsShapeBounds() const OVERRIDE
98     {
99         return computedShape()->lineOverlapsShapePaddingBounds(m_shapeLineTop, m_lineHeight);
100     }
101 
102 protected:
computedShapeLogicalBoundingBox()103     virtual LayoutRect computedShapeLogicalBoundingBox() const OVERRIDE { return computedShape()->shapePaddingLogicalBoundingBox(); }
104     virtual ShapeValue* shapeValue() const OVERRIDE;
getIntervals(LayoutUnit lineTop,LayoutUnit lineHeight,SegmentList & segments)105     virtual void getIntervals(LayoutUnit lineTop, LayoutUnit lineHeight, SegmentList& segments) const OVERRIDE
106     {
107         return computedShape()->getIncludedIntervals(lineTop, lineHeight, segments);
108     }
109 
110 private:
ShapeInsideInfo(const RenderBlock * renderer)111     ShapeInsideInfo(const RenderBlock* renderer)
112     : ShapeInfo<RenderBlock> (renderer)
113     , m_needsLayout(false)
114     { }
115 
116     SegmentRangeList m_segmentRanges;
117     bool m_needsLayout;
118     SegmentList m_segments;
119 };
120 
121 }
122 #endif
123