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

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

Issue 2795173002: Do not show image placeholders for CSS sprites (Closed)
Patch Set: remove a test Created 3 years, 6 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/resolver/ElementStyleResources.h ('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 88e90ddbe49e012d943fa8dcc93992f35c1fbe27..64c5618e274ece03a4a33b1a8378986c8baf742a 100644
--- a/third_party/WebKit/Source/core/css/resolver/ElementStyleResources.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/ElementStyleResources.cpp
@@ -40,6 +40,8 @@
#include "core/style/StyleInvalidImage.h"
#include "core/style/StylePendingImage.h"
#include "core/svg/SVGElementProxy.h"
+#include "platform/Length.h"
+#include "platform/loader/fetch/FetchParameters.h"
#include "platform/loader/fetch/ResourceFetcher.h"
namespace blink {
@@ -114,12 +116,26 @@ void ElementStyleResources::LoadPendingSVGDocuments(
}
}
+static bool ComputedStyleMayBeCSSSpriteBackgroundImage(
+ const ComputedStyle& style) {
+ // Simple heuristic to guess if CSS background image is used to create CSS
+ // sprites. For a legit background image it's very likely the X and the Y
+ // position will not be explicitly specifed. For CSS sprite image,
+ // background X or Y position will probably be specified.
+ const FillLayer& background = style.BackgroundLayers();
+ return style.HasBackgroundImage() &&
+ (background.XPosition().IsFixed() || background.YPosition().IsFixed());
+}
+
StyleImage* ElementStyleResources::LoadPendingImage(
ComputedStyle* style,
StylePendingImage* pending_image,
+ FetchParameters::PlaceholderImageRequestType placeholder_image_request_type,
CrossOriginAttributeValue cross_origin) {
- if (CSSImageValue* image_value = pending_image->CssImageValue())
- return image_value->CacheImage(*document_, cross_origin);
+ if (CSSImageValue* image_value = pending_image->CssImageValue()) {
+ return image_value->CacheImage(*document_, placeholder_image_request_type,
+ cross_origin);
+ }
if (CSSPaintValue* paint_value = pending_image->CssPaintValue()) {
StyleGeneratedImage* image = StyleGeneratedImage::Create(*paint_value);
@@ -133,9 +149,11 @@ StyleImage* ElementStyleResources::LoadPendingImage(
return StyleGeneratedImage::Create(*image_generator_value);
}
- if (CSSImageSetValue* image_set_value = pending_image->CssImageSetValue())
+ if (CSSImageSetValue* image_set_value = pending_image->CssImageSetValue()) {
return image_set_value->CacheImage(*document_, device_scale_factor_,
+ placeholder_image_request_type,
cross_origin);
+ }
NOTREACHED();
return nullptr;
@@ -166,9 +184,13 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
for (FillLayer* background_layer = &style->AccessBackgroundLayers();
background_layer; background_layer = background_layer->Next()) {
if (background_layer->GetImage() &&
- background_layer->GetImage()->IsPendingImage())
+ background_layer->GetImage()->IsPendingImage()) {
background_layer->SetImage(LoadPendingImage(
- style, ToStylePendingImage(background_layer->GetImage())));
+ style, ToStylePendingImage(background_layer->GetImage()),
+ ComputedStyleMayBeCSSSpriteBackgroundImage(*style)
+ ? FetchParameters::kDisallowPlaceholder
+ : FetchParameters::kAllowPlaceholder));
+ }
}
break;
}
@@ -178,10 +200,12 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
content_data; content_data = content_data->Next()) {
if (content_data->IsImage()) {
StyleImage* image = ToImageContentData(content_data)->GetImage();
- if (image->IsPendingImage())
+ if (image->IsPendingImage()) {
ToImageContentData(content_data)
->SetImage(
- LoadPendingImage(style, ToStylePendingImage(image)));
+ LoadPendingImage(style, ToStylePendingImage(image),
+ FetchParameters::kAllowPlaceholder));
+ }
}
}
break;
@@ -191,9 +215,12 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
for (size_t i = 0; i < cursor_list->size(); ++i) {
CursorData& current_cursor = cursor_list->at(i);
if (StyleImage* image = current_cursor.GetImage()) {
- if (image->IsPendingImage())
+ if (image->IsPendingImage()) {
+ // cursor images shouldn't be replaced with placeholders
current_cursor.SetImage(
- LoadPendingImage(style, ToStylePendingImage(image)));
+ LoadPendingImage(style, ToStylePendingImage(image),
+ FetchParameters::kDisallowPlaceholder));
+ }
}
}
}
@@ -201,16 +228,22 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
}
case CSSPropertyListStyleImage: {
if (style->ListStyleImage() &&
- style->ListStyleImage()->IsPendingImage())
+ style->ListStyleImage()->IsPendingImage()) {
+ // List style images shouldn't be replaced with placeholders
style->SetListStyleImage(LoadPendingImage(
- style, ToStylePendingImage(style->ListStyleImage())));
+ style, ToStylePendingImage(style->ListStyleImage()),
+ FetchParameters::kDisallowPlaceholder));
+ }
break;
}
case CSSPropertyBorderImageSource: {
if (style->BorderImageSource() &&
- style->BorderImageSource()->IsPendingImage())
+ style->BorderImageSource()->IsPendingImage()) {
+ // Border images shouldn't be replaced with placeholders
style->SetBorderImageSource(LoadPendingImage(
- style, ToStylePendingImage(style->BorderImageSource())));
+ style, ToStylePendingImage(style->BorderImageSource()),
+ FetchParameters::kDisallowPlaceholder));
+ }
break;
}
case CSSPropertyWebkitBoxReflect: {
@@ -219,7 +252,8 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
if (mask_image.GetImage() &&
mask_image.GetImage()->IsPendingImage()) {
StyleImage* loaded_image = LoadPendingImage(
- style, ToStylePendingImage(mask_image.GetImage()));
+ style, ToStylePendingImage(mask_image.GetImage()),
+ FetchParameters::kAllowPlaceholder);
reflection->SetMask(NinePieceImage(
loaded_image, mask_image.ImageSlices(), mask_image.Fill(),
mask_image.BorderSlices(), mask_image.Outset(),
@@ -230,27 +264,33 @@ void ElementStyleResources::LoadPendingImages(ComputedStyle* style) {
}
case CSSPropertyWebkitMaskBoxImageSource: {
if (style->MaskBoxImageSource() &&
- style->MaskBoxImageSource()->IsPendingImage())
+ style->MaskBoxImageSource()->IsPendingImage()) {
style->SetMaskBoxImageSource(LoadPendingImage(
- style, ToStylePendingImage(style->MaskBoxImageSource())));
+ style, ToStylePendingImage(style->MaskBoxImageSource()),
+ FetchParameters::kAllowPlaceholder));
+ }
break;
}
case CSSPropertyWebkitMaskImage: {
for (FillLayer* mask_layer = &style->AccessMaskLayers(); mask_layer;
mask_layer = mask_layer->Next()) {
if (mask_layer->GetImage() &&
- mask_layer->GetImage()->IsPendingImage())
+ mask_layer->GetImage()->IsPendingImage()) {
mask_layer->SetImage(LoadPendingImage(
- style, ToStylePendingImage(mask_layer->GetImage())));
+ style, ToStylePendingImage(mask_layer->GetImage()),
+ FetchParameters::kAllowPlaceholder));
+ }
}
break;
}
case CSSPropertyShapeOutside:
if (style->ShapeOutside() && style->ShapeOutside()->GetImage() &&
- style->ShapeOutside()->GetImage()->IsPendingImage())
+ style->ShapeOutside()->GetImage()->IsPendingImage()) {
style->ShapeOutside()->SetImage(LoadPendingImage(
style, ToStylePendingImage(style->ShapeOutside()->GetImage()),
+ FetchParameters::kAllowPlaceholder,
kCrossOriginAttributeAnonymous));
+ }
break;
default:
NOTREACHED();
« no previous file with comments | « third_party/WebKit/Source/core/css/resolver/ElementStyleResources.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698