Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. |
| 4 * All rights reserved. | 4 * All rights reserved. |
| 5 * Copyright (C) 2013 Google Inc. All rights reserved. | 5 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * | 21 * |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "core/css/resolver/ElementStyleResources.h" | 24 #include "core/css/resolver/ElementStyleResources.h" |
| 25 | 25 |
| 26 #include "core/CSSPropertyNames.h" | 26 #include "core/CSSPropertyNames.h" |
| 27 #include "core/css/CSSGradientValue.h" | 27 #include "core/css/CSSGradientValue.h" |
| 28 #include "core/css/CSSImageValue.h" | 28 #include "core/css/CSSImageValue.h" |
| 29 #include "core/css/CSSURIValue.h" | 29 #include "core/css/CSSURIValue.h" |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/frame/Settings.h" | |
| 32 #include "core/loader/resource/ImageResource.h" | |
| 31 #include "core/style/ComputedStyle.h" | 33 #include "core/style/ComputedStyle.h" |
| 32 #include "core/style/ContentData.h" | 34 #include "core/style/ContentData.h" |
| 33 #include "core/style/CursorData.h" | 35 #include "core/style/CursorData.h" |
| 34 #include "core/style/FillLayer.h" | 36 #include "core/style/FillLayer.h" |
| 35 #include "core/style/FilterOperation.h" | 37 #include "core/style/FilterOperation.h" |
| 36 #include "core/style/StyleFetchedImage.h" | 38 #include "core/style/StyleFetchedImage.h" |
| 37 #include "core/style/StyleFetchedImageSet.h" | 39 #include "core/style/StyleFetchedImageSet.h" |
| 38 #include "core/style/StyleGeneratedImage.h" | 40 #include "core/style/StyleGeneratedImage.h" |
| 39 #include "core/style/StyleImage.h" | 41 #include "core/style/StyleImage.h" |
| 40 #include "core/style/StyleInvalidImage.h" | 42 #include "core/style/StyleInvalidImage.h" |
| 41 #include "core/style/StylePendingImage.h" | 43 #include "core/style/StylePendingImage.h" |
| 42 #include "core/svg/SVGElementProxy.h" | 44 #include "core/svg/SVGElementProxy.h" |
| 45 #include "platform/Length.h" | |
| 46 #include "platform/LengthPoint.h" | |
| 43 #include "platform/loader/fetch/ResourceFetcher.h" | 47 #include "platform/loader/fetch/ResourceFetcher.h" |
| 44 | 48 |
| 45 namespace blink { | 49 namespace blink { |
| 46 | 50 |
| 47 ElementStyleResources::ElementStyleResources(Document& document, | 51 ElementStyleResources::ElementStyleResources(Document& document, |
| 48 float deviceScaleFactor) | 52 float deviceScaleFactor) |
| 49 : m_document(&document), m_deviceScaleFactor(deviceScaleFactor) {} | 53 : m_document(&document), m_deviceScaleFactor(deviceScaleFactor) {} |
| 50 | 54 |
| 51 StyleImage* ElementStyleResources::styleImage(CSSPropertyID property, | 55 StyleImage* ElementStyleResources::styleImage(CSSPropertyID property, |
| 52 const CSSValue& value) { | 56 const CSSValue& value) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 computedStyle->mutableFilter().operations(); | 111 computedStyle->mutableFilter().operations(); |
| 108 for (auto& filterOperation : filterOperations) { | 112 for (auto& filterOperation : filterOperations) { |
| 109 if (filterOperation->type() != FilterOperation::REFERENCE) | 113 if (filterOperation->type() != FilterOperation::REFERENCE) |
| 110 continue; | 114 continue; |
| 111 ReferenceFilterOperation& referenceOperation = | 115 ReferenceFilterOperation& referenceOperation = |
| 112 toReferenceFilterOperation(*filterOperation); | 116 toReferenceFilterOperation(*filterOperation); |
| 113 referenceOperation.elementProxy().resolve(*m_document); | 117 referenceOperation.elementProxy().resolve(*m_document); |
| 114 } | 118 } |
| 115 } | 119 } |
| 116 | 120 |
| 121 static bool isSprite(const ComputedStyle& style) { | |
| 122 // Simple hueristic to guess if CSS background image is used to create CSS | |
|
Raj
2017/04/04 08:02:02
This heuristic is similar to:
https://cs.chromium
| |
| 123 // sprites. For a legit background image it's very likely the height or the | |
| 124 // width will be set to auto. For CSS sprite image, height or width will | |
| 125 // probably be specified. | |
| 126 | |
| 127 return style.hasBackgroundImage() && | |
| 128 (!style.logicalHeight().isAuto() || !style.logicalWidth().isAuto()); | |
| 129 } | |
| 130 | |
| 131 static bool isImagePlaceholderAllowed(const Document& document, | |
| 132 const ComputedStyle& style) { | |
| 133 return document.settings() && | |
| 134 document.settings()->getFetchImagePlaceholders() && !isSprite(style); | |
| 135 } | |
| 136 | |
| 117 StyleImage* ElementStyleResources::loadPendingImage( | 137 StyleImage* ElementStyleResources::loadPendingImage( |
| 118 ComputedStyle* style, | 138 ComputedStyle* style, |
| 119 StylePendingImage* pendingImage, | 139 StylePendingImage* pendingImage, |
| 120 CrossOriginAttributeValue crossOrigin) { | 140 CrossOriginAttributeValue crossOrigin) { |
| 121 if (CSSImageValue* imageValue = pendingImage->cssImageValue()) | 141 if (CSSImageValue* imageValue = pendingImage->cssImageValue()) { |
| 122 return imageValue->cacheImage(*m_document, crossOrigin); | 142 return imageValue->cacheImage( |
| 143 *m_document, crossOrigin, | |
| 144 isImagePlaceholderAllowed(*m_document, *style)); | |
| 145 } | |
| 123 | 146 |
| 124 if (CSSPaintValue* paintValue = pendingImage->cssPaintValue()) { | 147 if (CSSPaintValue* paintValue = pendingImage->cssPaintValue()) { |
| 125 StyleGeneratedImage* image = StyleGeneratedImage::create(*paintValue); | 148 StyleGeneratedImage* image = StyleGeneratedImage::create(*paintValue); |
| 126 style->addPaintImage(image); | 149 style->addPaintImage(image); |
| 127 return image; | 150 return image; |
| 128 } | 151 } |
| 129 | 152 |
| 130 if (CSSImageGeneratorValue* imageGeneratorValue = | 153 if (CSSImageGeneratorValue* imageGeneratorValue = |
| 131 pendingImage->cssImageGeneratorValue()) { | 154 pendingImage->cssImageGeneratorValue()) { |
| 132 imageGeneratorValue->loadSubimages(*m_document); | 155 imageGeneratorValue->loadSubimages(*m_document); |
| 133 return StyleGeneratedImage::create(*imageGeneratorValue); | 156 return StyleGeneratedImage::create(*imageGeneratorValue); |
| 134 } | 157 } |
| 135 | 158 |
| 136 if (CSSImageSetValue* imageSetValue = pendingImage->cssImageSetValue()) | 159 if (CSSImageSetValue* imageSetValue = pendingImage->cssImageSetValue()) { |
| 137 return imageSetValue->cacheImage(*m_document, m_deviceScaleFactor, | 160 return imageSetValue->cacheImage( |
| 138 crossOrigin); | 161 *m_document, m_deviceScaleFactor, crossOrigin, |
| 162 isImagePlaceholderAllowed(*m_document, *style)); | |
| 163 } | |
| 139 | 164 |
| 140 ASSERT_NOT_REACHED(); | 165 ASSERT_NOT_REACHED(); |
| 141 return nullptr; | 166 return nullptr; |
| 142 } | 167 } |
| 143 | 168 |
| 144 void ElementStyleResources::loadPendingImages(ComputedStyle* style) { | 169 void ElementStyleResources::loadPendingImages(ComputedStyle* style) { |
| 145 // We must loop over the properties and then look at the style to see if | 170 // We must loop over the properties and then look at the style to see if |
| 146 // a pending image exists, and only load that image. For example: | 171 // a pending image exists, and only load that image. For example: |
| 147 // | 172 // |
| 148 // <style> | 173 // <style> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 } | 280 } |
| 256 } | 281 } |
| 257 } | 282 } |
| 258 | 283 |
| 259 void ElementStyleResources::loadPendingResources(ComputedStyle* computedStyle) { | 284 void ElementStyleResources::loadPendingResources(ComputedStyle* computedStyle) { |
| 260 loadPendingImages(computedStyle); | 285 loadPendingImages(computedStyle); |
| 261 loadPendingSVGDocuments(computedStyle); | 286 loadPendingSVGDocuments(computedStyle); |
| 262 } | 287 } |
| 263 | 288 |
| 264 } // namespace blink | 289 } // namespace blink |
| OLD | NEW |