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 X and the Y | |
| 123 // position will not be explicitly specifed. For CSS sprite image, | |
| 124 // background X or Y position will probably be specified. | |
| 125 const FillLayer& background = style.BackgroundLayers(); | |
| 126 return style.HasBackgroundImage() && | |
| 127 (background.XPosition().IsFixed() || background.YPosition().IsFixed()); | |
| 128 } | |
| 129 | |
| 117 StyleImage* ElementStyleResources::LoadPendingImage( | 130 StyleImage* ElementStyleResources::LoadPendingImage( |
| 118 ComputedStyle* style, | 131 ComputedStyle* style, |
| 119 StylePendingImage* pending_image, | 132 StylePendingImage* pending_image, |
| 133 FetchParameters::PlaceholderImageRequestType placeholder_image_request_type, | |
| 120 CrossOriginAttributeValue cross_origin) { | 134 CrossOriginAttributeValue cross_origin) { |
| 121 if (CSSImageValue* image_value = pending_image->CssImageValue()) | 135 if (CSSImageValue* image_value = pending_image->CssImageValue()) { |
| 122 return image_value->CacheImage(*document_, cross_origin); | 136 return image_value->CacheImage(*document_, placeholder_image_request_type, |
| 137 cross_origin); | |
| 138 } | |
| 123 | 139 |
| 124 if (CSSPaintValue* paint_value = pending_image->CssPaintValue()) { | 140 if (CSSPaintValue* paint_value = pending_image->CssPaintValue()) { |
| 125 StyleGeneratedImage* image = StyleGeneratedImage::Create(*paint_value); | 141 StyleGeneratedImage* image = StyleGeneratedImage::Create(*paint_value); |
| 126 style->AddPaintImage(image); | 142 style->AddPaintImage(image); |
| 127 return image; | 143 return image; |
| 128 } | 144 } |
| 129 | 145 |
| 130 if (CSSImageGeneratorValue* image_generator_value = | 146 if (CSSImageGeneratorValue* image_generator_value = |
| 131 pending_image->CssImageGeneratorValue()) { | 147 pending_image->CssImageGeneratorValue()) { |
| 132 image_generator_value->LoadSubimages(*document_); | 148 image_generator_value->LoadSubimages(*document_); |
| 133 return StyleGeneratedImage::Create(*image_generator_value); | 149 return StyleGeneratedImage::Create(*image_generator_value); |
| 134 } | 150 } |
| 135 | 151 |
| 136 if (CSSImageSetValue* image_set_value = pending_image->CssImageSetValue()) | 152 if (CSSImageSetValue* image_set_value = pending_image->CssImageSetValue()) { |
| 137 return image_set_value->CacheImage(*document_, device_scale_factor_, | 153 return image_set_value->CacheImage(*document_, device_scale_factor_, |
| 154 placeholder_image_request_type, | |
| 138 cross_origin); | 155 cross_origin); |
| 156 } | |
| 139 | 157 |
| 140 NOTREACHED(); | 158 NOTREACHED(); |
| 141 return nullptr; | 159 return nullptr; |
| 142 } | 160 } |
| 143 | 161 |
| 144 void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { | 162 void ElementStyleResources::LoadPendingImages(ComputedStyle* style) { |
| 145 // We must loop over the properties and then look at the style to see if | 163 // 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: | 164 // a pending image exists, and only load that image. For example: |
| 147 // | 165 // |
| 148 // <style> | 166 // <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 | 177 // 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 | 178 // used. If we didn't null check below we'd crash since the none actually |
| 161 // removed all background images. | 179 // removed all background images. |
| 162 | 180 |
| 163 for (CSSPropertyID property : pending_image_properties_) { | 181 for (CSSPropertyID property : pending_image_properties_) { |
| 164 switch (property) { | 182 switch (property) { |
| 165 case CSSPropertyBackgroundImage: { | 183 case CSSPropertyBackgroundImage: { |
| 166 for (FillLayer* background_layer = &style->AccessBackgroundLayers(); | 184 for (FillLayer* background_layer = &style->AccessBackgroundLayers(); |
| 167 background_layer; background_layer = background_layer->Next()) { | 185 background_layer; background_layer = background_layer->Next()) { |
| 168 if (background_layer->GetImage() && | 186 if (background_layer->GetImage() && |
| 169 background_layer->GetImage()->IsPendingImage()) | 187 background_layer->GetImage()->IsPendingImage()) { |
| 170 background_layer->SetImage(LoadPendingImage( | 188 background_layer->SetImage(LoadPendingImage( |
| 171 style, ToStylePendingImage(background_layer->GetImage()))); | 189 style, ToStylePendingImage(background_layer->GetImage()), |
| 190 ComputedStyleMayBeCSSSpriteBackgroundImage(*style) | |
| 191 ? FetchParameters::kDisallowPlaceholder | |
| 192 : FetchParameters::kAllowPlaceholder)); | |
| 193 } | |
| 172 } | 194 } |
| 173 break; | 195 break; |
| 174 } | 196 } |
| 175 case CSSPropertyContent: { | 197 case CSSPropertyContent: { |
| 176 for (ContentData* content_data = | 198 for (ContentData* content_data = |
| 177 const_cast<ContentData*>(style->GetContentData()); | 199 const_cast<ContentData*>(style->GetContentData()); |
| 178 content_data; content_data = content_data->Next()) { | 200 content_data; content_data = content_data->Next()) { |
| 179 if (content_data->IsImage()) { | 201 if (content_data->IsImage()) { |
| 180 StyleImage* image = ToImageContentData(content_data)->GetImage(); | 202 StyleImage* image = ToImageContentData(content_data)->GetImage(); |
| 181 if (image->IsPendingImage()) | 203 if (image->IsPendingImage()) { |
| 182 ToImageContentData(content_data) | 204 ToImageContentData(content_data) |
| 183 ->SetImage( | 205 ->SetImage( |
| 184 LoadPendingImage(style, ToStylePendingImage(image))); | 206 LoadPendingImage(style, ToStylePendingImage(image), |
| 207 FetchParameters::kAllowPlaceholder)); | |
| 208 } | |
| 185 } | 209 } |
| 186 } | 210 } |
| 187 break; | 211 break; |
| 188 } | 212 } |
| 189 case CSSPropertyCursor: { | 213 case CSSPropertyCursor: { |
| 190 if (CursorList* cursor_list = style->Cursors()) { | 214 if (CursorList* cursor_list = style->Cursors()) { |
| 191 for (size_t i = 0; i < cursor_list->size(); ++i) { | 215 for (size_t i = 0; i < cursor_list->size(); ++i) { |
| 192 CursorData& current_cursor = cursor_list->at(i); | 216 CursorData& current_cursor = cursor_list->at(i); |
| 193 if (StyleImage* image = current_cursor.GetImage()) { | 217 if (StyleImage* image = current_cursor.GetImage()) { |
| 194 if (image->IsPendingImage()) | 218 if (image->IsPendingImage()) { |
| 195 current_cursor.SetImage( | 219 current_cursor.SetImage( |
| 196 LoadPendingImage(style, ToStylePendingImage(image))); | 220 LoadPendingImage(style, ToStylePendingImage(image), |
| 221 FetchParameters::kDisallowPlaceholder)); | |
|
sclittle
2017/06/21 20:46:56
nit: could you add a comment stating that cursor i
| |
| 222 } | |
| 197 } | 223 } |
| 198 } | 224 } |
| 199 } | 225 } |
| 200 break; | 226 break; |
| 201 } | 227 } |
| 202 case CSSPropertyListStyleImage: { | 228 case CSSPropertyListStyleImage: { |
| 203 if (style->ListStyleImage() && | 229 if (style->ListStyleImage() && |
| 204 style->ListStyleImage()->IsPendingImage()) | 230 style->ListStyleImage()->IsPendingImage()) { |
| 205 style->SetListStyleImage(LoadPendingImage( | 231 style->SetListStyleImage(LoadPendingImage( |
| 206 style, ToStylePendingImage(style->ListStyleImage()))); | 232 style, ToStylePendingImage(style->ListStyleImage()), |
| 233 FetchParameters::kDisallowPlaceholder)); | |
| 234 } | |
| 207 break; | 235 break; |
| 208 } | 236 } |
| 209 case CSSPropertyBorderImageSource: { | 237 case CSSPropertyBorderImageSource: { |
| 210 if (style->BorderImageSource() && | 238 if (style->BorderImageSource() && |
| 211 style->BorderImageSource()->IsPendingImage()) | 239 style->BorderImageSource()->IsPendingImage()) { |
| 212 style->SetBorderImageSource(LoadPendingImage( | 240 style->SetBorderImageSource(LoadPendingImage( |
| 213 style, ToStylePendingImage(style->BorderImageSource()))); | 241 style, ToStylePendingImage(style->BorderImageSource()), |
| 242 FetchParameters::kDisallowPlaceholder)); | |
| 243 } | |
| 214 break; | 244 break; |
| 215 } | 245 } |
| 216 case CSSPropertyWebkitBoxReflect: { | 246 case CSSPropertyWebkitBoxReflect: { |
| 217 if (StyleReflection* reflection = style->BoxReflect()) { | 247 if (StyleReflection* reflection = style->BoxReflect()) { |
| 218 const NinePieceImage& mask_image = reflection->Mask(); | 248 const NinePieceImage& mask_image = reflection->Mask(); |
| 219 if (mask_image.GetImage() && | 249 if (mask_image.GetImage() && |
| 220 mask_image.GetImage()->IsPendingImage()) { | 250 mask_image.GetImage()->IsPendingImage()) { |
| 221 StyleImage* loaded_image = LoadPendingImage( | 251 StyleImage* loaded_image = LoadPendingImage( |
| 222 style, ToStylePendingImage(mask_image.GetImage())); | 252 style, ToStylePendingImage(mask_image.GetImage()), |
| 253 FetchParameters::kAllowPlaceholder); | |
| 223 reflection->SetMask(NinePieceImage( | 254 reflection->SetMask(NinePieceImage( |
| 224 loaded_image, mask_image.ImageSlices(), mask_image.Fill(), | 255 loaded_image, mask_image.ImageSlices(), mask_image.Fill(), |
| 225 mask_image.BorderSlices(), mask_image.Outset(), | 256 mask_image.BorderSlices(), mask_image.Outset(), |
| 226 mask_image.HorizontalRule(), mask_image.VerticalRule())); | 257 mask_image.HorizontalRule(), mask_image.VerticalRule())); |
| 227 } | 258 } |
| 228 } | 259 } |
| 229 break; | 260 break; |
| 230 } | 261 } |
| 231 case CSSPropertyWebkitMaskBoxImageSource: { | 262 case CSSPropertyWebkitMaskBoxImageSource: { |
| 232 if (style->MaskBoxImageSource() && | 263 if (style->MaskBoxImageSource() && |
| 233 style->MaskBoxImageSource()->IsPendingImage()) | 264 style->MaskBoxImageSource()->IsPendingImage()) { |
| 234 style->SetMaskBoxImageSource(LoadPendingImage( | 265 style->SetMaskBoxImageSource(LoadPendingImage( |
| 235 style, ToStylePendingImage(style->MaskBoxImageSource()))); | 266 style, ToStylePendingImage(style->MaskBoxImageSource()), |
| 267 FetchParameters::kAllowPlaceholder)); | |
| 268 } | |
| 236 break; | 269 break; |
| 237 } | 270 } |
| 238 case CSSPropertyWebkitMaskImage: { | 271 case CSSPropertyWebkitMaskImage: { |
| 239 for (FillLayer* mask_layer = &style->AccessMaskLayers(); mask_layer; | 272 for (FillLayer* mask_layer = &style->AccessMaskLayers(); mask_layer; |
| 240 mask_layer = mask_layer->Next()) { | 273 mask_layer = mask_layer->Next()) { |
| 241 if (mask_layer->GetImage() && | 274 if (mask_layer->GetImage() && |
| 242 mask_layer->GetImage()->IsPendingImage()) | 275 mask_layer->GetImage()->IsPendingImage()) { |
| 243 mask_layer->SetImage(LoadPendingImage( | 276 mask_layer->SetImage(LoadPendingImage( |
| 244 style, ToStylePendingImage(mask_layer->GetImage()))); | 277 style, ToStylePendingImage(mask_layer->GetImage()), |
| 278 FetchParameters::kAllowPlaceholder)); | |
| 279 } | |
| 245 } | 280 } |
| 246 break; | 281 break; |
| 247 } | 282 } |
| 248 case CSSPropertyShapeOutside: | 283 case CSSPropertyShapeOutside: |
| 249 if (style->ShapeOutside() && style->ShapeOutside()->GetImage() && | 284 if (style->ShapeOutside() && style->ShapeOutside()->GetImage() && |
| 250 style->ShapeOutside()->GetImage()->IsPendingImage()) | 285 style->ShapeOutside()->GetImage()->IsPendingImage()) { |
| 251 style->ShapeOutside()->SetImage(LoadPendingImage( | 286 style->ShapeOutside()->SetImage(LoadPendingImage( |
| 252 style, ToStylePendingImage(style->ShapeOutside()->GetImage()), | 287 style, ToStylePendingImage(style->ShapeOutside()->GetImage()), |
| 288 FetchParameters::kAllowPlaceholder, | |
| 253 kCrossOriginAttributeAnonymous)); | 289 kCrossOriginAttributeAnonymous)); |
| 290 } | |
| 254 break; | 291 break; |
| 255 default: | 292 default: |
| 256 NOTREACHED(); | 293 NOTREACHED(); |
| 257 } | 294 } |
| 258 } | 295 } |
| 259 } | 296 } |
| 260 | 297 |
| 261 void ElementStyleResources::LoadPendingResources( | 298 void ElementStyleResources::LoadPendingResources( |
| 262 ComputedStyle* computed_style) { | 299 ComputedStyle* computed_style) { |
| 263 LoadPendingImages(computed_style); | 300 LoadPendingImages(computed_style); |
| 264 LoadPendingSVGDocuments(computed_style); | 301 LoadPendingSVGDocuments(computed_style); |
| 265 } | 302 } |
| 266 | 303 |
| 267 } // namespace blink | 304 } // namespace blink |
| OLD | NEW |