Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: Source/core/rendering/RenderImage.cpp

Issue 114323004: Simplify RenderImage::imageDimensionsChanged() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated per Ojan's comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/RenderImage.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 bool imageSizeChanged = false; 178 bool imageSizeChanged = false;
179 179
180 // Set image dimensions, taking into account the size of the alt text. 180 // Set image dimensions, taking into account the size of the alt text.
181 if (m_imageResource->errorOccurred() || !newImage) 181 if (m_imageResource->errorOccurred() || !newImage)
182 imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage() ); 182 imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage() );
183 183
184 imageDimensionsChanged(imageSizeChanged, rect); 184 imageDimensionsChanged(imageSizeChanged, rect);
185 } 185 }
186 186
187 bool RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize, bool im ageSizeChanged) 187 void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize)
188 { 188 {
189 if (newSize == intrinsicSize() && !imageSizeChanged)
190 return false;
191 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage()) 189 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage())
192 return imageSizeChanged; 190 return;
193 setIntrinsicSize(newSize); 191 setIntrinsicSize(newSize);
194 return true;
195 } 192 }
196 193
197 void RenderImage::updateInnerContentRect() 194 void RenderImage::updateInnerContentRect()
198 { 195 {
199 // Propagate container size to the image resource. 196 // Propagate container size to the image resource.
200 LayoutRect containerRect = replacedContentRect(); 197 LayoutRect containerRect = replacedContentRect();
201 IntSize containerSize(containerRect.width(), containerRect.height()); 198 IntSize containerSize(containerRect.width(), containerRect.height());
202 if (!containerSize.isEmpty()) 199 if (!containerSize.isEmpty())
203 m_imageResource->setContainerSizeForRenderer(containerSize); 200 m_imageResource->setContainerSizeForRenderer(containerSize);
204 } 201 }
205 202
206 void RenderImage::imageDimensionsChanged(bool imageSizeChanged, const IntRect* r ect) 203 void RenderImage::imageDimensionsChanged(bool imageSizeChangedToAccomodateAltTex t, const IntRect* rect)
207 { 204 {
208 bool intrinsicSizeChanged = updateIntrinsicSizeIfNeeded(m_imageResource->int rinsicSize(style()->effectiveZoom()), imageSizeChanged); 205 LayoutSize oldIntrinsicSize = intrinsicSize();
206 LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize(style()->effect iveZoom());
207 updateIntrinsicSizeIfNeeded(newIntrinsicSize);
209 208
210 // In the case of generated image content using :before/:after/content, we m ight not be 209 // In the case of generated image content using :before/:after/content, we m ight not be
211 // in the render tree yet. In that case, we just need to update our intrinsi c size. 210 // in the render tree yet. In that case, we just need to update our intrinsi c size.
212 // layout() will be called after we are inserted in the tree which will take care of 211 // layout() will be called after we are inserted in the tree which will take care of
213 // what we are doing here. 212 // what we are doing here.
214 if (!containingBlock()) 213 if (!containingBlock())
215 return; 214 return;
216 215
217 bool shouldRepaint = true; 216 bool intrinsicSizeChanged = oldIntrinsicSize != newIntrinsicSize;
218 if (intrinsicSizeChanged) { 217 if (intrinsicSizeChanged || imageSizeChangedToAccomodateAltText)
219 if (!preferredLogicalWidthsDirty()) 218 setPreferredLogicalWidthsDirty();
220 setPreferredLogicalWidthsDirty();
221 219
222 bool hasOverrideSize = hasOverrideHeight() || hasOverrideWidth(); 220 // If the actual area occupied by the image has changed then a layout is req uired, otherwise a repaint will suffice.
223 if (!hasOverrideSize && !imageSizeChanged) { 221 bool hasSpecifiedSize = style()->logicalWidth().isSpecified() && style()->lo gicalHeight().isSpecified();
224 LogicalExtentComputedValues computedValues; 222 bool needsLayout = !selfNeedsLayout() && !hasSpecifiedSize && (intrinsicSize Changed || imageSizeChangedToAccomodateAltText);
ojan 2014/04/10 22:36:36 Why do we need the !selfNeedsLayout check? setNeed
rhogan 2014/04/16 20:55:42 No good reason - just didn't drop the existing che
225 computeLogicalWidthInRegion(computedValues); 223 if (needsLayout) {
226 LayoutUnit newWidth = computedValues.m_extent; 224 setNeedsLayout();
227 computeLogicalHeight(height(), 0, computedValues); 225 return;
ojan 2014/04/10 22:36:36 I'm a bit worried about this early return. Skippin
rhogan 2014/04/16 20:55:42 It's currently skipped if we decide you need a lay
ojan 2014/04/18 01:26:52 Ah, yes. I misread the old code.
228 LayoutUnit newHeight = computedValues.m_extent;
229
230 imageSizeChanged = width() != newWidth || height() != newHeight;
231 }
232
233 // FIXME: We only need to recompute the containing block's preferred siz e
234 // if the containing block's size depends on the image's size (i.e., the container uses shrink-to-fit sizing).
235 // There's no easy way to detect that shrink-to-fit is needed, always fo rce a layout.
236 bool containingBlockNeedsToRecomputePreferredSize =
237 style()->logicalWidth().isPercent()
238 || style()->logicalMaxWidth().isPercent()
239 || style()->logicalMinWidth().isPercent();
240
241 if (imageSizeChanged || hasOverrideSize || containingBlockNeedsToRecompu tePreferredSize) {
242 shouldRepaint = false;
243 if (!selfNeedsLayout())
244 setNeedsLayout();
245 }
246 } 226 }
247 227
248 if (everHadLayout() && !selfNeedsLayout()) { 228 if (everHadLayout() && !selfNeedsLayout()) {
249 // The inner content rectangle is calculated during layout, but may need an update now 229 // The inner content rectangle is calculated during layout, but may need an update now
250 // (unless the box has already been scheduled for layout). In order to c alculate it, we 230 // (unless the box has already been scheduled for layout). In order to c alculate it, we
251 // may need values from the containing block, though, so make sure that we're not too 231 // may need values from the containing block, though, so make sure that we're not too
252 // early. It may be that layout hasn't even taken place once yet. 232 // early. It may be that layout hasn't even taken place once yet.
253 updateInnerContentRect(); 233 updateInnerContentRect();
254 } 234 }
255 235
256 if (shouldRepaint) { 236 LayoutRect repaintRect;
257 LayoutRect repaintRect; 237 if (rect) {
258 if (rect) { 238 // The image changed rect is in source image coordinates (pre-zooming),
259 // The image changed rect is in source image coordinates (pre-zoomin g), 239 // so map from the bounds of the image to the contentsBox.
260 // so map from the bounds of the image to the contentsBox. 240 repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), m_ imageResource->imageSize(1.0f)), contentBoxRect()));
261 repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint() , m_imageResource->imageSize(1.0f)), contentBoxRect())); 241 // Guard against too-large changed rects.
262 // Guard against too-large changed rects. 242 repaintRect.intersect(contentBoxRect());
263 repaintRect.intersect(contentBoxRect()); 243 } else {
264 } else 244 repaintRect = contentBoxRect();
265 repaintRect = contentBoxRect(); 245 }
266 246
267 repaintRectangle(repaintRect); 247 repaintRectangle(repaintRect);
268 248
269 // Tell any potential compositing layers that the image needs updating. 249 // Tell any potential compositing layers that the image needs updating.
270 contentChanged(ImageChanged); 250 contentChanged(ImageChanged);
271 }
272 } 251 }
273 252
274 void RenderImage::notifyFinished(Resource* newImage) 253 void RenderImage::notifyFinished(Resource* newImage)
275 { 254 {
276 if (!m_imageResource) 255 if (!m_imageResource)
277 return; 256 return;
278 257
279 if (documentBeingDestroyed()) 258 if (documentBeingDestroyed())
280 return; 259 return;
281 260
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 return 0; 605 return 0;
627 606
628 ImageResource* cachedImage = m_imageResource->cachedImage(); 607 ImageResource* cachedImage = m_imageResource->cachedImage();
629 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage( )) 608 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage( ))
630 return toSVGImage(cachedImage->image())->embeddedContentBox(); 609 return toSVGImage(cachedImage->image())->embeddedContentBox();
631 610
632 return 0; 611 return 0;
633 } 612 }
634 613
635 } // namespace WebCore 614 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698