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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutImage.cpp

Issue 1427943002: Wrap SVGImage for container during paint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use IntSize for SVGImageForContainer Created 5 years, 1 month 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
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 invalidatePaintAndMarkForLayoutIfNeeded(); 130 invalidatePaintAndMarkForLayoutIfNeeded();
131 } 131 }
132 132
133 void LayoutImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize) 133 void LayoutImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize)
134 { 134 {
135 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage()) 135 if (m_imageResource->errorOccurred() || !m_imageResource->hasImage())
136 return; 136 return;
137 setIntrinsicSize(newSize); 137 setIntrinsicSize(newSize);
138 } 138 }
139 139
140 void LayoutImage::updateInnerContentRect()
141 {
142 // Propagate container size to the image resource.
143 LayoutRect containerRect = replacedContentRect();
144 IntSize containerSize(containerRect.width(), containerRect.height());
145 if (!containerSize.isEmpty())
146 m_imageResource->setContainerSizeForLayoutObject(containerSize);
147 }
148
149 void LayoutImage::invalidatePaintAndMarkForLayoutIfNeeded() 140 void LayoutImage::invalidatePaintAndMarkForLayoutIfNeeded()
150 { 141 {
151 LayoutSize oldIntrinsicSize = intrinsicSize(); 142 LayoutSize oldIntrinsicSize = intrinsicSize();
152 LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize(style()->effect iveZoom()); 143 LayoutSize newIntrinsicSize = m_imageResource->imageSize(style()->effectiveZ oom());
153 updateIntrinsicSizeIfNeeded(newIntrinsicSize); 144 updateIntrinsicSizeIfNeeded(newIntrinsicSize);
154 145
155 // In the case of generated image content using :before/:after/content, we m ight not be 146 // In the case of generated image content using :before/:after/content, we m ight not be
156 // in the layout tree yet. In that case, we just need to update our intrinsi c size. 147 // in the layout tree yet. In that case, we just need to update our intrinsi c size.
157 // layout() will be called after we are inserted in the tree which will take care of 148 // layout() will be called after we are inserted in the tree which will take care of
158 // what we are doing here. 149 // what we are doing here.
159 if (!containingBlock()) 150 if (!containingBlock())
160 return; 151 return;
161 152
162 bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize; 153 bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize;
163 if (imageSourceHasChangedSize) 154 if (imageSourceHasChangedSize)
164 setPreferredLogicalWidthsDirty(); 155 setPreferredLogicalWidthsDirty();
165 156
166 // If the actual area occupied by the image has changed and it is not constr ained by style then a layout is required. 157 // If the actual area occupied by the image has changed and it is not constr ained by style then a layout is required.
167 bool imageSizeIsConstrained = style()->logicalWidth().isSpecified() && style ()->logicalHeight().isSpecified(); 158 bool imageSizeIsConstrained = style()->logicalWidth().isSpecified() && style ()->logicalHeight().isSpecified();
168 159
169 // FIXME: We only need to recompute the containing block's preferred size if the containing block's size 160 // FIXME: We only need to recompute the containing block's preferred size if the containing block's size
170 // depends on the image's size (i.e., the container uses shrink-to-fit sizin g). 161 // depends on the image's size (i.e., the container uses shrink-to-fit sizin g).
171 // There's no easy way to detect that shrink-to-fit is needed, always force a layout. 162 // There's no easy way to detect that shrink-to-fit is needed, always force a layout.
172 bool containingBlockNeedsToRecomputePreferredSize = style()->logicalWidth(). hasPercent() || style()->logicalMaxWidth().hasPercent() || style()->logicalMinW idth().hasPercent(); 163 bool containingBlockNeedsToRecomputePreferredSize = style()->logicalWidth(). hasPercent() || style()->logicalMaxWidth().hasPercent() || style()->logicalMinW idth().hasPercent();
173 164
174 if (imageSourceHasChangedSize && (!imageSizeIsConstrained || containingBlock NeedsToRecomputePreferredSize)) { 165 if (imageSourceHasChangedSize && (!imageSizeIsConstrained || containingBlock NeedsToRecomputePreferredSize)) {
175 setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::SizeCha nged); 166 setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::SizeCha nged);
176 return; 167 return;
177 } 168 }
178 169
179 // The image hasn't changed in size or its style constrains its size, so a p aint invalidation will suffice.
180 if (everHadLayout() && !selfNeedsLayout()) {
181 // The inner content rectangle is calculated during layout, but may need an update now
182 // (unless the box has already been scheduled for layout). In order to c alculate it, we
183 // may need values from the containing block, though, so make sure that we're not too
184 // early. It may be that layout hasn't even taken place once yet.
185 updateInnerContentRect();
186 }
187
188 if (imageResource() && imageResource()->maybeAnimated()) 170 if (imageResource() && imageResource()->maybeAnimated())
189 setShouldDoFullPaintInvalidation(PaintInvalidationDelayedFull); 171 setShouldDoFullPaintInvalidation(PaintInvalidationDelayedFull);
190 else 172 else
191 setShouldDoFullPaintInvalidation(PaintInvalidationFull); 173 setShouldDoFullPaintInvalidation(PaintInvalidationFull);
192 174
193 // Tell any potential compositing layers that the image needs updating. 175 // Tell any potential compositing layers that the image needs updating.
194 contentChanged(ImageChanged); 176 contentChanged(ImageChanged);
195 } 177 }
196 178
197 void LayoutImage::notifyFinished(Resource* newImage) 179 void LayoutImage::notifyFinished(Resource* newImage)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 HitTestResult tempResult(result.hitTestRequest(), result.hitTestLocation()); 275 HitTestResult tempResult(result.hitTestRequest(), result.hitTestLocation());
294 bool inside = LayoutReplaced::nodeAtPoint(tempResult, locationInContainer, a ccumulatedOffset, hitTestAction); 276 bool inside = LayoutReplaced::nodeAtPoint(tempResult, locationInContainer, a ccumulatedOffset, hitTestAction);
295 277
296 if (!inside && result.hitTestRequest().listBased()) 278 if (!inside && result.hitTestRequest().listBased())
297 result.append(tempResult); 279 result.append(tempResult);
298 if (inside) 280 if (inside)
299 result = tempResult; 281 result = tempResult;
300 return inside; 282 return inside;
301 } 283 }
302 284
303 void LayoutImage::layout()
304 {
305 LayoutReplaced::layout();
306 updateInnerContentRect();
307 }
308
309 void LayoutImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, dou ble& intrinsicRatio) const 285 void LayoutImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, dou ble& intrinsicRatio) const
310 { 286 {
311 LayoutReplaced::computeIntrinsicRatioInformation(intrinsicSize, intrinsicRat io); 287 LayoutReplaced::computeIntrinsicRatioInformation(intrinsicSize, intrinsicRat io);
312 288
313 // Our intrinsicSize is empty if we're laying out generated images with rela tive width/height. Figure out the right intrinsic size to use. 289 // Our intrinsicSize is empty if we're laying out generated images with rela tive width/height. Figure out the right intrinsic size to use.
314 if (intrinsicSize.isEmpty() && (m_imageResource->imageHasRelativeWidth() || m_imageResource->imageHasRelativeHeight())) { 290 if (intrinsicSize.isEmpty() && (m_imageResource->imageHasRelativeWidth() || m_imageResource->imageHasRelativeHeight())) {
315 LayoutObject* containingBlock = isOutOfFlowPositioned() ? container() : this->containingBlock(); 291 LayoutObject* containingBlock = isOutOfFlowPositioned() ? container() : this->containingBlock();
316 if (containingBlock->isBox()) { 292 if (containingBlock->isBox()) {
317 LayoutBox* box = toLayoutBox(containingBlock); 293 LayoutBox* box = toLayoutBox(containingBlock);
318 intrinsicSize.setWidth(box->availableLogicalWidth().toFloat()); 294 intrinsicSize.setWidth(box->availableLogicalWidth().toFloat());
(...skipping 21 matching lines...) Expand all
340 return nullptr; 316 return nullptr;
341 317
342 ImageResource* cachedImage = m_imageResource->cachedImage(); 318 ImageResource* cachedImage = m_imageResource->cachedImage();
343 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage( )) 319 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage( ))
344 return toSVGImage(cachedImage->image())->embeddedContentBox(); 320 return toSVGImage(cachedImage->image())->embeddedContentBox();
345 321
346 return nullptr; 322 return nullptr;
347 } 323 }
348 324
349 } // namespace blink 325 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutImage.h ('k') | third_party/WebKit/Source/core/layout/LayoutImageResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698