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

Unified Diff: Source/core/rendering/RenderReplaced.cpp

Issue 22482004: Add support for the object-fit CSS property. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Oops, sorry! Forgot to update UseCounter.cpp Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/rendering/RenderReplaced.cpp
diff --git a/Source/core/rendering/RenderReplaced.cpp b/Source/core/rendering/RenderReplaced.cpp
index ff3d1914139ba5229ff8146dc5c2672e517372c0..9ca06dc6eef8bf3c517af8c1a15a45703bf48b9b 100644
--- a/Source/core/rendering/RenderReplaced.cpp
+++ b/Source/core/rendering/RenderReplaced.cpp
@@ -311,6 +311,42 @@ void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* conten
}
}
+LayoutRect RenderReplaced::replacedContentRect(const LayoutSize* overriddenIntrinsicSize) const
+{
+ LayoutRect contentRect = contentBoxRect();
+ EObjectFit objectFit = style()->objectFit();
+ if (objectFit == ObjectFitFill)
+ return contentRect;
+
+ LayoutSize intrinsicSize = overriddenIntrinsicSize ? *overriddenIntrinsicSize : this->intrinsicSize();
+ if (!intrinsicSize.width() || !intrinsicSize.height())
+ return contentRect;
+
+ LayoutRect finalRect = contentRect;
+ switch (objectFit) {
+ case ObjectFitContain:
+ case ObjectFitScaleDown:
+ case ObjectFitCover:
+ finalRect.setSize(fitLayoutSizeToAspectRatio(finalRect.size(), intrinsicSize, objectFit == ObjectFitCover ? AspectRatioFitGrow : AspectRatioFitShrink));
+ if (objectFit != ObjectFitScaleDown || finalRect.width() <= intrinsicSize.width())
+ break;
+ // fall through
+ case ObjectFitNone:
+ finalRect.setSize(intrinsicSize);
+ break;
+ case ObjectFitFill:
+ ASSERT_NOT_REACHED();
+ }
+
+ // 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;
+ finalRect.move(xOffset, yOffset);
+
+ return finalRect;
+}
+
void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const
{
// If there's an embeddedContentBox() of a remote, referenced document available, this code-path should never be used.

Powered by Google App Engine
This is Rietveld 408576698