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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 view()->frameView()->incrementVisuallyNonEmptyPixelCount(flooredIntSize(
m_imageResource->imageSize(1.0f))); | 169 view()->frameView()->incrementVisuallyNonEmptyPixelCount(flooredIntSize(
m_imageResource->imageSize(1.0f))); |
170 m_didIncrementVisuallyNonEmptyPixelCount = true; | 170 m_didIncrementVisuallyNonEmptyPixelCount = true; |
171 } | 171 } |
172 | 172 |
173 bool imageSizeChanged = false; | 173 bool imageSizeChanged = false; |
174 | 174 |
175 // Set image dimensions, taking into account the size of the alt text. | 175 // Set image dimensions, taking into account the size of the alt text. |
176 if (m_imageResource->errorOccurred() || !newImage) | 176 if (m_imageResource->errorOccurred() || !newImage) |
177 imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage()
); | 177 imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage()
); |
178 | 178 |
179 imageDimensionsChanged(imageSizeChanged, rect); | 179 repaintOrMarkForLayout(imageSizeChanged, rect); |
180 } | 180 } |
181 | 181 |
182 bool RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize, bool im
ageSizeChanged) | 182 void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize) |
183 { | 183 { |
184 if (newSize == intrinsicSize() && !imageSizeChanged) | |
185 return false; | |
186 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage()) | 184 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage()) |
187 return imageSizeChanged; | 185 return; |
188 setIntrinsicSize(newSize); | 186 setIntrinsicSize(newSize); |
189 return true; | |
190 } | 187 } |
191 | 188 |
192 void RenderImage::updateInnerContentRect() | 189 void RenderImage::updateInnerContentRect() |
193 { | 190 { |
194 // Propagate container size to the image resource. | 191 // Propagate container size to the image resource. |
195 LayoutRect containerRect = replacedContentRect(); | 192 LayoutRect containerRect = replacedContentRect(); |
196 IntSize containerSize(containerRect.width(), containerRect.height()); | 193 IntSize containerSize(containerRect.width(), containerRect.height()); |
197 if (!containerSize.isEmpty()) | 194 if (!containerSize.isEmpty()) |
198 m_imageResource->setContainerSizeForRenderer(containerSize); | 195 m_imageResource->setContainerSizeForRenderer(containerSize); |
199 } | 196 } |
200 | 197 |
201 void RenderImage::imageDimensionsChanged(bool imageSizeChanged, const IntRect* r
ect) | 198 void RenderImage::repaintOrMarkForLayout(bool imageSizeChangedToAccomodateAltTex
t, const IntRect* rect) |
202 { | 199 { |
203 bool intrinsicSizeChanged = updateIntrinsicSizeIfNeeded(m_imageResource->int
rinsicSize(style()->effectiveZoom()), imageSizeChanged); | 200 LayoutSize oldIntrinsicSize = intrinsicSize(); |
| 201 LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize(style()->effect
iveZoom()); |
| 202 updateIntrinsicSizeIfNeeded(newIntrinsicSize); |
204 | 203 |
205 // In the case of generated image content using :before/:after/content, we m
ight not be | 204 // In the case of generated image content using :before/:after/content, we m
ight not be |
206 // in the render tree yet. In that case, we just need to update our intrinsi
c size. | 205 // in the render tree yet. In that case, we just need to update our intrinsi
c size. |
207 // layout() will be called after we are inserted in the tree which will take
care of | 206 // layout() will be called after we are inserted in the tree which will take
care of |
208 // what we are doing here. | 207 // what we are doing here. |
209 if (!containingBlock()) | 208 if (!containingBlock()) |
210 return; | 209 return; |
211 | 210 |
212 bool shouldRepaint = true; | 211 bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize || ima
geSizeChangedToAccomodateAltText; |
213 if (intrinsicSizeChanged) { | 212 if (imageSourceHasChangedSize) |
214 if (!preferredLogicalWidthsDirty()) | 213 setPreferredLogicalWidthsDirty(); |
215 setPreferredLogicalWidthsDirty(); | |
216 | 214 |
217 bool hasOverrideSize = hasOverrideHeight() || hasOverrideWidth(); | 215 // If the actual area occupied by the image has changed and it is not constr
ained by style then a layout is required. |
218 if (!hasOverrideSize && !imageSizeChanged) { | 216 bool imageSizeIsConstrained = style()->logicalWidth().isSpecified() && style
()->logicalHeight().isSpecified(); |
219 LogicalExtentComputedValues computedValues; | 217 bool needsLayout = !imageSizeIsConstrained && imageSourceHasChangedSize; |
220 computeLogicalWidth(computedValues); | |
221 LayoutUnit newWidth = computedValues.m_extent; | |
222 computeLogicalHeight(height(), 0, computedValues); | |
223 LayoutUnit newHeight = computedValues.m_extent; | |
224 | 218 |
225 imageSizeChanged = width() != newWidth || height() != newHeight; | 219 // FIXME: We only need to recompute the containing block's preferred size if
the containing block's size |
226 } | 220 // depends on the image's size (i.e., the container uses shrink-to-fit sizin
g). |
| 221 // There's no easy way to detect that shrink-to-fit is needed, always force
a layout. |
| 222 bool containingBlockNeedsToRecomputePreferredSize = style()->logicalWidth()
.isPercent() || style()->logicalMaxWidth().isPercent() || style()->logicalMinWi
dth().isPercent(); |
227 | 223 |
228 // FIXME: We only need to recompute the containing block's preferred siz
e | 224 if (needsLayout || containingBlockNeedsToRecomputePreferredSize) { |
229 // if the containing block's size depends on the image's size (i.e., the
container uses shrink-to-fit sizing). | 225 setNeedsLayout(); |
230 // There's no easy way to detect that shrink-to-fit is needed, always fo
rce a layout. | 226 return; |
231 bool containingBlockNeedsToRecomputePreferredSize = | |
232 style()->logicalWidth().isPercent() | |
233 || style()->logicalMaxWidth().isPercent() | |
234 || style()->logicalMinWidth().isPercent(); | |
235 | |
236 if (imageSizeChanged || hasOverrideSize || containingBlockNeedsToRecompu
tePreferredSize) { | |
237 shouldRepaint = false; | |
238 if (!selfNeedsLayout()) | |
239 setNeedsLayout(); | |
240 } | |
241 } | 227 } |
242 | 228 |
| 229 // The image hasn't changed in size or its style constrains its size, so a r
epaint will suffice. |
243 if (everHadLayout() && !selfNeedsLayout()) { | 230 if (everHadLayout() && !selfNeedsLayout()) { |
244 // The inner content rectangle is calculated during layout, but may need
an update now | 231 // The inner content rectangle is calculated during layout, but may need
an update now |
245 // (unless the box has already been scheduled for layout). In order to c
alculate it, we | 232 // (unless the box has already been scheduled for layout). In order to c
alculate it, we |
246 // may need values from the containing block, though, so make sure that
we're not too | 233 // may need values from the containing block, though, so make sure that
we're not too |
247 // early. It may be that layout hasn't even taken place once yet. | 234 // early. It may be that layout hasn't even taken place once yet. |
248 updateInnerContentRect(); | 235 updateInnerContentRect(); |
249 } | 236 } |
250 | 237 |
251 if (shouldRepaint) { | 238 LayoutRect repaintRect; |
252 LayoutRect repaintRect; | 239 if (rect) { |
253 if (rect) { | 240 // The image changed rect is in source image coordinates (pre-zooming), |
254 // The image changed rect is in source image coordinates (pre-zoomin
g), | 241 // so map from the bounds of the image to the contentsBox. |
255 // so map from the bounds of the image to the contentsBox. | 242 repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), m_
imageResource->imageSize(1.0f)), contentBoxRect())); |
256 repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint()
, m_imageResource->imageSize(1.0f)), contentBoxRect())); | 243 // Guard against too-large changed rects. |
257 // Guard against too-large changed rects. | 244 repaintRect.intersect(contentBoxRect()); |
258 repaintRect.intersect(contentBoxRect()); | 245 } else { |
259 } else | 246 repaintRect = contentBoxRect(); |
260 repaintRect = contentBoxRect(); | 247 } |
261 | 248 |
262 { | 249 { |
263 // FIXME: We should not be allowing repaint during layout. crbug.com
/339584 | 250 // FIXME: We should not be allowing repaint during layout. crbug.com/339
584 |
264 AllowRepaintScope scoper(frameView()); | 251 AllowRepaintScope scoper(frameView()); |
265 repaintRectangle(repaintRect); | 252 repaintRectangle(repaintRect); |
266 } | 253 } |
267 | 254 |
268 // Tell any potential compositing layers that the image needs updating. | 255 // Tell any potential compositing layers that the image needs updating. |
269 contentChanged(ImageChanged); | 256 contentChanged(ImageChanged); |
270 } | |
271 } | 257 } |
272 | 258 |
273 void RenderImage::notifyFinished(Resource* newImage) | 259 void RenderImage::notifyFinished(Resource* newImage) |
274 { | 260 { |
275 if (!m_imageResource) | 261 if (!m_imageResource) |
276 return; | 262 return; |
277 | 263 |
278 if (documentBeingDestroyed()) | 264 if (documentBeingDestroyed()) |
279 return; | 265 return; |
280 | 266 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 return 0; | 623 return 0; |
638 | 624 |
639 ImageResource* cachedImage = m_imageResource->cachedImage(); | 625 ImageResource* cachedImage = m_imageResource->cachedImage(); |
640 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage(
)) | 626 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage(
)) |
641 return toSVGImage(cachedImage->image())->embeddedContentBox(); | 627 return toSVGImage(cachedImage->image())->embeddedContentBox(); |
642 | 628 |
643 return 0; | 629 return 0; |
644 } | 630 } |
645 | 631 |
646 } // namespace WebCore | 632 } // namespace WebCore |
OLD | NEW |