| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) | 5 * (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) |
| 6 * (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 6 * (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
| 8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 9 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. | 9 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. |
| 10 * | 10 * |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 view()->frameView()->incrementVisuallyNonEmptyPixelCount(flooredIntSize(
m_imageResource->imageSize(1.0f))); | 171 view()->frameView()->incrementVisuallyNonEmptyPixelCount(flooredIntSize(
m_imageResource->imageSize(1.0f))); |
| 172 m_didIncrementVisuallyNonEmptyPixelCount = true; | 172 m_didIncrementVisuallyNonEmptyPixelCount = true; |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool imageSizeChanged = false; | 175 bool imageSizeChanged = false; |
| 176 | 176 |
| 177 // Set image dimensions, taking into account the size of the alt text. | 177 // Set image dimensions, taking into account the size of the alt text. |
| 178 if (m_imageResource->errorOccurred() || !newImage) | 178 if (m_imageResource->errorOccurred() || !newImage) |
| 179 imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage()
); | 179 imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage()
); |
| 180 | 180 |
| 181 repaintOrMarkForLayout(imageSizeChanged, rect); | 181 paintInvalidationOrMarkForLayout(imageSizeChanged, rect); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize) | 184 void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize) |
| 185 { | 185 { |
| 186 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage()) | 186 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage()) |
| 187 return; | 187 return; |
| 188 setIntrinsicSize(newSize); | 188 setIntrinsicSize(newSize); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void RenderImage::updateInnerContentRect() | 191 void RenderImage::updateInnerContentRect() |
| 192 { | 192 { |
| 193 // Propagate container size to the image resource. | 193 // Propagate container size to the image resource. |
| 194 LayoutRect containerRect = replacedContentRect(); | 194 LayoutRect containerRect = replacedContentRect(); |
| 195 IntSize containerSize(containerRect.width(), containerRect.height()); | 195 IntSize containerSize(containerRect.width(), containerRect.height()); |
| 196 if (!containerSize.isEmpty()) | 196 if (!containerSize.isEmpty()) |
| 197 m_imageResource->setContainerSizeForRenderer(containerSize); | 197 m_imageResource->setContainerSizeForRenderer(containerSize); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void RenderImage::repaintOrMarkForLayout(bool imageSizeChangedToAccomodateAltTex
t, const IntRect* rect) | 200 void RenderImage::paintInvalidationOrMarkForLayout(bool imageSizeChangedToAccomo
dateAltText, const IntRect* rect) |
| 201 { | 201 { |
| 202 LayoutSize oldIntrinsicSize = intrinsicSize(); | 202 LayoutSize oldIntrinsicSize = intrinsicSize(); |
| 203 LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize(style()->effect
iveZoom()); | 203 LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize(style()->effect
iveZoom()); |
| 204 updateIntrinsicSizeIfNeeded(newIntrinsicSize); | 204 updateIntrinsicSizeIfNeeded(newIntrinsicSize); |
| 205 | 205 |
| 206 // In the case of generated image content using :before/:after/content, we m
ight not be | 206 // In the case of generated image content using :before/:after/content, we m
ight not be |
| 207 // in the render tree yet. In that case, we just need to update our intrinsi
c size. | 207 // in the render tree yet. In that case, we just need to update our intrinsi
c size. |
| 208 // layout() will be called after we are inserted in the tree which will take
care of | 208 // layout() will be called after we are inserted in the tree which will take
care of |
| 209 // what we are doing here. | 209 // what we are doing here. |
| 210 if (!containingBlock()) | 210 if (!containingBlock()) |
| 211 return; | 211 return; |
| 212 | 212 |
| 213 bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize || ima
geSizeChangedToAccomodateAltText; | 213 bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize || ima
geSizeChangedToAccomodateAltText; |
| 214 if (imageSourceHasChangedSize) | 214 if (imageSourceHasChangedSize) |
| 215 setPreferredLogicalWidthsDirty(); | 215 setPreferredLogicalWidthsDirty(); |
| 216 | 216 |
| 217 // If the actual area occupied by the image has changed and it is not constr
ained by style then a layout is required. | 217 // If the actual area occupied by the image has changed and it is not constr
ained by style then a layout is required. |
| 218 bool imageSizeIsConstrained = style()->logicalWidth().isSpecified() && style
()->logicalHeight().isSpecified(); | 218 bool imageSizeIsConstrained = style()->logicalWidth().isSpecified() && style
()->logicalHeight().isSpecified(); |
| 219 | 219 |
| 220 // FIXME: We only need to recompute the containing block's preferred size if
the containing block's size | 220 // FIXME: We only need to recompute the containing block's preferred size if
the containing block's size |
| 221 // depends on the image's size (i.e., the container uses shrink-to-fit sizin
g). | 221 // depends on the image's size (i.e., the container uses shrink-to-fit sizin
g). |
| 222 // There's no easy way to detect that shrink-to-fit is needed, always force
a layout. | 222 // There's no easy way to detect that shrink-to-fit is needed, always force
a layout. |
| 223 bool containingBlockNeedsToRecomputePreferredSize = style()->logicalWidth().
isPercent() || style()->logicalMaxWidth().isPercent() || style()->logicalMinWid
th().isPercent(); | 223 bool containingBlockNeedsToRecomputePreferredSize = style()->logicalWidth().
isPercent() || style()->logicalMaxWidth().isPercent() || style()->logicalMinWid
th().isPercent(); |
| 224 | 224 |
| 225 if (imageSourceHasChangedSize && (!imageSizeIsConstrained || containingBlock
NeedsToRecomputePreferredSize)) { | 225 if (imageSourceHasChangedSize && (!imageSizeIsConstrained || containingBlock
NeedsToRecomputePreferredSize)) { |
| 226 setNeedsLayoutAndFullPaintInvalidation(); | 226 setNeedsLayoutAndFullPaintInvalidation(); |
| 227 return; | 227 return; |
| 228 } | 228 } |
| 229 | 229 |
| 230 // The image hasn't changed in size or its style constrains its size, so a r
epaint will suffice. | 230 // The image hasn't changed in size or its style constrains its size, so a p
aint invalidation will suffice. |
| 231 if (everHadLayout() && !selfNeedsLayout()) { | 231 if (everHadLayout() && !selfNeedsLayout()) { |
| 232 // The inner content rectangle is calculated during layout, but may need
an update now | 232 // The inner content rectangle is calculated during layout, but may need
an update now |
| 233 // (unless the box has already been scheduled for layout). In order to c
alculate it, we | 233 // (unless the box has already been scheduled for layout). In order to c
alculate it, we |
| 234 // may need values from the containing block, though, so make sure that
we're not too | 234 // may need values from the containing block, though, so make sure that
we're not too |
| 235 // early. It may be that layout hasn't even taken place once yet. | 235 // early. It may be that layout hasn't even taken place once yet. |
| 236 updateInnerContentRect(); | 236 updateInnerContentRect(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 LayoutRect repaintRect; | 239 LayoutRect paintInvalidationRect; |
| 240 if (rect) { | 240 if (rect) { |
| 241 // The image changed rect is in source image coordinates (without zoom), | 241 // The image changed rect is in source image coordinates (without zoom), |
| 242 // so map from the bounds of the image to the contentsBox. | 242 // so map from the bounds of the image to the contentsBox. |
| 243 const LayoutSize imageSizeWithoutZoom = m_imageResource->imageSize(1 / s
tyle()->effectiveZoom()); | 243 const LayoutSize imageSizeWithoutZoom = m_imageResource->imageSize(1 / s
tyle()->effectiveZoom()); |
| 244 repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), im
ageSizeWithoutZoom), contentBoxRect())); | 244 paintInvalidationRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatP
oint(), imageSizeWithoutZoom), contentBoxRect())); |
| 245 // Guard against too-large changed rects. | 245 // Guard against too-large changed rects. |
| 246 repaintRect.intersect(contentBoxRect()); | 246 paintInvalidationRect.intersect(contentBoxRect()); |
| 247 } else { | 247 } else { |
| 248 repaintRect = contentBoxRect(); | 248 paintInvalidationRect = contentBoxRect(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 { | 251 { |
| 252 // FIXME: We should not be allowing repaint during layout. crbug.com/339
584 | 252 // FIXME: We should not be allowing paint invalidations during layout. c
rbug.com/339584 |
| 253 AllowPaintInvalidationScope scoper(frameView()); | 253 AllowPaintInvalidationScope scoper(frameView()); |
| 254 invalidatePaintRectangle(repaintRect); | 254 invalidatePaintRectangle(paintInvalidationRect); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Tell any potential compositing layers that the image needs updating. | 257 // Tell any potential compositing layers that the image needs updating. |
| 258 contentChanged(ImageChanged); | 258 contentChanged(ImageChanged); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void RenderImage::notifyFinished(Resource* newImage) | 261 void RenderImage::notifyFinished(Resource* newImage) |
| 262 { | 262 { |
| 263 if (!m_imageResource) | 263 if (!m_imageResource) |
| 264 return; | 264 return; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 { | 424 { |
| 425 ASSERT(areaElement->imageElement() == node()); | 425 ASSERT(areaElement->imageElement() == node()); |
| 426 | 426 |
| 427 Path path = areaElement->computePath(this); | 427 Path path = areaElement->computePath(this); |
| 428 if (path.isEmpty()) | 428 if (path.isEmpty()) |
| 429 return; | 429 return; |
| 430 | 430 |
| 431 RenderStyle* areaElementStyle = areaElement->computedStyle(); | 431 RenderStyle* areaElementStyle = areaElement->computedStyle(); |
| 432 unsigned short outlineWidth = areaElementStyle->outlineWidth(); | 432 unsigned short outlineWidth = areaElementStyle->outlineWidth(); |
| 433 | 433 |
| 434 IntRect repaintRect = enclosingIntRect(path.boundingRect()); | 434 IntRect paintInvalidationRect = enclosingIntRect(path.boundingRect()); |
| 435 repaintRect.moveBy(-absoluteContentBox().location()); | 435 paintInvalidationRect.moveBy(-absoluteContentBox().location()); |
| 436 repaintRect.inflate(outlineWidth); | 436 paintInvalidationRect.inflate(outlineWidth); |
| 437 | 437 |
| 438 invalidatePaintRectangle(repaintRect); | 438 invalidatePaintRectangle(paintInvalidationRect); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void RenderImage::paintIntoRect(GraphicsContext* context, const LayoutRect& rect
) | 441 void RenderImage::paintIntoRect(GraphicsContext* context, const LayoutRect& rect
) |
| 442 { | 442 { |
| 443 IntRect alignedRect = pixelSnappedIntRect(rect); | 443 IntRect alignedRect = pixelSnappedIntRect(rect); |
| 444 if (!m_imageResource->hasImage() || m_imageResource->errorOccurred() || alig
nedRect.width() <= 0 || alignedRect.height() <= 0) | 444 if (!m_imageResource->hasImage() || m_imageResource->errorOccurred() || alig
nedRect.width() <= 0 || alignedRect.height() <= 0) |
| 445 return; | 445 return; |
| 446 | 446 |
| 447 RefPtr<Image> img = m_imageResource->image(alignedRect.width(), alignedRect.
height()); | 447 RefPtr<Image> img = m_imageResource->image(alignedRect.width(), alignedRect.
height()); |
| 448 if (!img || img->isNull()) | 448 if (!img || img->isNull()) |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 return 0; | 628 return 0; |
| 629 | 629 |
| 630 ImageResource* cachedImage = m_imageResource->cachedImage(); | 630 ImageResource* cachedImage = m_imageResource->cachedImage(); |
| 631 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage(
)) | 631 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage(
)) |
| 632 return toSVGImage(cachedImage->image())->embeddedContentBox(); | 632 return toSVGImage(cachedImage->image())->embeddedContentBox(); |
| 633 | 633 |
| 634 return 0; | 634 return 0; |
| 635 } | 635 } |
| 636 | 636 |
| 637 } // namespace blink | 637 } // namespace blink |
| OLD | NEW |