summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/RenderReplaced.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/rendering/RenderReplaced.cpp')
-rw-r--r--Source/WebCore/rendering/RenderReplaced.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/Source/WebCore/rendering/RenderReplaced.cpp b/Source/WebCore/rendering/RenderReplaced.cpp
index a818ad0fa..6b36b13e3 100644
--- a/Source/WebCore/rendering/RenderReplaced.cpp
+++ b/Source/WebCore/rendering/RenderReplaced.cpp
@@ -287,6 +287,31 @@ bool RenderReplaced::hasReplacedLogicalHeight() const
return false;
}
+bool RenderReplaced::setNeedsLayoutIfNeededAfterIntrinsicSizeChange()
+{
+ setPreferredLogicalWidthsDirty(true);
+
+ // If the actual area occupied by the image has changed and it is not constrained by style then a layout is required.
+ bool imageSizeIsConstrained = style().logicalWidth().isSpecified() && style().logicalHeight().isSpecified();
+
+ // FIXME: We only need to recompute the containing block's preferred size
+ // if the containing block's size depends on the image's size (i.e., the container uses shrink-to-fit sizing).
+ // There's no easy way to detect that shrink-to-fit is needed, always force a layout.
+ bool containingBlockNeedsToRecomputePreferredSize =
+ style().logicalWidth().isPercentOrCalculated()
+ || style().logicalMaxWidth().isPercentOrCalculated()
+ || style().logicalMinWidth().isPercentOrCalculated();
+
+ bool layoutSizeDependsOnIntrinsicSize = style().aspectRatioType() == AspectRatioFromIntrinsic;
+
+ if (!imageSizeIsConstrained || containingBlockNeedsToRecomputePreferredSize || layoutSizeDependsOnIntrinsicSize) {
+ setNeedsLayout();
+ return true;
+ }
+
+ return false;
+}
+
void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* contentRenderer, FloatSize& constrainedSize, double& intrinsicRatio) const
{
FloatSize intrinsicSize;
@@ -338,8 +363,6 @@ LayoutRect RenderReplaced::replacedContentRect(const LayoutSize& intrinsicSize)
return contentRect;
ObjectFit objectFit = style().objectFit();
- if (objectFit == ObjectFitFill)
- return contentRect;
LayoutRect finalRect = contentRect;
switch (objectFit) {
@@ -354,13 +377,14 @@ LayoutRect RenderReplaced::replacedContentRect(const LayoutSize& intrinsicSize)
finalRect.setSize(intrinsicSize);
break;
case ObjectFitFill:
- ASSERT_NOT_REACHED();
+ break;
}
- // FIXME: This is where object-position should be taken into account, but since it's not
- // implemented yet, assume the initial value of "50% 50%".
- LayoutUnit xOffset = (contentRect.width() - finalRect.width()) / 2;
- LayoutUnit yOffset = (contentRect.height() - finalRect.height()) / 2;
+ LengthPoint objectPosition = style().objectPosition();
+
+ LayoutUnit xOffset = minimumValueForLength(objectPosition.x(), contentRect.width() - finalRect.width());
+ LayoutUnit yOffset = minimumValueForLength(objectPosition.y(), contentRect.height() - finalRect.height());
+
finalRect.move(xOffset, yOffset);
return finalRect;