| 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 setShapeSize(LayoutUnit logicalWidth, LayoutUnit logicalHeight) | 71 void setShapeSize(LayoutUnit logicalWidth, LayoutUnit logicalHeight) |
| 72 { | 72 { |
| 73 switch (resolvedLayoutBox()) { | 73 switch (resolvedLayoutBox()) { |
| 74 case MarginBox: | 74 case MarginBox: |
| 75 logicalHeight += m_renderer->marginLogicalHeight(); | 75 logicalHeight += m_renderer.marginLogicalHeight(); |
| 76 logicalWidth += m_renderer->marginLogicalWidth(); | 76 logicalWidth += m_renderer.marginLogicalWidth(); |
| 77 break; | 77 break; |
| 78 case BorderBox: | 78 case BorderBox: |
| 79 break; | 79 break; |
| 80 case PaddingBox: | 80 case PaddingBox: |
| 81 logicalHeight -= m_renderer->borderLogicalHeight(); | 81 logicalHeight -= m_renderer.borderLogicalHeight(); |
| 82 logicalWidth -= m_renderer->borderLogicalWidth(); | 82 logicalWidth -= m_renderer.borderLogicalWidth(); |
| 83 break; | 83 break; |
| 84 case ContentBox: | 84 case ContentBox: |
| 85 logicalHeight -= m_renderer->borderAndPaddingLogicalHeight(); | 85 logicalHeight -= m_renderer.borderAndPaddingLogicalHeight(); |
| 86 logicalWidth -= m_renderer->borderAndPaddingLogicalWidth(); | 86 logicalWidth -= m_renderer.borderAndPaddingLogicalWidth(); |
| 87 break; | 87 break; |
| 88 case BoxMissing: | 88 case BoxMissing: |
| 89 // A non-missing box value must be supplied. | 89 // A non-missing box value must be supplied. |
| 90 ASSERT_NOT_REACHED(); | 90 ASSERT_NOT_REACHED(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 LayoutSize newLogicalSize(logicalWidth, logicalHeight); | 93 LayoutSize newLogicalSize(logicalWidth, logicalHeight); |
| 94 if (m_shapeLogicalSize == newLogicalSize) | 94 if (m_shapeLogicalSize == newLogicalSize) |
| 95 return; | 95 return; |
| 96 dirtyShapeSize(); | 96 dirtyShapeSize(); |
| 97 m_shapeLogicalSize = newLogicalSize; | 97 m_shapeLogicalSize = newLogicalSize; |
| 98 } | 98 } |
| 99 | 99 |
| 100 SegmentList computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight
) const; | 100 SegmentList computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight
) const; |
| 101 | 101 |
| 102 LayoutUnit shapeLogicalTop() const { return computedShapeLogicalBoundingBox(
).y() + logicalTopOffset(); } | 102 LayoutUnit shapeLogicalTop() const { return computedShapeLogicalBoundingBox(
).y() + logicalTopOffset(); } |
| 103 LayoutUnit shapeLogicalBottom() const { return computedShapeLogicalBoundingB
ox().maxY() + logicalTopOffset(); } | 103 LayoutUnit shapeLogicalBottom() const { return computedShapeLogicalBoundingB
ox().maxY() + logicalTopOffset(); } |
| 104 LayoutUnit shapeLogicalLeft() const { return computedShapeLogicalBoundingBox
().x() + logicalLeftOffset(); } | 104 LayoutUnit shapeLogicalLeft() const { return computedShapeLogicalBoundingBox
().x() + logicalLeftOffset(); } |
| 105 LayoutUnit shapeLogicalRight() const { return computedShapeLogicalBoundingBo
x().maxX() + logicalLeftOffset(); } | 105 LayoutUnit shapeLogicalRight() const { return computedShapeLogicalBoundingBo
x().maxX() + logicalLeftOffset(); } |
| 106 LayoutUnit shapeLogicalWidth() const { return computedShapeLogicalBoundingBo
x().width(); } | 106 LayoutUnit shapeLogicalWidth() const { return computedShapeLogicalBoundingBo
x().width(); } |
| 107 LayoutUnit shapeLogicalHeight() const { return computedShapeLogicalBoundingB
ox().height(); } | 107 LayoutUnit shapeLogicalHeight() const { return computedShapeLogicalBoundingB
ox().height(); } |
| 108 | 108 |
| 109 LayoutUnit logicalLineTop() const { return m_shapeLineTop + logicalTopOffset
(); } | 109 LayoutUnit logicalLineTop() const { return m_shapeLineTop + logicalTopOffset
(); } |
| 110 LayoutUnit logicalLineBottom() const { return m_shapeLineTop + m_lineHeight
+ logicalTopOffset(); } | 110 LayoutUnit logicalLineBottom() const { return m_shapeLineTop + m_lineHeight
+ logicalTopOffset(); } |
| 111 | 111 |
| 112 LayoutUnit shapeContainingBlockHeight() const { return (m_renderer->style()-
>boxSizing() == CONTENT_BOX) ? (m_shapeLogicalSize.height() + m_renderer->border
AndPaddingLogicalHeight()) : m_shapeLogicalSize.height(); } | 112 LayoutUnit shapeContainingBlockHeight() const { return (m_renderer.style()->
boxSizing() == CONTENT_BOX) ? (m_shapeLogicalSize.height() + m_renderer.borderAn
dPaddingLogicalHeight()) : m_shapeLogicalSize.height(); } |
| 113 | 113 |
| 114 virtual bool lineOverlapsShapeBounds() const = 0; | 114 virtual bool lineOverlapsShapeBounds() const = 0; |
| 115 | 115 |
| 116 void dirtyShapeSize() { m_shape.clear(); } | 116 void dirtyShapeSize() { m_shape.clear(); } |
| 117 bool shapeSizeDirty() { return !m_shape.get(); } | 117 bool shapeSizeDirty() { return !m_shape.get(); } |
| 118 const RenderType* owner() const { return m_renderer; } | 118 const RenderType& owner() const { return m_renderer; } |
| 119 LayoutSize shapeSize() const { return m_shapeLogicalSize; } | 119 LayoutSize shapeSize() const { return m_shapeLogicalSize; } |
| 120 | 120 |
| 121 protected: | 121 protected: |
| 122 ShapeInfo(const RenderType* renderer): m_renderer(renderer) { } | 122 ShapeInfo(const RenderType& renderer): m_renderer(renderer) { } |
| 123 | 123 |
| 124 const Shape* computedShape() const; | 124 const Shape& computedShape() const; |
| 125 | 125 |
| 126 virtual LayoutBox resolvedLayoutBox() const = 0; | 126 virtual LayoutBox resolvedLayoutBox() const = 0; |
| 127 virtual LayoutRect computedShapeLogicalBoundingBox() const = 0; | 127 virtual LayoutRect computedShapeLogicalBoundingBox() const = 0; |
| 128 virtual ShapeValue* shapeValue() const = 0; | 128 virtual ShapeValue* shapeValue() const = 0; |
| 129 virtual void getIntervals(LayoutUnit, LayoutUnit, SegmentList&) const = 0; | 129 virtual void getIntervals(LayoutUnit, LayoutUnit, SegmentList&) const = 0; |
| 130 | 130 |
| 131 LayoutUnit logicalTopOffset() const | 131 LayoutUnit logicalTopOffset() const |
| 132 { | 132 { |
| 133 switch (resolvedLayoutBox()) { | 133 switch (resolvedLayoutBox()) { |
| 134 case MarginBox: | 134 case MarginBox: |
| 135 return -m_renderer->marginBefore(); | 135 return -m_renderer.marginBefore(); |
| 136 case BorderBox: | 136 case BorderBox: |
| 137 return LayoutUnit(); | 137 return LayoutUnit(); |
| 138 case PaddingBox: | 138 case PaddingBox: |
| 139 return m_renderer->borderBefore(); | 139 return m_renderer.borderBefore(); |
| 140 case ContentBox: | 140 case ContentBox: |
| 141 return m_renderer->borderAndPaddingBefore(); | 141 return m_renderer.borderAndPaddingBefore(); |
| 142 case BoxMissing: | 142 case BoxMissing: |
| 143 // A non-missing box value must be supplied. | 143 // A non-missing box value must be supplied. |
| 144 ASSERT_NOT_REACHED(); | 144 ASSERT_NOT_REACHED(); |
| 145 } | 145 } |
| 146 return LayoutUnit(); | 146 return LayoutUnit(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 LayoutUnit logicalLeftOffset() const | 149 LayoutUnit logicalLeftOffset() const |
| 150 { | 150 { |
| 151 switch (resolvedLayoutBox()) { | 151 switch (resolvedLayoutBox()) { |
| 152 case MarginBox: | 152 case MarginBox: |
| 153 return -m_renderer->marginStart(); | 153 return -m_renderer.marginStart(); |
| 154 case BorderBox: | 154 case BorderBox: |
| 155 return LayoutUnit(); | 155 return LayoutUnit(); |
| 156 case PaddingBox: | 156 case PaddingBox: |
| 157 return m_renderer->borderStart(); | 157 return m_renderer.borderStart(); |
| 158 case ContentBox: | 158 case ContentBox: |
| 159 return m_renderer->borderAndPaddingStart(); | 159 return m_renderer.borderAndPaddingStart(); |
| 160 case BoxMissing: | 160 case BoxMissing: |
| 161 // A non-missing box value must be supplied. | 161 // A non-missing box value must be supplied. |
| 162 ASSERT_NOT_REACHED(); | 162 ASSERT_NOT_REACHED(); |
| 163 } | 163 } |
| 164 return LayoutUnit(); | 164 return LayoutUnit(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 LayoutUnit m_shapeLineTop; | 167 LayoutUnit m_shapeLineTop; |
| 168 LayoutUnit m_lineHeight; | 168 LayoutUnit m_lineHeight; |
| 169 | 169 |
| 170 const RenderType* m_renderer; | 170 const RenderType& m_renderer; |
| 171 | 171 |
| 172 private: | 172 private: |
| 173 mutable OwnPtr<Shape> m_shape; | 173 mutable OwnPtr<Shape> m_shape; |
| 174 LayoutSize m_shapeLogicalSize; | 174 LayoutSize m_shapeLogicalSize; |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 bool checkShapeImageOrigin(Document&, ImageResource&); | 177 bool checkShapeImageOrigin(Document&, ImageResource&); |
| 178 | 178 |
| 179 } | 179 } |
| 180 #endif | 180 #endif |
| OLD | NEW |