| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "core/css/CSSImageValue.h" | 28 #include "core/css/CSSImageValue.h" |
| 29 #include "core/css/CSSPrimitiveValue.h" | 29 #include "core/css/CSSPrimitiveValue.h" |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/fetch/FetchInitiatorTypeNames.h" | 31 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 32 #include "core/fetch/FetchRequest.h" | 32 #include "core/fetch/FetchRequest.h" |
| 33 #include "core/fetch/ImageResource.h" | 33 #include "core/fetch/ImageResource.h" |
| 34 #include "core/fetch/ResourceFetcher.h" | 34 #include "core/fetch/ResourceFetcher.h" |
| 35 #include "core/fetch/ResourceLoaderOptions.h" | 35 #include "core/fetch/ResourceLoaderOptions.h" |
| 36 #include "core/style/StyleFetchedImageSet.h" | 36 #include "core/style/StyleFetchedImageSet.h" |
| 37 #include "core/style/StyleInvalidImage.h" |
| 37 #include "platform/weborigin/KURL.h" | 38 #include "platform/weborigin/KURL.h" |
| 38 #include "platform/weborigin/SecurityPolicy.h" | 39 #include "platform/weborigin/SecurityPolicy.h" |
| 39 #include "wtf/text/StringBuilder.h" | 40 #include "wtf/text/StringBuilder.h" |
| 40 #include <algorithm> | 41 #include <algorithm> |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 CSSImageSetValue::CSSImageSetValue() | 45 CSSImageSetValue::CSSImageSetValue() |
| 45 : CSSValueList(ImageSetClass, CommaSeparator) | 46 : CSSValueList(ImageSetClass, CommaSeparator) |
| 46 , m_isCachePending(true) | |
| 47 , m_cachedScaleFactor(1) | 47 , m_cachedScaleFactor(1) |
| 48 { | 48 { |
| 49 } | 49 } |
| 50 | 50 |
| 51 CSSImageSetValue::~CSSImageSetValue() | 51 CSSImageSetValue::~CSSImageSetValue() |
| 52 { | 52 { |
| 53 #if !ENABLE(OILPAN) | 53 #if !ENABLE(OILPAN) |
| 54 if (m_cachedImageSet) | 54 if (m_cachedImage && m_cachedImage->isImageResourceSet()) |
| 55 m_cachedImageSet->clearImageSetValue(); | 55 toStyleFetchedImageSet(*m_cachedImage).clearImageSetValue(); |
| 56 #endif | 56 #endif |
| 57 } | 57 } |
| 58 | 58 |
| 59 void CSSImageSetValue::fillImageSet() | 59 void CSSImageSetValue::fillImageSet() |
| 60 { | 60 { |
| 61 size_t length = this->length(); | 61 size_t length = this->length(); |
| 62 size_t i = 0; | 62 size_t i = 0; |
| 63 while (i < length) { | 63 while (i < length) { |
| 64 CSSImageValue* imageValue = toCSSImageValue(item(i)); | 64 CSSImageValue* imageValue = toCSSImageValue(item(i)); |
| 65 String imageURL = imageValue->url(); | 65 String imageURL = imageValue->url(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 88 for (size_t i = 0; i < numberOfImages; ++i) { | 88 for (size_t i = 0; i < numberOfImages; ++i) { |
| 89 image = m_imagesInSet.at(i); | 89 image = m_imagesInSet.at(i); |
| 90 if (image.scaleFactor >= scaleFactor) | 90 if (image.scaleFactor >= scaleFactor) |
| 91 return image; | 91 return image; |
| 92 } | 92 } |
| 93 return image; | 93 return image; |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool CSSImageSetValue::isCachePending(float deviceScaleFactor) const | 96 bool CSSImageSetValue::isCachePending(float deviceScaleFactor) const |
| 97 { | 97 { |
| 98 return m_isCachePending || deviceScaleFactor != m_cachedScaleFactor; | 98 return !m_cachedImage || deviceScaleFactor != m_cachedScaleFactor; |
| 99 } | 99 } |
| 100 | 100 |
| 101 StyleFetchedImageSet* CSSImageSetValue::cachedImageSet(float deviceScaleFactor)
const | 101 StyleImage* CSSImageSetValue::cachedImage(float deviceScaleFactor) const |
| 102 { | 102 { |
| 103 ASSERT(!isCachePending(deviceScaleFactor)); | 103 ASSERT(!isCachePending(deviceScaleFactor)); |
| 104 return m_cachedImageSet.get(); | 104 return m_cachedImage.get(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 StyleFetchedImageSet* CSSImageSetValue::cacheImageSet(Document* document, float
deviceScaleFactor, CrossOriginAttributeValue crossOrigin) | 107 StyleImage* CSSImageSetValue::cacheImage(Document* document, float deviceScaleFa
ctor, CrossOriginAttributeValue crossOrigin) |
| 108 { | 108 { |
| 109 ASSERT(document); | 109 ASSERT(document); |
| 110 | 110 |
| 111 if (!m_imagesInSet.size()) | 111 if (!m_imagesInSet.size()) |
| 112 fillImageSet(); | 112 fillImageSet(); |
| 113 | 113 |
| 114 if (m_isCachePending || deviceScaleFactor != m_cachedScaleFactor) { | 114 if (isCachePending(deviceScaleFactor)) { |
| 115 // FIXME: In the future, we want to take much more than deviceScaleFacto
r into acount here. | 115 // FIXME: In the future, we want to take much more than deviceScaleFacto
r into acount here. |
| 116 // All forms of scale should be included: Page::pageScaleFactor(), Local
Frame::pageZoomFactor(), | 116 // All forms of scale should be included: Page::pageScaleFactor(), Local
Frame::pageZoomFactor(), |
| 117 // and any CSS transforms. https://bugs.webkit.org/show_bug.cgi?id=81698 | 117 // and any CSS transforms. https://bugs.webkit.org/show_bug.cgi?id=81698 |
| 118 ImageWithScale image = bestImageForScaleFactor(deviceScaleFactor); | 118 ImageWithScale image = bestImageForScaleFactor(deviceScaleFactor); |
| 119 FetchRequest request(ResourceRequest(document->completeURL(image.imageUR
L)), FetchInitiatorTypeNames::css); | 119 FetchRequest request(ResourceRequest(document->completeURL(image.imageUR
L)), FetchInitiatorTypeNames::css); |
| 120 request.mutableResourceRequest().setHTTPReferrer(image.referrer); | 120 request.mutableResourceRequest().setHTTPReferrer(image.referrer); |
| 121 | 121 |
| 122 if (crossOrigin != CrossOriginAttributeNotSet) | 122 if (crossOrigin != CrossOriginAttributeNotSet) |
| 123 request.setCrossOriginAccessControl(document->securityOrigin(), cros
sOrigin); | 123 request.setCrossOriginAccessControl(document->securityOrigin(), cros
sOrigin); |
| 124 | 124 |
| 125 if (ResourcePtr<ImageResource> cachedImage = ImageResource::fetch(reques
t, document->fetcher())) { | 125 if (ResourcePtr<ImageResource> cachedImage = ImageResource::fetch(reques
t, document->fetcher())) |
| 126 m_cachedImageSet = StyleFetchedImageSet::create(cachedImage.get(), i
mage.scaleFactor, this, request.url()); | 126 m_cachedImage = StyleFetchedImageSet::create(cachedImage.get(), imag
e.scaleFactor, this, request.url()); |
| 127 m_cachedScaleFactor = deviceScaleFactor; | 127 else |
| 128 m_isCachePending = false; | 128 m_cachedImage = StyleInvalidImage::create(image.imageURL); |
| 129 } | 129 m_cachedScaleFactor = deviceScaleFactor; |
| 130 } | 130 } |
| 131 | 131 |
| 132 return m_cachedImageSet.get(); | 132 return m_cachedImage.get(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 String CSSImageSetValue::customCSSText() const | 135 String CSSImageSetValue::customCSSText() const |
| 136 { | 136 { |
| 137 StringBuilder result; | 137 StringBuilder result; |
| 138 result.append("-webkit-image-set("); | 138 result.append("-webkit-image-set("); |
| 139 | 139 |
| 140 size_t length = this->length(); | 140 size_t length = this->length(); |
| 141 size_t i = 0; | 141 size_t i = 0; |
| 142 while (i < length) { | 142 while (i < length) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 157 | 157 |
| 158 ++i; | 158 ++i; |
| 159 } | 159 } |
| 160 | 160 |
| 161 result.append(')'); | 161 result.append(')'); |
| 162 return result.toString(); | 162 return result.toString(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool CSSImageSetValue::hasFailedOrCanceledSubresources() const | 165 bool CSSImageSetValue::hasFailedOrCanceledSubresources() const |
| 166 { | 166 { |
| 167 if (!m_cachedImageSet) | 167 if (!m_cachedImage) |
| 168 return false; | 168 return false; |
| 169 if (Resource* cachedResource = m_cachedImageSet->cachedImage()) | 169 if (Resource* cachedResource = m_cachedImage->cachedImage()) |
| 170 return cachedResource->loadFailedOrCanceled(); | 170 return cachedResource->loadFailedOrCanceled(); |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| 173 | 173 |
| 174 DEFINE_TRACE_AFTER_DISPATCH(CSSImageSetValue) | 174 DEFINE_TRACE_AFTER_DISPATCH(CSSImageSetValue) |
| 175 { | 175 { |
| 176 visitor->trace(m_cachedImageSet); | 176 visitor->trace(m_cachedImage); |
| 177 CSSValueList::traceAfterDispatch(visitor); | 177 CSSValueList::traceAfterDispatch(visitor); |
| 178 } | 178 } |
| 179 | 179 |
| 180 PassRefPtrWillBeRawPtr<CSSImageSetValue> CSSImageSetValue::valueWithURLsMadeAbso
lute() | 180 PassRefPtrWillBeRawPtr<CSSImageSetValue> CSSImageSetValue::valueWithURLsMadeAbso
lute() |
| 181 { | 181 { |
| 182 RefPtrWillBeRawPtr<CSSImageSetValue> value = CSSImageSetValue::create(); | 182 RefPtrWillBeRawPtr<CSSImageSetValue> value = CSSImageSetValue::create(); |
| 183 for (auto& item : *this) | 183 for (auto& item : *this) |
| 184 item->isImageValue() ? value->append(toCSSImageValue(*item).valueWithURL
MadeAbsolute()) : value->append(item); | 184 item->isImageValue() ? value->append(toCSSImageValue(*item).valueWithURL
MadeAbsolute()) : value->append(item); |
| 185 return value.release(); | 185 return value.release(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 | 188 |
| 189 } // namespace blink | 189 } // namespace blink |
| OLD | NEW |