| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 CSSImageGeneratorValue::CSSImageGeneratorValue(ClassType classType) | 36 CSSImageGeneratorValue::CSSImageGeneratorValue(ClassType classType) |
| 37 : CSSValue(classType) | 37 : CSSValue(classType) |
| 38 { | 38 { |
| 39 } | 39 } |
| 40 | 40 |
| 41 CSSImageGeneratorValue::~CSSImageGeneratorValue() | 41 CSSImageGeneratorValue::~CSSImageGeneratorValue() |
| 42 { | 42 { |
| 43 } | 43 } |
| 44 | 44 |
| 45 void CSSImageGeneratorValue::addClient(LayoutObject* renderer, const IntSize& si
ze) | 45 void CSSImageGeneratorValue::addClient(LayoutObject* layoutObject, const IntSize
& size) |
| 46 { | 46 { |
| 47 ASSERT(renderer); | 47 ASSERT(layoutObject); |
| 48 #if !ENABLE(OILPAN) | 48 #if !ENABLE(OILPAN) |
| 49 ref(); | 49 ref(); |
| 50 #else | 50 #else |
| 51 if (m_clients.isEmpty()) { | 51 if (m_clients.isEmpty()) { |
| 52 ASSERT(!m_keepAlive); | 52 ASSERT(!m_keepAlive); |
| 53 m_keepAlive = adoptPtr(new Persistent<CSSImageGeneratorValue>(this)); | 53 m_keepAlive = adoptPtr(new Persistent<CSSImageGeneratorValue>(this)); |
| 54 } | 54 } |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 if (!size.isEmpty()) | 57 if (!size.isEmpty()) |
| 58 m_sizes.add(size); | 58 m_sizes.add(size); |
| 59 | 59 |
| 60 LayoutObjectSizeCountMap::iterator it = m_clients.find(renderer); | 60 LayoutObjectSizeCountMap::iterator it = m_clients.find(layoutObject); |
| 61 if (it == m_clients.end()) | 61 if (it == m_clients.end()) |
| 62 m_clients.add(renderer, SizeAndCount(size, 1)); | 62 m_clients.add(layoutObject, SizeAndCount(size, 1)); |
| 63 else { | 63 else { |
| 64 SizeAndCount& sizeCount = it->value; | 64 SizeAndCount& sizeCount = it->value; |
| 65 ++sizeCount.count; | 65 ++sizeCount.count; |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 void CSSImageGeneratorValue::removeClient(LayoutObject* renderer) | 69 void CSSImageGeneratorValue::removeClient(LayoutObject* layoutObject) |
| 70 { | 70 { |
| 71 ASSERT(renderer); | 71 ASSERT(layoutObject); |
| 72 LayoutObjectSizeCountMap::iterator it = m_clients.find(renderer); | 72 LayoutObjectSizeCountMap::iterator it = m_clients.find(layoutObject); |
| 73 ASSERT_WITH_SECURITY_IMPLICATION(it != m_clients.end()); | 73 ASSERT_WITH_SECURITY_IMPLICATION(it != m_clients.end()); |
| 74 | 74 |
| 75 IntSize removedImageSize; | 75 IntSize removedImageSize; |
| 76 SizeAndCount& sizeCount = it->value; | 76 SizeAndCount& sizeCount = it->value; |
| 77 IntSize size = sizeCount.size; | 77 IntSize size = sizeCount.size; |
| 78 if (!size.isEmpty()) { | 78 if (!size.isEmpty()) { |
| 79 m_sizes.remove(size); | 79 m_sizes.remove(size); |
| 80 if (!m_sizes.contains(size)) | 80 if (!m_sizes.contains(size)) |
| 81 m_images.remove(size); | 81 m_images.remove(size); |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (!--sizeCount.count) | 84 if (!--sizeCount.count) |
| 85 m_clients.remove(renderer); | 85 m_clients.remove(layoutObject); |
| 86 | 86 |
| 87 #if !ENABLE(OILPAN) | 87 #if !ENABLE(OILPAN) |
| 88 deref(); | 88 deref(); |
| 89 #else | 89 #else |
| 90 if (m_clients.isEmpty()) { | 90 if (m_clients.isEmpty()) { |
| 91 ASSERT(m_keepAlive); | 91 ASSERT(m_keepAlive); |
| 92 m_keepAlive = nullptr; | 92 m_keepAlive = nullptr; |
| 93 } | 93 } |
| 94 #endif | 94 #endif |
| 95 } | 95 } |
| 96 | 96 |
| 97 Image* CSSImageGeneratorValue::getImage(LayoutObject* renderer, const IntSize& s
ize) | 97 Image* CSSImageGeneratorValue::getImage(LayoutObject* layoutObject, const IntSiz
e& size) |
| 98 { | 98 { |
| 99 LayoutObjectSizeCountMap::iterator it = m_clients.find(renderer); | 99 LayoutObjectSizeCountMap::iterator it = m_clients.find(layoutObject); |
| 100 if (it != m_clients.end()) { | 100 if (it != m_clients.end()) { |
| 101 SizeAndCount& sizeCount = it->value; | 101 SizeAndCount& sizeCount = it->value; |
| 102 IntSize oldSize = sizeCount.size; | 102 IntSize oldSize = sizeCount.size; |
| 103 if (oldSize != size) { | 103 if (oldSize != size) { |
| 104 RefPtrWillBeRawPtr<CSSImageGeneratorValue> protect(this); | 104 RefPtrWillBeRawPtr<CSSImageGeneratorValue> protect(this); |
| 105 removeClient(renderer); | 105 removeClient(layoutObject); |
| 106 addClient(renderer, size); | 106 addClient(layoutObject, size); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Don't generate an image for empty sizes. | 110 // Don't generate an image for empty sizes. |
| 111 if (size.isEmpty()) | 111 if (size.isEmpty()) |
| 112 return 0; | 112 return 0; |
| 113 | 113 |
| 114 // Look up the image in our cache. | 114 // Look up the image in our cache. |
| 115 return m_images.get(size); | 115 return m_images.get(size); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void CSSImageGeneratorValue::putImage(const IntSize& size, PassRefPtr<Image> ima
ge) | 118 void CSSImageGeneratorValue::putImage(const IntSize& size, PassRefPtr<Image> ima
ge) |
| 119 { | 119 { |
| 120 m_images.add(size, image); | 120 m_images.add(size, image); |
| 121 } | 121 } |
| 122 | 122 |
| 123 PassRefPtr<Image> CSSImageGeneratorValue::image(LayoutObject* renderer, const In
tSize& size) | 123 PassRefPtr<Image> CSSImageGeneratorValue::image(LayoutObject* layoutObject, cons
t IntSize& size) |
| 124 { | 124 { |
| 125 switch (classType()) { | 125 switch (classType()) { |
| 126 case CanvasClass: | 126 case CanvasClass: |
| 127 return toCSSCanvasValue(this)->image(renderer, size); | 127 return toCSSCanvasValue(this)->image(layoutObject, size); |
| 128 case CrossfadeClass: | 128 case CrossfadeClass: |
| 129 return toCSSCrossfadeValue(this)->image(renderer, size); | 129 return toCSSCrossfadeValue(this)->image(layoutObject, size); |
| 130 case LinearGradientClass: | 130 case LinearGradientClass: |
| 131 return toCSSLinearGradientValue(this)->image(renderer, size); | 131 return toCSSLinearGradientValue(this)->image(layoutObject, size); |
| 132 case RadialGradientClass: | 132 case RadialGradientClass: |
| 133 return toCSSRadialGradientValue(this)->image(renderer, size); | 133 return toCSSRadialGradientValue(this)->image(layoutObject, size); |
| 134 default: | 134 default: |
| 135 ASSERT_NOT_REACHED(); | 135 ASSERT_NOT_REACHED(); |
| 136 } | 136 } |
| 137 return nullptr; | 137 return nullptr; |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool CSSImageGeneratorValue::isFixedSize() const | 140 bool CSSImageGeneratorValue::isFixedSize() const |
| 141 { | 141 { |
| 142 switch (classType()) { | 142 switch (classType()) { |
| 143 case CanvasClass: | 143 case CanvasClass: |
| 144 return toCSSCanvasValue(this)->isFixedSize(); | 144 return toCSSCanvasValue(this)->isFixedSize(); |
| 145 case CrossfadeClass: | 145 case CrossfadeClass: |
| 146 return toCSSCrossfadeValue(this)->isFixedSize(); | 146 return toCSSCrossfadeValue(this)->isFixedSize(); |
| 147 case LinearGradientClass: | 147 case LinearGradientClass: |
| 148 return toCSSLinearGradientValue(this)->isFixedSize(); | 148 return toCSSLinearGradientValue(this)->isFixedSize(); |
| 149 case RadialGradientClass: | 149 case RadialGradientClass: |
| 150 return toCSSRadialGradientValue(this)->isFixedSize(); | 150 return toCSSRadialGradientValue(this)->isFixedSize(); |
| 151 default: | 151 default: |
| 152 ASSERT_NOT_REACHED(); | 152 ASSERT_NOT_REACHED(); |
| 153 } | 153 } |
| 154 return false; | 154 return false; |
| 155 } | 155 } |
| 156 | 156 |
| 157 IntSize CSSImageGeneratorValue::fixedSize(const LayoutObject* renderer) | 157 IntSize CSSImageGeneratorValue::fixedSize(const LayoutObject* layoutObject) |
| 158 { | 158 { |
| 159 switch (classType()) { | 159 switch (classType()) { |
| 160 case CanvasClass: | 160 case CanvasClass: |
| 161 return toCSSCanvasValue(this)->fixedSize(renderer); | 161 return toCSSCanvasValue(this)->fixedSize(layoutObject); |
| 162 case CrossfadeClass: | 162 case CrossfadeClass: |
| 163 return toCSSCrossfadeValue(this)->fixedSize(renderer); | 163 return toCSSCrossfadeValue(this)->fixedSize(layoutObject); |
| 164 case LinearGradientClass: | 164 case LinearGradientClass: |
| 165 return toCSSLinearGradientValue(this)->fixedSize(renderer); | 165 return toCSSLinearGradientValue(this)->fixedSize(layoutObject); |
| 166 case RadialGradientClass: | 166 case RadialGradientClass: |
| 167 return toCSSRadialGradientValue(this)->fixedSize(renderer); | 167 return toCSSRadialGradientValue(this)->fixedSize(layoutObject); |
| 168 default: | 168 default: |
| 169 ASSERT_NOT_REACHED(); | 169 ASSERT_NOT_REACHED(); |
| 170 } | 170 } |
| 171 return IntSize(); | 171 return IntSize(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool CSSImageGeneratorValue::isPending() const | 174 bool CSSImageGeneratorValue::isPending() const |
| 175 { | 175 { |
| 176 switch (classType()) { | 176 switch (classType()) { |
| 177 case CrossfadeClass: | 177 case CrossfadeClass: |
| 178 return toCSSCrossfadeValue(this)->isPending(); | 178 return toCSSCrossfadeValue(this)->isPending(); |
| 179 case CanvasClass: | 179 case CanvasClass: |
| 180 return toCSSCanvasValue(this)->isPending(); | 180 return toCSSCanvasValue(this)->isPending(); |
| 181 case LinearGradientClass: | 181 case LinearGradientClass: |
| 182 return toCSSLinearGradientValue(this)->isPending(); | 182 return toCSSLinearGradientValue(this)->isPending(); |
| 183 case RadialGradientClass: | 183 case RadialGradientClass: |
| 184 return toCSSRadialGradientValue(this)->isPending(); | 184 return toCSSRadialGradientValue(this)->isPending(); |
| 185 default: | 185 default: |
| 186 ASSERT_NOT_REACHED(); | 186 ASSERT_NOT_REACHED(); |
| 187 } | 187 } |
| 188 return false; | 188 return false; |
| 189 } | 189 } |
| 190 | 190 |
| 191 bool CSSImageGeneratorValue::knownToBeOpaque(const LayoutObject* renderer) const | 191 bool CSSImageGeneratorValue::knownToBeOpaque(const LayoutObject* layoutObject) c
onst |
| 192 { | 192 { |
| 193 switch (classType()) { | 193 switch (classType()) { |
| 194 case CrossfadeClass: | 194 case CrossfadeClass: |
| 195 return toCSSCrossfadeValue(this)->knownToBeOpaque(renderer); | 195 return toCSSCrossfadeValue(this)->knownToBeOpaque(layoutObject); |
| 196 case CanvasClass: | 196 case CanvasClass: |
| 197 return false; | 197 return false; |
| 198 case LinearGradientClass: | 198 case LinearGradientClass: |
| 199 return toCSSLinearGradientValue(this)->knownToBeOpaque(renderer); | 199 return toCSSLinearGradientValue(this)->knownToBeOpaque(layoutObject); |
| 200 case RadialGradientClass: | 200 case RadialGradientClass: |
| 201 return toCSSRadialGradientValue(this)->knownToBeOpaque(renderer); | 201 return toCSSRadialGradientValue(this)->knownToBeOpaque(layoutObject); |
| 202 default: | 202 default: |
| 203 ASSERT_NOT_REACHED(); | 203 ASSERT_NOT_REACHED(); |
| 204 } | 204 } |
| 205 return false; | 205 return false; |
| 206 } | 206 } |
| 207 | 207 |
| 208 void CSSImageGeneratorValue::loadSubimages(Document* document) | 208 void CSSImageGeneratorValue::loadSubimages(Document* document) |
| 209 { | 209 { |
| 210 switch (classType()) { | 210 switch (classType()) { |
| 211 case CrossfadeClass: | 211 case CrossfadeClass: |
| 212 toCSSCrossfadeValue(this)->loadSubimages(document); | 212 toCSSCrossfadeValue(this)->loadSubimages(document); |
| 213 break; | 213 break; |
| 214 case CanvasClass: | 214 case CanvasClass: |
| 215 toCSSCanvasValue(this)->loadSubimages(document); | 215 toCSSCanvasValue(this)->loadSubimages(document); |
| 216 break; | 216 break; |
| 217 case LinearGradientClass: | 217 case LinearGradientClass: |
| 218 toCSSLinearGradientValue(this)->loadSubimages(document); | 218 toCSSLinearGradientValue(this)->loadSubimages(document); |
| 219 break; | 219 break; |
| 220 case RadialGradientClass: | 220 case RadialGradientClass: |
| 221 toCSSRadialGradientValue(this)->loadSubimages(document); | 221 toCSSRadialGradientValue(this)->loadSubimages(document); |
| 222 break; | 222 break; |
| 223 default: | 223 default: |
| 224 ASSERT_NOT_REACHED(); | 224 ASSERT_NOT_REACHED(); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace blink | 228 } // namespace blink |
| OLD | NEW |