Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / shapes / ShapeOutsideInfo.h
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 ShapeOutsideInfo_h
31 #define ShapeOutsideInfo_h
32
33 #include "core/rendering/shapes/Shape.h"
34 #include "core/rendering/style/RenderStyle.h"
35 #include "core/rendering/style/ShapeValue.h"
36 #include "platform/geometry/FloatRect.h"
37 #include "platform/geometry/LayoutSize.h"
38 #include "wtf/OwnPtr.h"
39 #include "wtf/Vector.h"
40
41 namespace WebCore {
42
43 class RenderBlockFlow;
44 class RenderBox;
45 class FloatingObject;
46
47 class ShapeOutsideInfo FINAL {
48     WTF_MAKE_FAST_ALLOCATED;
49 public:
50     void setReferenceBoxLogicalSize(LayoutSize);
51
52     SegmentList computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) const;
53
54     LayoutUnit shapeLogicalTop() const { return computedShape().shapeMarginLogicalBoundingBox().y() + logicalTopOffset(); }
55     LayoutUnit shapeLogicalBottom() const { return computedShape().shapeMarginLogicalBoundingBox().maxY() + logicalTopOffset(); }
56     LayoutUnit shapeLogicalLeft() const { return computedShape().shapeMarginLogicalBoundingBox().x() + logicalLeftOffset(); }
57     LayoutUnit shapeLogicalRight() const { return computedShape().shapeMarginLogicalBoundingBox().maxX() + logicalLeftOffset(); }
58     LayoutUnit shapeLogicalWidth() const { return computedShape().shapeMarginLogicalBoundingBox().width(); }
59     LayoutUnit shapeLogicalHeight() const { return computedShape().shapeMarginLogicalBoundingBox().height(); }
60
61     LayoutUnit logicalLineTop() const { return m_referenceBoxLineTop + logicalTopOffset(); }
62     LayoutUnit logicalLineBottom() const { return m_referenceBoxLineTop + m_lineHeight + logicalTopOffset(); }
63
64     LayoutUnit leftMarginBoxDelta() const { return m_leftMarginBoxDelta; }
65     LayoutUnit rightMarginBoxDelta() const { return m_rightMarginBoxDelta; }
66     bool lineOverlapsShape() const { return m_lineOverlapsShape; }
67
68     static PassOwnPtr<ShapeOutsideInfo> createInfo(const RenderBox& renderer) { return adoptPtr(new ShapeOutsideInfo(renderer)); }
69     static bool isEnabledFor(const RenderBox&);
70     void updateDeltasForContainingBlockLine(const RenderBlockFlow&, const FloatingObject&, LayoutUnit lineTop, LayoutUnit lineHeight);
71
72     bool lineOverlapsShapeBounds() const
73     {
74         return computedShape().lineOverlapsShapeMarginBounds(m_referenceBoxLineTop, m_lineHeight);
75     }
76
77     static ShapeOutsideInfo& ensureInfo(const RenderBox& key)
78     {
79         InfoMap& infoMap = ShapeOutsideInfo::infoMap();
80         if (ShapeOutsideInfo* info = infoMap.get(&key))
81             return *info;
82         InfoMap::AddResult result = infoMap.add(&key, ShapeOutsideInfo::createInfo(key));
83         return *result.storedValue->value;
84     }
85     static void removeInfo(const RenderBox& key) { infoMap().remove(&key); }
86     static ShapeOutsideInfo* info(const RenderBox& key) { return infoMap().get(&key); }
87
88     void markShapeAsDirty() { m_shape.clear(); }
89     bool isShapeDirty() { return !m_shape.get(); }
90     LayoutSize shapeSize() const { return m_referenceBoxLogicalSize; }
91
92     LayoutRect computedShapePhysicalBoundingBox() const;
93     FloatPoint shapeToRendererPoint(FloatPoint) const;
94     FloatSize shapeToRendererSize(FloatSize) const;
95     const Shape& computedShape() const;
96
97 protected:
98     ShapeOutsideInfo(const RenderBox& renderer)
99         : m_renderer(renderer)
100         , m_lineOverlapsShape(false)
101     { }
102
103 private:
104     LayoutUnit logicalTopOffset() const;
105     LayoutUnit logicalLeftOffset() const;
106
107     typedef HashMap<const RenderBox*, OwnPtr<ShapeOutsideInfo> > InfoMap;
108     static InfoMap& infoMap()
109     {
110         DEFINE_STATIC_LOCAL(InfoMap, staticInfoMap, ());
111         return staticInfoMap;
112     }
113
114     LayoutUnit m_referenceBoxLineTop;
115     LayoutUnit m_lineHeight;
116
117     const RenderBox& m_renderer;
118     mutable OwnPtr<Shape> m_shape;
119     LayoutSize m_referenceBoxLogicalSize;
120     LayoutUnit m_leftMarginBoxDelta;
121     LayoutUnit m_rightMarginBoxDelta;
122     LayoutUnit m_borderBoxLineTop;
123     bool m_lineOverlapsShape;
124 };
125
126 }
127 #endif