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

Unified Diff: Source/core/platform/graphics/LayoutSize.h

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/platform/graphics/LayoutSize.h
diff --git a/Source/core/platform/graphics/LayoutSize.h b/Source/core/platform/graphics/LayoutSize.h
index 3bce732113d63b08f772bc32e6d75e8a8da6a34c..4821adb6bd5e7bc1af3c9901793dc38cd5b7bec3 100644
--- a/Source/core/platform/graphics/LayoutSize.h
+++ b/Source/core/platform/graphics/LayoutSize.h
@@ -170,6 +170,24 @@ inline LayoutSize roundedLayoutSize(const FloatSize& s)
return LayoutSize(s);
}
+// Convert the specified scaled size to one that agrees with the specified aspect ratio
+// (expressed as a size, too).
ojan 2013/08/08 02:36:55 Blink (and WebKit) style is to leave out "what" co
mstensho (USE GERRIT) 2013/08/08 07:26:42 Done.
+enum AspectRatioFit { // How to set a size with the specified aspect ratio
+ AspectRatioFitShrink, // Shrink in one dimension to gain aspect ratio
+ AspectRatioFitGrow // Grow in one dimension to gain aspect ratio
+};
ojan 2013/08/08 02:36:55 Needs another line-break here.
mstensho (USE GERRIT) 2013/08/08 07:26:42 Done.
+inline LayoutSize fitLayoutSizeToAspectRatio(const LayoutSize& scaledSize, const LayoutSize& aspectRatio, AspectRatioFit fit)
ojan 2013/08/08 02:36:55 I think this method makes more sense as a member o
mstensho (USE GERRIT) 2013/08/08 07:26:42 Done.
+{
+ // Set a new width or height to get to a size that honors the aspect ratio. If fit is
+ // AspectRatioFitGrow, increase in the dimension that is scaled less. Otherwise,
+ // decrease in the dimension that is scaled more.
+ float heightScale = scaledSize.height().toFloat() / aspectRatio.height().toFloat();
+ float widthScale = scaledSize.width().toFloat() / aspectRatio.width().toFloat();
+ if ((widthScale > heightScale) != (fit == AspectRatioFitGrow))
+ return LayoutSize(scaledSize.height() * aspectRatio.width() / aspectRatio.height(), scaledSize.height());
+ return LayoutSize(scaledSize.width(), scaledSize.width() * aspectRatio.height() / aspectRatio.width());
+}
+
} // namespace WebCore
#endif // LayoutSize_h

Powered by Google App Engine
This is Rietveld 408576698