| 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 20 matching lines...) Expand all Loading... |
| 31 #include "core/layout/LayoutObject.h" | 31 #include "core/layout/LayoutObject.h" |
| 32 #include "platform/graphics/Image.h" | 32 #include "platform/graphics/Image.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 CSSImageGeneratorValue::CSSImageGeneratorValue(ClassType class_type) | 36 CSSImageGeneratorValue::CSSImageGeneratorValue(ClassType class_type) |
| 37 : CSSValue(class_type) {} | 37 : CSSValue(class_type) {} |
| 38 | 38 |
| 39 CSSImageGeneratorValue::~CSSImageGeneratorValue() {} | 39 CSSImageGeneratorValue::~CSSImageGeneratorValue() {} |
| 40 | 40 |
| 41 void CSSImageGeneratorValue::AddClient(const LayoutObject* layout_object, | 41 void CSSImageGeneratorValue::AddClient(const ImageResourceObserver* client, |
| 42 const IntSize& size) { | 42 const IntSize& size) { |
| 43 DCHECK(layout_object); | 43 DCHECK(client); |
| 44 if (clients_.IsEmpty()) { | 44 if (clients_.IsEmpty()) { |
| 45 DCHECK(!keep_alive_); | 45 DCHECK(!keep_alive_); |
| 46 keep_alive_ = this; | 46 keep_alive_ = this; |
| 47 } | 47 } |
| 48 | 48 |
| 49 if (!size.IsEmpty()) | 49 if (!size.IsEmpty()) |
| 50 sizes_.insert(size); | 50 sizes_.insert(size); |
| 51 | 51 |
| 52 LayoutObjectSizeCountMap::iterator it = clients_.find(layout_object); | 52 ClientSizeCountMap::iterator it = clients_.find(client); |
| 53 if (it == clients_.end()) { | 53 if (it == clients_.end()) { |
| 54 clients_.insert(layout_object, SizeAndCount(size, 1)); | 54 clients_.insert(client, SizeAndCount(size, 1)); |
| 55 } else { | 55 } else { |
| 56 SizeAndCount& size_count = it->value; | 56 SizeAndCount& size_count = it->value; |
| 57 ++size_count.count; | 57 ++size_count.count; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 CSSImageGeneratorValue* CSSImageGeneratorValue::ValueWithURLsMadeAbsolute() { | 61 CSSImageGeneratorValue* CSSImageGeneratorValue::ValueWithURLsMadeAbsolute() { |
| 62 if (IsCrossfadeValue()) | 62 if (IsCrossfadeValue()) |
| 63 return ToCSSCrossfadeValue(this)->ValueWithURLsMadeAbsolute(); | 63 return ToCSSCrossfadeValue(this)->ValueWithURLsMadeAbsolute(); |
| 64 return this; | 64 return this; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void CSSImageGeneratorValue::RemoveClient(const LayoutObject* layout_object) { | 67 void CSSImageGeneratorValue::RemoveClient(const ImageResourceObserver* client) { |
| 68 DCHECK(layout_object); | 68 DCHECK(client); |
| 69 LayoutObjectSizeCountMap::iterator it = clients_.find(layout_object); | 69 ClientSizeCountMap::iterator it = clients_.find(client); |
| 70 SECURITY_DCHECK(it != clients_.end()); | 70 SECURITY_DCHECK(it != clients_.end()); |
| 71 | 71 |
| 72 IntSize removed_image_size; | 72 IntSize removed_image_size; |
| 73 SizeAndCount& size_count = it->value; | 73 SizeAndCount& size_count = it->value; |
| 74 IntSize size = size_count.size; | 74 IntSize size = size_count.size; |
| 75 if (!size.IsEmpty()) { | 75 if (!size.IsEmpty()) { |
| 76 sizes_.erase(size); | 76 sizes_.erase(size); |
| 77 if (!sizes_.Contains(size)) | 77 if (!sizes_.Contains(size)) |
| 78 images_.erase(size); | 78 images_.erase(size); |
| 79 } | 79 } |
| 80 | 80 |
| 81 if (!--size_count.count) | 81 if (!--size_count.count) |
| 82 clients_.erase(layout_object); | 82 clients_.erase(client); |
| 83 | 83 |
| 84 if (clients_.IsEmpty()) { | 84 if (clients_.IsEmpty()) { |
| 85 DCHECK(keep_alive_); | 85 DCHECK(keep_alive_); |
| 86 keep_alive_.Clear(); | 86 keep_alive_.Clear(); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 Image* CSSImageGeneratorValue::GetImage(const LayoutObject* layout_object, | 90 Image* CSSImageGeneratorValue::GetImage(const ImageResourceObserver* client, |
| 91 const Document&, |
| 92 const ComputedStyle&, |
| 91 const IntSize& size) { | 93 const IntSize& size) { |
| 92 LayoutObjectSizeCountMap::iterator it = clients_.find(layout_object); | 94 ClientSizeCountMap::iterator it = clients_.find(client); |
| 93 if (it != clients_.end()) { | 95 if (it != clients_.end()) { |
| 94 SizeAndCount& size_count = it->value; | 96 SizeAndCount& size_count = it->value; |
| 95 IntSize old_size = size_count.size; | 97 IntSize old_size = size_count.size; |
| 96 if (old_size != size) { | 98 if (old_size != size) { |
| 97 RemoveClient(layout_object); | 99 RemoveClient(client); |
| 98 AddClient(layout_object, size); | 100 AddClient(client, size); |
| 99 } | 101 } |
| 100 } | 102 } |
| 101 | 103 |
| 102 // Don't generate an image for empty sizes. | 104 // Don't generate an image for empty sizes. |
| 103 if (size.IsEmpty()) | 105 if (size.IsEmpty()) |
| 104 return nullptr; | 106 return nullptr; |
| 105 | 107 |
| 106 // Look up the image in our cache. | 108 // Look up the image in our cache. |
| 107 return images_.at(size); | 109 return images_.at(size); |
| 108 } | 110 } |
| 109 | 111 |
| 110 void CSSImageGeneratorValue::PutImage(const IntSize& size, | 112 void CSSImageGeneratorValue::PutImage(const IntSize& size, |
| 111 PassRefPtr<Image> image) { | 113 PassRefPtr<Image> image) { |
| 112 images_.insert(size, std::move(image)); | 114 images_.insert(size, std::move(image)); |
| 113 } | 115 } |
| 114 | 116 |
| 115 PassRefPtr<Image> CSSImageGeneratorValue::GetImage( | 117 PassRefPtr<Image> CSSImageGeneratorValue::GetImage( |
| 116 const LayoutObject& layout_object, | 118 const ImageResourceObserver& client, |
| 119 const Document& document, |
| 120 const ComputedStyle& style, |
| 117 const IntSize& size) { | 121 const IntSize& size) { |
| 118 switch (GetClassType()) { | 122 switch (GetClassType()) { |
| 119 case kCrossfadeClass: | 123 case kCrossfadeClass: |
| 120 return ToCSSCrossfadeValue(this)->GetImage(layout_object, size); | 124 return ToCSSCrossfadeValue(this)->GetImage(client, document, style, size); |
| 121 case kLinearGradientClass: | 125 case kLinearGradientClass: |
| 122 return ToCSSLinearGradientValue(this)->GetImage(layout_object, size); | 126 return ToCSSLinearGradientValue(this)->GetImage(client, document, style, |
| 127 size); |
| 123 case kPaintClass: | 128 case kPaintClass: |
| 124 return ToCSSPaintValue(this)->GetImage(layout_object, size); | 129 return ToCSSPaintValue(this)->GetImage(client, document, style, size); |
| 125 case kRadialGradientClass: | 130 case kRadialGradientClass: |
| 126 return ToCSSRadialGradientValue(this)->GetImage(layout_object, size); | 131 return ToCSSRadialGradientValue(this)->GetImage(client, document, style, |
| 132 size); |
| 127 case kConicGradientClass: | 133 case kConicGradientClass: |
| 128 return ToCSSConicGradientValue(this)->GetImage(layout_object, size); | 134 return ToCSSConicGradientValue(this)->GetImage(client, document, style, |
| 135 size); |
| 129 default: | 136 default: |
| 130 NOTREACHED(); | 137 NOTREACHED(); |
| 131 } | 138 } |
| 132 return nullptr; | 139 return nullptr; |
| 133 } | 140 } |
| 134 | 141 |
| 135 bool CSSImageGeneratorValue::IsFixedSize() const { | 142 bool CSSImageGeneratorValue::IsFixedSize() const { |
| 136 switch (GetClassType()) { | 143 switch (GetClassType()) { |
| 137 case kCrossfadeClass: | 144 case kCrossfadeClass: |
| 138 return ToCSSCrossfadeValue(this)->IsFixedSize(); | 145 return ToCSSCrossfadeValue(this)->IsFixedSize(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 break; | 231 break; |
| 225 case kConicGradientClass: | 232 case kConicGradientClass: |
| 226 ToCSSConicGradientValue(this)->LoadSubimages(document); | 233 ToCSSConicGradientValue(this)->LoadSubimages(document); |
| 227 break; | 234 break; |
| 228 default: | 235 default: |
| 229 NOTREACHED(); | 236 NOTREACHED(); |
| 230 } | 237 } |
| 231 } | 238 } |
| 232 | 239 |
| 233 } // namespace blink | 240 } // namespace blink |
| OLD | NEW |