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

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

Issue 2795173002: Do not show image placeholders for CSS sprites (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSImageValue.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/css/resolver/ElementStyleResources.cpp
diff --git a/third_party/WebKit/Source/core/css/resolver/ElementStyleResources.cpp b/third_party/WebKit/Source/core/css/resolver/ElementStyleResources.cpp
index 5ef3af8e8908e949fc1952cb65be7d28d0b07271..b8cb1b322bd3704536570afd1241606cca5df8ee 100644
--- a/third_party/WebKit/Source/core/css/resolver/ElementStyleResources.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/ElementStyleResources.cpp
@@ -28,6 +28,8 @@
#include "core/css/CSSImageValue.h"
#include "core/css/CSSURIValue.h"
#include "core/dom/Document.h"
+#include "core/frame/Settings.h"
+#include "core/loader/resource/ImageResource.h"
#include "core/style/ComputedStyle.h"
#include "core/style/ContentData.h"
#include "core/style/CursorData.h"
@@ -40,6 +42,8 @@
#include "core/style/StyleInvalidImage.h"
#include "core/style/StylePendingImage.h"
#include "core/svg/SVGElementProxy.h"
+#include "platform/Length.h"
+#include "platform/LengthPoint.h"
#include "platform/loader/fetch/ResourceFetcher.h"
namespace blink {
@@ -114,12 +118,31 @@ void ElementStyleResources::loadPendingSVGDocuments(
}
}
+static bool isSprite(const ComputedStyle& style) {
+ // 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
+ // sprites. For a legit background image it's very likely the height or the
+ // width will be set to auto. For CSS sprite image, height or width will
+ // probably be specified.
+
+ return style.hasBackgroundImage() &&
+ (!style.logicalHeight().isAuto() || !style.logicalWidth().isAuto());
+}
+
+static bool isImagePlaceholderAllowed(const Document& document,
+ const ComputedStyle& style) {
+ return document.settings() &&
+ document.settings()->getFetchImagePlaceholders() && !isSprite(style);
+}
+
StyleImage* ElementStyleResources::loadPendingImage(
ComputedStyle* style,
StylePendingImage* pendingImage,
CrossOriginAttributeValue crossOrigin) {
- if (CSSImageValue* imageValue = pendingImage->cssImageValue())
- return imageValue->cacheImage(*m_document, crossOrigin);
+ if (CSSImageValue* imageValue = pendingImage->cssImageValue()) {
+ return imageValue->cacheImage(
+ *m_document, crossOrigin,
+ isImagePlaceholderAllowed(*m_document, *style));
+ }
if (CSSPaintValue* paintValue = pendingImage->cssPaintValue()) {
StyleGeneratedImage* image = StyleGeneratedImage::create(*paintValue);
@@ -133,9 +156,11 @@ StyleImage* ElementStyleResources::loadPendingImage(
return StyleGeneratedImage::create(*imageGeneratorValue);
}
- if (CSSImageSetValue* imageSetValue = pendingImage->cssImageSetValue())
- return imageSetValue->cacheImage(*m_document, m_deviceScaleFactor,
- crossOrigin);
+ if (CSSImageSetValue* imageSetValue = pendingImage->cssImageSetValue()) {
+ return imageSetValue->cacheImage(
+ *m_document, m_deviceScaleFactor, crossOrigin,
+ isImagePlaceholderAllowed(*m_document, *style));
+ }
ASSERT_NOT_REACHED();
return nullptr;
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSImageValue.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698