| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
| 9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
| 10 * disclaimer. | 10 * disclaimer. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "platform/LayoutUnit.h" | 36 #include "platform/LayoutUnit.h" |
| 37 #include "platform/geometry/FloatRect.h" | 37 #include "platform/geometry/FloatRect.h" |
| 38 #include "wtf/OwnPtr.h" | 38 #include "wtf/OwnPtr.h" |
| 39 #include "wtf/Vector.h" | 39 #include "wtf/Vector.h" |
| 40 | 40 |
| 41 namespace WebCore { | 41 namespace WebCore { |
| 42 | 42 |
| 43 template<class KeyType, class InfoType> | 43 template<class KeyType, class InfoType> |
| 44 class MappedInfo { | 44 class MappedInfo { |
| 45 public: | 45 public: |
| 46 static InfoType* ensureInfo(const KeyType* key) | 46 static InfoType& ensureInfo(const KeyType& key) |
| 47 { | 47 { |
| 48 InfoMap& infoMap = MappedInfo<KeyType, InfoType>::infoMap(); | 48 InfoMap& infoMap = MappedInfo<KeyType, InfoType>::infoMap(); |
| 49 if (InfoType* info = infoMap.get(key)) | 49 if (InfoType* info = infoMap.get(&key)) |
| 50 return info; | 50 return *info; |
| 51 typename InfoMap::AddResult result = infoMap.add(key, InfoType::createIn
fo(key)); | 51 typename InfoMap::AddResult result = infoMap.add(&key, InfoType::createI
nfo(key)); |
| 52 return result.storedValue->value.get(); | 52 return *result.storedValue->value; |
| 53 } | 53 } |
| 54 static void removeInfo(const KeyType* key) { infoMap().remove(key); } | 54 static void removeInfo(const KeyType& key) { infoMap().remove(&key); } |
| 55 static InfoType* info(const KeyType* key) { return infoMap().get(key); } | 55 static InfoType* info(const KeyType& key) { return infoMap().get(&key); } |
| 56 private: | 56 private: |
| 57 typedef HashMap<const KeyType*, OwnPtr<InfoType> > InfoMap; | 57 typedef HashMap<const KeyType*, OwnPtr<InfoType> > InfoMap; |
| 58 static InfoMap& infoMap() | 58 static InfoMap& infoMap() |
| 59 { | 59 { |
| 60 DEFINE_STATIC_LOCAL(InfoMap, staticInfoMap, ()); | 60 DEFINE_STATIC_LOCAL(InfoMap, staticInfoMap, ()); |
| 61 return staticInfoMap; | 61 return staticInfoMap; |
| 62 } | 62 } |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 template<class RenderType> | 65 template<class RenderType> |
| 66 class ShapeInfo { | 66 class ShapeInfo { |
| 67 WTF_MAKE_FAST_ALLOCATED; | 67 WTF_MAKE_FAST_ALLOCATED; |
| 68 public: | 68 public: |
| 69 virtual ~ShapeInfo() { } | 69 virtual ~ShapeInfo() { } |
| 70 | 70 |
| 71 void setReferenceBoxLogicalSize(LayoutSize newReferenceBoxLogicalSize) | 71 void setReferenceBoxLogicalSize(LayoutSize newReferenceBoxLogicalSize) |
| 72 { | 72 { |
| 73 switch (referenceBox()) { | 73 switch (referenceBox()) { |
| 74 case MarginBox: | 74 case MarginBox: |
| 75 newReferenceBoxLogicalSize.expand(m_renderer->marginLogicalWidth(),
m_renderer->marginLogicalHeight()); | 75 newReferenceBoxLogicalSize.expand(m_renderer.marginLogicalWidth(), m
_renderer.marginLogicalHeight()); |
| 76 break; | 76 break; |
| 77 case BorderBox: | 77 case BorderBox: |
| 78 break; | 78 break; |
| 79 case PaddingBox: | 79 case PaddingBox: |
| 80 newReferenceBoxLogicalSize.shrink(m_renderer->borderLogicalWidth(),
m_renderer->borderLogicalHeight()); | 80 newReferenceBoxLogicalSize.shrink(m_renderer.borderLogicalWidth(), m
_renderer.borderLogicalHeight()); |
| 81 break; | 81 break; |
| 82 case ContentBox: | 82 case ContentBox: |
| 83 newReferenceBoxLogicalSize.shrink(m_renderer->borderAndPaddingLogica
lWidth(), m_renderer->borderAndPaddingLogicalHeight()); | 83 newReferenceBoxLogicalSize.shrink(m_renderer.borderAndPaddingLogical
Width(), m_renderer.borderAndPaddingLogicalHeight()); |
| 84 break; | 84 break; |
| 85 case BoxMissing: | 85 case BoxMissing: |
| 86 // A non-missing box value must be supplied. | 86 // A non-missing box value must be supplied. |
| 87 ASSERT_NOT_REACHED(); | 87 ASSERT_NOT_REACHED(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 if (m_referenceBoxLogicalSize == newReferenceBoxLogicalSize) | 90 if (m_referenceBoxLogicalSize == newReferenceBoxLogicalSize) |
| 91 return; | 91 return; |
| 92 markShapeAsDirty(); | 92 markShapeAsDirty(); |
| 93 m_referenceBoxLogicalSize = newReferenceBoxLogicalSize; | 93 m_referenceBoxLogicalSize = newReferenceBoxLogicalSize; |
| 94 } | 94 } |
| 95 | 95 |
| 96 SegmentList computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight
) const; | 96 SegmentList computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight
) const; |
| 97 | 97 |
| 98 LayoutUnit shapeLogicalTop() const { return computedShapeLogicalBoundingBox(
).y() + logicalTopOffset(); } | 98 LayoutUnit shapeLogicalTop() const { return computedShapeLogicalBoundingBox(
).y() + logicalTopOffset(); } |
| 99 LayoutUnit shapeLogicalBottom() const { return computedShapeLogicalBoundingB
ox().maxY() + logicalTopOffset(); } | 99 LayoutUnit shapeLogicalBottom() const { return computedShapeLogicalBoundingB
ox().maxY() + logicalTopOffset(); } |
| 100 LayoutUnit shapeLogicalLeft() const { return computedShapeLogicalBoundingBox
().x() + logicalLeftOffset(); } | 100 LayoutUnit shapeLogicalLeft() const { return computedShapeLogicalBoundingBox
().x() + logicalLeftOffset(); } |
| 101 LayoutUnit shapeLogicalRight() const { return computedShapeLogicalBoundingBo
x().maxX() + logicalLeftOffset(); } | 101 LayoutUnit shapeLogicalRight() const { return computedShapeLogicalBoundingBo
x().maxX() + logicalLeftOffset(); } |
| 102 LayoutUnit shapeLogicalWidth() const { return computedShapeLogicalBoundingBo
x().width(); } | 102 LayoutUnit shapeLogicalWidth() const { return computedShapeLogicalBoundingBo
x().width(); } |
| 103 LayoutUnit shapeLogicalHeight() const { return computedShapeLogicalBoundingB
ox().height(); } | 103 LayoutUnit shapeLogicalHeight() const { return computedShapeLogicalBoundingB
ox().height(); } |
| 104 | 104 |
| 105 LayoutUnit logicalLineTop() const { return m_referenceBoxLineTop + logicalTo
pOffset(); } | 105 LayoutUnit logicalLineTop() const { return m_referenceBoxLineTop + logicalTo
pOffset(); } |
| 106 LayoutUnit logicalLineBottom() const { return m_referenceBoxLineTop + m_line
Height + logicalTopOffset(); } | 106 LayoutUnit logicalLineBottom() const { return m_referenceBoxLineTop + m_line
Height + logicalTopOffset(); } |
| 107 | 107 |
| 108 LayoutUnit shapeContainingBlockHeight() const { return (m_renderer->style()-
>boxSizing() == CONTENT_BOX) ? (m_referenceBoxLogicalSize.height() + m_renderer-
>borderAndPaddingLogicalHeight()) : m_referenceBoxLogicalSize.height(); } | 108 LayoutUnit shapeContainingBlockHeight() const { return (m_renderer.style()->
boxSizing() == CONTENT_BOX) ? (m_referenceBoxLogicalSize.height() + m_renderer.b
orderAndPaddingLogicalHeight()) : m_referenceBoxLogicalSize.height(); } |
| 109 | 109 |
| 110 virtual bool lineOverlapsShapeBounds() const = 0; | 110 virtual bool lineOverlapsShapeBounds() const = 0; |
| 111 | 111 |
| 112 void markShapeAsDirty() { m_shape.clear(); } | 112 void markShapeAsDirty() { m_shape.clear(); } |
| 113 bool isShapeDirty() { return !m_shape.get(); } | 113 bool isShapeDirty() { return !m_shape.get(); } |
| 114 const RenderType* owner() const { return m_renderer; } | 114 const RenderType& owner() const { return m_renderer; } |
| 115 LayoutSize shapeSize() const { return m_referenceBoxLogicalSize; } | 115 LayoutSize shapeSize() const { return m_referenceBoxLogicalSize; } |
| 116 | 116 |
| 117 protected: | 117 protected: |
| 118 ShapeInfo(const RenderType* renderer): m_renderer(renderer) { } | 118 ShapeInfo(const RenderType& renderer): m_renderer(renderer) { } |
| 119 | 119 |
| 120 const Shape* computedShape() const; | 120 const Shape& computedShape() const; |
| 121 | 121 |
| 122 virtual LayoutBox referenceBox() const = 0; | 122 virtual LayoutBox referenceBox() const = 0; |
| 123 virtual LayoutRect computedShapeLogicalBoundingBox() const = 0; | 123 virtual LayoutRect computedShapeLogicalBoundingBox() const = 0; |
| 124 virtual ShapeValue* shapeValue() const = 0; | 124 virtual ShapeValue* shapeValue() const = 0; |
| 125 virtual void getIntervals(LayoutUnit, LayoutUnit, SegmentList&) const = 0; | 125 virtual void getIntervals(LayoutUnit, LayoutUnit, SegmentList&) const = 0; |
| 126 | 126 |
| 127 LayoutUnit logicalTopOffset() const | 127 LayoutUnit logicalTopOffset() const |
| 128 { | 128 { |
| 129 switch (referenceBox()) { | 129 switch (referenceBox()) { |
| 130 case MarginBox: | 130 case MarginBox: |
| 131 return -m_renderer->marginBefore(); | 131 return -m_renderer.marginBefore(); |
| 132 case BorderBox: | 132 case BorderBox: |
| 133 return LayoutUnit(); | 133 return LayoutUnit(); |
| 134 case PaddingBox: | 134 case PaddingBox: |
| 135 return m_renderer->borderBefore(); | 135 return m_renderer.borderBefore(); |
| 136 case ContentBox: | 136 case ContentBox: |
| 137 return m_renderer->borderAndPaddingBefore(); | 137 return m_renderer.borderAndPaddingBefore(); |
| 138 case BoxMissing: | 138 case BoxMissing: |
| 139 // A non-missing box value must be supplied. | 139 // A non-missing box value must be supplied. |
| 140 ASSERT_NOT_REACHED(); | 140 ASSERT_NOT_REACHED(); |
| 141 } | 141 } |
| 142 return LayoutUnit(); | 142 return LayoutUnit(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 LayoutUnit logicalLeftOffset() const | 145 LayoutUnit logicalLeftOffset() const |
| 146 { | 146 { |
| 147 switch (referenceBox()) { | 147 switch (referenceBox()) { |
| 148 case MarginBox: | 148 case MarginBox: |
| 149 return -m_renderer->marginStart(); | 149 return -m_renderer.marginStart(); |
| 150 case BorderBox: | 150 case BorderBox: |
| 151 return LayoutUnit(); | 151 return LayoutUnit(); |
| 152 case PaddingBox: | 152 case PaddingBox: |
| 153 return m_renderer->borderStart(); | 153 return m_renderer.borderStart(); |
| 154 case ContentBox: | 154 case ContentBox: |
| 155 return m_renderer->borderAndPaddingStart(); | 155 return m_renderer.borderAndPaddingStart(); |
| 156 case BoxMissing: | 156 case BoxMissing: |
| 157 // A non-missing box value must be supplied. | 157 // A non-missing box value must be supplied. |
| 158 ASSERT_NOT_REACHED(); | 158 ASSERT_NOT_REACHED(); |
| 159 } | 159 } |
| 160 return LayoutUnit(); | 160 return LayoutUnit(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 LayoutUnit m_referenceBoxLineTop; | 163 LayoutUnit m_referenceBoxLineTop; |
| 164 LayoutUnit m_lineHeight; | 164 LayoutUnit m_lineHeight; |
| 165 | 165 |
| 166 const RenderType* m_renderer; | 166 const RenderType& m_renderer; |
| 167 | 167 |
| 168 private: | 168 private: |
| 169 mutable OwnPtr<Shape> m_shape; | 169 mutable OwnPtr<Shape> m_shape; |
| 170 LayoutSize m_referenceBoxLogicalSize; | 170 LayoutSize m_referenceBoxLogicalSize; |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 bool checkShapeImageOrigin(Document&, ImageResource&); | 173 bool checkShapeImageOrigin(Document&, ImageResource&); |
| 174 | 174 |
| 175 } | 175 } |
| 176 #endif | 176 #endif |
| OLD | NEW |