Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / shapes / ShapeInfo.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 ShapeInfo_h
31 #define ShapeInfo_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/LayoutUnit.h"
37 #include "platform/geometry/FloatRect.h"
38 #include "wtf/OwnPtr.h"
39 #include "wtf/Vector.h"
40
41 namespace WebCore {
42
43 template<class KeyType, class InfoType>
44 class MappedInfo {
45 public:
46     static InfoType& ensureInfo(const KeyType& key)
47     {
48         InfoMap& infoMap = MappedInfo<KeyType, InfoType>::infoMap();
49         if (InfoType* info = infoMap.get(&key))
50             return *info;
51         typename InfoMap::AddResult result = infoMap.add(&key, InfoType::createInfo(key));
52         return *result.storedValue->value;
53     }
54     static void removeInfo(const KeyType& key) { infoMap().remove(&key); }
55     static InfoType* info(const KeyType& key) { return infoMap().get(&key); }
56 private:
57     typedef HashMap<const KeyType*, OwnPtr<InfoType> > InfoMap;
58     static InfoMap& infoMap()
59     {
60         DEFINE_STATIC_LOCAL(InfoMap, staticInfoMap, ());
61         return staticInfoMap;
62     }
63 };
64
65 template<class RenderType>
66 class ShapeInfo {
67     WTF_MAKE_FAST_ALLOCATED;
68 public:
69     virtual ~ShapeInfo() { }
70
71     void setReferenceBoxLogicalSize(LayoutSize);
72
73     SegmentList computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) const;
74
75     LayoutUnit shapeLogicalTop() const { return computedShapeLogicalBoundingBox().y() + logicalTopOffset(); }
76     LayoutUnit shapeLogicalBottom() const { return computedShapeLogicalBoundingBox().maxY() + logicalTopOffset(); }
77     LayoutUnit shapeLogicalLeft() const { return computedShapeLogicalBoundingBox().x() + logicalLeftOffset(); }
78     LayoutUnit shapeLogicalRight() const { return computedShapeLogicalBoundingBox().maxX() + logicalLeftOffset(); }
79     LayoutUnit shapeLogicalWidth() const { return computedShapeLogicalBoundingBox().width(); }
80     LayoutUnit shapeLogicalHeight() const { return computedShapeLogicalBoundingBox().height(); }
81
82     LayoutUnit logicalLineTop() const { return m_referenceBoxLineTop + logicalTopOffset(); }
83     LayoutUnit logicalLineBottom() const { return m_referenceBoxLineTop + m_lineHeight + logicalTopOffset(); }
84
85     LayoutUnit shapeContainingBlockHeight() const { return (m_renderer.style()->boxSizing() == CONTENT_BOX) ? (m_referenceBoxLogicalSize.height() + m_renderer.borderAndPaddingLogicalHeight()) : m_referenceBoxLogicalSize.height(); }
86
87     virtual bool lineOverlapsShapeBounds() const = 0;
88
89     void markShapeAsDirty() { m_shape.clear(); }
90     bool isShapeDirty() { return !m_shape.get(); }
91     const RenderType& owner() const { return m_renderer; }
92     LayoutSize shapeSize() const { return m_referenceBoxLogicalSize; }
93
94 protected:
95     ShapeInfo(const RenderType& renderer): m_renderer(renderer) { }
96
97     const Shape& computedShape() const;
98
99     virtual LayoutBox referenceBox() const = 0;
100     virtual LayoutRect computedShapeLogicalBoundingBox() const = 0;
101     virtual ShapeValue* shapeValue() const = 0;
102     virtual void getIntervals(LayoutUnit, LayoutUnit, SegmentList&) const = 0;
103
104     virtual const RenderStyle* styleForWritingMode() const = 0;
105
106     LayoutUnit logicalTopOffset() const;
107     LayoutUnit logicalLeftOffset() const;
108
109     LayoutUnit m_referenceBoxLineTop;
110     LayoutUnit m_lineHeight;
111
112     const RenderType& m_renderer;
113
114 private:
115     mutable OwnPtr<Shape> m_shape;
116     LayoutSize m_referenceBoxLogicalSize;
117 };
118
119 bool checkShapeImageOrigin(Document&, ImageResource&);
120
121 }
122 #endif