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