Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: third_party/WebKit/Source/core/css/resolver/ElementStyleResources.cpp

Issue 2795173002: Do not show image placeholders for CSS sprites (Closed)
Patch Set: Added layout test expected result Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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) {
kouhei (in TOK) 2017/04/11 07:45:59 I'd prefer to have a more descriptive name. Comput
Raj 2017/04/20 19:01:17 Done.
122 // Simple heuristic to guess if CSS background image is used to create CSS
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 return style.hasBackgroundImage() &&
127 (!style.logicalHeight().isAuto() || !style.logicalWidth().isAuto());
kouhei (in TOK) 2017/04/11 07:45:59 Would you provide more info about this heuristic?
Raj 2017/04/20 19:01:17 The heuristic is to catch only the following case:
kouhei (in TOK) 2017/04/24 00:02:19 Would you add test case for this?
Raj 2017/04/28 03:43:26 Added test.
128 }
129
130 static bool isImagePlaceholderAllowed(const Document& document,
131 const ComputedStyle& style) {
132 return document.settings() &&
133 document.settings()->getFetchImagePlaceholders() && !isSprite(style);
kouhei (in TOK) 2017/04/11 07:45:59 It looks like we are introducing another check so
Raj 2017/04/20 19:01:17 Check not needed here. Removed.
134 }
135
117 StyleImage* ElementStyleResources::loadPendingImage( 136 StyleImage* ElementStyleResources::loadPendingImage(
118 ComputedStyle* style, 137 ComputedStyle* style,
119 StylePendingImage* pendingImage, 138 StylePendingImage* pendingImage,
120 CrossOriginAttributeValue crossOrigin) { 139 CrossOriginAttributeValue crossOrigin) {
121 if (CSSImageValue* imageValue = pendingImage->cssImageValue()) 140 if (CSSImageValue* imageValue = pendingImage->cssImageValue()) {
122 return imageValue->cacheImage(*m_document, crossOrigin); 141 return imageValue->cacheImage(
142 *m_document, crossOrigin,
143 isImagePlaceholderAllowed(*m_document, *style));
144 }
123 145
124 if (CSSPaintValue* paintValue = pendingImage->cssPaintValue()) { 146 if (CSSPaintValue* paintValue = pendingImage->cssPaintValue()) {
125 StyleGeneratedImage* image = StyleGeneratedImage::create(*paintValue); 147 StyleGeneratedImage* image = StyleGeneratedImage::create(*paintValue);
126 style->addPaintImage(image); 148 style->addPaintImage(image);
127 return image; 149 return image;
128 } 150 }
129 151
130 if (CSSImageGeneratorValue* imageGeneratorValue = 152 if (CSSImageGeneratorValue* imageGeneratorValue =
131 pendingImage->cssImageGeneratorValue()) { 153 pendingImage->cssImageGeneratorValue()) {
132 imageGeneratorValue->loadSubimages(*m_document); 154 imageGeneratorValue->loadSubimages(*m_document);
133 return StyleGeneratedImage::create(*imageGeneratorValue); 155 return StyleGeneratedImage::create(*imageGeneratorValue);
134 } 156 }
135 157
136 if (CSSImageSetValue* imageSetValue = pendingImage->cssImageSetValue()) 158 if (CSSImageSetValue* imageSetValue = pendingImage->cssImageSetValue()) {
137 return imageSetValue->cacheImage(*m_document, m_deviceScaleFactor, 159 return imageSetValue->cacheImage(
138 crossOrigin); 160 *m_document, m_deviceScaleFactor, crossOrigin,
161 isImagePlaceholderAllowed(*m_document, *style));
162 }
139 163
140 NOTREACHED(); 164 NOTREACHED();
141 return nullptr; 165 return nullptr;
142 } 166 }
143 167
144 void ElementStyleResources::loadPendingImages(ComputedStyle* style) { 168 void ElementStyleResources::loadPendingImages(ComputedStyle* style) {
145 // We must loop over the properties and then look at the style to see if 169 // 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: 170 // a pending image exists, and only load that image. For example:
147 // 171 //
148 // <style> 172 // <style>
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 279 }
256 } 280 }
257 } 281 }
258 282
259 void ElementStyleResources::loadPendingResources(ComputedStyle* computedStyle) { 283 void ElementStyleResources::loadPendingResources(ComputedStyle* computedStyle) {
260 loadPendingImages(computedStyle); 284 loadPendingImages(computedStyle);
261 loadPendingSVGDocuments(computedStyle); 285 loadPendingSVGDocuments(computedStyle);
262 } 286 }
263 287
264 } // namespace blink 288 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698