Chromium Code Reviews| Index: Source/core/rendering/RenderBlock.cpp |
| diff --git a/Source/core/rendering/RenderBlock.cpp b/Source/core/rendering/RenderBlock.cpp |
| index 5f0eb9c7f4b07ca76caf9e01d55a68562f1ef96b..340c1c43279cadbc8cb93c7398c4b711c5a212eb 100644 |
| --- a/Source/core/rendering/RenderBlock.cpp |
| +++ b/Source/core/rendering/RenderBlock.cpp |
| @@ -32,6 +32,7 @@ |
| #include "core/dom/shadow/ShadowRoot.h" |
| #include "core/editing/Editor.h" |
| #include "core/editing/FrameSelection.h" |
| +#include "core/fetch/ResourceLoadPriorityOptimizer.h" |
| #include "core/frame/Frame.h" |
| #include "core/frame/FrameView.h" |
| #include "core/page/Page.h" |
| @@ -58,6 +59,8 @@ |
| #include "core/rendering/RenderTheme.h" |
| #include "core/rendering/RenderView.h" |
| #include "core/rendering/shapes/ShapeOutsideInfo.h" |
| +#include "core/rendering/style/ContentData.h" |
| +#include "core/rendering/style/RenderStyle.h" |
| #include "platform/geometry/FloatQuad.h" |
| #include "platform/geometry/TransformState.h" |
| #include "platform/graphics/GraphicsContextStateSaver.h" |
| @@ -169,6 +172,12 @@ static void removeBlockFromDescendantAndContainerMaps(RenderBlock* block, Tracke |
| } |
| } |
| +static void appendImageResourceIfNotNull(Vector<ImageResource*>& imageResources, ImageResource* imageResource) |
| +{ |
| + if (imageResource) |
| + imageResources.append(imageResource); |
| +} |
| + |
| RenderBlock::~RenderBlock() |
| { |
| if (hasColumns()) |
| @@ -1252,6 +1261,72 @@ void RenderBlock::layout() |
| invalidateBackgroundObscurationStatus(); |
| } |
| +void RenderBlock::didLayout(ResourceLoadPriorityOptimizer& optimizer) |
| +{ |
| + RenderBox::didLayout(optimizer); |
| + updateStyleImageLoadingPriorities(optimizer); |
| +} |
| + |
| +void RenderBlock::didScroll(ResourceLoadPriorityOptimizer& optimizer) |
| +{ |
| + RenderBox::didScroll(optimizer); |
| + updateStyleImageLoadingPriorities(optimizer); |
| +} |
| + |
| +void RenderBlock::updateStyleImageLoadingPriorities(ResourceLoadPriorityOptimizer& optimizer) |
| +{ |
| + RenderStyle* blockStyle = style(); |
| + if (!blockStyle) |
| + return; |
| + |
| + Vector<ImageResource*> images; |
| + |
| + const FillLayer* styleLayers[2] = {blockStyle->backgroundLayers(), blockStyle->maskLayers()}; |
| + for (int i = 0; i < 2; ++i) { |
| + for (const FillLayer* layer = styleLayers[i]; layer; layer = layer->next()) { |
|
eseidel
2013/12/10 17:15:30
Oh, I see. I had envisoned:
appendLayers(images,
shatch
2013/12/10 18:56:19
Done.
|
| + if (layer->image()) { |
|
eseidel
2013/12/10 17:15:30
nit: This could now drop at least the inner {}
shatch
2013/12/10 18:56:19
Done.
|
| + appendImageResourceIfNotNull(images, layer->image()->cachedImage()); |
| + } |
| + } |
| + } |
| + ContentData* contentData = const_cast<ContentData*>(blockStyle->contentData()); |
|
eseidel
2013/12/10 17:15:30
The const disease!
shatch
2013/12/10 18:56:19
Oops, yeah doesn't even need to be cast.
|
| + if (contentData && contentData->isImage()) { |
| + ImageContentData* imageContentData = static_cast<ImageContentData*>(contentData); |
|
eseidel
2013/12/10 17:15:30
I'm surprised we don't have a toImageContentData()
|
| + if (imageContentData->image()) |
| + appendImageResourceIfNotNull(images, imageContentData->image()->cachedImage()); |
| + } |
| + if (blockStyle->boxReflect()) { |
|
eseidel
2013/12/10 17:15:30
nit: These two ifs could now combine into one line
shatch
2013/12/10 18:56:19
Done.
|
| + if (blockStyle->boxReflect()->mask().image()) { |
| + appendImageResourceIfNotNull(images, blockStyle->boxReflect()->mask().image()->cachedImage()); |
| + } |
| + } |
| + if (blockStyle->listStyleImage()) |
|
eseidel
2013/12/10 17:15:30
You could even push this check inside if you like.
eseidel
2013/12/10 17:17:05
By this I mean:
appendImageIfNotNull(images, block
shatch
2013/12/10 18:56:19
Done.
|
| + appendImageResourceIfNotNull(images, blockStyle->listStyleImage()->cachedImage()); |
| + if (blockStyle->borderImageSource()) |
| + appendImageResourceIfNotNull(images, blockStyle->borderImageSource()->cachedImage()); |
| + if (blockStyle->maskBoxImageSource()) |
| + appendImageResourceIfNotNull(images, blockStyle->maskBoxImageSource()->cachedImage()); |
| + |
| + if (images.isEmpty()) |
| + return; |
| + |
| + LayoutRect viewBounds = viewRect(); |
| + LayoutRect objectBounds = absoluteContentBox(); |
| + // The object bounds might be empty right now, so intersects will fail since it doesn't deal |
| + // with empty rects. Use LayoutRect::contains in that case. |
| + bool isVisible; |
| + if (!objectBounds.isEmpty()) |
|
eseidel
2013/12/10 17:15:30
I'd just pick the behavior you want for empty rect
shatch
2013/12/10 18:56:19
Addressed in other comment in RenderImage.
|
| + isVisible = viewBounds.intersects(objectBounds); |
| + else |
| + isVisible = viewBounds.contains(objectBounds); |
| + |
| + ResourceLoadPriorityOptimizer::VisibilityStatus status = isVisible ? |
| + ResourceLoadPriorityOptimizer::Visible : ResourceLoadPriorityOptimizer::NotVisible; |
| + |
| + for (Vector<ImageResource*>::iterator it = images.begin(), end = images.end(); it != end; ++it) |
| + optimizer.notifyImageResourceVisibility(*it, status); |
| +} |
| + |
| void RenderBlock::relayoutShapeDescendantIfMoved(RenderBlock* child, LayoutSize offset) |
| { |
| LayoutUnit left = isHorizontalWritingMode() ? offset.width() : offset.height(); |