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 22 matching lines...) Expand all Loading... | |
| 33 #include "core/style/CursorData.h" | 33 #include "core/style/CursorData.h" |
| 34 #include "core/style/FillLayer.h" | 34 #include "core/style/FillLayer.h" |
| 35 #include "core/style/FilterOperation.h" | 35 #include "core/style/FilterOperation.h" |
| 36 #include "core/style/StyleFetchedImage.h" | 36 #include "core/style/StyleFetchedImage.h" |
| 37 #include "core/style/StyleFetchedImageSet.h" | 37 #include "core/style/StyleFetchedImageSet.h" |
| 38 #include "core/style/StyleGeneratedImage.h" | 38 #include "core/style/StyleGeneratedImage.h" |
| 39 #include "core/style/StyleImage.h" | 39 #include "core/style/StyleImage.h" |
| 40 #include "core/style/StyleInvalidImage.h" | 40 #include "core/style/StyleInvalidImage.h" |
| 41 #include "core/style/StylePendingImage.h" | 41 #include "core/style/StylePendingImage.h" |
| 42 #include "core/svg/SVGElementProxy.h" | 42 #include "core/svg/SVGElementProxy.h" |
| 43 #include "platform/Length.h" | |
| 44 #include "platform/loader/fetch/FetchParameters.h" | |
| 43 #include "platform/loader/fetch/ResourceFetcher.h" | 45 #include "platform/loader/fetch/ResourceFetcher.h" |
| 44 | 46 |
| 45 namespace blink { | 47 namespace blink { |
| 46 | 48 |
| 47 ElementStyleResources::ElementStyleResources(Document& document, | 49 ElementStyleResources::ElementStyleResources(Document& document, |
| 48 float device_scale_factor) | 50 float device_scale_factor) |
| 49 : document_(&document), device_scale_factor_(device_scale_factor) {} | 51 : document_(&document), device_scale_factor_(device_scale_factor) {} |
| 50 | 52 |
| 51 StyleImage* ElementStyleResources::GetStyleImage(CSSPropertyID property, | 53 StyleImage* ElementStyleResources::GetStyleImage(CSSPropertyID property, |
| 52 const CSSValue& value) { | 54 const CSSValue& value) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 computed_style->MutableFilter().Operations(); | 109 computed_style->MutableFilter().Operations(); |
| 108 for (auto& filter_operation : filter_operations) { | 110 for (auto& filter_operation : filter_operations) { |
| 109 if (filter_operation->GetType() != FilterOperation::REFERENCE) | 111 if (filter_operation->GetType() != FilterOperation::REFERENCE) |
| 110 continue; | 112 continue; |
| 111 ReferenceFilterOperation& reference_operation = | 113 ReferenceFilterOperation& reference_operation = |
| 112 ToReferenceFilterOperation(*filter_operation); | 114 ToReferenceFilterOperation(*filter_operation); |
| 113 reference_operation.ElementProxy().Resolve(*document_); | 115 reference_operation.ElementProxy().Resolve(*document_); |
| 114 } | 116 } |
| 115 } | 117 } |
| 116 | 118 |
| 119 static bool ComputedStyleMayBeCSSSpriteBackgroundImage( | |
| 120 const ComputedStyle& style) { | |
| 121 // Simple heuristic to guess if CSS background image is used to create CSS | |
| 122 // sprites. For a legit background image it's very likely the height or the | |
| 123 // width will be set to auto. For CSS sprite image, height or width will | |
| 124 // probably be specified. | |
| 125 return style.HasBackgroundImage() && | |
| 126 (!style.LogicalHeight().IsAuto() || !style.LogicalWidth().IsAuto()); | |
|
sclittle
2017/04/28 23:55:54
These LogicalWidth/Height().IsAuto() checks seem o
Raj
2017/04/30 18:35:28
I tested all examples from below link and some oth
sclittle
2017/05/08 20:34:44
Any updates from testing these rules out on a few
rajendrant
2017/06/12 20:31:04
As you suggested, I changed the check to (backgrou
| |
| 127 } | |
| 128 | |
| 117 StyleImage* ElementStyleResources::LoadPendingImage( | 129 StyleImage* ElementStyleResources::LoadPendingImage( |
| 118 ComputedStyle* style, | 130 ComputedStyle* style, |
| 119 StylePendingImage* pending_image, | 131 StylePendingImage* pending_image, |
| 132 FetchParameters::PlaceholderImageRequestType placeholder_image_request_type, | |
| 120 CrossOriginAttributeValue cross_origin) { | 133 CrossOriginAttributeValue cross_origin) { |
| 121 if (CSSImageValue* image_value = pending_image->CssImageValue()) | 134 if (CSSImageValue* image_value = pending_image->CssImageValue()) { |
| 122 return image_value->CacheImage(*document_, cross_origin); | 135 return image_value->CacheImage(*document_, placeholder_image_request_type, |
| 136 cross_origin); | |
| 137 } | |
| 123 | 138 |
| 124 if (CSSPaintValue* paint_value = pending_image->CssPaintValue()) { | 139 if (CSSPaintValue* paint_value = pending_image->CssPaintValue()) { |
| 125 StyleGeneratedImage* image = StyleGeneratedImage::Create(*paint_value); | 140 StyleGeneratedImage* image = StyleGeneratedImage::Create(*paint_value); |
| 126 style->AddPaintImage(image); | 141 style->AddPaintImage(image); |
| 127 return image; | 142 return image; |
| 128 } | 143 } |
| 129 | 144 |
| 130 if (CSSImageGeneratorValue* image_generator_value = | 145 if (CSSImageGeneratorValue* image_generator_value = |
| 131 pending_image->CssImageGeneratorValue()) { | 146 pending_image->CssImageGeneratorValue()) { |
| 132 image_generator_value->LoadSubimages(*document_); | 147 image_generator_value->LoadSubimages(*document_); |
| 133 return StyleGeneratedImage::Create(*image_generator_value); | 148 return StyleGeneratedImage::Create(*image_generator_value); |
| 134 } | 149 } |
| 135 | 150 |
| 136 if (CSSImageSetValue* image_set_value = pending_image->CssImageSetValue()) | 151 if (CSSImageSetValue* image_set_value = pending_image->CssImageSetValue()) { |
| 137 return image_set_value->CacheImage(*document_, device_scale_factor_, | 152 return image_set_value->CacheImage(*document_, device_scale_factor_, |
| 153 placeholder_image_request_type, | |
| 138 cross_origin); | 154 cross_origin); |
| 155 } | |
| 139 | 156 |
| 140 NOTREACHED(); | 157 NOTREACHED(); |
| 141 return nullptr; | 158 return nullptr; |
| 142 } | 159 } |
| 143 | 160 |
| 144 void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { | 161 void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { |
| 145 // We must loop over the properties and then look at the style to see if | 162 // 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: | 163 // a pending image exists, and only load that image. For example: |
| 147 // | 164 // |
| 148 // <style> | 165 // <style> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 159 // If we eagerly loaded the images we'd fetch a.png, even though it's not | 176 // If we eagerly loaded the images we'd fetch a.png, even though it's not |
| 160 // used. If we didn't null check below we'd crash since the none actually | 177 // used. If we didn't null check below we'd crash since the none actually |
| 161 // removed all background images. | 178 // removed all background images. |
| 162 | 179 |
| 163 for (CSSPropertyID property : pending_image_properties_) { | 180 for (CSSPropertyID property : pending_image_properties_) { |
| 164 switch (property) { | 181 switch (property) { |
| 165 case CSSPropertyBackgroundImage: { | 182 case CSSPropertyBackgroundImage: { |
| 166 for (FillLayer* background_layer = &style->AccessBackgroundLayers(); | 183 for (FillLayer* background_layer = &style->AccessBackgroundLayers(); |
| 167 background_layer; background_layer = background_layer->Next()) { | 184 background_layer; background_layer = background_layer->Next()) { |
| 168 if (background_layer->GetImage() && | 185 if (background_layer->GetImage() && |
| 169 background_layer->GetImage()->IsPendingImage()) | 186 background_layer->GetImage()->IsPendingImage()) { |
| 170 background_layer->SetImage(LoadPendingImage( | 187 background_layer->SetImage(LoadPendingImage( |
| 171 style, ToStylePendingImage(background_layer->GetImage()))); | 188 style, ToStylePendingImage(background_layer->GetImage()), |
| 189 ComputedStyleMayBeCSSSpriteBackgroundImage(*style) | |
| 190 ? FetchParameters::kDisallowPlaceholder | |
| 191 : FetchParameters::kAllowPlaceholder)); | |
| 192 } | |
| 172 } | 193 } |
| 173 break; | 194 break; |
| 174 } | 195 } |
| 175 case CSSPropertyContent: { | 196 case CSSPropertyContent: { |
| 176 for (ContentData* content_data = | 197 for (ContentData* content_data = |
| 177 const_cast<ContentData*>(style->GetContentData()); | 198 const_cast<ContentData*>(style->GetContentData()); |
| 178 content_data; content_data = content_data->Next()) { | 199 content_data; content_data = content_data->Next()) { |
| 179 if (content_data->IsImage()) { | 200 if (content_data->IsImage()) { |
| 180 StyleImage* image = ToImageContentData(content_data)->GetImage(); | 201 StyleImage* image = ToImageContentData(content_data)->GetImage(); |
| 181 if (image->IsPendingImage()) | 202 if (image->IsPendingImage()) { |
| 182 ToImageContentData(content_data) | 203 ToImageContentData(content_data) |
| 183 ->SetImage( | 204 ->SetImage( |
| 184 LoadPendingImage(style, ToStylePendingImage(image))); | 205 LoadPendingImage(style, ToStylePendingImage(image), |
| 206 FetchParameters::kAllowPlaceholder)); | |
| 207 } | |
| 185 } | 208 } |
| 186 } | 209 } |
| 187 break; | 210 break; |
| 188 } | 211 } |
| 189 case CSSPropertyCursor: { | 212 case CSSPropertyCursor: { |
| 190 if (CursorList* cursor_list = style->Cursors()) { | 213 if (CursorList* cursor_list = style->Cursors()) { |
| 191 for (size_t i = 0; i < cursor_list->size(); ++i) { | 214 for (size_t i = 0; i < cursor_list->size(); ++i) { |
| 192 CursorData& current_cursor = cursor_list->at(i); | 215 CursorData& current_cursor = cursor_list->at(i); |
| 193 if (StyleImage* image = current_cursor.GetImage()) { | 216 if (StyleImage* image = current_cursor.GetImage()) { |
| 194 if (image->IsPendingImage()) | 217 if (image->IsPendingImage()) { |
| 195 current_cursor.SetImage( | 218 current_cursor.SetImage( |
| 196 LoadPendingImage(style, ToStylePendingImage(image))); | 219 LoadPendingImage(style, ToStylePendingImage(image), |
| 220 FetchParameters::kAllowPlaceholder)); | |
| 221 } | |
| 197 } | 222 } |
| 198 } | 223 } |
| 199 } | 224 } |
| 200 break; | 225 break; |
| 201 } | 226 } |
| 202 case CSSPropertyListStyleImage: { | 227 case CSSPropertyListStyleImage: { |
| 203 if (style->ListStyleImage() && | 228 if (style->ListStyleImage() && |
| 204 style->ListStyleImage()->IsPendingImage()) | 229 style->ListStyleImage()->IsPendingImage()) { |
| 205 style->SetListStyleImage(LoadPendingImage( | 230 style->SetListStyleImage(LoadPendingImage( |
| 206 style, ToStylePendingImage(style->ListStyleImage()))); | 231 style, ToStylePendingImage(style->ListStyleImage()), |
| 232 FetchParameters::kAllowPlaceholder)); | |
| 233 } | |
| 207 break; | 234 break; |
| 208 } | 235 } |
| 209 case CSSPropertyBorderImageSource: { | 236 case CSSPropertyBorderImageSource: { |
| 210 if (style->BorderImageSource() && | 237 if (style->BorderImageSource() && |
| 211 style->BorderImageSource()->IsPendingImage()) | 238 style->BorderImageSource()->IsPendingImage()) { |
| 212 style->SetBorderImageSource(LoadPendingImage( | 239 style->SetBorderImageSource(LoadPendingImage( |
| 213 style, ToStylePendingImage(style->BorderImageSource()))); | 240 style, ToStylePendingImage(style->BorderImageSource()), |
| 241 FetchParameters::kAllowPlaceholder)); | |
| 242 } | |
| 214 break; | 243 break; |
| 215 } | 244 } |
| 216 case CSSPropertyWebkitBoxReflect: { | 245 case CSSPropertyWebkitBoxReflect: { |
| 217 if (StyleReflection* reflection = style->BoxReflect()) { | 246 if (StyleReflection* reflection = style->BoxReflect()) { |
| 218 const NinePieceImage& mask_image = reflection->Mask(); | 247 const NinePieceImage& mask_image = reflection->Mask(); |
| 219 if (mask_image.GetImage() && | 248 if (mask_image.GetImage() && |
| 220 mask_image.GetImage()->IsPendingImage()) { | 249 mask_image.GetImage()->IsPendingImage()) { |
| 221 StyleImage* loaded_image = LoadPendingImage( | 250 StyleImage* loaded_image = LoadPendingImage( |
| 222 style, ToStylePendingImage(mask_image.GetImage())); | 251 style, ToStylePendingImage(mask_image.GetImage()), |
| 252 FetchParameters::kAllowPlaceholder); | |
| 223 reflection->SetMask(NinePieceImage( | 253 reflection->SetMask(NinePieceImage( |
| 224 loaded_image, mask_image.ImageSlices(), mask_image.Fill(), | 254 loaded_image, mask_image.ImageSlices(), mask_image.Fill(), |
| 225 mask_image.BorderSlices(), mask_image.Outset(), | 255 mask_image.BorderSlices(), mask_image.Outset(), |
| 226 mask_image.HorizontalRule(), mask_image.VerticalRule())); | 256 mask_image.HorizontalRule(), mask_image.VerticalRule())); |
| 227 } | 257 } |
| 228 } | 258 } |
| 229 break; | 259 break; |
| 230 } | 260 } |
| 231 case CSSPropertyWebkitMaskBoxImageSource: { | 261 case CSSPropertyWebkitMaskBoxImageSource: { |
| 232 if (style->MaskBoxImageSource() && | 262 if (style->MaskBoxImageSource() && |
| 233 style->MaskBoxImageSource()->IsPendingImage()) | 263 style->MaskBoxImageSource()->IsPendingImage()) { |
| 234 style->SetMaskBoxImageSource(LoadPendingImage( | 264 style->SetMaskBoxImageSource(LoadPendingImage( |
| 235 style, ToStylePendingImage(style->MaskBoxImageSource()))); | 265 style, ToStylePendingImage(style->MaskBoxImageSource()), |
| 266 FetchParameters::kAllowPlaceholder)); | |
| 267 } | |
| 236 break; | 268 break; |
| 237 } | 269 } |
| 238 case CSSPropertyWebkitMaskImage: { | 270 case CSSPropertyWebkitMaskImage: { |
| 239 for (FillLayer* mask_layer = &style->AccessMaskLayers(); mask_layer; | 271 for (FillLayer* mask_layer = &style->AccessMaskLayers(); mask_layer; |
| 240 mask_layer = mask_layer->Next()) { | 272 mask_layer = mask_layer->Next()) { |
| 241 if (mask_layer->GetImage() && | 273 if (mask_layer->GetImage() && |
| 242 mask_layer->GetImage()->IsPendingImage()) | 274 mask_layer->GetImage()->IsPendingImage()) { |
| 243 mask_layer->SetImage(LoadPendingImage( | 275 mask_layer->SetImage(LoadPendingImage( |
| 244 style, ToStylePendingImage(mask_layer->GetImage()))); | 276 style, ToStylePendingImage(mask_layer->GetImage()), |
| 277 FetchParameters::kAllowPlaceholder)); | |
| 278 } | |
| 245 } | 279 } |
| 246 break; | 280 break; |
| 247 } | 281 } |
| 248 case CSSPropertyShapeOutside: | 282 case CSSPropertyShapeOutside: |
| 249 if (style->ShapeOutside() && style->ShapeOutside()->GetImage() && | 283 if (style->ShapeOutside() && style->ShapeOutside()->GetImage() && |
| 250 style->ShapeOutside()->GetImage()->IsPendingImage()) | 284 style->ShapeOutside()->GetImage()->IsPendingImage()) { |
| 251 style->ShapeOutside()->SetImage(LoadPendingImage( | 285 style->ShapeOutside()->SetImage(LoadPendingImage( |
| 252 style, ToStylePendingImage(style->ShapeOutside()->GetImage()), | 286 style, ToStylePendingImage(style->ShapeOutside()->GetImage()), |
| 287 FetchParameters::kAllowPlaceholder, | |
| 253 kCrossOriginAttributeAnonymous)); | 288 kCrossOriginAttributeAnonymous)); |
| 289 } | |
| 254 break; | 290 break; |
| 255 default: | 291 default: |
| 256 NOTREACHED(); | 292 NOTREACHED(); |
| 257 } | 293 } |
| 258 } | 294 } |
| 259 } | 295 } |
| 260 | 296 |
| 261 void ElementStyleResources::LoadPendingResources( | 297 void ElementStyleResources::LoadPendingResources( |
| 262 ComputedStyle* computed_style) { | 298 ComputedStyle* computed_style) { |
| 263 LoadPendingImages(computed_style); | 299 LoadPendingImages(computed_style); |
| 264 LoadPendingSVGDocuments(computed_style); | 300 LoadPendingSVGDocuments(computed_style); |
| 265 } | 301 } |
| 266 | 302 |
| 267 } // namespace blink | 303 } // namespace blink |
| OLD | NEW |