2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
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.
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
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"
43 template<class KeyType, class InfoType>
46 static InfoType& ensureInfo(const KeyType& key)
48 InfoMap& infoMap = MappedInfo<KeyType, InfoType>::infoMap();
49 if (InfoType* info = infoMap.get(&key))
51 typename InfoMap::AddResult result = infoMap.add(&key, InfoType::createInfo(key));
52 return *result.storedValue->value;
54 static void removeInfo(const KeyType& key) { infoMap().remove(&key); }
55 static InfoType* info(const KeyType& key) { return infoMap().get(&key); }
57 typedef HashMap<const KeyType*, OwnPtr<InfoType> > InfoMap;
58 static InfoMap& infoMap()
60 DEFINE_STATIC_LOCAL(InfoMap, staticInfoMap, ());
65 template<class RenderType>
67 WTF_MAKE_FAST_ALLOCATED;
69 virtual ~ShapeInfo() { }
71 void setReferenceBoxLogicalSize(LayoutSize);
73 SegmentList computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) const;
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(); }
82 LayoutUnit logicalLineTop() const { return m_referenceBoxLineTop + logicalTopOffset(); }
83 LayoutUnit logicalLineBottom() const { return m_referenceBoxLineTop + m_lineHeight + logicalTopOffset(); }
85 LayoutUnit shapeContainingBlockHeight() const { return (m_renderer.style()->boxSizing() == CONTENT_BOX) ? (m_referenceBoxLogicalSize.height() + m_renderer.borderAndPaddingLogicalHeight()) : m_referenceBoxLogicalSize.height(); }
87 virtual bool lineOverlapsShapeBounds() const = 0;
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; }
95 ShapeInfo(const RenderType& renderer): m_renderer(renderer) { }
97 const Shape& computedShape() const;
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;
104 virtual const RenderStyle* styleForWritingMode() const = 0;
106 LayoutUnit logicalTopOffset() const;
107 LayoutUnit logicalLeftOffset() const;
109 LayoutUnit m_referenceBoxLineTop;
110 LayoutUnit m_lineHeight;
112 const RenderType& m_renderer;
115 mutable OwnPtr<Shape> m_shape;
116 LayoutSize m_referenceBoxLogicalSize;
119 bool checkShapeImageOrigin(Document&, ImageResource&);